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