jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1513847 - /jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/lib/FileOps.java
Date Wed, 14 Aug 2013 12:44:42 GMT
Author: andy
Date: Wed Aug 14 12:44:41 2013
New Revision: 1513847

URL: http://svn.apache.org/r1513847
Log:
basename(String) to return the basename without extension.
extension(String) to get the extension.

Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/lib/FileOps.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/lib/FileOps.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/lib/FileOps.java?rev=1513847&r1=1513846&r2=1513847&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/lib/FileOps.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/lib/FileOps.java Wed Aug 14 12:44:41
2013
@@ -147,16 +147,28 @@ public class FileOps
         return Tuple.create(path, fn) ;
     }
 
+    /** Return the basename (no path, no extension) */
     public static String basename(String filename)
     {
         int j = filename.lastIndexOf('/') ;
         if ( j < 0 )
             j = filename.lastIndexOf('\\') ;
 
-        if ( j >= 0 )
-            return  filename.substring(j+1) ;
-        else
-            return filename ;
+        String fn = ( j >= 0 ) ? filename.substring(j+1) : filename ;
+        int i = fn.lastIndexOf('.') ;
+        
+        if ( i > -1 )
+            return fn.substring(0, i) ;
+        return fn ;
+    }
+    
+    /** Return the extension (or "") */
+    public static String extension(String filename) {
+        int iSlash = filename.lastIndexOf( '/' );      
+        int iBack = filename.lastIndexOf( '\\' );
+        int iExt = filename.lastIndexOf( '.' ); 
+        if (iBack > iSlash) iSlash = iBack;
+        return iExt > iSlash ? filename.substring( iExt+1 ).toLowerCase() : "";
     }
     
     public static String fullPath(String filename)



Mime
View raw message