1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include "unicode.h"
24
25 #include <stdlib.h>
26
27 #ifdef __APPLE__
28 #include <CoreFoundation/CoreFoundation.h>
29
30 char* StringNFD2NFC(
const char *str) {
31 CFStringRef nfd = CFStringCreateWithCString(
NULL, str, kCFStringEncodingUTF8);
32 CFMutableStringRef nfc = CFStringCreateMutableCopy(
NULL,
0, nfd);
33 CFStringNormalize(nfc, kCFStringNormalizationFormC);
34 CFIndex length16 = CFStringGetLength(nfc);
35 size_t buflen = (length16+
1) *
4;
36 char *cstr = malloc(buflen);
37 if(!cstr) {
38 exit(-
1);
39 }
40 CFStringGetCString(nfc, cstr, buflen, kCFStringEncodingUTF8);
41 CFRelease(nfc);
42 CFRelease(nfd);
43 return cstr;
44 }
45
46 #endif
47