diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index 413a5dbfe..63b1a032e 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -1163,8 +1163,7 @@ public class StringUtils { * @since 2.4 */ public static boolean containsAny(String str, char[] searchChars) { - if (str == null || str.length() == 0 || - searchChars == null || searchChars.length == 0) { + if (str == null || str.length() == 0 || searchChars == null || searchChars.length == 0) { return false; } for (int i = 0; i < str.length(); i++) { @@ -1179,12 +1178,15 @@ public class StringUtils { } /** - *
Checks if the String contains any character in the given - * set of characters.
- * - *A null
String will return false
.
- * A null
search string will return false
.
+ * Checks if the String contains any character in the given set of characters. + *
+ * + *
+ * A null
String will return false
. A null
search string will return
+ * false
.
+ *
* StringUtils.containsAny(null, *) = false * StringUtils.containsAny("", *) = false @@ -1194,11 +1196,12 @@ public class StringUtils { * StringUtils.containsAny("zzabyycdxx", "by") = true * StringUtils.containsAny("aba","z") = false *- * - * @param str the String to check, may be null - * @param searchChars the chars to search for, may be null - * @return the
true
if any of the chars are found,
- * false
if no match or null input
+ *
+ * @param str
+ * the String to check, may be null
+ * @param searchChars
+ * the chars to search for, may be null
+ * @return the true
if any of the chars are found, false
if no match or null input
* @since 2.4
*/
public static boolean containsAny(String str, String searchChars) {
@@ -2283,7 +2286,7 @@ public class StringUtils {
* @since 2.4
*/
public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator) {
- return splitByWholeSeparatorWorker( str, separator, -1, true ) ;
+ return splitByWholeSeparatorWorker(str, separator, -1, true);
}
/**
@@ -2315,7 +2318,7 @@ public class StringUtils {
* @return an array of parsed Strings, null
if null String was input
* @since 2.4
*/
- public static String[] splitByWholeSeparatorPreserveAllTokens( String str, String separator, int max ) {
+ public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator, int max) {
return splitByWholeSeparatorWorker(str, separator, max, true);
}
@@ -2333,76 +2336,72 @@ public class StringUtils {
* @return an array of parsed Strings, null
if null String input
* @since 2.4
*/
- private static String[] splitByWholeSeparatorWorker( String str, String separator,
- int max, boolean preserveAllTokens )
- {
+ private static String[] splitByWholeSeparatorWorker(String str, String separator, int max, boolean preserveAllTokens) {
if (str == null) {
return null;
}
- int len = str.length() ;
+ int len = str.length();
if (len == 0) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
- if ( ( separator == null ) || ( EMPTY.equals( separator ) ) ) {
+ if ((separator == null) || (EMPTY.equals(separator))) {
// Split on whitespace.
- return splitWorker( str, null, max, preserveAllTokens ) ;
+ return splitWorker(str, null, max, preserveAllTokens);
}
+ int separatorLength = separator.length();
- int separatorLength = separator.length() ;
+ ArrayList substrings = new ArrayList();
+ int numberOfSubstrings = 0;
+ int beg = 0;
+ int end = 0;
+ while (end < len) {
+ end = str.indexOf(separator, beg);
- ArrayList substrings = new ArrayList() ;
- int numberOfSubstrings = 0 ;
- int beg = 0 ;
- int end = 0 ;
- while ( end < len ) {
- end = str.indexOf( separator, beg ) ;
+ if (end > -1) {
+ if (end > beg) {
+ numberOfSubstrings += 1;
- if ( end > -1 ) {
- if ( end > beg ) {
- numberOfSubstrings += 1 ;
-
- if ( numberOfSubstrings == max ) {
- end = len ;
- substrings.add( str.substring( beg ) ) ;
+ if (numberOfSubstrings == max) {
+ end = len;
+ substrings.add(str.substring(beg));
} else {
// The following is OK, because String.substring( beg, end ) excludes
// the character at the position 'end'.
- substrings.add( str.substring( beg, end ) ) ;
+ substrings.add(str.substring(beg, end));
// Set the starting point for the next search.
// The following is equivalent to beg = end + (separatorLength - 1) + 1,
// which is the right calculation:
- beg = end + separatorLength ;
+ beg = end + separatorLength;
}
} else {
// We found a consecutive occurrence of the separator, so skip it.
- if( preserveAllTokens ) {
- numberOfSubstrings += 1 ;
- if ( numberOfSubstrings == max ) {
- end = len ;
- substrings.add( str.substring( beg ) ) ;
+ if (preserveAllTokens) {
+ numberOfSubstrings += 1;
+ if (numberOfSubstrings == max) {
+ end = len;
+ substrings.add(str.substring(beg));
} else {
- substrings.add( EMPTY );
+ substrings.add(EMPTY);
}
}
- beg = end + separatorLength ;
+ beg = end + separatorLength;
}
} else {
// String.substring( beg ) goes from 'beg' to the end of the String.
- substrings.add( str.substring( beg ) ) ;
- end = len ;
+ substrings.add(str.substring(beg));
+ end = len;
}
}
- return (String[]) substrings.toArray( new String[substrings.size()] ) ;
+ return (String[]) substrings.toArray(new String[substrings.size()]);
}
-
- //-----------------------------------------------------------------------
+ // -----------------------------------------------------------------------
/**
* Splits the provided text into an array, using whitespace as the
* separator, preserving all tokens, including empty tokens created by
@@ -2770,8 +2769,7 @@ public class StringUtils {
if (type == currentType) {
continue;
}
- if (camelCase && type == Character.LOWERCASE_LETTER
- && currentType == Character.UPPERCASE_LETTER) {
+ if (camelCase && type == Character.LOWERCASE_LETTER && currentType == Character.UPPERCASE_LETTER) {
int newTokenStart = pos - 1;
if (newTokenStart != tokenStart) {
list.add(new String(c, tokenStart, newTokenStart - tokenStart));
@@ -3267,7 +3265,7 @@ public class StringUtils {
if (isEmpty(str) || isEmpty(remove)) {
return str;
}
- if (startsWithIgnoreCase(str, remove)){
+ if (startsWithIgnoreCase(str, remove)) {
return str.substring(remove.length());
}
return str;
@@ -3603,7 +3601,6 @@ public class StringUtils {
* @since 2.4
*/
public static String replaceEachRepeatedly(String text, String[] repl, String[] with) {
-
// timeToLive should be 0 if not used or nothing to replace, else it's
// the length of the replace array
int timeToLive = repl == null ? 0 : repl.length;
@@ -3656,16 +3653,12 @@ public class StringUtils {
* and/or size 0)
* @since 2.4
*/
- private static String replaceEach(String text, String[] repl, String[] with,
- boolean repeat, int timeToLive) {
+ private static String replaceEach(String text, String[] repl, String[] with, boolean repeat, int timeToLive) {
- // mchyzer Performance note: This creates very few new objects (one major goal)
+ // mchyzer Performance note: This creates very few new objects (one major goal)
// let me know if there are performance requests, we can create a harness to measure
-
- if (text == null || text.length() == 0 ||
- repl == null || repl.length == 0 ||
- with == null || with.length == 0)
- {
+
+ if (text == null || text.length() == 0 || repl == null || repl.length == 0 || with == null || with.length == 0) {
return text;
}
@@ -3679,7 +3672,10 @@ public class StringUtils {
// make sure lengths are ok, these need to be equal
if (replLength != withLength) {
- throw new IllegalArgumentException("Search and Replace array lengths don't match: " + replLength + " vs " + withLength);
+ throw new IllegalArgumentException("Search and Replace array lengths don't match: "
+ + replLength
+ + " vs "
+ + withLength);
}
// keep track of which still have matches
@@ -3697,7 +3693,7 @@ public class StringUtils {
continue;
}
tempIndex = text.indexOf(repl[i]);
-
+
// see if we need to keep searching for this
if (tempIndex == -1) {
noMoreMatchesForReplIndex[i] = true;
@@ -3721,15 +3717,15 @@ public class StringUtils {
int increase = 0;
// count the replacement text elements that are larger than their corresponding text being replaced
- for (int i=0; i