Module Wax_utils.UnicodeSource

Sourceval terminal_width : ?offset:int -> string -> int

terminal_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.

Sourceval expand_tabs : ?offset:int -> string -> string

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.

Sourceval utf16_code_units : string -> int list

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).

Sourceval utf16_length : string -> int

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.

Sourceval utf16_offset_to_byte : string -> int -> int

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.

Sourceval utf16_decode : int list -> string option

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.

Sourceval scalar_of_hex : string -> Uchar.t option

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).

Sourceval escape_string : ?hex_prefix:string -> string -> int * string

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.

Sourceval has_hex_escape : string -> bool

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).

Sourceval char_width : int -> Uchar.t -> int

char_width pos u returns the display width of the Unicode character u, accounting for tabs assuming starting position pos.