kinow commented on a change in pull request #644:
URL: https://github.com/apache/commons-lang/pull/644#discussion_r523267569
##########
File path: src/main/java/org/apache/commons/lang3/StringUtils.java
##########
@@ -2854,6 +2854,39 @@ public static int indexOfAny(final CharSequence cs,
final String searchChars) {
return indexOfAny(cs, searchChars.toCharArray());
}
+ /**
+ * <p>Search a CharSequence to find the first index of any
+ * character in the given set of characters starting with
+ * a given index.</p>
+ *
+ * <p>A {@code null} String will return {@code -1}.
+ * A {@code null} search string will return {@code -1}.</p>
+ *
+ * <pre>
+ * StringUtils.indexOfAny(null, 0, *) = -1
+ * StringUtils.indexOfAny("", 0, *) = -1
+ * StringUtils.indexOfAny(*, 0, null) = -1
+ * StringUtils.indexOfAny(*, 0, "") = -1
+ * StringUtils.indexOfAny("zzabyycdxx", 0, "za") = 0
+ * StringUtils.indexOfAny("zzabyycdxx", 0, "by") = 3
+ * StringUtils.indexOfAny("aba", 0, "z") = -1
+ * StringUtils.indexOfAny("aba", 1, "a") = 1
+ * StringUtils.indexOfAny("aba", -1, "a") = -1
+ * </pre>
+ *
+ * @param cs the CharSequence to check, may be null
+ * @param beginIndex the start position to search
+ * @param searchChars the chars to search for, may be null
+ * @return the index of any of the chars, -1 if no match,null input or
the beginIndex smaller than 0
+ * @since 3.12
+ */
+ public static int indexOfAny(final CharSequence cs, int beginIndex, final
String searchChars) {
+ if (isEmpty(cs) || isEmpty(searchChars) || beginIndex < 0) {
+ return INDEX_NOT_FOUND;
+ }
+ return indexOfAny(cs.toString().substring(beginIndex),
searchChars.toCharArray());
Review comment:
Looks good I think. Only thing I'd like to confirm is what happens with
those surrogate pairs. (Can't recall if that affects the length of the string,
in which case it could give unexpected results here?)
https://garygregory.wordpress.com/2015/11/03/java-lowercase-conversion-turkey/
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]