Text conversion v0.1.0

Source
Converting between code pages and UTF-16.

MultiByteToWideChar

pub extern func MultiByteToWideChar(
    codePage: CodePage,
    flags: uint32,
    multiByteStr: *char8,
    multiByte: int32,
    wideCharStr: *char16,
    wideChar: int32
) -> int32

pub extern func MultiByteToWideChar(
    codePage: uint32,
    flags: uint32,
    multiByteStr: *char8,
    multiByte: int32,
    wideCharStr: *char16,
    wideChar: int32
) -> int32

Maps a character string to a UTF-16 wide character string.

See also: https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar

Source

Parameters

NameTypeDescription
codePageCodePage / uint32the code page to convert through, as a CodePage value
flagsuint32the call's flag bits, combined with |
multiByteStr*char8the bytes to convert
multiByteint32how many bytes, or -1 to stop at the terminator
wideCharStr*char16receives the UTF-16 units, or null to ask how many are needed
wideCharint32how many units the output holds, or zero to ask

Returns: the units written, the units needed when asked, or zero on failure

WideCharToMultiByte

pub extern func WideCharToMultiByte(
    codePage: uint32,
    flags: uint32,
    wideCharStr: *char16,
    wideChar: int32,
    multiByteStr: *char8,
    multiByte: int32,
    defaultChar: *char8,
    usedDefaultChar: *bool32
) -> int32

Converts UTF-16 text to another code page.

See also: https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte

Source

Parameters

NameTypeDescription
codePageuint32the code page to convert through, as a CodePage value
flagsuint32the call's flag bits, combined with |
wideCharStr*char16receives the UTF-16 units, or null to ask how many are needed
wideCharint32how many units the output holds, or zero to ask
multiByteStr*char8the bytes to convert
multiByteint32how many bytes, or -1 to stop at the terminator
defaultChar*char8the byte to substitute for an unconvertible unit, or null
usedDefaultChar*bool32receives whether any substitution happened, or null

Returns: the bytes written, the bytes needed when asked, or zero on failure