commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1465505 - in /commons/proper/io/trunk/src: changes/changes.xml main/java/org/apache/commons/io/FilenameUtils.java test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
Date Sun, 07 Apr 2013 23:10:06 GMT
Author: sebb
Date: Sun Apr  7 23:10:05 2013
New Revision: 1465505

URL: http://svn.apache.org/r1465505
Log:
IO-375 FilenameUtils.splitOnTokens(String text) check for '**' could be simplified 

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java

Modified: commons/proper/io/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1465505&r1=1465504&r2=1465505&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Sun Apr  7 23:10:05 2013
@@ -47,7 +47,10 @@ The <action> type attribute can be add,u
   <body>
     <!-- The release date is the date RC is cut -->
     <release version="2.5" date="2013-??-??" description="New features and bug fixes.">
   
-      <action issue="IO-374" dev="sebb" type="fix">
+      <action issue="IO-375" dev="sebb" type="update">
+        FilenameUtils.splitOnTokens(String text) check for '**' could be simplified 
+      </action>            
+      <action issue="IO-374" dev="sebb" type="update">
         WildcardFileFilter ctors should not use null to mean IOCase.SENSITIVE when delegating
to other ctors
       </action>            
       <action issue="IO-362" dev="ggregory" type="fix" due-to="mmadson, ggregory">

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java?rev=1465505&r1=1465504&r2=1465505&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java Sun Apr
 7 23:10:05 2013
@@ -1375,6 +1375,7 @@ public class FilenameUtils {
         final char[] array = text.toCharArray();
         final ArrayList<String> list = new ArrayList<String>();
         final StringBuilder buffer = new StringBuilder();
+        char prevChar = 0;
         for (int i = 0; i < array.length; i++) {
             final char ch = array[i];
             if (ch == '?' || ch == '*') {
@@ -1384,13 +1385,13 @@ public class FilenameUtils {
                 }
                 if (ch == '?') {
                     list.add("?");
-                } else if (list.isEmpty() || // ch == '*' here; check if previous char was
'*'
-                        i > 0 && list.get(list.size() - 1).equals("*") == false)
{
+                } else if (prevChar != '*' ) {// ch == '*' here; check if previous char was
'*'
                     list.add("*");
                 }
             } else {
                 buffer.append(ch);
             }
+            prevChar = ch;
         }
         if (buffer.length() != 0) {
             list.add(buffer.toString());

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java?rev=1465505&r1=1465504&r2=1465505&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
Sun Apr  7 23:10:05 2013
@@ -123,6 +123,7 @@ public class FilenameUtilsWildcardTestCa
         assertArrayEquals( new String[] { "*" }, FilenameUtils.splitOnTokens("****") );
         assertArrayEquals( new String[] { "*", "?", "?", "*" }, FilenameUtils.splitOnTokens("*??*")
);
         assertArrayEquals( new String[] { "*", "?", "*", "?", "*" }, FilenameUtils.splitOnTokens("*?**?*")
);
+        assertArrayEquals( new String[] { "*", "?", "*", "?", "*" }, FilenameUtils.splitOnTokens("*?***?*")
);
         assertArrayEquals( new String[] { "h", "?", "?", "*" }, FilenameUtils.splitOnTokens("h??*")
);
         assertArrayEquals( new String[] { "" }, FilenameUtils.splitOnTokens("") );
     }



Mime
View raw message