1 /* Grapheme cluster break function test.
2 Copyright (C) 2010-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program 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.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Ben Pfaff <blp@cs.stanford.edu>, 2010. */
29 graphemebreakproperty_to_string (int gbp)
34 #define CASE(VALUE) case GBP_##VALUE: return #VALUE;
52 main (int argc, char *argv[])
62 fprintf (stderr, "usage: %s FILENAME\n"
63 "where FILENAME is the location of the GraphemeBreakTest.txt\n"
64 "test file.\n", argv[0]);
69 stream = fopen (filename, "r");
72 fprintf (stderr, "error during fopen of '%s'\n", filename);
78 while (fgets (line, sizeof line, stream))
86 comment = strchr (line, '#');
89 if (line[strspn (line, " \t\r\n")] == '\0')
99 p += strspn (p, " \t\r\n");
100 if (!strncmp (p, "\303\267" /* ÷ */, 2))
105 else if (!strncmp (p, "\303\227" /* × */, 2))
107 should_break = false;
112 fprintf (stderr, "%s:%d.%d: syntax error expecting `÷' or `÷'\n",
113 filename, lineno, (int) (p - line + 1));
117 p += strspn (p, " \t\r\n");
122 unsigned int next_int;
125 if (sscanf (p, "%x%n", &next_int, &n) != 1)
127 fprintf (stderr, "%s:%d.%d: syntax error at `%s' expecting "
128 "hexadecimal Unicode code point number\n",
129 filename, lineno, (int) (p - line + 1), p);
137 if (uc_is_grapheme_break (prev, next) != should_break)
139 int prev_gbp = uc_graphemeclusterbreak_property (prev);
140 int next_gbp = uc_graphemeclusterbreak_property (next);
141 fprintf (stderr, "%s:%d: should %s U+%04X (%s) and "
144 should_break ? "break" : "join",
145 prev, graphemebreakproperty_to_string (prev_gbp),
146 next, graphemebreakproperty_to_string (next_gbp));
150 p += strspn (p, " \t\r\n");