ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r577781 - in /ant/core/trunk/src: main/org/apache/tools/ant/util/StringUtils.java tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
Date Thu, 20 Sep 2007 14:51:12 GMT
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: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message