Is there any sense in talking about keeping the source code in an easy to
deal with order, for example, in our product, when we order source, we use
Eclipse's default Sort Members function.
Gary
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Saturday, November 01, 2003 11:21
To: [EMAIL PROTECTED]
Subject: cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang
StringUtils.java
scolebourne2003/11/01 11:20:35
Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
lang/src/java/org/apache/commons/lang StringUtils.java
Log:
Move remove code to relevant position in source file
Revision ChangesPath
1.55 +3 -1 jakarta-
commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java
Index: StringUtilsTest.java
===
RCS file: /home/cvs/jakarta-
commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- StringUtilsTest.java29 Oct 2003 02:16:30 - 1.54
+++ StringUtilsTest.java1 Nov 2003 19:20:35 - 1.55
@@ -1000,6 +1000,7 @@
assertEquals(StringUtils.removeStart(www.domain.com, www.),
domain.com);
assertEquals(StringUtils.removeStart(domain.com, www.),
domain.com);
assertEquals(StringUtils.removeStart(domain.com, ),
domain.com);
+assertEquals(StringUtils.removeStart(domain.com, null),
domain.com);
}
public void testRemoveEnd() {
@@ -1017,6 +1018,7 @@
assertEquals(StringUtils.removeEnd(www.domain.com, .com),
www.domain);
assertEquals(StringUtils.removeEnd(www.domain, .com),
www.domain);
assertEquals(StringUtils.removeEnd(domain.com, ),
domain.com);
+assertEquals(StringUtils.removeEnd(domain.com, null),
domain.com);
}
}
1.115 +74 -70jakarta-
commons/lang/src/java/org/apache/commons/lang/StringUtils.java
Index: StringUtils.java
===
RCS file: /home/cvs/jakarta-
commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -r1.114 -r1.115
--- StringUtils.java29 Oct 2003 02:16:15 - 1.114
+++ StringUtils.java1 Nov 2003 19:20:35 - 1.115
@@ -80,7 +80,9 @@
* - substring extraction relative to other strings/li
* libSplit/Join/b
* - splits a String into an array of substrings and vice
versa/li
- * libReplace/Delete/Overlay/b
+ * libRemove/Delete/b
+ * - removes part of a String/li
+ * libReplace/Overlay/b
* - Searches a String and replaces one String with another/li
* libChomp/Chop/b
* - removes the last part of a String/li
@@ -2457,6 +2459,76 @@
return new String(chs, 0, count);
}
+// Remove
+//-
--
+/**
+ * pRemoves a substring only if it is at the begining of a source
string,
+ * otherwise returns the source string./p
+ *
+ * pA codenull/code source string will return
codenull/code.
+ * An empty () source string will return the empty string.
+ * A codenull/code search string will return the source
string./p
+ *
+ * pre
+ * StringUtils.removeStart(null, *) = null
+ * StringUtils.removeStart(, *)=
+ * StringUtils.removeStart(*, null) = *
+ * StringUtils.removeStart(www.domain.com, www.) =
domain.com
+ * StringUtils.removeStart(domain.com, www.) =
domain.com
+ * StringUtils.removeStart(www.domain.com, domain) =
www.domain.com
+ * StringUtils.removeStart(abc, )= abc
+ * /pre
+ *
+ * @param str the source String to search, may be null
+ * @param remove the String to search for and remove, may be null
+ * @return the substring with the string removed if found,
+ * codenull/code if null String input
+ * @since 2.1
+ */
+public static String removeStart(String str, String remove) {
+if (str == null || str.length() == 0 || remove == null ||
remove.length() == 0) {
+return str;
+}
+if (str.startsWith(remove)){
+return str.substring(remove.length());
+}
+return str;
+}
+
+/**
+ * pRemoves a substring only if it is at the end of a source
string,
+ * otherwise returns the source string./p
+ *
+ * pA codenull/code source string will return
codenull/code.
+ * An empty () source string will return the empty string.
+ * A codenull/code