From b7f1bb58a60692345362f1e9db11207ce431affd Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Thu, 13 Mar 2014 00:40:11 +0400 Subject: [PATCH] Fixing bugs in unicode character class encoding/decoding --- .../teavm/classlib/impl/unicode/UnicodeHelper.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java index 1362c2712..9f8d28b53 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java @@ -93,13 +93,14 @@ public class UnicodeHelper { public static String compressRle(byte[] bytes) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < bytes.length; ++i) { + for (int i = 0; i < bytes.length;) { byte b = bytes[i]; if (i < bytes.length - 1 && b == bytes[i + 1]) { int count = 0; - while (i < bytes.length && bytes[i++] == b) { + while (i < bytes.length && bytes[i + count] == b) { ++count; } + i += count; if (count < 80) { sb.append(UnicodeHelper.encodeByte((byte)(b + 32))); sb.append(UnicodeHelper.encodeByte((byte)count)); @@ -111,9 +112,8 @@ public class UnicodeHelper { count /= 0x40; } } - --i; } else { - sb.append(UnicodeHelper.encodeByte(bytes[i])); + sb.append(UnicodeHelper.encodeByte(bytes[i++])); } } return sb.toString(); @@ -127,7 +127,7 @@ public class UnicodeHelper { int codePoint = 0; for (int i = 0; i < encoded.length(); ++i) { byte b = decodeByte(encoded.charAt(i)); - int count = 1; + int count; if (b == 64) { b = decodeByte(encoded.charAt(++i)); count = 0; @@ -141,7 +141,7 @@ public class UnicodeHelper { b -= 32; count = decodeByte(encoded.charAt(++i)); } else { - buffer[index++] = b; + count = 1; } if (count == 1) { buffer[index++] = b;