Kouhei Sutou
null+****@clear*****
Mon Apr 9 12:44:54 JST 2018
Kouhei Sutou 2018-04-09 12:44:54 +0900 (Mon, 09 Apr 2018) New Revision: fb1fece70fb65aa7dffa456b43af8e010d6fa3c1 https://github.com/groonga/groonga/commit/fb1fece70fb65aa7dffa456b43af8e010d6fa3c1 Message: Add a test program for NFKC implementation Added files: lib/nfkc_dump.c Modified files: .gitignore lib/Makefile.am Modified: .gitignore (+1 -0) =================================================================== --- .gitignore 2018-04-09 12:23:13 +0900 (3ac7403ea) +++ .gitignore 2018-04-09 12:44:54 +0900 (78a9566da) @@ -93,6 +93,7 @@ CMakeFiles /lib/icudump /lib/grn_ecmascript.out /lib/metadata.rc +/lib/nfkc_dump /coverage /coverage.info /test/unit/lib/*-*.*.*/ Modified: lib/Makefile.am (+9 -0) =================================================================== --- lib/Makefile.am 2018-04-09 12:23:13 +0900 (9a2217ee1) +++ lib/Makefile.am 2018-04-09 12:44:54 +0900 (c5cfd966f) @@ -69,6 +69,15 @@ libgroonga_la_LIBADD += \ $(ATOMIC_LIBS) \ $(ARROW_LIBS) +nfkc_dump_SOURCES = \ + nfkc_dump.c + +nfkc_dump_LDADD = \ + libgroonga.la + +noinst_PROGRAMS = \ + nfkc_dump + if WITH_LEMON BUILT_SOURCES = \ grn_ecmascript.c Added: lib/nfkc_dump.c (+96 -0) 100644 =================================================================== --- /dev/null +++ lib/nfkc_dump.c 2018-04-09 12:44:54 +0900 (3b258af26) @@ -0,0 +1,96 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2018 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "grn.h" +#include "grn_nfkc.h" + +#include <stdio.h> +#include <stdlib.h> + +#ifdef GRN_WITH_NFKC + +#define MAX_UNICODE 0x110000 + +static inline int +ucs2utf8(unsigned int i, unsigned char *buf) +{ + unsigned char *p = buf; + if (i < 0x80) { + *p++ = i; + } else { + if (i < 0x800) { + *p++ = (i >> 6) | 0xc0; + } else { + if (i < 0x00010000) { + *p++ = (i >> 12) | 0xe0; + } else { + if (i < 0x00200000) { + *p++ = (i >> 18) | 0xf0; + } else { + if (i < 0x04000000) { + *p++ = (i >> 24) | 0xf8; + } else if (i < 0x80000000) { + *p++ = (i >> 30) | 0xfc; + *p++ = ((i >> 24) & 0x3f) | 0x80; + } + *p++ = ((i >> 18) & 0x3f) | 0x80; + } + *p++ = ((i >> 12) & 0x3f) | 0x80; + } + *p++ = ((i >> 6) & 0x3f) | 0x80; + } + *p++ = (0x3f & i) | 0x80; + } + *p = '\0'; + return (p - buf); +} + +#endif /* GRN_WITH_NFKC */ + +int +main(int argc, char **argv) +{ + int unicode_version = 5; + + if (argc == 2) { + if (strcmp(argv[1], "5") == 0) { + unicode_version = 5; + } else if (strcmp(argv[1], "9") == 0) { + unicode_version = 9; + } else { + return EXIT_FAILURE; + } + } + +#ifdef GRN_WITH_NFKC + if (unicode_version == 5) { + uint64_t code_point; + char utf8[7]; + + for (code_point = 1; code_point < MAX_UNICODE; code_point++) { + ucs2utf8(code_point, (unsigned char *)utf8); + printf("%#0" GRN_FMT_INT64X ": %s: <%s>\n", + code_point, + grn_char_type_to_string(grn_nfkc50_char_type(utf8)), + utf8); + } + } +#endif + + return EXIT_SUCCESS; +} -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180409/c9b13fe4/attachment-0001.htm