...
1
2
3
4
5
6
7 package cases
8
9
10
11
12
13
14
15
23 import "C"
24
25 import "unsafe"
26
27 func doICU(tag, caser, input string) string {
28 err := C.UErrorCode(0)
29 loc := C.CString(tag)
30 cm := C.ucasemap_open(loc, C.uint32_t(0), &err)
31
32 buf := make([]byte, len(input)*4)
33 dst := (*C.char)(unsafe.Pointer(&buf[0]))
34 src := C.CString(input)
35
36 cn := C.int32_t(0)
37
38 switch caser {
39 case "fold":
40 cn = C.ucasemap_utf8FoldCase(cm,
41 dst, C.int32_t(len(buf)),
42 src, C.int32_t(len(input)),
43 &err)
44 case "lower":
45 cn = C.ucasemap_utf8ToLower(cm,
46 dst, C.int32_t(len(buf)),
47 src, C.int32_t(len(input)),
48 &err)
49 case "upper":
50 cn = C.ucasemap_utf8ToUpper(cm,
51 dst, C.int32_t(len(buf)),
52 src, C.int32_t(len(input)),
53 &err)
54 case "title":
55 cn = C.ucasemap_utf8ToTitle(cm,
56 dst, C.int32_t(len(buf)),
57 src, C.int32_t(len(input)),
58 &err)
59 }
60 return string(buf[:cn])
61 }
62
View as plain text