MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ encode_utf8()

MAYAFLUX_API std::string MayaFlux::Portal::Text::encode_utf8 ( uint32_t  codepoint)

Encode a Unicode codepoint as a UTF-8 byte sequence.

Counterpart to the decode step lay_out() performs via utf8proc_iterate. Invalid codepoints (surrogates, > 0x10FFFF) return an empty string.

Parameters
codepointUnicode codepoint to encode.
Returns
1-4 byte UTF-8 sequence, or empty on invalid input.

Definition at line 166 of file TypeSetter.cpp.

167{
168 if (!utf8proc_codepoint_valid(static_cast<utf8proc_int32_t>(codepoint))) {
169 return {};
170 }
171
172 std::array<utf8proc_uint8_t, 4> buf {};
173 const utf8proc_ssize_t n = utf8proc_encode_char(
174 static_cast<utf8proc_int32_t>(codepoint), buf.data());
175
176 if (n <= 0) {
177 return {};
178 }
179
180 return { reinterpret_cast<const char*>(buf.data()), static_cast<size_t>(n) };
181}

Referenced by insert_codepoint().

+ Here is the caller graph for this function: