malloca: Silence a warning from clang's memory sanitizer.
[gnulib.git] / tests / uniwidth / test-uc_width2.c
blob1792dafca968397c5fcd925356aeb0a74fc0e167
1 /* Test of uc_width() function.
2 Copyright (C) 2007-2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2008. */
19 #include <config.h>
21 #include "uniwidth.h"
23 #include <stdio.h>
25 #include "macros.h"
27 /* One of 0, '0', '1', 'A', '2'. */
28 static char current_width;
29 /* The interval for which the current_width holds. */
30 static ucs4_t current_start;
31 static ucs4_t current_end;
33 static void
34 finish_interval (void)
36 if (current_width != 0)
38 if (current_start == current_end)
39 printf ("%04X\t\t%c\n", (unsigned) current_start, current_width);
40 else
41 printf ("%04X..%04X\t%c\n", (unsigned) current_start,
42 (unsigned) current_end, current_width);
43 current_width = 0;
47 static void
48 add_to_interval (ucs4_t uc, char width)
50 if (current_width == width && uc == current_end + 1)
51 current_end = uc;
52 else
54 finish_interval ();
55 current_width = width;
56 current_start = current_end = uc;
60 int
61 main ()
63 ucs4_t uc;
65 for (uc = 0; uc < 0x110000; uc++)
67 int w1 = uc_width (uc, "UTF-8");
68 int w2 = uc_width (uc, "GBK");
69 char width =
70 (w1 == 0 && w2 == 0 ? '0' :
71 w1 == 1 && w2 == 1 ? '1' :
72 w1 == 1 && w2 == 2 ? 'A' :
73 w1 == 2 && w2 == 2 ? '2' :
74 0);
75 if (width == 0)
77 /* uc must be a control character. */
78 ASSERT (w1 < 0 && w2 < 0);
80 else
81 add_to_interval (uc, width);
83 finish_interval ();
85 return 0;