Debian Codegraph @

pt_pal_editor/src/unicode.c

raw symbols SCIP
1 #include <stdint.h>
2 #include <wchar.h>
3 #include "unicode.h"
4
5 // this is probably broken, but it "works" for now
6 uint32_t unicharToAnsi(char *dstBuffer, const UNICHAR *inputString, uint32_t maxDstLen)
7 {
8 uint32_t i;
9 UNICHAR wideChar;
10
11 if (inputString == NULL || dstBuffer == NULL)
12 return 0;
13
14 i = 0;
15 while (i < maxDstLen && inputString[i] != '\0')
16 {
17 wideChar = inputString[i];
18 #ifdef _WIN32
19 if (wideChar >= 256)
20 #else
21 if (wideChar < 0)
22 #endif
23 {
24 *dstBuffer++ = '?';
25
26 #ifdef _WIN32
27 if ((wideChar & 0xFF00) == 0xD800) // lead surrogate, skip the next widechar (trail)
28 i++;
29 #endif
30 }
31 else
32 {
33 *dstBuffer++ = (char)wideChar;
34 }
35
36 i++;
37 }
38
39 if (maxDstLen > 1)
40 *dstBuffer = '\0';
41
42 return i;
43 }