LANG-1300: fixed CharSequenceUtils indexOf for Supplementary chars
This commit is contained in:
parent
66f8569ecc
commit
12e597a78c
|
@ -84,16 +84,18 @@ public class CharSequenceUtils {
|
||||||
}
|
}
|
||||||
//supplementary characters (LANG1300)
|
//supplementary characters (LANG1300)
|
||||||
if (searchChar <= Character.MAX_CODE_POINT) {
|
if (searchChar <= Character.MAX_CODE_POINT) {
|
||||||
|
int ind = 0;
|
||||||
char[] chars = Character.toChars(searchChar);
|
char[] chars = Character.toChars(searchChar);
|
||||||
for (int i = start; i < sz; i++) {
|
for (int i = start; i < sz - 1; i++) {
|
||||||
if (cs.charAt(i) == chars[0]) {
|
char high = cs.charAt(i);
|
||||||
if (i + 1 == sz) {
|
char low = cs.charAt(i + 1);
|
||||||
break;
|
if (high == chars[0] && low == chars[1]) {
|
||||||
}
|
return ind;
|
||||||
if (cs.charAt(i + 1) == chars[1]) {
|
} else if (Character.isSurrogatePair(high, low)) {
|
||||||
return i;
|
//skip over 1
|
||||||
}
|
i++;
|
||||||
}
|
}
|
||||||
|
ind++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NOT_FOUND;
|
return NOT_FOUND;
|
||||||
|
@ -148,6 +150,7 @@ public class CharSequenceUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//supplementary characters (LANG1300)
|
//supplementary characters (LANG1300)
|
||||||
|
//NOTE - we must do a forward traversal for this to avoid duplicating code points
|
||||||
if (searchChar <= Character.MAX_CODE_POINT) {
|
if (searchChar <= Character.MAX_CODE_POINT) {
|
||||||
char[] chars = Character.toChars(searchChar);
|
char[] chars = Character.toChars(searchChar);
|
||||||
for (int i = start; i >= 0; --i) {
|
for (int i = start; i >= 0; --i) {
|
||||||
|
|
|
@ -300,6 +300,8 @@ public class StringUtilsEqualsIndexOfTest {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.appendCodePoint(CODE_POINT);
|
builder.appendCodePoint(CODE_POINT);
|
||||||
assertEquals(0, StringUtils.indexOf(builder, CODE_POINT, 0));
|
assertEquals(0, StringUtils.indexOf(builder, CODE_POINT, 0));
|
||||||
|
builder.appendCodePoint(CODE_POINT);
|
||||||
|
assertEquals(1, StringUtils.indexOf(builder, CODE_POINT, 1));
|
||||||
//inner branch on the supplementary character block
|
//inner branch on the supplementary character block
|
||||||
char[] tmp = {(char) 55361};
|
char[] tmp = {(char) 55361};
|
||||||
builder = new StringBuilder();
|
builder = new StringBuilder();
|
||||||
|
|
Loading…
Reference in New Issue