Package dev.gmitch215.bytebox.builtin
Class Text
java.lang.Object
dev.gmitch215.bytebox.builtin.Text
The platform's own encoders, exposed as themselves.
Every charset beyond UTF-8 costs a table in the binary if the class library provides it, and the
isolate already has TextDecoder, which handles every encoding the WHATWG registry lists.
Base64 and hexadecimal are here for the same reason: the platform has them and a Java
implementation would be bytes spent on something already present.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringdecode(byte[] bytes) Decodes UTF-8.static StringDecodes bytes in a named encoding.static Stringdecode(org.teavm.jso.typedarrays.ArrayBuffer bytes) Decodes UTF-8.static StringDecodes bytes in a named encoding.static org.teavm.jso.typedarrays.Uint8ArrayEncodes text as UTF-8.static org.teavm.jso.typedarrays.ArrayBufferfromBase64(String base64) Decodes base64.static org.teavm.jso.typedarrays.ArrayBufferDecodes hexadecimal.static booleanReports whether the runtime knows an encoding.static StringtoBase64(byte[] bytes) Encodes bytes as base64.static StringtoBase64(org.teavm.jso.typedarrays.ArrayBuffer bytes) Encodes bytes as base64.static StringtoHex(byte[] bytes) Encodes bytes as lowercase hexadecimal.static StringtoHex(org.teavm.jso.typedarrays.ArrayBuffer bytes) Encodes bytes as lowercase hexadecimal.static StringReversesurlEncode(String).static StringPercent-encodes a value for use in a URL.
-
Method Details
-
encode
Encodes text as UTF-8.- Parameters:
text- the text- Returns:
- the bytes
-
decode
Decodes UTF-8.- Parameters:
bytes- the bytes- Returns:
- the text
-
decode
Decodes bytes in a named encoding.- Parameters:
bytes- the bytesencoding- a WHATWG label, such asshift_jisorwindows-1252- Returns:
- the text
-
decode
Decodes UTF-8.- Parameters:
bytes- the bytes- Returns:
- the text
-
decode
Decodes bytes in a named encoding.- Parameters:
bytes- the bytesencoding- a WHATWG label, such asshift_jisorwindows-1252- Returns:
- the text
-
supports
Reports whether the runtime knows an encoding.- Parameters:
encoding- a WHATWG label- Returns:
- whether a decoder can be built for it
-
toBase64
Encodes bytes as base64.- Parameters:
bytes- the bytes- Returns:
- the base64 text
-
toBase64
Encodes bytes as base64.- Parameters:
bytes- the bytes- Returns:
- the base64 text
-
fromBase64
Decodes base64.- Parameters:
base64- the base64 text- Returns:
- the bytes
-
toHex
Encodes bytes as lowercase hexadecimal.- Parameters:
bytes- the bytes- Returns:
- the hexadecimal text
-
toHex
Encodes bytes as lowercase hexadecimal.- Parameters:
bytes- the bytes- Returns:
- the hexadecimal text
-
fromHex
Decodes hexadecimal.- Parameters:
hex- the hexadecimal text, with an even number of digits- Returns:
- the bytes
-
urlEncode
Percent-encodes a value for use in a URL.- Parameters:
value- the value- Returns:
- the encoded value
-
urlDecode
ReversesurlEncode(String).- Parameters:
value- the encoded value- Returns:
- the decoded value
-