Wax_utils.UnicodeSourceterminal_width s returns the width of the string s when displayed in a terminal.
The optional argument offset (default 0) specifies the starting column position, which is used to correctly calculate the width of tab characters.
expand_tabs s returns a copy of s where tab characters are replaced by spaces, assuming a tab width of 8.
The optional argument offset (default 0) specifies the starting column position.
utf16_code_units s is the sequence of UTF-16 code units (each a 16-bit value) encoding the valid-UTF-8 string s; a scalar outside the basic multilingual plane becomes a surrogate pair (two units).
utf16_length s is the number of UTF-16 code units that encode s (equivalently List.length (utf16_code_units s), without building the list). Editors such as VS Code count character positions in these units.
utf16_offset_to_byte s n is the byte offset in s just after its first n UTF-16 code units — the inverse of utf16_length for a prefix. Clamped to String.length s; if n falls inside a surrogate pair the offset is past that whole scalar.
utf16_decode units is the UTF-8 string the UTF-16 units (each a 16-bit value) encode — the inverse of utf16_code_units — pairing surrogates. None if a surrogate is unpaired.
scalar_of_hex s decodes the hex digits s (the payload of a \u{...} escape) to a Unicode scalar value. None if s is not valid hex, overflows a native int, or is out of the scalar range (above U+10FFFF or a surrogate).
escape_string s returns a pair (len, escaped) where escaped is the escaped version of s suitable for WAT/Wax string literals, and len is its display length.
Byte escapes are written \HH by default; hex_prefix is inserted after the backslash, so ~hex_prefix:"x" produces Rust-style \xHH escapes for Wax.
has_hex_escape s is true if s contains a control character that requires a hex escape in WAT (e.g. below U+0020 other than tab/cr/nl, or U+007F).