Author: jhm
Date: Thu Sep 20 07:51:11 2007
New Revision: 577781

URL: http://svn.apache.org/viewvc?rev=577781&view=rev
Log:
* Test for removeSuffix()
* Test + Impl of removePrefix()

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java
    
ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java?rev=577781&r1=577780&r2=577781&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java 
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java Thu Sep 
20 07:51:11 2007
@@ -256,4 +256,19 @@
             return string;
         }
     }
+
+    /**
+     * Removes the prefix from a given string, if the string contains 
+     * that prefix.
+     * @param string String for check
+     * @param prefix Prefix to remove
+     * @return the <i>string</i> with the <i>prefix</i>
+     */
+    public static String removePrefix(String string, String prefix) {
+        if (string.startsWith(prefix)) {
+            return string.substring(prefix.length());
+        } else {
+            return string;
+        }
+    }
 }

Modified: 
ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java?rev=577781&r1=577780&r2=577781&view=diff
==============================================================================
--- 
ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java 
(original)
+++ 
ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java 
Thu Sep 20 07:51:11 2007
@@ -117,4 +117,38 @@
        assertEquals(StringUtils.parseHumanSizes("1P"), PETABYTE);
        assertEquals(StringUtils.parseHumanSizes("1"), 1L);
     }
+    
+    public void testRemoveSuffix() {
+        String prefix = "Prefix";
+        String name = "Name";
+        String suffix = "Suffix";
+        String input = prefix + name + suffix;
+        assertEquals(
+            "Does not remove the suffix right.",    
+            prefix + name, 
+            StringUtils.removeSuffix(input, suffix)
+        );
+        assertEquals(
+            "Should leave the string unattended.",    
+            prefix + name + suffix, 
+            StringUtils.removeSuffix(input, "bla")
+        );
+    }
+    
+    public void testRemovePrefix() {
+        String prefix = "Prefix";
+        String name = "Name";
+        String suffix = "Suffix";
+        String input = prefix + name + suffix;
+        assertEquals(
+            "Does not remove the prefix right.",    
+            name + suffix, 
+            StringUtils.removePrefix(input, prefix)
+        );
+        assertEquals(
+            "Should leave the string unattended.",    
+            prefix + name + suffix, 
+            StringUtils.removePrefix(input, "bla")
+        );
+    }    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to