mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fixes some charset-related errors
This commit is contained in:
parent
3a9be43894
commit
c6ff897bdd
|
@ -51,8 +51,8 @@ public class UTF16Helper {
|
|||
}
|
||||
|
||||
public static int buildCodePoint(char a, char b) {
|
||||
return ((a & SURROGATE_BIT_INV_MASK) << MEANINGFUL_SURROGATE_BITS) |
|
||||
(b & SURROGATE_BIT_INV_MASK) + SUPPLEMENTARY_PLANE;
|
||||
return (((a & SURROGATE_BIT_INV_MASK) << MEANINGFUL_SURROGATE_BITS) | (b & SURROGATE_BIT_INV_MASK)) +
|
||||
SUPPLEMENTARY_PLANE;
|
||||
}
|
||||
|
||||
public static boolean isSurrogate(char c) {
|
||||
|
|
|
@ -35,7 +35,7 @@ public class UTF8Charset extends Charset {
|
|||
dest.put((byte)(0x80 | (ch & 0x3F)));
|
||||
} else if (UTF16Helper.isHighSurrogate(ch)) {
|
||||
char low = source.get();
|
||||
if (!UTF16Helper.isLowSurrogate(ch)) {
|
||||
if (!UTF16Helper.isLowSurrogate(low)) {
|
||||
source.back(1);
|
||||
dest.put((byte)'?');
|
||||
} else {
|
||||
|
|
|
@ -198,11 +198,10 @@ public class TCharacter extends TObject implements TComparable<TCharacter> {
|
|||
}
|
||||
|
||||
public static int codePointBefore(TCharSequence seq, int index) {
|
||||
if (index == 1 || !UTF16Helper.isLowSurrogate(seq.charAt(index - 2)) ||
|
||||
!UTF16Helper.isHighSurrogate(seq.charAt(index - 2))) {
|
||||
if (index == 1 || !isLowSurrogate(seq.charAt(index - 1)) || !isHighSurrogate(seq.charAt(index - 2))) {
|
||||
return seq.charAt(index - 1);
|
||||
}
|
||||
return UTF16Helper.buildCodePoint(seq.charAt(index - 2), seq.charAt(index - 1));
|
||||
return toCodePoint(seq.charAt(index - 2), seq.charAt(index - 1));
|
||||
}
|
||||
|
||||
public static int codePointBefore(char[] a, int index) {
|
||||
|
@ -329,7 +328,7 @@ public class TCharacter extends TObject implements TComparable<TCharacter> {
|
|||
}
|
||||
|
||||
public static int codePointCount(TCharSequence seq, int beginIndex, int endIndex) {
|
||||
int count = endIndex;
|
||||
int count = endIndex - beginIndex;
|
||||
--endIndex;
|
||||
for (int i = beginIndex; i < endIndex; ++i) {
|
||||
if (UTF16Helper.isHighSurrogate(seq.charAt(i)) && UTF16Helper.isLowSurrogate(seq.charAt(i + 1))) {
|
||||
|
|
|
@ -95,7 +95,7 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
|
|||
this.characters = new char[sb.length()];
|
||||
ByteBuffer source = new ByteBuffer(bytes, offset, offset + length);
|
||||
char[] destChars = new char[TMath.max(8, TMath.min(length * 2, 1024))];
|
||||
CharBuffer dest = new CharBuffer(destChars, 0, length * 2);
|
||||
CharBuffer dest = new CharBuffer(destChars, 0, destChars.length);
|
||||
while (!source.end()) {
|
||||
charset.decode(source, dest);
|
||||
sb.append(destChars, 0, dest.position());
|
||||
|
@ -269,7 +269,7 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
|
|||
char lo = UTF16Helper.lowSurrogate(ch);
|
||||
for (int i = fromIndex; i >= 1; --i) {
|
||||
if (characters[i] == lo && characters[i - 1] == hi) {
|
||||
return i;
|
||||
return i - 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue
Block a user