Module encoding/utf16

encoding/utf16

UTF-8 to UTF-16 conversion and vice versa.

Converts between Yo's UTF-8 str and UTF-16 code units (ArrayList(u16)).

Example

{ utf8_to_utf16, utf16_to_utf8 } :: import "std/encoding/utf16";

words := utf8_to_utf16("hello");
s := utf16_to_utf8(words);

Functions

utf8_to_utf16 function
fn(s : str) -> ArrayList(u16)

Convert a UTF-8 string to an ArrayList(u16) of UTF-16 code units.

Handles BMP characters directly and encodes supplementary characters as surrogate pairs.

Parameters

NameTypeNotes
sstr

Returns: ArrayList(u16)

utf16_to_utf8 function
fn(data : ArrayList(u16), using(exn : Exception)) -> String

Convert UTF-16 code units to a UTF-8 String.

Decodes surrogate pairs back into supplementary code points. Throws via Exception on unpaired surrogates.

Parameters

NameTypeNotes
dataArrayList(u16)

Effects

NameTypeNotes
exnExceptioncomptime, implicit

Returns: String