MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / getchar32

Function getchar32

common/console.cpp:200–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198 }
199
200 static char32_t getchar32() {
201#if defined(_WIN32)
202 HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
203 wchar_t high_surrogate = 0;
204
205 while (true) {
206 INPUT_RECORD record;
207 DWORD count;
208 if (!ReadConsoleInputW(hConsole, &record, 1, &count) || count == 0) {
209 return WEOF;
210 }
211
212 if (record.EventType == KEY_EVENT && record.Event.KeyEvent.bKeyDown) {
213 wchar_t wc = record.Event.KeyEvent.uChar.UnicodeChar;
214 if (wc == 0) {
215 const DWORD ctrl_mask = LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED;
216 const bool ctrl_pressed = (record.Event.KeyEvent.dwControlKeyState & ctrl_mask) != 0;
217 switch (record.Event.KeyEvent.wVirtualKeyCode) {
218 case VK_LEFT: return ctrl_pressed ? KEY_CTRL_ARROW_LEFT : KEY_ARROW_LEFT;
219 case VK_RIGHT: return ctrl_pressed ? KEY_CTRL_ARROW_RIGHT : KEY_ARROW_RIGHT;
220 case VK_UP: return KEY_ARROW_UP;
221 case VK_DOWN: return KEY_ARROW_DOWN;
222 case VK_HOME: return KEY_HOME;
223 case VK_END: return KEY_END;
224 case VK_DELETE: return KEY_DELETE;
225 default: continue;
226 }
227 }
228
229 if ((wc >= 0xD800) && (wc <= 0xDBFF)) { // Check if wc is a high surrogate
230 high_surrogate = wc;
231 continue;
232 }
233 if ((wc >= 0xDC00) && (wc <= 0xDFFF)) { // Check if wc is a low surrogate
234 if (high_surrogate != 0) { // Check if we have a high surrogate
235 return ((high_surrogate - 0xD800) << 10) + (wc - 0xDC00) + 0x10000;
236 }
237 }
238
239 high_surrogate = 0; // Reset the high surrogate
240 return static_cast<char32_t>(wc);
241 }
242 }
243#else
244 wchar_t wc = getwchar();
245 if (static_cast<wint_t>(wc) == WEOF) {
246 return WEOF;
247 }
248
249#if WCHAR_MAX == 0xFFFF
250 if ((wc >= 0xD800) && (wc <= 0xDBFF)) { // Check if wc is a high surrogate
251 wchar_t low_surrogate = getwchar();
252 if ((low_surrogate >= 0xDC00) && (low_surrogate <= 0xDFFF)) { // Check if the next wchar is a low surrogate
253 return (static_cast<char32_t>(wc & 0x03FF) << 10) + (low_surrogate & 0x03FF) + 0x10000;
254 }
255 }
256 if ((wc >= 0xD800) && (wc <= 0xDFFF)) { // Invalid surrogate pair
257 return 0xFFFD; // Return the replacement character U+FFFD

Callers 1

readline_advancedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected