UTF8
UTF-8 encoding/decoding in accordance with RFC 3629.
NOTE: Syntax utilized for encoding/decoding operations are reversed, as it relates to UTF8, due to nomenclature used by the encoding:core module abstractions. The UTF-8 specification is a byte encoding, which differs from base encoding implementations which are text encodings. As such, UTF8 "encoding" operations reflect the transformation of UTF-8 bytes to text, while UTF8 "decoding" operations reflect the transformation of text to UTF-8 bytes.
e.g.
val utf8 = UTF8.Builder {
replacement(strategy = UTF8.ReplacementStrategy.KOTLIN)
backFillBuffers(enable = true)
}
val text = "Hello World!"
val utf8Bytes = text.decodeToByteArray(utf8)
println(utf8Bytes.toList()) // [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]
val text2 = utf8Bytes.encodeToString(utf8)
assertEquals(text, text2)See also
Inheritors
Types
A helper for calculating the exact output byte-size of a text to UTF-8 byte transformation.
Holder of a configuration for the UTF8 encoder/decoder.
A static instance of UTF8 configured with UTF8.Builder DEFAULT values.
Defines behavior of UTF-8 transformations when an invalid sequence is encountered.
A static instance of UTF8 configured with a UTF8.Builder.replacement strategy of ReplacementStrategy.THROW, and remaining UTF8.Builder DEFAULT values.