UTF16 strings use surrogate pairs to encode codepoints >= 0x10000, so we should save the high surrogate.
| 1148 | // UTF16 strings use surrogate pairs to encode codepoints >= 0x10000, so |
| 1149 | // we should save the high surrogate. |
| 1150 | void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c) |
| 1151 | { |
| 1152 | if (c == 0 && InputQueueSurrogate == 0) |
| 1153 | return; |
| 1154 | |
| 1155 | if ((c & 0xFC00) == 0xD800) // High surrogate, must save |
| 1156 | { |
| 1157 | if (InputQueueSurrogate != 0) |
| 1158 | InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID); |
| 1159 | InputQueueSurrogate = c; |
| 1160 | return; |
| 1161 | } |
| 1162 | |
| 1163 | ImWchar cp = c; |
| 1164 | if (InputQueueSurrogate != 0) |
| 1165 | { |
| 1166 | if ((c & 0xFC00) != 0xDC00) // Invalid low surrogate |
| 1167 | { |
| 1168 | InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID); |
| 1169 | } |
| 1170 | else |
| 1171 | { |
| 1172 | #if IM_UNICODE_CODEPOINT_MAX == 0xFFFF |
| 1173 | cp = IM_UNICODE_CODEPOINT_INVALID; // Codepoint will not fit in ImWchar |
| 1174 | #else |
| 1175 | cp = (ImWchar)(((InputQueueSurrogate - 0xD800) << 10) + (c - 0xDC00) + 0x10000); |
| 1176 | #endif |
| 1177 | } |
| 1178 | |
| 1179 | InputQueueSurrogate = 0; |
| 1180 | } |
| 1181 | InputQueueCharacters.push_back(cp); |
| 1182 | } |
| 1183 | |
| 1184 | void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars) |
| 1185 | { |