8302590: Add String.indexOf(int ch, int fromIndex, int toIndex)

Reviewed-by: rriggs, alanb
This commit is contained in:
Raffaello Giulietti 2023-03-03 20:51:13 +00:00
parent cd4b88d0d2
commit 5b2e2e4695
4 changed files with 295 additions and 17 deletions

View file

@ -419,20 +419,18 @@ final class StringUTF16 {
};
}
public static int indexOf(byte[] value, int ch, int fromIndex) {
int max = value.length >> 1;
if (fromIndex < 0) {
fromIndex = 0;
} else if (fromIndex >= max) {
// Note: fromIndex might be near -1>>>1.
public static int indexOf(byte[] value, int ch, int fromIndex, int toIndex) {
fromIndex = Math.max(fromIndex, 0);
toIndex = Math.min(toIndex, value.length >> 1);
if (fromIndex >= toIndex) {
return -1;
}
if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
// handle most cases here (ch is a BMP code point or a
// negative value (invalid code point))
return indexOfChar(value, ch, fromIndex, max);
return indexOfChar(value, ch, fromIndex, toIndex);
} else {
return indexOfSupplementary(value, ch, fromIndex, max);
return indexOfSupplementary(value, ch, fromIndex, toIndex);
}
}