Browse the docs

silk.platform.windows.wtf8.

Lossless conversion between Windows UTF-16 code units and canonical WTF-8 bytes.

When to use#

Use Wtf8.encode for raw host values and Wtf8.decodeBytes for their inverse. Lone surrogates remain bytes. Use String.fromUtf8 separately when a caller needs valid Unicode text.

Import as Wtf8 with import silk.platform.windows.wtf8 { Wtf8 }.

Public declarations: 3.

InvalidWtf8#

silk
pub struct InvalidWtf8

A malformed or noncanonical WTF-8 byte sequence.

Implementation Debug for InvalidWtf8#

silk
impl Debug for InvalidWtf8

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes InvalidWtf8.

Wtf8Point#

silk
pub struct Wtf8Point

One decoded code point, including a possible lone surrogate, and the next byte offset.

Field value#

silk
pub value: u32

The code point, from 0 through 0x10ffff, including lone surrogates.

Field end#

silk
pub end: usize

The byte offset immediately after the code point.

Wtf8#

silk
pub struct Wtf8

Conversion of arbitrary UTF-16 code units to canonical WTF-8 bytes, without replacement characters.

Implementation Wtf8#

silk
impl Wtf8

Associated function encode#

silk
pub effect fn encode(units: &[u16]) -> Bytes ! OutOfMemoryError ? &mut Allocator

Returns canonical WTF-8 bytes for units. Pairs become one scalar; lone surrogates survive.

Details#

NUL is preserved. Host APIs that use NUL terminators must reject embedded NUL separately.

Errors#

  • OutOfMemoryError if the output cannot be allocated.

Associated function pointBytes#

silk
pub fn pointBytes(bytes: &[u8], at: usize) -> Option<Wtf8Point>

Decodes one canonical WTF-8 code point at at, or returns an absent option for invalid input.

Details#

An absent result also indicates the end of input. Callers start at zero and advance to end. Overlong encodings, values above 0x10ffff, and separately encoded adjacent surrogate pairs are rejected. Lone surrogates and NUL are accepted. This operation does not allocate.

Associated function decodeBytes#

silk
pub effect fn decodeBytes(bytes: &[u8]) -> List<u16> ! InvalidWtf8 | OutOfMemoryError ? &mut Allocator

Returns the UTF-16 code units of canonical WTF-8 bytes, preserving lone surrogates and NUL.

Errors#

  • InvalidWtf8 for malformed bytes or separately encoded adjacent high and low surrogates.

  • OutOfMemoryError if the output cannot be allocated.

Category: Windows platform.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page