kinow commented on a change in pull request #644:
URL: https://github.com/apache/commons-lang/pull/644#discussion_r523271674
##########
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:
Maybe we should just document that it's not supported for now. Or spend
some more time making it support special locales/chars?
```java
Locale turkish = Locale.forLanguageTag("tr");
assertEquals(1, StringUtils.indexOfAny("TITLE".toLowerCase(turkish), 0,
"i")); // error, -1 returned
```
WDYT @garydgregory ?
@arturobernalg if you have any thoughts too, but in the meantime, could you
squash your commits? Your change is very well written, and concise. But there
are now 13 commits due to review feedback. We can squash it too when merging,
but it'd be simpler if you could do it, please.
Thanks!
----------------------------------------------------------------
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]