Debian Codegraph @

lib/nfkc_dump.c

raw symbols SCIP
1 /*
2 Copyright(C) 2018 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifdef WIN32
20 # define GROONGA_MAIN
21 #endif /* WIN32 */
22
23 #include "grn.h"
24 #include "grn_nfkc.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #ifdef GRN_WITH_NFKC
30
31 #define MAX_UNICODE 0x110000
32
33 static inline int
34 ucs2utf8(unsigned int i, unsigned char *buf)
35 {
36 unsigned char *p = buf;
37 if (i < 0x80) {
38 *p++ = i;
39 } else {
40 if (i < 0x800) {
41 *p++ = (i >> 6) | 0xc0;
42 } else {
43 if (i < 0x00010000) {
44 *p++ = (i >> 12) | 0xe0;
45 } else {
46 if (i < 0x00200000) {
47 *p++ = (i >> 18) | 0xf0;
48 } else {
49 if (i < 0x04000000) {
50 *p++ = (i >> 24) | 0xf8;
51 } else if (i < 0x80000000) {
52 *p++ = (i >> 30) | 0xfc;
53 *p++ = ((i >> 24) & 0x3f) | 0x80;
54 }
55 *p++ = ((i >> 18) & 0x3f) | 0x80;
56 }
57 *p++ = ((i >> 12) & 0x3f) | 0x80;
58 }
59 *p++ = ((i >> 6) & 0x3f) | 0x80;
60 }
61 *p++ = (0x3f & i) | 0x80;
62 }
63 *p = '\0';
64 return (p - buf);
65 }
66
67 #endif /* GRN_WITH_NFKC */
68
69 int
70 main(int argc, char **argv)
71 {
72 int unicode_version = 5;
73
74 if (argc == 2) {
75 if (strcmp(argv[1], "5") == 0) {
76 unicode_version = 5;
77 } else if (strcmp(argv[1], "10") == 0) {
78 unicode_version = 10;
79 } else {
80 return EXIT_FAILURE;
81 }
82 }
83
84 #ifdef GRN_WITH_NFKC
85 if (unicode_version == 5) {
86 uint64_t code_point;
87 char utf8[7];
88
89 for (code_point = 1; code_point < MAX_UNICODE; code_point++) {
90 ucs2utf8(code_point, (unsigned char *)utf8);
91 printf("%#0" GRN_FMT_INT64X ": %s: <%s>\n",
92 code_point,
93 grn_char_type_to_string(grn_nfkc50_char_type(utf8)),
94 utf8);
95 }
96 } else if (unicode_version == 10) {
97 uint64_t code_point;
98 char utf8[7];
99
100 for (code_point = 1; code_point < MAX_UNICODE; code_point++) {
101 ucs2utf8(code_point, (unsigned char *)utf8);
102 printf("%#0" GRN_FMT_INT64X ": %s: <%s>\n",
103 code_point,
104 grn_char_type_to_string(grn_nfkc100_char_type(utf8)),
105 utf8);
106 }
107 }
108 #endif
109
110 return EXIT_SUCCESS;
111 }