diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/charset/UTF16Helper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/charset/UTF16Helper.java index 44ad12c12..12fc86a3a 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/charset/UTF16Helper.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/charset/UTF16Helper.java @@ -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) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/charset/UTF8Charset.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/charset/UTF8Charset.java index 84e595d6a..8485cede1 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/charset/UTF8Charset.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/charset/UTF8Charset.java @@ -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 { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java index 252f28ff0..d64b1e07c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java @@ -198,11 +198,10 @@ public class TCharacter extends TObject implements TComparable { } 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 { } 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))) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java index 0f4320526..5ac53c3be 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java @@ -95,7 +95,7 @@ public class TString extends TObject implements TSerializable, TComparable= 1; --i) { if (characters[i] == lo && characters[i - 1] == hi) { - return i; + return i - 1; } } return -1;