Windows UTF-8 to zero-terminated UTF-16 conversion helper.
utf16 (source -- result)
Converts one accepted UTF-8 source into one zero-terminated Nat16 Array containing the UTF-16 representation.
- Accepted source forms are
StringView, Text, and String.
- These inputs are normalized through
String.makeStringView before conversion begins.
- The whole source is interpreted as UTF-8 and converted to UTF-16 code units.
- Unicode code points outside the Basic Multilingual Plane are represented by ordinary UTF-16 surrogate pairs.
- The resulting
Nat16 Array always ends with one trailing 0n16 terminator.
- The returned array owns its storage and is independent of the source lifetime.
- The result remains dynamic even when the source is known at compile time.
- The resulting array can be passed through
storageAddress to imported Windows functions that expect zero-terminated UTF-16 input.
Failure conditions
- Invalid UTF-8 input causes assertion failure.
- An empty source causes assertion failure.
- Unexpected conversion failure likewise causes assertion failure.
- These failure paths use the assertion text
MultiByteToWideChar failed.
See also
- String: UTF-8 string views, owned strings, formatting helpers, and text conversion utilities.
- Array: Growable array.
- windows/kernel32: Kernel32 declarations for synchronization, process, thread, file, and timing helpers.