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

Link copied to clipboard
class Builder

A Builder

Link copied to clipboard
open class CharPreProcessor

A helper for calculating the exact output byte-size of a text to UTF-8 byte transformation.

Link copied to clipboard

Holder of a configuration for the UTF8 encoder/decoder.

Link copied to clipboard
object Default : UTF8

A static instance of UTF8 configured with UTF8.Builder DEFAULT values.

Link copied to clipboard

Defines behavior of UTF-8 transformations when an invalid sequence is encountered.

Link copied to clipboard

A static instance of UTF8 configured with a UTF8.Builder.replacement strategy of ReplacementStrategy.THROW, and remaining UTF8.Builder DEFAULT values.

Functions

Link copied to clipboard
protected override fun name(): String
Link copied to clipboard
Link copied to clipboard