scolebourne 2003/08/01 16:58:30
Modified: lang/src/java/org/apache/commons/lang StringUtils.java
Log:
Reorder indexOf methods in file
Revision Changes Path
1.91 +102 -102
jakarta-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.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- StringUtils.java 1 Aug 2003 23:54:41 -0000 1.90
+++ StringUtils.java 1 Aug 2003 23:58:30 -0000 1.91
@@ -1011,107 +1011,6 @@
return (str.indexOf(searchStr) >= 0);
}
- // IndexOfAny strings
- //-----------------------------------------------------------------------
- /**
- * <p>Find the first index of any of a set of potential substrings.</p>
- *
- * <p>A <code>null</code> String will return <code>-1</code>.
- * A <code>null</code> or zero length search array will return <code>-1</code>.
- * A <code>null</code> search array entry will be ignored, but a search
- * array containing "" will return <code>0</code> if <code>str</code> is not
- * null. This method uses [EMAIL PROTECTED] String#indexOf(String)}.</p>
- *
- * <pre>
- * StringUtils.indexOfAny(null, *) = -1
- * StringUtils.indexOfAny(*, null) = -1
- * StringUtils.indexOfAny(*, []) = -1
- * StringUtils.indexOfAny("zzabyycdxx", ["ab","cd"]) = 2
- * StringUtils.indexOfAny("zzabyycdxx", ["cd","ab"]) = 2
- * StringUtils.indexOfAny("zzabyycdxx", ["mn","op"]) = -1
- * StringUtils.indexOfAny("zzabyycdxx", ["zab","aby"]) = 1
- * StringUtils.indexOfAny("zzabyycdxx", [""]) = 0
- * StringUtils.indexOfAny("", [""]) = 0
- * StringUtils.indexOfAny("", ["a"]) = -1
- * </pre>
- *
- * @param str the String to check, may be null
- * @param searchStrs the Strings to search for, may be null
- * @return the first index of any of the searchStrs in str, -1 if no match
- */
- public static int indexOfAny(String str, String[] searchStrs) {
- if ((str == null) || (searchStrs == null)) {
- return -1;
- }
- int sz = searchStrs.length;
-
- // String's can't have a MAX_VALUEth index.
- int ret = Integer.MAX_VALUE;
-
- int tmp = 0;
- for (int i = 0; i < sz; i++) {
- String search = searchStrs[i];
- if (search == null) {
- continue;
- }
- tmp = str.indexOf(search);
- if (tmp == -1) {
- continue;
- }
-
- if (tmp < ret) {
- ret = tmp;
- }
- }
-
- return (ret == Integer.MAX_VALUE) ? -1 : ret;
- }
-
- /**
- * <p>Find the latest index of any of a set of potential substrings.</p>
- *
- * <p>A <code>null</code> String will return <code>-1</code>.
- * A <code>null</code> search array will return <code>-1</code>.
- * A <code>null</code> or zero length search array entry will be ignored,
- * but a search array containing "" will return the length of <code>str</code>
- * if <code>str</code> is not null. This method uses [EMAIL PROTECTED]
String#indexOf(String)}</p>
- *
- * <pre>
- * StringUtils.lastIndexOfAny(null, *) = -1
- * StringUtils.lastIndexOfAny(*, null) = -1
- * StringUtils.lastIndexOfAny(*, []) = -1
- * StringUtils.lastIndexOfAny(*, [null]) = -1
- * StringUtils.lastIndexOfAny("zzabyycdxx", ["ab","cd"]) = 6
- * StringUtils.lastIndexOfAny("zzabyycdxx", ["cd","ab"]) = 6
- * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1
- * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1
- * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn",""]) = 10
- * </pre>
- *
- * @param str the String to check, may be null
- * @param searchStrs the Strings to search for, may be null
- * @return the last index of any of the Strings, -1 if no match
- */
- public static int lastIndexOfAny(String str, String[] searchStrs) {
- if ((str == null) || (searchStrs == null)) {
- return -1;
- }
- int sz = searchStrs.length;
- int ret = -1;
- int tmp = 0;
- for (int i = 0; i < sz; i++) {
- String search = searchStrs[i];
- if (search == null) {
- continue;
- }
- tmp = str.lastIndexOf(search);
- if (tmp > ret) {
- ret = tmp;
- }
- }
- return ret;
- }
-
// IndexOfAny chars
//-----------------------------------------------------------------------
/**
@@ -1383,6 +1282,107 @@
return containsNone(str, invalidChars.toCharArray());
}
+ // IndexOfAny strings
+ //-----------------------------------------------------------------------
+ /**
+ * <p>Find the first index of any of a set of potential substrings.</p>
+ *
+ * <p>A <code>null</code> String will return <code>-1</code>.
+ * A <code>null</code> or zero length search array will return <code>-1</code>.
+ * A <code>null</code> search array entry will be ignored, but a search
+ * array containing "" will return <code>0</code> if <code>str</code> is not
+ * null. This method uses [EMAIL PROTECTED] String#indexOf(String)}.</p>
+ *
+ * <pre>
+ * StringUtils.indexOfAny(null, *) = -1
+ * StringUtils.indexOfAny(*, null) = -1
+ * StringUtils.indexOfAny(*, []) = -1
+ * StringUtils.indexOfAny("zzabyycdxx", ["ab","cd"]) = 2
+ * StringUtils.indexOfAny("zzabyycdxx", ["cd","ab"]) = 2
+ * StringUtils.indexOfAny("zzabyycdxx", ["mn","op"]) = -1
+ * StringUtils.indexOfAny("zzabyycdxx", ["zab","aby"]) = 1
+ * StringUtils.indexOfAny("zzabyycdxx", [""]) = 0
+ * StringUtils.indexOfAny("", [""]) = 0
+ * StringUtils.indexOfAny("", ["a"]) = -1
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param searchStrs the Strings to search for, may be null
+ * @return the first index of any of the searchStrs in str, -1 if no match
+ */
+ public static int indexOfAny(String str, String[] searchStrs) {
+ if ((str == null) || (searchStrs == null)) {
+ return -1;
+ }
+ int sz = searchStrs.length;
+
+ // String's can't have a MAX_VALUEth index.
+ int ret = Integer.MAX_VALUE;
+
+ int tmp = 0;
+ for (int i = 0; i < sz; i++) {
+ String search = searchStrs[i];
+ if (search == null) {
+ continue;
+ }
+ tmp = str.indexOf(search);
+ if (tmp == -1) {
+ continue;
+ }
+
+ if (tmp < ret) {
+ ret = tmp;
+ }
+ }
+
+ return (ret == Integer.MAX_VALUE) ? -1 : ret;
+ }
+
+ /**
+ * <p>Find the latest index of any of a set of potential substrings.</p>
+ *
+ * <p>A <code>null</code> String will return <code>-1</code>.
+ * A <code>null</code> search array will return <code>-1</code>.
+ * A <code>null</code> or zero length search array entry will be ignored,
+ * but a search array containing "" will return the length of <code>str</code>
+ * if <code>str</code> is not null. This method uses [EMAIL PROTECTED]
String#indexOf(String)}</p>
+ *
+ * <pre>
+ * StringUtils.lastIndexOfAny(null, *) = -1
+ * StringUtils.lastIndexOfAny(*, null) = -1
+ * StringUtils.lastIndexOfAny(*, []) = -1
+ * StringUtils.lastIndexOfAny(*, [null]) = -1
+ * StringUtils.lastIndexOfAny("zzabyycdxx", ["ab","cd"]) = 6
+ * StringUtils.lastIndexOfAny("zzabyycdxx", ["cd","ab"]) = 6
+ * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1
+ * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1
+ * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn",""]) = 10
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param searchStrs the Strings to search for, may be null
+ * @return the last index of any of the Strings, -1 if no match
+ */
+ public static int lastIndexOfAny(String str, String[] searchStrs) {
+ if ((str == null) || (searchStrs == null)) {
+ return -1;
+ }
+ int sz = searchStrs.length;
+ int ret = -1;
+ int tmp = 0;
+ for (int i = 0; i < sz; i++) {
+ String search = searchStrs[i];
+ if (search == null) {
+ continue;
+ }
+ tmp = str.lastIndexOf(search);
+ if (tmp > ret) {
+ ret = tmp;
+ }
+ }
+ return ret;
+ }
+
// Substring
//-----------------------------------------------------------------------
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]