Skip to content

ui::Utf16Decoder

Header: winui/core/Utf8.hpp.

Puts UTF-16 code units that arrive one at a time, as typed characters do, back together into UTF-8. A high surrogate is held until its low half arrives. A half without its partner comes out as U+FFFD. Keep one per input source. It is a plain value with one unit of state.

Example:

// An emoji arrives as two units: the first returns nothing, the second the whole character.
void on_typed_unit(ui::Utf16Decoder& decoder, ui::TextBoxControl& editor, char16_t unit)
{
    if (const std::string typed = decoder.feed(unit); !typed.empty())
    {
        editor.replace_selection(typed);
    }
}

ui::Utf16Decoder decoder; // one per input source

feed

std::string feed(char16_t unit)

Feeds one unit and returns the text it completes: empty while a high surrogate waits, otherwise one code point, or two when a stranded high surrogate is flushed first.