Helper to write raw bytes or convert to WideChar based on destination
| 97 | #if defined(MMKV_WIN32) |
| 98 | // Helper to write raw bytes or convert to WideChar based on destination |
| 99 | static void WriteUTF8ToStream(const char* utf8_str) { |
| 100 | HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); |
| 101 | DWORD consoleMode; |
| 102 | |
| 103 | if (GetConsoleMode(hOut, &consoleMode)) { |
| 104 | // --- CONSOLE: Convert to UTF-16 and write --- |
| 105 | int wlen = MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, NULL, 0); |
| 106 | if (wlen > 0) { |
| 107 | wchar_t* wbuf = (wchar_t*)malloc(wlen * sizeof(wchar_t)); |
| 108 | if (wbuf) { |
| 109 | MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, wbuf, wlen); |
| 110 | WriteConsoleW(hOut, wbuf, wlen - 1, NULL, NULL); |
| 111 | free(wbuf); |
| 112 | } |
| 113 | } |
| 114 | } else { |
| 115 | // --- FILE/PIPE: Write raw UTF-8 bytes --- |
| 116 | DWORD bytesWritten; |
| 117 | WriteFile(hOut, utf8_str, (DWORD)strlen(utf8_str), &bytesWritten, NULL); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // Main VarArg Function |
| 122 | static void PrintUTF8(const char* format, ...) { |