Package org.teavm.classlib.impl
Class Base46
java.lang.Object
org.teavm.classlib.impl.Base46
Base47 encoding is best fit for encoding varible length numbers in JavaScript strings.
47 = (int)(93 / 2), where 94 is the number of ASCII characters representable in JavaScript string without escaping. These characters are encoded by one byte in UTF-8 charset. All other character require either escaping or two or more bytes in UTF-8.
We divide 93 by 2 for the following trick. Representing integers takes 5 bytes in Base93. However, we often need smaller integers that might be represented by one or two bytes. By each Base93 digit we can encode both part of the number and a flag indicating whether the number contains one more digit.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
static int
decodeDigit
(char c) static long
decodeLong
(CharFlow seq) static int
decodeUnsigned
(CharFlow seq) static long
static void
encode
(StringBuilder sb, int number) static void
encode
(StringBuilder sb, long number) static char
encodeDigit
(int digit) static void
encodeUnsigned
(StringBuilder sb, int number) static void
encodeUnsigned
(StringBuilder sb, long number)
-
Method Details
-
encodeUnsigned
-
encode
-
encodeUnsigned
-
encode
-
decodeUnsigned
-
decode
-
decodeUnsignedLong
-
decodeLong
-
encodeDigit
public static char encodeDigit(int digit) -
decodeDigit
public static int decodeDigit(char c)
-