MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / AddInputCharacterUTF16

Method AddInputCharacterUTF16

KBotExt/imgui/imgui.cpp:1315–1347  ·  view source on GitHub ↗

UTF16 strings use surrogate pairs to encode codepoints >= 0x10000, so we should save the high surrogate.

Source from the content-addressed store, hash-verified

1313// UTF16 strings use surrogate pairs to encode codepoints >= 0x10000, so
1314// we should save the high surrogate.
1315void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c)
1316{
1317 if ((c == 0 && InputQueueSurrogate == 0) || !AppAcceptingEvents)
1318 return;
1319
1320 if ((c & 0xFC00) == 0xD800) // High surrogate, must save
1321 {
1322 if (InputQueueSurrogate != 0)
1323 AddInputCharacter(IM_UNICODE_CODEPOINT_INVALID);
1324 InputQueueSurrogate = c;
1325 return;
1326 }
1327
1328 ImWchar cp = c;
1329 if (InputQueueSurrogate != 0)
1330 {
1331 if ((c & 0xFC00) != 0xDC00) // Invalid low surrogate
1332 {
1333 AddInputCharacter(IM_UNICODE_CODEPOINT_INVALID);
1334 }
1335 else
1336 {
1337#if IM_UNICODE_CODEPOINT_MAX == 0xFFFF
1338 cp = IM_UNICODE_CODEPOINT_INVALID; // Codepoint will not fit in ImWchar
1339#else
1340 cp = (ImWchar)(((InputQueueSurrogate - 0xD800) << 10) + (c - 0xDC00) + 0x10000);
1341#endif
1342 }
1343
1344 InputQueueSurrogate = 0;
1345 }
1346 AddInputCharacter((unsigned)cp);
1347}
1348
1349void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
1350{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected