1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public int indexOf(int ch, int fromIndex)
{
int max = offset + count;
char v[] = value;
if (fromIndex < 0)
{
fromIndex = 0;
}
else if (fromIndex >= count)
{
// Note: fromIndex might be near -1>>>1.
return -1;
}
int i = offset + fromIndex;
if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT)
{
// handle most cases here (ch is a BMP code point or a
// negative value (invalid code point))
for (; i < max; i++)
{
if (v[i] == ch)
{
return i - offset;
}
}
return -1;
}
if (ch <= Character.MAX_CODE_POINT)
{
// handle supplementary characters here
char[] surrogates = Character.toChars(ch);
for (; i < max; i++)
{
if (v[i] == surrogates[0])
{
if (i + 1 == max)
{
break;
}
if (v[i + 1] == surrogates[1])
{
return i - offset;
}
}
}
}
return -1;
} |