[GitHub] commons-lang pull request #273: add lastIndexOfAnyChar method just like inde...

2018-01-12 Thread garydgregory
Github user garydgregory commented on a diff in the pull request:

https://github.com/apache/commons-lang/pull/273#discussion_r161278859
  
--- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
@@ -2122,6 +2122,81 @@ public static int indexOfAny(final CharSequence cs, 
final String searchChars) {
 return indexOfAny(cs, searchChars.toCharArray());
 }
 
+/**
+ * Search a CharSequence to find the last index of any
--- End diff --

Use the active voice in Javadoc: "Returns...", "Searches...", "Gets..." and 
so on.


---


[GitHub] commons-lang pull request #273: add lastIndexOfAnyChar method just like inde...

2018-01-12 Thread garydgregory
Github user garydgregory commented on a diff in the pull request:

https://github.com/apache/commons-lang/pull/273#discussion_r161279018
  
--- Diff: 
src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java ---
@@ -379,6 +379,44 @@ public void testIndexOfAny_StringCharArray() {
 assertEquals(-1, StringUtils.indexOfAny("ab", 'z'));
 }
 
+@Test
+public void testLastIndexOfAny_StringCharArray() {
+assertEquals(-1, StringUtils.lastIndexOfAnyChar(null, (char[]) 
null));
--- End diff --

Maybe use INDEX_NOT_FOUND as a static import instead of -1...


---


[GitHub] commons-lang pull request #273: add lastIndexOfAnyChar method just like inde...

2018-01-12 Thread garydgregory
Github user garydgregory commented on a diff in the pull request:

https://github.com/apache/commons-lang/pull/273#discussion_r161278687
  
--- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
@@ -2122,6 +2122,81 @@ public static int indexOfAny(final CharSequence cs, 
final String searchChars) {
 return indexOfAny(cs, searchChars.toCharArray());
 }
 
+/**
+ * Search a CharSequence to find the last index of any
+ * character in the given set of characters.
+ *
+ * A {@code null} String will return {@code -1}.
+ * A {@code null} search string will return {@code -1}.
+ *
+ * 
+ * StringUtils.lastIndexOfAnyChar(null, *)= -1
+ * StringUtils.lastIndexOfAnyChar("", *)  = -1
+ * StringUtils.lastIndexOfAnyChar(*, null)= -1
+ * StringUtils.lastIndexOfAnyChar(*, "")  = -1
+ * StringUtils.lastIndexOfAnyChar("zzabyycdxx", "za") = 2
+ * StringUtils.lastIndexOfAnyChar("zzabyycdxx", "by") = 5
+ * StringUtils.lastIndexOfAnyChar("ab", 'a')  = 0
+ * StringUtils.lastIndexOfAnyChar("ab", 'b')  = 1
+ * StringUtils.lastIndexOfAnyChar("aba","z")  = -1
+ * 
+ *
+ * @param cs  the CharSequence to check, may be null
+ * @param searchChars  the chars to search for, may be null
+ * @return the last index of any of the chars, -1 if no match or null 
input
+ */
+ public static int lastIndexOfAnyChar( final CharSequence cs,final 
String searchChars) {
+return searchChars == null ? INDEX_NOT_FOUND : 
lastIndexOfAnyChar(cs,searchChars.toCharArray());
+}
+
+   /**
+ * Search a CharSequence to find the last index of any
+ * character in the given set of characters.
+ *
+ * A {@code null} String will return {@code -1}.
+ * A {@code null} or zero length search array will return {@code 
-1}.
+ *
+ * 
+ * StringUtils.lastIndexOfAnyChar(null, *)= -1
+ * StringUtils.lastIndexOfAnyChar("", *)  = -1
+ * StringUtils.lastIndexOfAnyChar(*, null)= -1
+ * StringUtils.lastIndexOfAnyChar(*, [])  = -1
+ * StringUtils.lastIndexOfAnyChar("zzabyycdxx",['z','a']) = 2
+ * StringUtils.lastIndexOfAnyChar("zzabyycdxx",['b','y']) = 5
+ * StringUtils.lastIndexOfAnyChar("aba", ['z'])   = -1
+ * 
+ *
+ * @param cs  the CharSequence to check, may be null
+ * @param searchChars  the chars to search for, may be null
+ * @return the last index of any of the chars, -1 if no match or null 
input
+ */
+public static int lastIndexOfAnyChar( final CharSequence cs,final 
char... searchChars) {
--- End diff --

Fix formatting.


---


[GitHub] commons-lang pull request #273: add lastIndexOfAnyChar method just like inde...

2017-06-29 Thread qxo
GitHub user qxo opened a pull request:

https://github.com/apache/commons-lang/pull/273

add lastIndexOfAnyChar method just like indexOfAny



You can merge this pull request into a Git repository by running:

$ git pull https://github.com/qxo/commons-lang master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/commons-lang/pull/273.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #273


commit 67dcca991c14c0a8b4e59c83a76b9f7cf8309a64
Author: qxo <49526...@qq.com>
Date:   2017-06-29T12:52:27Z

add lastIndexOfAnyChar




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---