Skip to content

std.utf16

utf-8 <-> utf-16 (native order, no bom); malformed input fails, never repaired

pub Utf16Error :: errors {
invalid_utf8,
invalid_utf16,
buffer_too_small,
out_of_memory,
}
  • invalid_utf8: the UTF-8 input is not well formed
  • invalid_utf16: the UTF-16 input has an unpaired surrogate
  • buffer_too_small: the destination cannot hold the whole result
  • out_of_memory: the arena could not supply the result’s storage
pub utf16_len :: fn(src: []const u8) -> usize ! Utf16Error

exact utf-16 length in units; .invalid_utf8

pub utf8_len :: fn(src: []const u16) -> usize ! Utf16Error

exact utf-8 length in bytes; .invalid_utf16

pub utf8_to_utf16 :: fn(src: []const u8, dst: []u16) -> usize ! Utf16Error

returns units written; .invalid_utf8, .buffer_too_small; dst untouched on error

pub utf16_to_utf8 :: fn(src: []const u16, dst: []u8) -> usize ! Utf16Error

returns bytes written; .invalid_utf16, .buffer_too_small; dst untouched on error

pub alloc_utf16 :: fn(a: *Arena, src: []const u8) -> []u16 ! Utf16Error

in a; .invalid_utf8, .out_of_memory

pub alloc_utf16z :: fn(a: *Arena, src: []const u8) -> []u16 ! Utf16Error

alloc_utf16 plus a 0 unit after the end (LPCWSTR); len excludes it

pub alloc_utf8 :: fn(a: *Arena, src: []const u16) -> []u8 ! Utf16Error

in a; .invalid_utf16, .out_of_memory