Skip to content

Commit

Permalink
fixed files form Lang #30
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent bff9abf commit f67aca7
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions projects/Lang/30/org/apache/commons/lang3/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1373,13 +1373,21 @@ public static int indexOfAny(CharSequence cs, char[] searchChars) {
return INDEX_NOT_FOUND;
}
int csLen = cs.length();
int csLast = csLen - 1;
int searchLen = searchChars.length;
int searchLast = searchLen - 1;
for (int i = 0; i < csLen; i++) {
char ch = cs.charAt(i);
for (int j = 0; j < searchLen; j++) {
if (searchChars[j] == ch) {
if (i < csLast && j < searchLast && Character.isHighSurrogate(ch)) {
// ch is a supplementary character
if (searchChars[j + 1] == cs.charAt(i + 1)) {
return i;
}
} else {
return i;
}
}
}
}
Expand Down Expand Up @@ -1440,7 +1448,7 @@ public static int indexOfAny(CharSequence cs, String searchChars) {
* <code>false</code> if no match or null input
* @since 2.4
*/
public static boolean containsAny(CharSequence cs, char[] searchChars) {
public static boolean containsAny(String cs, char[] searchChars) {
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
return false;
}
Expand All @@ -1452,9 +1460,12 @@ public static boolean containsAny(CharSequence cs, char[] searchChars) {
char ch = cs.charAt(i);
for (int j = 0; j < searchLength; j++) {
if (searchChars[j] == ch) {
if (i < csLast && j < searchLast && ch >= Character.MIN_HIGH_SURROGATE && ch <= Character.MAX_HIGH_SURROGATE) {
if (Character.isHighSurrogate(ch)) {
if (j == searchLast) {
// missing low surrogate, fine, like String.indexOf(String)
if (searchChars[j + 1] == cs.charAt(i + 1)) {
return true;
}
if (i < csLast && searchChars[j + 1] == cs.charAt(i + 1)) {
return true;
}
} else {
Expand Down Expand Up @@ -1494,7 +1505,7 @@ public static boolean containsAny(CharSequence cs, char[] searchChars) {
* @return the <code>true</code> if any of the chars are found, <code>false</code> if no match or null input
* @since 2.4
*/
public static boolean containsAny(CharSequence cs, String searchChars) {
public static boolean containsAny(String cs, String searchChars) {
if (searchChars == null) {
return false;
}
Expand Down Expand Up @@ -1530,13 +1541,21 @@ public static int indexOfAnyBut(CharSequence cs, char[] searchChars) {
return INDEX_NOT_FOUND;
}
int csLen = cs.length();
int csLast = csLen - 1;
int searchLen = searchChars.length;
int searchLast = searchLen - 1;
outer:
for (int i = 0; i < csLen; i++) {
char ch = cs.charAt(i);
for (int j = 0; j < searchLen; j++) {
if (searchChars[j] == ch) {
if (i < csLast && j < searchLast && Character.isHighSurrogate(ch)) {
if (searchChars[j + 1] == cs.charAt(i + 1)) {
continue outer;
}
} else {
continue outer;
}
}
}
return i;
Expand Down Expand Up @@ -1573,8 +1592,16 @@ public static int indexOfAnyBut(String str, String searchChars) {
int strLen = str.length();
for (int i = 0; i < strLen; i++) {
char ch = str.charAt(i);
if (searchChars.indexOf(ch) < 0) {
boolean chFound = searchChars.indexOf(ch) >= 0;
if (i + 1 < strLen && Character.isHighSurrogate(ch)) {
char ch2 = str.charAt(i + 1);
if (chFound && searchChars.indexOf(ch2) < 0) {
return i;
}
} else {
if (!chFound) {
return i;
}
}
}
return INDEX_NOT_FOUND;
Expand Down Expand Up @@ -1675,14 +1702,25 @@ public static boolean containsNone(CharSequence cs, char[] searchChars) {
return true;
}
int csLen = cs.length();
int csLast = csLen - 1;
int searchLen = searchChars.length;
int searchLast = searchLen - 1;
for (int i = 0; i < csLen; i++) {
char ch = cs.charAt(i);
for (int j = 0; j < searchLen; j++) {
if (searchChars[j] == ch) {
if (Character.isHighSurrogate(ch)) {
if (j == searchLast) {
// missing low surrogate, fine, like String.indexOf(String)
return false;
}
if (i < csLast && searchChars[j + 1] == cs.charAt(i + 1)) {
return false;
}
} else {
// ch is in the Basic Multilingual Plane
return false;
}
}
}
}
Expand Down

0 comments on commit f67aca7

Please sign in to comment.