1*84d9c625SLionel Sambuc /* $NetBSD: charset.c,v 1.4 2013/09/04 19:44:21 tron Exp $ */
2f7cf2976SLionel Sambuc
3f7cf2976SLionel Sambuc /*
4*84d9c625SLionel Sambuc * Copyright (C) 1984-2012 Mark Nudelman
5f7cf2976SLionel Sambuc *
6f7cf2976SLionel Sambuc * You may distribute under the terms of either the GNU General Public
7f7cf2976SLionel Sambuc * License or the Less License, as specified in the README file.
8f7cf2976SLionel Sambuc *
9*84d9c625SLionel Sambuc * For more information, see the README file.
10f7cf2976SLionel Sambuc */
11f7cf2976SLionel Sambuc
12f7cf2976SLionel Sambuc
13f7cf2976SLionel Sambuc /*
14f7cf2976SLionel Sambuc * Functions to define the character set
15f7cf2976SLionel Sambuc * and do things specific to the character set.
16f7cf2976SLionel Sambuc */
17f7cf2976SLionel Sambuc
18f7cf2976SLionel Sambuc #include "less.h"
19f7cf2976SLionel Sambuc #if HAVE_LOCALE
20f7cf2976SLionel Sambuc #include <locale.h>
21f7cf2976SLionel Sambuc #include <ctype.h>
22f7cf2976SLionel Sambuc #include <langinfo.h>
23f7cf2976SLionel Sambuc #endif
24f7cf2976SLionel Sambuc
25f7cf2976SLionel Sambuc #include "charset.h"
26f7cf2976SLionel Sambuc
27f7cf2976SLionel Sambuc public int utf_mode = 0;
28f7cf2976SLionel Sambuc
29f7cf2976SLionel Sambuc /*
30f7cf2976SLionel Sambuc * Predefined character sets,
31f7cf2976SLionel Sambuc * selected by the LESSCHARSET environment variable.
32f7cf2976SLionel Sambuc */
33f7cf2976SLionel Sambuc struct charset {
34f7cf2976SLionel Sambuc char *name;
35f7cf2976SLionel Sambuc int *p_flag;
36f7cf2976SLionel Sambuc char *desc;
37f7cf2976SLionel Sambuc } charsets[] = {
38f7cf2976SLionel Sambuc { "ascii", NULL, "8bcccbcc18b95.b" },
39f7cf2976SLionel Sambuc { "utf-8", &utf_mode, "8bcccbcc18b95.b126.bb" },
40f7cf2976SLionel Sambuc { "iso8859", NULL, "8bcccbcc18b95.33b." },
41f7cf2976SLionel Sambuc { "latin3", NULL, "8bcccbcc18b95.33b5.b8.b15.b4.b12.b18.b12.b." },
42f7cf2976SLionel Sambuc { "arabic", NULL, "8bcccbcc18b95.33b.3b.7b2.13b.3b.b26.5b19.b" },
43f7cf2976SLionel Sambuc { "greek", NULL, "8bcccbcc18b95.33b4.2b4.b3.b35.b44.b" },
44f7cf2976SLionel Sambuc { "greek2005", NULL, "8bcccbcc18b95.33b14.b35.b44.b" },
45f7cf2976SLionel Sambuc { "hebrew", NULL, "8bcccbcc18b95.33b.b29.32b28.2b2.b" },
46f7cf2976SLionel Sambuc { "koi8-r", NULL, "8bcccbcc18b95.b." },
47f7cf2976SLionel Sambuc { "KOI8-T", NULL, "8bcccbcc18b95.b8.b6.b8.b.b.5b7.3b4.b4.b3.b.b.3b." },
48f7cf2976SLionel Sambuc { "georgianps", NULL, "8bcccbcc18b95.3b11.4b12.2b." },
49f7cf2976SLionel Sambuc { "tcvn", NULL, "b..b...bcccbccbbb7.8b95.b48.5b." },
50f7cf2976SLionel Sambuc { "TIS-620", NULL, "8bcccbcc18b95.b.4b.11b7.8b." },
51f7cf2976SLionel Sambuc { "next", NULL, "8bcccbcc18b95.bb125.bb" },
52f7cf2976SLionel Sambuc { "dos", NULL, "8bcccbcc12bc5b95.b." },
53f7cf2976SLionel Sambuc { "windows-1251", NULL, "8bcccbcc12bc5b95.b24.b." },
54f7cf2976SLionel Sambuc { "windows-1252", NULL, "8bcccbcc12bc5b95.b.b11.b.2b12.b." },
55f7cf2976SLionel Sambuc { "windows-1255", NULL, "8bcccbcc12bc5b95.b.b8.b.5b9.b.4b." },
56f7cf2976SLionel Sambuc { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." },
57f7cf2976SLionel Sambuc { "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" },
58f7cf2976SLionel Sambuc { NULL, NULL, NULL }
59f7cf2976SLionel Sambuc };
60f7cf2976SLionel Sambuc
61f7cf2976SLionel Sambuc /*
62f7cf2976SLionel Sambuc * Support "locale charmap"/nl_langinfo(CODESET) values, as well as others.
63f7cf2976SLionel Sambuc */
64f7cf2976SLionel Sambuc struct cs_alias {
65f7cf2976SLionel Sambuc char *name;
66f7cf2976SLionel Sambuc char *oname;
67f7cf2976SLionel Sambuc } cs_aliases[] = {
68f7cf2976SLionel Sambuc { "UTF-8", "utf-8" },
69f7cf2976SLionel Sambuc { "ANSI_X3.4-1968", "ascii" },
70f7cf2976SLionel Sambuc { "US-ASCII", "ascii" },
71f7cf2976SLionel Sambuc { "latin1", "iso8859" },
72f7cf2976SLionel Sambuc { "ISO-8859-1", "iso8859" },
73f7cf2976SLionel Sambuc { "latin9", "iso8859" },
74f7cf2976SLionel Sambuc { "ISO-8859-15", "iso8859" },
75f7cf2976SLionel Sambuc { "latin2", "iso8859" },
76f7cf2976SLionel Sambuc { "ISO-8859-2", "iso8859" },
77f7cf2976SLionel Sambuc { "ISO-8859-3", "latin3" },
78f7cf2976SLionel Sambuc { "latin4", "iso8859" },
79f7cf2976SLionel Sambuc { "ISO-8859-4", "iso8859" },
80f7cf2976SLionel Sambuc { "cyrillic", "iso8859" },
81f7cf2976SLionel Sambuc { "ISO-8859-5", "iso8859" },
82f7cf2976SLionel Sambuc { "ISO-8859-6", "arabic" },
83f7cf2976SLionel Sambuc { "ISO-8859-7", "greek" },
84f7cf2976SLionel Sambuc { "IBM9005", "greek2005" },
85f7cf2976SLionel Sambuc { "ISO-8859-8", "hebrew" },
86f7cf2976SLionel Sambuc { "latin5", "iso8859" },
87f7cf2976SLionel Sambuc { "ISO-8859-9", "iso8859" },
88f7cf2976SLionel Sambuc { "latin6", "iso8859" },
89f7cf2976SLionel Sambuc { "ISO-8859-10", "iso8859" },
90f7cf2976SLionel Sambuc { "latin7", "iso8859" },
91f7cf2976SLionel Sambuc { "ISO-8859-13", "iso8859" },
92f7cf2976SLionel Sambuc { "latin8", "iso8859" },
93f7cf2976SLionel Sambuc { "ISO-8859-14", "iso8859" },
94f7cf2976SLionel Sambuc { "latin10", "iso8859" },
95f7cf2976SLionel Sambuc { "ISO-8859-16", "iso8859" },
96f7cf2976SLionel Sambuc { "IBM437", "dos" },
97f7cf2976SLionel Sambuc { "EBCDIC-US", "ebcdic" },
98f7cf2976SLionel Sambuc { "IBM1047", "IBM-1047" },
99f7cf2976SLionel Sambuc { "KOI8-R", "koi8-r" },
100f7cf2976SLionel Sambuc { "KOI8-U", "koi8-r" },
101f7cf2976SLionel Sambuc { "GEORGIAN-PS", "georgianps" },
102f7cf2976SLionel Sambuc { "TCVN5712-1", "tcvn" },
103f7cf2976SLionel Sambuc { "NEXTSTEP", "next" },
104f7cf2976SLionel Sambuc { "windows", "windows-1252" }, /* backward compatibility */
105f7cf2976SLionel Sambuc { "CP1251", "windows-1251" },
106f7cf2976SLionel Sambuc { "CP1252", "windows-1252" },
107f7cf2976SLionel Sambuc { "CP1255", "windows-1255" },
108f7cf2976SLionel Sambuc { NULL, NULL }
109f7cf2976SLionel Sambuc };
110f7cf2976SLionel Sambuc
111f7cf2976SLionel Sambuc #define IS_BINARY_CHAR 01
112f7cf2976SLionel Sambuc #define IS_CONTROL_CHAR 02
113f7cf2976SLionel Sambuc
114f7cf2976SLionel Sambuc static char chardef[256];
115f7cf2976SLionel Sambuc static char *binfmt = NULL;
116f7cf2976SLionel Sambuc static char *utfbinfmt = NULL;
117f7cf2976SLionel Sambuc public int binattr = AT_STANDOUT;
118f7cf2976SLionel Sambuc
119f7cf2976SLionel Sambuc static void ichardef __P((char *));
120f7cf2976SLionel Sambuc static int icharset __P((char *, int));
121f7cf2976SLionel Sambuc static void ilocale __P((void));
122f7cf2976SLionel Sambuc
123f7cf2976SLionel Sambuc /*
124f7cf2976SLionel Sambuc * Define a charset, given a description string.
125f7cf2976SLionel Sambuc * The string consists of 256 letters,
126f7cf2976SLionel Sambuc * one for each character in the charset.
127f7cf2976SLionel Sambuc * If the string is shorter than 256 letters, missing letters
128f7cf2976SLionel Sambuc * are taken to be identical to the last one.
129f7cf2976SLionel Sambuc * A decimal number followed by a letter is taken to be a
130f7cf2976SLionel Sambuc * repetition of the letter.
131f7cf2976SLionel Sambuc *
132f7cf2976SLionel Sambuc * Each letter is one of:
133f7cf2976SLionel Sambuc * . normal character
134f7cf2976SLionel Sambuc * b binary character
135f7cf2976SLionel Sambuc * c control character
136f7cf2976SLionel Sambuc */
137f7cf2976SLionel Sambuc static void
ichardef(s)138f7cf2976SLionel Sambuc ichardef(s)
139f7cf2976SLionel Sambuc char *s;
140f7cf2976SLionel Sambuc {
141f7cf2976SLionel Sambuc register char *cp;
142f7cf2976SLionel Sambuc register int n;
143f7cf2976SLionel Sambuc register char v;
144f7cf2976SLionel Sambuc
145f7cf2976SLionel Sambuc n = 0;
146f7cf2976SLionel Sambuc v = 0;
147f7cf2976SLionel Sambuc cp = chardef;
148f7cf2976SLionel Sambuc while (*s != '\0')
149f7cf2976SLionel Sambuc {
150f7cf2976SLionel Sambuc switch (*s++)
151f7cf2976SLionel Sambuc {
152f7cf2976SLionel Sambuc case '.':
153f7cf2976SLionel Sambuc v = 0;
154f7cf2976SLionel Sambuc break;
155f7cf2976SLionel Sambuc case 'c':
156f7cf2976SLionel Sambuc v = IS_CONTROL_CHAR;
157f7cf2976SLionel Sambuc break;
158f7cf2976SLionel Sambuc case 'b':
159f7cf2976SLionel Sambuc v = IS_BINARY_CHAR|IS_CONTROL_CHAR;
160f7cf2976SLionel Sambuc break;
161f7cf2976SLionel Sambuc
162f7cf2976SLionel Sambuc case '0': case '1': case '2': case '3': case '4':
163f7cf2976SLionel Sambuc case '5': case '6': case '7': case '8': case '9':
164f7cf2976SLionel Sambuc n = (10 * n) + (s[-1] - '0');
165f7cf2976SLionel Sambuc continue;
166f7cf2976SLionel Sambuc
167f7cf2976SLionel Sambuc default:
168f7cf2976SLionel Sambuc error("invalid chardef", NULL_PARG);
169f7cf2976SLionel Sambuc quit(QUIT_ERROR);
170f7cf2976SLionel Sambuc /*NOTREACHED*/
171f7cf2976SLionel Sambuc }
172f7cf2976SLionel Sambuc
173f7cf2976SLionel Sambuc do
174f7cf2976SLionel Sambuc {
175f7cf2976SLionel Sambuc if (cp >= chardef + sizeof(chardef))
176f7cf2976SLionel Sambuc {
177f7cf2976SLionel Sambuc error("chardef longer than 256", NULL_PARG);
178f7cf2976SLionel Sambuc quit(QUIT_ERROR);
179f7cf2976SLionel Sambuc /*NOTREACHED*/
180f7cf2976SLionel Sambuc }
181f7cf2976SLionel Sambuc *cp++ = v;
182f7cf2976SLionel Sambuc } while (--n > 0);
183f7cf2976SLionel Sambuc n = 0;
184f7cf2976SLionel Sambuc }
185f7cf2976SLionel Sambuc
186f7cf2976SLionel Sambuc while (cp < chardef + sizeof(chardef))
187f7cf2976SLionel Sambuc *cp++ = v;
188f7cf2976SLionel Sambuc }
189f7cf2976SLionel Sambuc
190f7cf2976SLionel Sambuc /*
191f7cf2976SLionel Sambuc * Define a charset, given a charset name.
192f7cf2976SLionel Sambuc * The valid charset names are listed in the "charsets" array.
193f7cf2976SLionel Sambuc */
194f7cf2976SLionel Sambuc static int
icharset(name,no_error)195f7cf2976SLionel Sambuc icharset(name, no_error)
196f7cf2976SLionel Sambuc register char *name;
197f7cf2976SLionel Sambuc int no_error;
198f7cf2976SLionel Sambuc {
199f7cf2976SLionel Sambuc register struct charset *p;
200f7cf2976SLionel Sambuc register struct cs_alias *a;
201f7cf2976SLionel Sambuc
202f7cf2976SLionel Sambuc if (name == NULL || *name == '\0')
203f7cf2976SLionel Sambuc return (0);
204f7cf2976SLionel Sambuc
205f7cf2976SLionel Sambuc /* First see if the name is an alias. */
206f7cf2976SLionel Sambuc for (a = cs_aliases; a->name != NULL; a++)
207f7cf2976SLionel Sambuc {
208f7cf2976SLionel Sambuc if (strcmp(name, a->name) == 0)
209f7cf2976SLionel Sambuc {
210f7cf2976SLionel Sambuc name = a->oname;
211f7cf2976SLionel Sambuc break;
212f7cf2976SLionel Sambuc }
213f7cf2976SLionel Sambuc }
214f7cf2976SLionel Sambuc
215f7cf2976SLionel Sambuc for (p = charsets; p->name != NULL; p++)
216f7cf2976SLionel Sambuc {
217f7cf2976SLionel Sambuc if (strcmp(name, p->name) == 0)
218f7cf2976SLionel Sambuc {
219f7cf2976SLionel Sambuc ichardef(p->desc);
220f7cf2976SLionel Sambuc if (p->p_flag != NULL)
221f7cf2976SLionel Sambuc *(p->p_flag) = 1;
222f7cf2976SLionel Sambuc return (1);
223f7cf2976SLionel Sambuc }
224f7cf2976SLionel Sambuc }
225f7cf2976SLionel Sambuc
226f7cf2976SLionel Sambuc if (!no_error) {
227f7cf2976SLionel Sambuc error("invalid charset name", NULL_PARG);
228f7cf2976SLionel Sambuc quit(QUIT_ERROR);
229f7cf2976SLionel Sambuc }
230f7cf2976SLionel Sambuc return (0);
231f7cf2976SLionel Sambuc }
232f7cf2976SLionel Sambuc
233f7cf2976SLionel Sambuc #if HAVE_LOCALE
234f7cf2976SLionel Sambuc /*
235f7cf2976SLionel Sambuc * Define a charset, given a locale name.
236f7cf2976SLionel Sambuc */
237f7cf2976SLionel Sambuc static void
ilocale()238f7cf2976SLionel Sambuc ilocale()
239f7cf2976SLionel Sambuc {
240f7cf2976SLionel Sambuc register int c;
241f7cf2976SLionel Sambuc
242f7cf2976SLionel Sambuc for (c = 0; c < (int) sizeof(chardef); c++)
243f7cf2976SLionel Sambuc {
244f7cf2976SLionel Sambuc if (isprint(c))
245f7cf2976SLionel Sambuc chardef[c] = 0;
246f7cf2976SLionel Sambuc else if (iscntrl(c))
247f7cf2976SLionel Sambuc chardef[c] = IS_CONTROL_CHAR;
248f7cf2976SLionel Sambuc else
249f7cf2976SLionel Sambuc chardef[c] = IS_BINARY_CHAR|IS_CONTROL_CHAR;
250f7cf2976SLionel Sambuc }
251f7cf2976SLionel Sambuc }
252f7cf2976SLionel Sambuc #endif
253f7cf2976SLionel Sambuc
254f7cf2976SLionel Sambuc /*
255f7cf2976SLionel Sambuc * Define the printing format for control (or binary utf) chars.
256f7cf2976SLionel Sambuc */
257f7cf2976SLionel Sambuc static void
setbinfmt(s,fmtvarptr,default_fmt)258f7cf2976SLionel Sambuc setbinfmt(s, fmtvarptr, default_fmt)
259f7cf2976SLionel Sambuc char *s;
260f7cf2976SLionel Sambuc char **fmtvarptr;
261f7cf2976SLionel Sambuc char *default_fmt;
262f7cf2976SLionel Sambuc {
263f7cf2976SLionel Sambuc if (s && utf_mode)
264f7cf2976SLionel Sambuc {
265f7cf2976SLionel Sambuc /* It would be too hard to account for width otherwise. */
266f7cf2976SLionel Sambuc char *t = s;
267f7cf2976SLionel Sambuc while (*t)
268f7cf2976SLionel Sambuc {
269f7cf2976SLionel Sambuc if (*t < ' ' || *t > '~')
270f7cf2976SLionel Sambuc {
271f7cf2976SLionel Sambuc s = default_fmt;
272f7cf2976SLionel Sambuc goto attr;
273f7cf2976SLionel Sambuc }
274f7cf2976SLionel Sambuc t++;
275f7cf2976SLionel Sambuc }
276f7cf2976SLionel Sambuc }
277f7cf2976SLionel Sambuc
278f7cf2976SLionel Sambuc /* %n is evil */
279f7cf2976SLionel Sambuc if (s == NULL || *s == '\0' ||
280f7cf2976SLionel Sambuc (*s == '*' && (s[1] == '\0' || s[2] == '\0' || strchr(s + 2, 'n'))) ||
281f7cf2976SLionel Sambuc (*s != '*' && strchr(s, 'n')))
282f7cf2976SLionel Sambuc s = default_fmt;
283f7cf2976SLionel Sambuc
284f7cf2976SLionel Sambuc /*
285f7cf2976SLionel Sambuc * Select the attributes if it starts with "*".
286f7cf2976SLionel Sambuc */
287f7cf2976SLionel Sambuc attr:
288f7cf2976SLionel Sambuc if (*s == '*')
289f7cf2976SLionel Sambuc {
290f7cf2976SLionel Sambuc switch (s[1])
291f7cf2976SLionel Sambuc {
292f7cf2976SLionel Sambuc case 'd': binattr = AT_BOLD; break;
293f7cf2976SLionel Sambuc case 'k': binattr = AT_BLINK; break;
294f7cf2976SLionel Sambuc case 's': binattr = AT_STANDOUT; break;
295f7cf2976SLionel Sambuc case 'u': binattr = AT_UNDERLINE; break;
296f7cf2976SLionel Sambuc default: binattr = AT_NORMAL; break;
297f7cf2976SLionel Sambuc }
298f7cf2976SLionel Sambuc s += 2;
299f7cf2976SLionel Sambuc }
300f7cf2976SLionel Sambuc *fmtvarptr = s;
301f7cf2976SLionel Sambuc }
302f7cf2976SLionel Sambuc
303f7cf2976SLionel Sambuc /*
304f7cf2976SLionel Sambuc *
305f7cf2976SLionel Sambuc */
306f7cf2976SLionel Sambuc static void
set_charset()307f7cf2976SLionel Sambuc set_charset()
308f7cf2976SLionel Sambuc {
309f7cf2976SLionel Sambuc char *s;
310f7cf2976SLionel Sambuc
311f7cf2976SLionel Sambuc /*
312f7cf2976SLionel Sambuc * See if environment variable LESSCHARSET is defined.
313f7cf2976SLionel Sambuc */
314f7cf2976SLionel Sambuc s = lgetenv("LESSCHARSET");
315f7cf2976SLionel Sambuc if (icharset(s, 0))
316f7cf2976SLionel Sambuc return;
317f7cf2976SLionel Sambuc
318f7cf2976SLionel Sambuc /*
319f7cf2976SLionel Sambuc * LESSCHARSET is not defined: try LESSCHARDEF.
320f7cf2976SLionel Sambuc */
321f7cf2976SLionel Sambuc s = lgetenv("LESSCHARDEF");
322f7cf2976SLionel Sambuc if (s != NULL && *s != '\0')
323f7cf2976SLionel Sambuc {
324f7cf2976SLionel Sambuc ichardef(s);
325f7cf2976SLionel Sambuc return;
326f7cf2976SLionel Sambuc }
327f7cf2976SLionel Sambuc
328f7cf2976SLionel Sambuc #if HAVE_LOCALE
329f7cf2976SLionel Sambuc #ifdef CODESET
330f7cf2976SLionel Sambuc /*
331f7cf2976SLionel Sambuc * Try using the codeset name as the charset name.
332f7cf2976SLionel Sambuc */
333f7cf2976SLionel Sambuc s = nl_langinfo(CODESET);
334f7cf2976SLionel Sambuc if (icharset(s, 1))
335f7cf2976SLionel Sambuc return;
336f7cf2976SLionel Sambuc #endif
337f7cf2976SLionel Sambuc #endif
338f7cf2976SLionel Sambuc
339f7cf2976SLionel Sambuc #if HAVE_STRSTR
340f7cf2976SLionel Sambuc /*
341f7cf2976SLionel Sambuc * Check whether LC_ALL, LC_CTYPE or LANG look like UTF-8 is used.
342f7cf2976SLionel Sambuc */
343f7cf2976SLionel Sambuc if ((s = lgetenv("LC_ALL")) != NULL ||
344f7cf2976SLionel Sambuc (s = lgetenv("LC_CTYPE")) != NULL ||
345f7cf2976SLionel Sambuc (s = lgetenv("LANG")) != NULL)
346f7cf2976SLionel Sambuc {
347f7cf2976SLionel Sambuc if ( strstr(s, "UTF-8") != NULL || strstr(s, "utf-8") != NULL
348f7cf2976SLionel Sambuc || strstr(s, "UTF8") != NULL || strstr(s, "utf8") != NULL)
349f7cf2976SLionel Sambuc if (icharset("utf-8", 1))
350f7cf2976SLionel Sambuc return;
351f7cf2976SLionel Sambuc }
352f7cf2976SLionel Sambuc #endif
353f7cf2976SLionel Sambuc
354f7cf2976SLionel Sambuc #if HAVE_LOCALE
355f7cf2976SLionel Sambuc /*
356f7cf2976SLionel Sambuc * Get character definitions from locale functions,
357f7cf2976SLionel Sambuc * rather than from predefined charset entry.
358f7cf2976SLionel Sambuc */
359f7cf2976SLionel Sambuc ilocale();
360f7cf2976SLionel Sambuc #if MSDOS_COMPILER
361f7cf2976SLionel Sambuc /*
362f7cf2976SLionel Sambuc * Default to "dos".
363f7cf2976SLionel Sambuc */
364f7cf2976SLionel Sambuc (void) icharset("dos", 1);
365f7cf2976SLionel Sambuc #else
366f7cf2976SLionel Sambuc /*
367f7cf2976SLionel Sambuc * Default to "latin1".
368f7cf2976SLionel Sambuc */
369f7cf2976SLionel Sambuc (void) icharset("latin1", 1);
370f7cf2976SLionel Sambuc #endif
371f7cf2976SLionel Sambuc #endif
372f7cf2976SLionel Sambuc }
373f7cf2976SLionel Sambuc
374f7cf2976SLionel Sambuc /*
375f7cf2976SLionel Sambuc * Initialize charset data structures.
376f7cf2976SLionel Sambuc */
377f7cf2976SLionel Sambuc public void
init_charset()378f7cf2976SLionel Sambuc init_charset()
379f7cf2976SLionel Sambuc {
380f7cf2976SLionel Sambuc char *s;
381f7cf2976SLionel Sambuc
382f7cf2976SLionel Sambuc #if HAVE_LOCALE
383f7cf2976SLionel Sambuc setlocale(LC_ALL, "");
384f7cf2976SLionel Sambuc #endif
385f7cf2976SLionel Sambuc
386f7cf2976SLionel Sambuc set_charset();
387f7cf2976SLionel Sambuc
388f7cf2976SLionel Sambuc s = lgetenv("LESSBINFMT");
389f7cf2976SLionel Sambuc setbinfmt(s, &binfmt, "*s<%02X>");
390f7cf2976SLionel Sambuc
391f7cf2976SLionel Sambuc s = lgetenv("LESSUTFBINFMT");
392f7cf2976SLionel Sambuc setbinfmt(s, &utfbinfmt, "<U+%04lX>");
393f7cf2976SLionel Sambuc }
394f7cf2976SLionel Sambuc
395f7cf2976SLionel Sambuc /*
396f7cf2976SLionel Sambuc * Is a given character a "binary" character?
397f7cf2976SLionel Sambuc */
398f7cf2976SLionel Sambuc public int
binary_char(c)399f7cf2976SLionel Sambuc binary_char(c)
400f7cf2976SLionel Sambuc LWCHAR c;
401f7cf2976SLionel Sambuc {
402f7cf2976SLionel Sambuc if (utf_mode)
403f7cf2976SLionel Sambuc return (is_ubin_char(c));
404f7cf2976SLionel Sambuc c &= 0377;
405f7cf2976SLionel Sambuc return (chardef[c] & IS_BINARY_CHAR);
406f7cf2976SLionel Sambuc }
407f7cf2976SLionel Sambuc
408f7cf2976SLionel Sambuc /*
409f7cf2976SLionel Sambuc * Is a given character a "control" character?
410f7cf2976SLionel Sambuc */
411f7cf2976SLionel Sambuc public int
control_char(c)412f7cf2976SLionel Sambuc control_char(c)
413f7cf2976SLionel Sambuc LWCHAR c;
414f7cf2976SLionel Sambuc {
415f7cf2976SLionel Sambuc c &= 0377;
416f7cf2976SLionel Sambuc return (chardef[c] & IS_CONTROL_CHAR);
417f7cf2976SLionel Sambuc }
418f7cf2976SLionel Sambuc
419f7cf2976SLionel Sambuc /*
420f7cf2976SLionel Sambuc * Return the printable form of a character.
421f7cf2976SLionel Sambuc * For example, in the "ascii" charset '\3' is printed as "^C".
422f7cf2976SLionel Sambuc */
423f7cf2976SLionel Sambuc public char *
prchar(c)424f7cf2976SLionel Sambuc prchar(c)
425f7cf2976SLionel Sambuc LWCHAR c;
426f7cf2976SLionel Sambuc {
427f7cf2976SLionel Sambuc /* {{ This buffer can be overrun if LESSBINFMT is a long string. }} */
428f7cf2976SLionel Sambuc static char buf[32];
429f7cf2976SLionel Sambuc
430f7cf2976SLionel Sambuc c &= 0377;
431f7cf2976SLionel Sambuc if ((c < 128 || !utf_mode) && !control_char(c))
432f7cf2976SLionel Sambuc SNPRINTF1(buf, sizeof(buf), "%c", (int) c);
433f7cf2976SLionel Sambuc else if (c == ESC)
434f7cf2976SLionel Sambuc strcpy(buf, "ESC");
435f7cf2976SLionel Sambuc #if IS_EBCDIC_HOST
436f7cf2976SLionel Sambuc else if (!binary_char(c) && c < 64)
437f7cf2976SLionel Sambuc SNPRINTF1(buf, sizeof(buf), "^%c",
438f7cf2976SLionel Sambuc /*
439f7cf2976SLionel Sambuc * This array roughly inverts CONTROL() #defined in less.h,
440f7cf2976SLionel Sambuc * and should be kept in sync with CONTROL() and IBM-1047.
441f7cf2976SLionel Sambuc */
442f7cf2976SLionel Sambuc "@ABC.I.?...KLMNO"
443f7cf2976SLionel Sambuc "PQRS.JH.XY.."
444f7cf2976SLionel Sambuc "\\]^_"
445f7cf2976SLionel Sambuc "......W[.....EFG"
446f7cf2976SLionel Sambuc "..V....D....TU.Z"[c]);
447f7cf2976SLionel Sambuc #else
448f7cf2976SLionel Sambuc else if (c < 128 && !control_char(c ^ 0100))
449f7cf2976SLionel Sambuc SNPRINTF1(buf, sizeof(buf), "^%c", (int) (c ^ 0100));
450f7cf2976SLionel Sambuc #endif
451f7cf2976SLionel Sambuc else
452f7cf2976SLionel Sambuc SNPRINTF1(buf, sizeof(buf), binfmt, c);
453f7cf2976SLionel Sambuc return (buf);
454f7cf2976SLionel Sambuc }
455f7cf2976SLionel Sambuc
456f7cf2976SLionel Sambuc /*
457f7cf2976SLionel Sambuc * Return the printable form of a UTF-8 character.
458f7cf2976SLionel Sambuc */
459f7cf2976SLionel Sambuc public char *
prutfchar(ch)460f7cf2976SLionel Sambuc prutfchar(ch)
461f7cf2976SLionel Sambuc LWCHAR ch;
462f7cf2976SLionel Sambuc {
463f7cf2976SLionel Sambuc static char buf[32];
464f7cf2976SLionel Sambuc
465f7cf2976SLionel Sambuc if (ch == ESC)
466f7cf2976SLionel Sambuc strcpy(buf, "ESC");
467f7cf2976SLionel Sambuc else if (ch < 128 && control_char(ch))
468f7cf2976SLionel Sambuc {
469f7cf2976SLionel Sambuc if (!control_char(ch ^ 0100))
470f7cf2976SLionel Sambuc SNPRINTF1(buf, sizeof(buf), "^%c", ((char) ch) ^ 0100);
471f7cf2976SLionel Sambuc else
472f7cf2976SLionel Sambuc SNPRINTF1(buf, sizeof(buf), binfmt, (char) ch);
473f7cf2976SLionel Sambuc } else if (is_ubin_char(ch))
474f7cf2976SLionel Sambuc SNPRINTF1(buf, sizeof(buf), utfbinfmt, ch);
475f7cf2976SLionel Sambuc else
476f7cf2976SLionel Sambuc {
477f7cf2976SLionel Sambuc int len;
478f7cf2976SLionel Sambuc if (ch >= 0x80000000)
479f7cf2976SLionel Sambuc {
480f7cf2976SLionel Sambuc len = 3;
481f7cf2976SLionel Sambuc ch = 0xFFFD;
482f7cf2976SLionel Sambuc } else
483f7cf2976SLionel Sambuc {
484f7cf2976SLionel Sambuc len = (ch < 0x80) ? 1
485f7cf2976SLionel Sambuc : (ch < 0x800) ? 2
486f7cf2976SLionel Sambuc : (ch < 0x10000) ? 3
487f7cf2976SLionel Sambuc : (ch < 0x200000) ? 4
488f7cf2976SLionel Sambuc : (ch < 0x4000000) ? 5
489f7cf2976SLionel Sambuc : 6;
490f7cf2976SLionel Sambuc }
491f7cf2976SLionel Sambuc buf[len] = '\0';
492f7cf2976SLionel Sambuc if (len == 1)
493f7cf2976SLionel Sambuc *buf = (char) ch;
494f7cf2976SLionel Sambuc else
495f7cf2976SLionel Sambuc {
496f7cf2976SLionel Sambuc *buf = ((1 << len) - 1) << (8 - len);
497f7cf2976SLionel Sambuc while (--len > 0)
498f7cf2976SLionel Sambuc {
499f7cf2976SLionel Sambuc buf[len] = (char) (0x80 | (ch & 0x3F));
500f7cf2976SLionel Sambuc ch >>= 6;
501f7cf2976SLionel Sambuc }
502f7cf2976SLionel Sambuc *buf |= ch;
503f7cf2976SLionel Sambuc }
504f7cf2976SLionel Sambuc }
505f7cf2976SLionel Sambuc return (buf);
506f7cf2976SLionel Sambuc }
507f7cf2976SLionel Sambuc
508f7cf2976SLionel Sambuc /*
509f7cf2976SLionel Sambuc * Get the length of a UTF-8 character in bytes.
510f7cf2976SLionel Sambuc */
511f7cf2976SLionel Sambuc public int
utf_len(ch)512f7cf2976SLionel Sambuc utf_len(ch)
513f7cf2976SLionel Sambuc char ch;
514f7cf2976SLionel Sambuc {
515f7cf2976SLionel Sambuc if ((ch & 0x80) == 0)
516f7cf2976SLionel Sambuc return 1;
517f7cf2976SLionel Sambuc if ((ch & 0xE0) == 0xC0)
518f7cf2976SLionel Sambuc return 2;
519f7cf2976SLionel Sambuc if ((ch & 0xF0) == 0xE0)
520f7cf2976SLionel Sambuc return 3;
521f7cf2976SLionel Sambuc if ((ch & 0xF8) == 0xF0)
522f7cf2976SLionel Sambuc return 4;
523f7cf2976SLionel Sambuc if ((ch & 0xFC) == 0xF8)
524f7cf2976SLionel Sambuc return 5;
525f7cf2976SLionel Sambuc if ((ch & 0xFE) == 0xFC)
526f7cf2976SLionel Sambuc return 6;
527f7cf2976SLionel Sambuc /* Invalid UTF-8 encoding. */
528f7cf2976SLionel Sambuc return 1;
529f7cf2976SLionel Sambuc }
530f7cf2976SLionel Sambuc
531f7cf2976SLionel Sambuc /*
532f7cf2976SLionel Sambuc * Is a UTF-8 character well-formed?
533f7cf2976SLionel Sambuc */
534f7cf2976SLionel Sambuc public int
is_utf8_well_formed(s)535f7cf2976SLionel Sambuc is_utf8_well_formed(s)
536f7cf2976SLionel Sambuc unsigned char *s;
537f7cf2976SLionel Sambuc {
538f7cf2976SLionel Sambuc int i;
539f7cf2976SLionel Sambuc int len;
540f7cf2976SLionel Sambuc
541f7cf2976SLionel Sambuc if (IS_UTF8_INVALID(s[0]))
542f7cf2976SLionel Sambuc return (0);
543f7cf2976SLionel Sambuc
544f7cf2976SLionel Sambuc len = utf_len((char) s[0]);
545f7cf2976SLionel Sambuc if (len == 1)
546f7cf2976SLionel Sambuc return (1);
547f7cf2976SLionel Sambuc if (len == 2)
548f7cf2976SLionel Sambuc {
549f7cf2976SLionel Sambuc if (s[0] < 0xC2)
550f7cf2976SLionel Sambuc return (0);
551f7cf2976SLionel Sambuc } else
552f7cf2976SLionel Sambuc {
553f7cf2976SLionel Sambuc unsigned char mask;
554f7cf2976SLionel Sambuc mask = (~((1 << (8-len)) - 1)) & 0xFF;
555f7cf2976SLionel Sambuc if (s[0] == mask && (s[1] & mask) == 0x80)
556f7cf2976SLionel Sambuc return (0);
557f7cf2976SLionel Sambuc }
558f7cf2976SLionel Sambuc
559f7cf2976SLionel Sambuc for (i = 1; i < len; i++)
560f7cf2976SLionel Sambuc if (!IS_UTF8_TRAIL(s[i]))
561f7cf2976SLionel Sambuc return (0);
562f7cf2976SLionel Sambuc return (1);
563f7cf2976SLionel Sambuc }
564f7cf2976SLionel Sambuc
565f7cf2976SLionel Sambuc /*
566f7cf2976SLionel Sambuc * Get the value of a UTF-8 character.
567f7cf2976SLionel Sambuc */
568f7cf2976SLionel Sambuc public LWCHAR
get_wchar(p)569f7cf2976SLionel Sambuc get_wchar(p)
570f7cf2976SLionel Sambuc char *p;
571f7cf2976SLionel Sambuc {
572f7cf2976SLionel Sambuc switch (utf_len(p[0]))
573f7cf2976SLionel Sambuc {
574f7cf2976SLionel Sambuc case 1:
575f7cf2976SLionel Sambuc default:
576f7cf2976SLionel Sambuc /* 0xxxxxxx */
577f7cf2976SLionel Sambuc return (LWCHAR)
578f7cf2976SLionel Sambuc (p[0] & 0xFF);
579f7cf2976SLionel Sambuc case 2:
580f7cf2976SLionel Sambuc /* 110xxxxx 10xxxxxx */
581f7cf2976SLionel Sambuc return (LWCHAR) (
582f7cf2976SLionel Sambuc ((p[0] & 0x1F) << 6) |
583f7cf2976SLionel Sambuc (p[1] & 0x3F));
584f7cf2976SLionel Sambuc case 3:
585f7cf2976SLionel Sambuc /* 1110xxxx 10xxxxxx 10xxxxxx */
586f7cf2976SLionel Sambuc return (LWCHAR) (
587f7cf2976SLionel Sambuc ((p[0] & 0x0F) << 12) |
588f7cf2976SLionel Sambuc ((p[1] & 0x3F) << 6) |
589f7cf2976SLionel Sambuc (p[2] & 0x3F));
590f7cf2976SLionel Sambuc case 4:
591f7cf2976SLionel Sambuc /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
592f7cf2976SLionel Sambuc return (LWCHAR) (
593f7cf2976SLionel Sambuc ((p[0] & 0x07) << 18) |
594f7cf2976SLionel Sambuc ((p[1] & 0x3F) << 12) |
595f7cf2976SLionel Sambuc ((p[2] & 0x3F) << 6) |
596f7cf2976SLionel Sambuc (p[3] & 0x3F));
597f7cf2976SLionel Sambuc case 5:
598f7cf2976SLionel Sambuc /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
599f7cf2976SLionel Sambuc return (LWCHAR) (
600f7cf2976SLionel Sambuc ((p[0] & 0x03) << 24) |
601f7cf2976SLionel Sambuc ((p[1] & 0x3F) << 18) |
602f7cf2976SLionel Sambuc ((p[2] & 0x3F) << 12) |
603f7cf2976SLionel Sambuc ((p[3] & 0x3F) << 6) |
604f7cf2976SLionel Sambuc (p[4] & 0x3F));
605f7cf2976SLionel Sambuc case 6:
606f7cf2976SLionel Sambuc /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
607f7cf2976SLionel Sambuc return (LWCHAR) (
608f7cf2976SLionel Sambuc ((p[0] & 0x01) << 30) |
609f7cf2976SLionel Sambuc ((p[1] & 0x3F) << 24) |
610f7cf2976SLionel Sambuc ((p[2] & 0x3F) << 18) |
611f7cf2976SLionel Sambuc ((p[3] & 0x3F) << 12) |
612f7cf2976SLionel Sambuc ((p[4] & 0x3F) << 6) |
613f7cf2976SLionel Sambuc (p[5] & 0x3F));
614f7cf2976SLionel Sambuc }
615f7cf2976SLionel Sambuc }
616f7cf2976SLionel Sambuc
617f7cf2976SLionel Sambuc /*
618f7cf2976SLionel Sambuc * Store a character into a UTF-8 string.
619f7cf2976SLionel Sambuc */
620f7cf2976SLionel Sambuc public void
put_wchar(pp,ch)621f7cf2976SLionel Sambuc put_wchar(pp, ch)
622f7cf2976SLionel Sambuc char **pp;
623f7cf2976SLionel Sambuc LWCHAR ch;
624f7cf2976SLionel Sambuc {
625f7cf2976SLionel Sambuc if (!utf_mode || ch < 0x80)
626f7cf2976SLionel Sambuc {
627f7cf2976SLionel Sambuc /* 0xxxxxxx */
628f7cf2976SLionel Sambuc *(*pp)++ = (char) ch;
629f7cf2976SLionel Sambuc } else if (ch < 0x800)
630f7cf2976SLionel Sambuc {
631f7cf2976SLionel Sambuc /* 110xxxxx 10xxxxxx */
632f7cf2976SLionel Sambuc *(*pp)++ = (char) (0xC0 | ((ch >> 6) & 0x1F));
633f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | (ch & 0x3F));
634f7cf2976SLionel Sambuc } else if (ch < 0x10000)
635f7cf2976SLionel Sambuc {
636f7cf2976SLionel Sambuc /* 1110xxxx 10xxxxxx 10xxxxxx */
637f7cf2976SLionel Sambuc *(*pp)++ = (char) (0xE0 | ((ch >> 12) & 0x0F));
638f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F));
639f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | (ch & 0x3F));
640f7cf2976SLionel Sambuc } else if (ch < 0x200000)
641f7cf2976SLionel Sambuc {
642f7cf2976SLionel Sambuc /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
643f7cf2976SLionel Sambuc *(*pp)++ = (char) (0xF0 | ((ch >> 18) & 0x07));
644f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F));
645f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F));
646f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | (ch & 0x3F));
647f7cf2976SLionel Sambuc } else if (ch < 0x4000000)
648f7cf2976SLionel Sambuc {
649f7cf2976SLionel Sambuc /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
650f7cf2976SLionel Sambuc *(*pp)++ = (char) (0xF0 | ((ch >> 24) & 0x03));
651f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F));
652f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F));
653f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F));
654f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | (ch & 0x3F));
655f7cf2976SLionel Sambuc } else
656f7cf2976SLionel Sambuc {
657f7cf2976SLionel Sambuc /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
658f7cf2976SLionel Sambuc *(*pp)++ = (char) (0xF0 | ((ch >> 30) & 0x01));
659f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 24) & 0x3F));
660f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F));
661f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F));
662f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F));
663f7cf2976SLionel Sambuc *(*pp)++ = (char) (0x80 | (ch & 0x3F));
664f7cf2976SLionel Sambuc }
665f7cf2976SLionel Sambuc }
666f7cf2976SLionel Sambuc
667f7cf2976SLionel Sambuc /*
668f7cf2976SLionel Sambuc * Step forward or backward one character in a string.
669f7cf2976SLionel Sambuc */
670f7cf2976SLionel Sambuc public LWCHAR
step_char(pp,dir,limit)671f7cf2976SLionel Sambuc step_char(pp, dir, limit)
672f7cf2976SLionel Sambuc char **pp;
673f7cf2976SLionel Sambuc signed int dir;
674f7cf2976SLionel Sambuc char *limit;
675f7cf2976SLionel Sambuc {
676f7cf2976SLionel Sambuc LWCHAR ch;
677f7cf2976SLionel Sambuc int len;
678f7cf2976SLionel Sambuc char *p = *pp;
679f7cf2976SLionel Sambuc
680f7cf2976SLionel Sambuc if (!utf_mode)
681f7cf2976SLionel Sambuc {
682f7cf2976SLionel Sambuc /* It's easy if chars are one byte. */
683f7cf2976SLionel Sambuc if (dir > 0)
684f7cf2976SLionel Sambuc ch = (LWCHAR) ((p < limit) ? *p++ : 0);
685f7cf2976SLionel Sambuc else
686f7cf2976SLionel Sambuc ch = (LWCHAR) ((p > limit) ? *--p : 0);
687f7cf2976SLionel Sambuc } else if (dir > 0)
688f7cf2976SLionel Sambuc {
689f7cf2976SLionel Sambuc len = utf_len(*p);
690f7cf2976SLionel Sambuc if (p + len > limit)
691f7cf2976SLionel Sambuc {
692f7cf2976SLionel Sambuc ch = 0;
693f7cf2976SLionel Sambuc p = limit;
694f7cf2976SLionel Sambuc } else
695f7cf2976SLionel Sambuc {
696f7cf2976SLionel Sambuc ch = get_wchar(p);
697f7cf2976SLionel Sambuc p += len;
698f7cf2976SLionel Sambuc }
699f7cf2976SLionel Sambuc } else
700f7cf2976SLionel Sambuc {
701f7cf2976SLionel Sambuc while (p > limit && IS_UTF8_TRAIL(p[-1]))
702f7cf2976SLionel Sambuc p--;
703f7cf2976SLionel Sambuc if (p > limit)
704f7cf2976SLionel Sambuc ch = get_wchar(--p);
705f7cf2976SLionel Sambuc else
706f7cf2976SLionel Sambuc ch = 0;
707f7cf2976SLionel Sambuc }
708f7cf2976SLionel Sambuc *pp = p;
709f7cf2976SLionel Sambuc return ch;
710f7cf2976SLionel Sambuc }
711f7cf2976SLionel Sambuc
712f7cf2976SLionel Sambuc /*
713f7cf2976SLionel Sambuc * Unicode characters data
714f7cf2976SLionel Sambuc */
715f7cf2976SLionel Sambuc struct wchar_range { LWCHAR first, last; };
716f7cf2976SLionel Sambuc
717f7cf2976SLionel Sambuc /*
718f7cf2976SLionel Sambuc * Characters with general category values
719f7cf2976SLionel Sambuc * Mn: Mark, Nonspacing
720f7cf2976SLionel Sambuc * Me: Mark, Enclosing
721f7cf2976SLionel Sambuc * Last synched with
722f7cf2976SLionel Sambuc * <http://www.unicode.org/Public/5.0.0/ucd/UnicodeData-5.0.0d7.txt>
723f7cf2976SLionel Sambuc * dated 2005-11-30T00:58:48Z
724f7cf2976SLionel Sambuc */
725f7cf2976SLionel Sambuc static struct wchar_range comp_table[] = {
726f7cf2976SLionel Sambuc { 0x0300, 0x036F} /* Mn */, { 0x0483, 0x0486} /* Mn */,
727f7cf2976SLionel Sambuc { 0x0488, 0x0489} /* Me */,
728f7cf2976SLionel Sambuc { 0x0591, 0x05BD} /* Mn */, { 0x05BF, 0x05BF} /* Mn */,
729f7cf2976SLionel Sambuc { 0x05C1, 0x05C2} /* Mn */, { 0x05C4, 0x05C5} /* Mn */,
730f7cf2976SLionel Sambuc { 0x05C7, 0x05C7} /* Mn */, { 0x0610, 0x0615} /* Mn */,
731f7cf2976SLionel Sambuc { 0x064B, 0x065E} /* Mn */, { 0x0670, 0x0670} /* Mn */,
732f7cf2976SLionel Sambuc { 0x06D6, 0x06DC} /* Mn */,
733f7cf2976SLionel Sambuc { 0x06DE, 0x06DE} /* Me */,
734f7cf2976SLionel Sambuc { 0x06DF, 0x06E4} /* Mn */, { 0x06E7, 0x06E8} /* Mn */,
735f7cf2976SLionel Sambuc { 0x06EA, 0x06ED} /* Mn */, { 0x0711, 0x0711} /* Mn */,
736f7cf2976SLionel Sambuc { 0x0730, 0x074A} /* Mn */, { 0x07A6, 0x07B0} /* Mn */,
737f7cf2976SLionel Sambuc { 0x07EB, 0x07F3} /* Mn */, { 0x0901, 0x0902} /* Mn */,
738f7cf2976SLionel Sambuc { 0x093C, 0x093C} /* Mn */, { 0x0941, 0x0948} /* Mn */,
739f7cf2976SLionel Sambuc { 0x094D, 0x094D} /* Mn */, { 0x0951, 0x0954} /* Mn */,
740f7cf2976SLionel Sambuc { 0x0962, 0x0963} /* Mn */, { 0x0981, 0x0981} /* Mn */,
741f7cf2976SLionel Sambuc { 0x09BC, 0x09BC} /* Mn */, { 0x09C1, 0x09C4} /* Mn */,
742f7cf2976SLionel Sambuc { 0x09CD, 0x09CD} /* Mn */, { 0x09E2, 0x09E3} /* Mn */,
743f7cf2976SLionel Sambuc { 0x0A01, 0x0A02} /* Mn */, { 0x0A3C, 0x0A3C} /* Mn */,
744f7cf2976SLionel Sambuc { 0x0A41, 0x0A42} /* Mn */, { 0x0A47, 0x0A48} /* Mn */,
745f7cf2976SLionel Sambuc { 0x0A4B, 0x0A4D} /* Mn */, { 0x0A70, 0x0A71} /* Mn */,
746f7cf2976SLionel Sambuc { 0x0A81, 0x0A82} /* Mn */, { 0x0ABC, 0x0ABC} /* Mn */,
747f7cf2976SLionel Sambuc { 0x0AC1, 0x0AC5} /* Mn */, { 0x0AC7, 0x0AC8} /* Mn */,
748f7cf2976SLionel Sambuc { 0x0ACD, 0x0ACD} /* Mn */, { 0x0AE2, 0x0AE3} /* Mn */,
749f7cf2976SLionel Sambuc { 0x0B01, 0x0B01} /* Mn */, { 0x0B3C, 0x0B3C} /* Mn */,
750f7cf2976SLionel Sambuc { 0x0B3F, 0x0B3F} /* Mn */, { 0x0B41, 0x0B43} /* Mn */,
751f7cf2976SLionel Sambuc { 0x0B4D, 0x0B4D} /* Mn */, { 0x0B56, 0x0B56} /* Mn */,
752f7cf2976SLionel Sambuc { 0x0B82, 0x0B82} /* Mn */, { 0x0BC0, 0x0BC0} /* Mn */,
753f7cf2976SLionel Sambuc { 0x0BCD, 0x0BCD} /* Mn */, { 0x0C3E, 0x0C40} /* Mn */,
754f7cf2976SLionel Sambuc { 0x0C46, 0x0C48} /* Mn */, { 0x0C4A, 0x0C4D} /* Mn */,
755f7cf2976SLionel Sambuc { 0x0C55, 0x0C56} /* Mn */, { 0x0CBC, 0x0CBC} /* Mn */,
756f7cf2976SLionel Sambuc { 0x0CBF, 0x0CBF} /* Mn */, { 0x0CC6, 0x0CC6} /* Mn */,
757f7cf2976SLionel Sambuc { 0x0CCC, 0x0CCD} /* Mn */, { 0x0CE2, 0x0CE3} /* Mn */,
758f7cf2976SLionel Sambuc { 0x0D41, 0x0D43} /* Mn */, { 0x0D4D, 0x0D4D} /* Mn */,
759f7cf2976SLionel Sambuc { 0x0DCA, 0x0DCA} /* Mn */, { 0x0DD2, 0x0DD4} /* Mn */,
760f7cf2976SLionel Sambuc { 0x0DD6, 0x0DD6} /* Mn */, { 0x0E31, 0x0E31} /* Mn */,
761f7cf2976SLionel Sambuc { 0x0E34, 0x0E3A} /* Mn */, { 0x0E47, 0x0E4E} /* Mn */,
762f7cf2976SLionel Sambuc { 0x0EB1, 0x0EB1} /* Mn */, { 0x0EB4, 0x0EB9} /* Mn */,
763f7cf2976SLionel Sambuc { 0x0EBB, 0x0EBC} /* Mn */, { 0x0EC8, 0x0ECD} /* Mn */,
764f7cf2976SLionel Sambuc { 0x0F18, 0x0F19} /* Mn */, { 0x0F35, 0x0F35} /* Mn */,
765f7cf2976SLionel Sambuc { 0x0F37, 0x0F37} /* Mn */, { 0x0F39, 0x0F39} /* Mn */,
766f7cf2976SLionel Sambuc { 0x0F71, 0x0F7E} /* Mn */, { 0x0F80, 0x0F84} /* Mn */,
767f7cf2976SLionel Sambuc { 0x0F86, 0x0F87} /* Mn */, { 0x0F90, 0x0F97} /* Mn */,
768f7cf2976SLionel Sambuc { 0x0F99, 0x0FBC} /* Mn */, { 0x0FC6, 0x0FC6} /* Mn */,
769f7cf2976SLionel Sambuc { 0x102D, 0x1030} /* Mn */, { 0x1032, 0x1032} /* Mn */,
770f7cf2976SLionel Sambuc { 0x1036, 0x1037} /* Mn */, { 0x1039, 0x1039} /* Mn */,
771f7cf2976SLionel Sambuc { 0x1058, 0x1059} /* Mn */, { 0x135F, 0x135F} /* Mn */,
772f7cf2976SLionel Sambuc { 0x1712, 0x1714} /* Mn */, { 0x1732, 0x1734} /* Mn */,
773f7cf2976SLionel Sambuc { 0x1752, 0x1753} /* Mn */, { 0x1772, 0x1773} /* Mn */,
774f7cf2976SLionel Sambuc { 0x17B7, 0x17BD} /* Mn */, { 0x17C6, 0x17C6} /* Mn */,
775f7cf2976SLionel Sambuc { 0x17C9, 0x17D3} /* Mn */, { 0x17DD, 0x17DD} /* Mn */,
776f7cf2976SLionel Sambuc { 0x180B, 0x180D} /* Mn */, { 0x18A9, 0x18A9} /* Mn */,
777f7cf2976SLionel Sambuc { 0x1920, 0x1922} /* Mn */, { 0x1927, 0x1928} /* Mn */,
778f7cf2976SLionel Sambuc { 0x1932, 0x1932} /* Mn */, { 0x1939, 0x193B} /* Mn */,
779f7cf2976SLionel Sambuc { 0x1A17, 0x1A18} /* Mn */, { 0x1B00, 0x1B03} /* Mn */,
780f7cf2976SLionel Sambuc { 0x1B34, 0x1B34} /* Mn */, { 0x1B36, 0x1B3A} /* Mn */,
781f7cf2976SLionel Sambuc { 0x1B3C, 0x1B3C} /* Mn */, { 0x1B42, 0x1B42} /* Mn */,
782f7cf2976SLionel Sambuc { 0x1B6B, 0x1B73} /* Mn */, { 0x1DC0, 0x1DCA} /* Mn */,
783f7cf2976SLionel Sambuc { 0x1DFE, 0x1DFF} /* Mn */, { 0x20D0, 0x20DC} /* Mn */,
784f7cf2976SLionel Sambuc { 0x20DD, 0x20E0} /* Me */,
785f7cf2976SLionel Sambuc { 0x20E1, 0x20E1} /* Mn */,
786f7cf2976SLionel Sambuc { 0x20E2, 0x20E4} /* Me */,
787f7cf2976SLionel Sambuc { 0x20E5, 0x20EF} /* Mn */, { 0x302A, 0x302F} /* Mn */,
788f7cf2976SLionel Sambuc { 0x3099, 0x309A} /* Mn */, { 0xA806, 0xA806} /* Mn */,
789f7cf2976SLionel Sambuc { 0xA80B, 0xA80B} /* Mn */, { 0xA825, 0xA826} /* Mn */,
790f7cf2976SLionel Sambuc { 0xFB1E, 0xFB1E} /* Mn */, { 0xFE00, 0xFE0F} /* Mn */,
791f7cf2976SLionel Sambuc { 0xFE20, 0xFE23} /* Mn */, { 0x10A01, 0x10A03} /* Mn */,
792f7cf2976SLionel Sambuc { 0x10A05, 0x10A06} /* Mn */, { 0x10A0C, 0x10A0F} /* Mn */,
793f7cf2976SLionel Sambuc { 0x10A38, 0x10A3A} /* Mn */, { 0x10A3F, 0x10A3F} /* Mn */,
794f7cf2976SLionel Sambuc { 0x1D167, 0x1D169} /* Mn */, { 0x1D17B, 0x1D182} /* Mn */,
795f7cf2976SLionel Sambuc { 0x1D185, 0x1D18B} /* Mn */, { 0x1D1AA, 0x1D1AD} /* Mn */,
796f7cf2976SLionel Sambuc { 0x1D242, 0x1D244} /* Mn */, { 0xE0100, 0xE01EF} /* Mn */,
797f7cf2976SLionel Sambuc };
798f7cf2976SLionel Sambuc
799f7cf2976SLionel Sambuc /*
800f7cf2976SLionel Sambuc * Special pairs, not ranges.
801f7cf2976SLionel Sambuc */
802f7cf2976SLionel Sambuc static struct wchar_range comb_table[] = {
803f7cf2976SLionel Sambuc {0x0644,0x0622}, {0x0644,0x0623}, {0x0644,0x0625}, {0x0644,0x0627},
804f7cf2976SLionel Sambuc };
805f7cf2976SLionel Sambuc
806f7cf2976SLionel Sambuc /*
807f7cf2976SLionel Sambuc * Characters with general category values
808f7cf2976SLionel Sambuc * Cc: Other, Control
809f7cf2976SLionel Sambuc * Cf: Other, Format
810f7cf2976SLionel Sambuc * Cs: Other, Surrogate
811f7cf2976SLionel Sambuc * Co: Other, Private Use
812f7cf2976SLionel Sambuc * Cn: Other, Not Assigned
813f7cf2976SLionel Sambuc * Zl: Separator, Line
814f7cf2976SLionel Sambuc * Zp: Separator, Paragraph
815f7cf2976SLionel Sambuc * Last synched with
816f7cf2976SLionel Sambuc * <http://www.unicode.org/Public/5.0.0/ucd/UnicodeData-5.0.0d7.txt>
817f7cf2976SLionel Sambuc * dated 2005-11-30T00:58:48Z
818f7cf2976SLionel Sambuc */
819f7cf2976SLionel Sambuc static struct wchar_range ubin_table[] = {
820f7cf2976SLionel Sambuc { 0x0000, 0x0007} /* Cc */,
821f7cf2976SLionel Sambuc { 0x000B, 0x000C} /* Cc */,
822f7cf2976SLionel Sambuc { 0x000E, 0x001A} /* Cc */,
823f7cf2976SLionel Sambuc { 0x001C, 0x001F} /* Cc */,
824f7cf2976SLionel Sambuc { 0x007F, 0x009F} /* Cc */,
825f7cf2976SLionel Sambuc #if 0
826f7cf2976SLionel Sambuc { 0x00AD, 0x00AD} /* Cf */,
827f7cf2976SLionel Sambuc #endif
828f7cf2976SLionel Sambuc { 0x0370, 0x0373} /* Cn */, { 0x0376, 0x0379} /* Cn */,
829f7cf2976SLionel Sambuc { 0x037F, 0x0383} /* Cn */, { 0x038B, 0x038B} /* Cn */,
830f7cf2976SLionel Sambuc { 0x038D, 0x038D} /* Cn */, { 0x03A2, 0x03A2} /* Cn */,
831f7cf2976SLionel Sambuc { 0x03CF, 0x03CF} /* Cn */, { 0x0487, 0x0487} /* Cn */,
832f7cf2976SLionel Sambuc { 0x0514, 0x0530} /* Cn */, { 0x0557, 0x0558} /* Cn */,
833f7cf2976SLionel Sambuc { 0x0560, 0x0560} /* Cn */, { 0x0588, 0x0588} /* Cn */,
834f7cf2976SLionel Sambuc { 0x058B, 0x0590} /* Cn */, { 0x05C8, 0x05CF} /* Cn */,
835f7cf2976SLionel Sambuc { 0x05EB, 0x05EF} /* Cn */, { 0x05F5, 0x05FF} /* Cn */,
836f7cf2976SLionel Sambuc #if 0
837f7cf2976SLionel Sambuc { 0x0600, 0x0603} /* Cf */,
838f7cf2976SLionel Sambuc #endif
839f7cf2976SLionel Sambuc { 0x0604, 0x060A} /* Cn */, { 0x0616, 0x061A} /* Cn */,
840f7cf2976SLionel Sambuc { 0x061C, 0x061D} /* Cn */, { 0x0620, 0x0620} /* Cn */,
841f7cf2976SLionel Sambuc { 0x063B, 0x063F} /* Cn */, { 0x065F, 0x065F} /* Cn */,
842f7cf2976SLionel Sambuc #if 0
843f7cf2976SLionel Sambuc { 0x06DD, 0x06DD} /* Cf */,
844f7cf2976SLionel Sambuc #endif
845f7cf2976SLionel Sambuc { 0x070E, 0x070E} /* Cn */,
846f7cf2976SLionel Sambuc #if 0
847f7cf2976SLionel Sambuc { 0x070F, 0x070F} /* Cf */,
848f7cf2976SLionel Sambuc #endif
849f7cf2976SLionel Sambuc { 0x074B, 0x074C} /* Cn */, { 0x076E, 0x077F} /* Cn */,
850f7cf2976SLionel Sambuc { 0x07B2, 0x07BF} /* Cn */, { 0x07FB, 0x0900} /* Cn */,
851f7cf2976SLionel Sambuc { 0x093A, 0x093B} /* Cn */, { 0x094E, 0x094F} /* Cn */,
852f7cf2976SLionel Sambuc { 0x0955, 0x0957} /* Cn */, { 0x0971, 0x097A} /* Cn */,
853f7cf2976SLionel Sambuc { 0x0980, 0x0980} /* Cn */, { 0x0984, 0x0984} /* Cn */,
854f7cf2976SLionel Sambuc { 0x098D, 0x098E} /* Cn */, { 0x0991, 0x0992} /* Cn */,
855f7cf2976SLionel Sambuc { 0x09A9, 0x09A9} /* Cn */, { 0x09B1, 0x09B1} /* Cn */,
856f7cf2976SLionel Sambuc { 0x09B3, 0x09B5} /* Cn */, { 0x09BA, 0x09BB} /* Cn */,
857f7cf2976SLionel Sambuc { 0x09C5, 0x09C6} /* Cn */, { 0x09C9, 0x09CA} /* Cn */,
858f7cf2976SLionel Sambuc { 0x09CF, 0x09D6} /* Cn */, { 0x09D8, 0x09DB} /* Cn */,
859f7cf2976SLionel Sambuc { 0x09DE, 0x09DE} /* Cn */, { 0x09E4, 0x09E5} /* Cn */,
860f7cf2976SLionel Sambuc { 0x09FB, 0x0A00} /* Cn */, { 0x0A04, 0x0A04} /* Cn */,
861f7cf2976SLionel Sambuc { 0x0A0B, 0x0A0E} /* Cn */, { 0x0A11, 0x0A12} /* Cn */,
862f7cf2976SLionel Sambuc { 0x0A29, 0x0A29} /* Cn */, { 0x0A31, 0x0A31} /* Cn */,
863f7cf2976SLionel Sambuc { 0x0A34, 0x0A34} /* Cn */, { 0x0A37, 0x0A37} /* Cn */,
864f7cf2976SLionel Sambuc { 0x0A3A, 0x0A3B} /* Cn */, { 0x0A3D, 0x0A3D} /* Cn */,
865f7cf2976SLionel Sambuc { 0x0A43, 0x0A46} /* Cn */, { 0x0A49, 0x0A4A} /* Cn */,
866f7cf2976SLionel Sambuc { 0x0A4E, 0x0A58} /* Cn */, { 0x0A5D, 0x0A5D} /* Cn */,
867f7cf2976SLionel Sambuc { 0x0A5F, 0x0A65} /* Cn */, { 0x0A75, 0x0A80} /* Cn */,
868f7cf2976SLionel Sambuc { 0x0A84, 0x0A84} /* Cn */, { 0x0A8E, 0x0A8E} /* Cn */,
869f7cf2976SLionel Sambuc { 0x0A92, 0x0A92} /* Cn */, { 0x0AA9, 0x0AA9} /* Cn */,
870f7cf2976SLionel Sambuc { 0x0AB1, 0x0AB1} /* Cn */, { 0x0AB4, 0x0AB4} /* Cn */,
871f7cf2976SLionel Sambuc { 0x0ABA, 0x0ABB} /* Cn */, { 0x0AC6, 0x0AC6} /* Cn */,
872f7cf2976SLionel Sambuc { 0x0ACA, 0x0ACA} /* Cn */, { 0x0ACE, 0x0ACF} /* Cn */,
873f7cf2976SLionel Sambuc { 0x0AD1, 0x0ADF} /* Cn */, { 0x0AE4, 0x0AE5} /* Cn */,
874f7cf2976SLionel Sambuc { 0x0AF0, 0x0AF0} /* Cn */, { 0x0AF2, 0x0B00} /* Cn */,
875f7cf2976SLionel Sambuc { 0x0B04, 0x0B04} /* Cn */, { 0x0B0D, 0x0B0E} /* Cn */,
876f7cf2976SLionel Sambuc { 0x0B11, 0x0B12} /* Cn */, { 0x0B29, 0x0B29} /* Cn */,
877f7cf2976SLionel Sambuc { 0x0B31, 0x0B31} /* Cn */, { 0x0B34, 0x0B34} /* Cn */,
878f7cf2976SLionel Sambuc { 0x0B3A, 0x0B3B} /* Cn */, { 0x0B44, 0x0B46} /* Cn */,
879f7cf2976SLionel Sambuc { 0x0B49, 0x0B4A} /* Cn */, { 0x0B4E, 0x0B55} /* Cn */,
880f7cf2976SLionel Sambuc { 0x0B58, 0x0B5B} /* Cn */, { 0x0B5E, 0x0B5E} /* Cn */,
881f7cf2976SLionel Sambuc { 0x0B62, 0x0B65} /* Cn */, { 0x0B72, 0x0B81} /* Cn */,
882f7cf2976SLionel Sambuc { 0x0B84, 0x0B84} /* Cn */, { 0x0B8B, 0x0B8D} /* Cn */,
883f7cf2976SLionel Sambuc { 0x0B91, 0x0B91} /* Cn */, { 0x0B96, 0x0B98} /* Cn */,
884f7cf2976SLionel Sambuc { 0x0B9B, 0x0B9B} /* Cn */, { 0x0B9D, 0x0B9D} /* Cn */,
885f7cf2976SLionel Sambuc { 0x0BA0, 0x0BA2} /* Cn */, { 0x0BA5, 0x0BA7} /* Cn */,
886f7cf2976SLionel Sambuc { 0x0BAB, 0x0BAD} /* Cn */, { 0x0BBA, 0x0BBD} /* Cn */,
887f7cf2976SLionel Sambuc { 0x0BC3, 0x0BC5} /* Cn */, { 0x0BC9, 0x0BC9} /* Cn */,
888f7cf2976SLionel Sambuc { 0x0BCE, 0x0BD6} /* Cn */, { 0x0BD8, 0x0BE5} /* Cn */,
889f7cf2976SLionel Sambuc { 0x0BFB, 0x0C00} /* Cn */, { 0x0C04, 0x0C04} /* Cn */,
890f7cf2976SLionel Sambuc { 0x0C0D, 0x0C0D} /* Cn */, { 0x0C11, 0x0C11} /* Cn */,
891f7cf2976SLionel Sambuc { 0x0C29, 0x0C29} /* Cn */, { 0x0C34, 0x0C34} /* Cn */,
892f7cf2976SLionel Sambuc { 0x0C3A, 0x0C3D} /* Cn */, { 0x0C45, 0x0C45} /* Cn */,
893f7cf2976SLionel Sambuc { 0x0C49, 0x0C49} /* Cn */, { 0x0C4E, 0x0C54} /* Cn */,
894f7cf2976SLionel Sambuc { 0x0C57, 0x0C5F} /* Cn */, { 0x0C62, 0x0C65} /* Cn */,
895f7cf2976SLionel Sambuc { 0x0C70, 0x0C81} /* Cn */, { 0x0C84, 0x0C84} /* Cn */,
896f7cf2976SLionel Sambuc { 0x0C8D, 0x0C8D} /* Cn */, { 0x0C91, 0x0C91} /* Cn */,
897f7cf2976SLionel Sambuc { 0x0CA9, 0x0CA9} /* Cn */, { 0x0CB4, 0x0CB4} /* Cn */,
898f7cf2976SLionel Sambuc { 0x0CBA, 0x0CBB} /* Cn */, { 0x0CC5, 0x0CC5} /* Cn */,
899f7cf2976SLionel Sambuc { 0x0CC9, 0x0CC9} /* Cn */, { 0x0CCE, 0x0CD4} /* Cn */,
900f7cf2976SLionel Sambuc { 0x0CD7, 0x0CDD} /* Cn */, { 0x0CDF, 0x0CDF} /* Cn */,
901f7cf2976SLionel Sambuc { 0x0CE4, 0x0CE5} /* Cn */, { 0x0CF0, 0x0CF0} /* Cn */,
902f7cf2976SLionel Sambuc { 0x0CF3, 0x0D01} /* Cn */, { 0x0D04, 0x0D04} /* Cn */,
903f7cf2976SLionel Sambuc { 0x0D0D, 0x0D0D} /* Cn */, { 0x0D11, 0x0D11} /* Cn */,
904f7cf2976SLionel Sambuc { 0x0D29, 0x0D29} /* Cn */, { 0x0D3A, 0x0D3D} /* Cn */,
905f7cf2976SLionel Sambuc { 0x0D44, 0x0D45} /* Cn */, { 0x0D49, 0x0D49} /* Cn */,
906f7cf2976SLionel Sambuc { 0x0D4E, 0x0D56} /* Cn */, { 0x0D58, 0x0D5F} /* Cn */,
907f7cf2976SLionel Sambuc { 0x0D62, 0x0D65} /* Cn */, { 0x0D70, 0x0D81} /* Cn */,
908f7cf2976SLionel Sambuc { 0x0D84, 0x0D84} /* Cn */, { 0x0D97, 0x0D99} /* Cn */,
909f7cf2976SLionel Sambuc { 0x0DB2, 0x0DB2} /* Cn */, { 0x0DBC, 0x0DBC} /* Cn */,
910f7cf2976SLionel Sambuc { 0x0DBE, 0x0DBF} /* Cn */, { 0x0DC7, 0x0DC9} /* Cn */,
911f7cf2976SLionel Sambuc { 0x0DCB, 0x0DCE} /* Cn */, { 0x0DD5, 0x0DD5} /* Cn */,
912f7cf2976SLionel Sambuc { 0x0DD7, 0x0DD7} /* Cn */, { 0x0DE0, 0x0DF1} /* Cn */,
913f7cf2976SLionel Sambuc { 0x0DF5, 0x0E00} /* Cn */, { 0x0E3B, 0x0E3E} /* Cn */,
914f7cf2976SLionel Sambuc { 0x0E5C, 0x0E80} /* Cn */, { 0x0E83, 0x0E83} /* Cn */,
915f7cf2976SLionel Sambuc { 0x0E85, 0x0E86} /* Cn */, { 0x0E89, 0x0E89} /* Cn */,
916f7cf2976SLionel Sambuc { 0x0E8B, 0x0E8C} /* Cn */, { 0x0E8E, 0x0E93} /* Cn */,
917f7cf2976SLionel Sambuc { 0x0E98, 0x0E98} /* Cn */, { 0x0EA0, 0x0EA0} /* Cn */,
918f7cf2976SLionel Sambuc { 0x0EA4, 0x0EA4} /* Cn */, { 0x0EA6, 0x0EA6} /* Cn */,
919f7cf2976SLionel Sambuc { 0x0EA8, 0x0EA9} /* Cn */, { 0x0EAC, 0x0EAC} /* Cn */,
920f7cf2976SLionel Sambuc { 0x0EBA, 0x0EBA} /* Cn */, { 0x0EBE, 0x0EBF} /* Cn */,
921f7cf2976SLionel Sambuc { 0x0EC5, 0x0EC5} /* Cn */, { 0x0EC7, 0x0EC7} /* Cn */,
922f7cf2976SLionel Sambuc { 0x0ECE, 0x0ECF} /* Cn */, { 0x0EDA, 0x0EDB} /* Cn */,
923f7cf2976SLionel Sambuc { 0x0EDE, 0x0EFF} /* Cn */, { 0x0F48, 0x0F48} /* Cn */,
924f7cf2976SLionel Sambuc { 0x0F6B, 0x0F70} /* Cn */, { 0x0F8C, 0x0F8F} /* Cn */,
925f7cf2976SLionel Sambuc { 0x0F98, 0x0F98} /* Cn */, { 0x0FBD, 0x0FBD} /* Cn */,
926f7cf2976SLionel Sambuc { 0x0FCD, 0x0FCE} /* Cn */, { 0x0FD2, 0x0FFF} /* Cn */,
927f7cf2976SLionel Sambuc { 0x1022, 0x1022} /* Cn */, { 0x1028, 0x1028} /* Cn */,
928f7cf2976SLionel Sambuc { 0x102B, 0x102B} /* Cn */, { 0x1033, 0x1035} /* Cn */,
929f7cf2976SLionel Sambuc { 0x103A, 0x103F} /* Cn */, { 0x105A, 0x109F} /* Cn */,
930f7cf2976SLionel Sambuc { 0x10C6, 0x10CF} /* Cn */, { 0x10FD, 0x10FF} /* Cn */,
931f7cf2976SLionel Sambuc { 0x115A, 0x115E} /* Cn */, { 0x11A3, 0x11A7} /* Cn */,
932f7cf2976SLionel Sambuc { 0x11FA, 0x11FF} /* Cn */, { 0x1249, 0x1249} /* Cn */,
933f7cf2976SLionel Sambuc { 0x124E, 0x124F} /* Cn */, { 0x1257, 0x1257} /* Cn */,
934f7cf2976SLionel Sambuc { 0x1259, 0x1259} /* Cn */, { 0x125E, 0x125F} /* Cn */,
935f7cf2976SLionel Sambuc { 0x1289, 0x1289} /* Cn */, { 0x128E, 0x128F} /* Cn */,
936f7cf2976SLionel Sambuc { 0x12B1, 0x12B1} /* Cn */, { 0x12B6, 0x12B7} /* Cn */,
937f7cf2976SLionel Sambuc { 0x12BF, 0x12BF} /* Cn */, { 0x12C1, 0x12C1} /* Cn */,
938f7cf2976SLionel Sambuc { 0x12C6, 0x12C7} /* Cn */, { 0x12D7, 0x12D7} /* Cn */,
939f7cf2976SLionel Sambuc { 0x1311, 0x1311} /* Cn */, { 0x1316, 0x1317} /* Cn */,
940f7cf2976SLionel Sambuc { 0x135B, 0x135E} /* Cn */, { 0x137D, 0x137F} /* Cn */,
941f7cf2976SLionel Sambuc { 0x139A, 0x139F} /* Cn */, { 0x13F5, 0x1400} /* Cn */,
942f7cf2976SLionel Sambuc { 0x1677, 0x167F} /* Cn */, { 0x169D, 0x169F} /* Cn */,
943f7cf2976SLionel Sambuc { 0x16F1, 0x16FF} /* Cn */, { 0x170D, 0x170D} /* Cn */,
944f7cf2976SLionel Sambuc { 0x1715, 0x171F} /* Cn */, { 0x1737, 0x173F} /* Cn */,
945f7cf2976SLionel Sambuc { 0x1754, 0x175F} /* Cn */, { 0x176D, 0x176D} /* Cn */,
946f7cf2976SLionel Sambuc { 0x1771, 0x1771} /* Cn */, { 0x1774, 0x177F} /* Cn */,
947f7cf2976SLionel Sambuc #if 0
948f7cf2976SLionel Sambuc { 0x17B4, 0x17B5} /* Cf */,
949f7cf2976SLionel Sambuc #endif
950f7cf2976SLionel Sambuc { 0x17DE, 0x17DF} /* Cn */, { 0x17EA, 0x17EF} /* Cn */,
951f7cf2976SLionel Sambuc { 0x17FA, 0x17FF} /* Cn */, { 0x180F, 0x180F} /* Cn */,
952f7cf2976SLionel Sambuc { 0x181A, 0x181F} /* Cn */, { 0x1878, 0x187F} /* Cn */,
953f7cf2976SLionel Sambuc { 0x18AA, 0x18FF} /* Cn */, { 0x191D, 0x191F} /* Cn */,
954f7cf2976SLionel Sambuc { 0x192C, 0x192F} /* Cn */, { 0x193C, 0x193F} /* Cn */,
955f7cf2976SLionel Sambuc { 0x1941, 0x1943} /* Cn */, { 0x196E, 0x196F} /* Cn */,
956f7cf2976SLionel Sambuc { 0x1975, 0x197F} /* Cn */, { 0x19AA, 0x19AF} /* Cn */,
957f7cf2976SLionel Sambuc { 0x19CA, 0x19CF} /* Cn */, { 0x19DA, 0x19DD} /* Cn */,
958f7cf2976SLionel Sambuc { 0x1A1C, 0x1A1D} /* Cn */, { 0x1A20, 0x1AFF} /* Cn */,
959f7cf2976SLionel Sambuc { 0x1B4C, 0x1B4F} /* Cn */, { 0x1B7D, 0x1CFF} /* Cn */,
960f7cf2976SLionel Sambuc { 0x1DCB, 0x1DFD} /* Cn */, { 0x1E9C, 0x1E9F} /* Cn */,
961f7cf2976SLionel Sambuc { 0x1EFA, 0x1EFF} /* Cn */, { 0x1F16, 0x1F17} /* Cn */,
962f7cf2976SLionel Sambuc { 0x1F1E, 0x1F1F} /* Cn */, { 0x1F46, 0x1F47} /* Cn */,
963f7cf2976SLionel Sambuc { 0x1F4E, 0x1F4F} /* Cn */, { 0x1F58, 0x1F58} /* Cn */,
964f7cf2976SLionel Sambuc { 0x1F5A, 0x1F5A} /* Cn */, { 0x1F5C, 0x1F5C} /* Cn */,
965f7cf2976SLionel Sambuc { 0x1F5E, 0x1F5E} /* Cn */, { 0x1F7E, 0x1F7F} /* Cn */,
966f7cf2976SLionel Sambuc { 0x1FB5, 0x1FB5} /* Cn */, { 0x1FC5, 0x1FC5} /* Cn */,
967f7cf2976SLionel Sambuc { 0x1FD4, 0x1FD5} /* Cn */, { 0x1FDC, 0x1FDC} /* Cn */,
968f7cf2976SLionel Sambuc { 0x1FF0, 0x1FF1} /* Cn */, { 0x1FF5, 0x1FF5} /* Cn */,
969f7cf2976SLionel Sambuc { 0x1FFF, 0x1FFF} /* Cn */,
970f7cf2976SLionel Sambuc { 0x200B, 0x200F} /* Cf */,
971f7cf2976SLionel Sambuc { 0x2028, 0x2028} /* Zl */,
972f7cf2976SLionel Sambuc { 0x2029, 0x2029} /* Zp */,
973f7cf2976SLionel Sambuc { 0x202A, 0x202E} /* Cf */,
974f7cf2976SLionel Sambuc { 0x2060, 0x2063} /* Cf */,
975f7cf2976SLionel Sambuc { 0x2064, 0x2069} /* Cn */,
976f7cf2976SLionel Sambuc { 0x206A, 0x206F} /* Cf */,
977f7cf2976SLionel Sambuc { 0x2072, 0x2073} /* Cn */, { 0x208F, 0x208F} /* Cn */,
978f7cf2976SLionel Sambuc { 0x2095, 0x209F} /* Cn */, { 0x20B6, 0x20CF} /* Cn */,
979f7cf2976SLionel Sambuc { 0x20F0, 0x20FF} /* Cn */, { 0x214F, 0x2152} /* Cn */,
980f7cf2976SLionel Sambuc { 0x2185, 0x218F} /* Cn */, { 0x23E8, 0x23FF} /* Cn */,
981f7cf2976SLionel Sambuc { 0x2427, 0x243F} /* Cn */, { 0x244B, 0x245F} /* Cn */,
982f7cf2976SLionel Sambuc { 0x269D, 0x269F} /* Cn */, { 0x26B3, 0x2700} /* Cn */,
983f7cf2976SLionel Sambuc { 0x2705, 0x2705} /* Cn */, { 0x270A, 0x270B} /* Cn */,
984f7cf2976SLionel Sambuc { 0x2728, 0x2728} /* Cn */, { 0x274C, 0x274C} /* Cn */,
985f7cf2976SLionel Sambuc { 0x274E, 0x274E} /* Cn */, { 0x2753, 0x2755} /* Cn */,
986f7cf2976SLionel Sambuc { 0x2757, 0x2757} /* Cn */, { 0x275F, 0x2760} /* Cn */,
987f7cf2976SLionel Sambuc { 0x2795, 0x2797} /* Cn */, { 0x27B0, 0x27B0} /* Cn */,
988f7cf2976SLionel Sambuc { 0x27BF, 0x27BF} /* Cn */, { 0x27CB, 0x27CF} /* Cn */,
989f7cf2976SLionel Sambuc { 0x27EC, 0x27EF} /* Cn */, { 0x2B1B, 0x2B1F} /* Cn */,
990f7cf2976SLionel Sambuc { 0x2B24, 0x2BFF} /* Cn */, { 0x2C2F, 0x2C2F} /* Cn */,
991f7cf2976SLionel Sambuc { 0x2C5F, 0x2C5F} /* Cn */, { 0x2C6D, 0x2C73} /* Cn */,
992f7cf2976SLionel Sambuc { 0x2C78, 0x2C7F} /* Cn */, { 0x2CEB, 0x2CF8} /* Cn */,
993f7cf2976SLionel Sambuc { 0x2D26, 0x2D2F} /* Cn */, { 0x2D66, 0x2D6E} /* Cn */,
994f7cf2976SLionel Sambuc { 0x2D70, 0x2D7F} /* Cn */, { 0x2D97, 0x2D9F} /* Cn */,
995f7cf2976SLionel Sambuc { 0x2DA7, 0x2DA7} /* Cn */, { 0x2DAF, 0x2DAF} /* Cn */,
996f7cf2976SLionel Sambuc { 0x2DB7, 0x2DB7} /* Cn */, { 0x2DBF, 0x2DBF} /* Cn */,
997f7cf2976SLionel Sambuc { 0x2DC7, 0x2DC7} /* Cn */, { 0x2DCF, 0x2DCF} /* Cn */,
998f7cf2976SLionel Sambuc { 0x2DD7, 0x2DD7} /* Cn */, { 0x2DDF, 0x2DFF} /* Cn */,
999f7cf2976SLionel Sambuc { 0x2E18, 0x2E1B} /* Cn */, { 0x2E1E, 0x2E7F} /* Cn */,
1000f7cf2976SLionel Sambuc { 0x2E9A, 0x2E9A} /* Cn */, { 0x2EF4, 0x2EFF} /* Cn */,
1001f7cf2976SLionel Sambuc { 0x2FD6, 0x2FEF} /* Cn */, { 0x2FFC, 0x2FFF} /* Cn */,
1002f7cf2976SLionel Sambuc { 0x3040, 0x3040} /* Cn */, { 0x3097, 0x3098} /* Cn */,
1003f7cf2976SLionel Sambuc { 0x3100, 0x3104} /* Cn */, { 0x312D, 0x3130} /* Cn */,
1004f7cf2976SLionel Sambuc { 0x318F, 0x318F} /* Cn */, { 0x31B8, 0x31BF} /* Cn */,
1005f7cf2976SLionel Sambuc { 0x31D0, 0x31EF} /* Cn */, { 0x321F, 0x321F} /* Cn */,
1006f7cf2976SLionel Sambuc { 0x3244, 0x324F} /* Cn */, { 0x32FF, 0x32FF} /* Cn */,
1007f7cf2976SLionel Sambuc { 0x4DB6, 0x4DBF} /* Cn */, { 0x9FBC, 0x9FFF} /* Cn */,
1008f7cf2976SLionel Sambuc { 0xA48D, 0xA48F} /* Cn */, { 0xA4C7, 0xA6FF} /* Cn */,
1009f7cf2976SLionel Sambuc { 0xA71B, 0xA71F} /* Cn */, { 0xA722, 0xA7FF} /* Cn */,
1010f7cf2976SLionel Sambuc { 0xA82C, 0xA83F} /* Cn */, { 0xA878, 0xABFF} /* Cn */,
1011f7cf2976SLionel Sambuc { 0xD7A4, 0xD7FF} /* Cn */,
1012f7cf2976SLionel Sambuc { 0xD800, 0xDFFF} /* Cs */,
1013f7cf2976SLionel Sambuc { 0xE000, 0xF8FF} /* Co */,
1014f7cf2976SLionel Sambuc { 0xFA2E, 0xFA2F} /* Cn */, { 0xFA6B, 0xFA6F} /* Cn */,
1015f7cf2976SLionel Sambuc { 0xFADA, 0xFAFF} /* Cn */, { 0xFB07, 0xFB12} /* Cn */,
1016f7cf2976SLionel Sambuc { 0xFB18, 0xFB1C} /* Cn */, { 0xFB37, 0xFB37} /* Cn */,
1017f7cf2976SLionel Sambuc { 0xFB3D, 0xFB3D} /* Cn */, { 0xFB3F, 0xFB3F} /* Cn */,
1018f7cf2976SLionel Sambuc { 0xFB42, 0xFB42} /* Cn */, { 0xFB45, 0xFB45} /* Cn */,
1019f7cf2976SLionel Sambuc { 0xFBB2, 0xFBD2} /* Cn */, { 0xFD40, 0xFD4F} /* Cn */,
1020f7cf2976SLionel Sambuc { 0xFD90, 0xFD91} /* Cn */, { 0xFDC8, 0xFDEF} /* Cn */,
1021f7cf2976SLionel Sambuc { 0xFDFE, 0xFDFF} /* Cn */, { 0xFE1A, 0xFE1F} /* Cn */,
1022f7cf2976SLionel Sambuc { 0xFE24, 0xFE2F} /* Cn */, { 0xFE53, 0xFE53} /* Cn */,
1023f7cf2976SLionel Sambuc { 0xFE67, 0xFE67} /* Cn */, { 0xFE6C, 0xFE6F} /* Cn */,
1024f7cf2976SLionel Sambuc { 0xFE75, 0xFE75} /* Cn */, { 0xFEFD, 0xFEFE} /* Cn */,
1025f7cf2976SLionel Sambuc { 0xFEFF, 0xFEFF} /* Cf */,
1026f7cf2976SLionel Sambuc { 0xFF00, 0xFF00} /* Cn */, { 0xFFBF, 0xFFC1} /* Cn */,
1027f7cf2976SLionel Sambuc { 0xFFC8, 0xFFC9} /* Cn */, { 0xFFD0, 0xFFD1} /* Cn */,
1028f7cf2976SLionel Sambuc { 0xFFD8, 0xFFD9} /* Cn */, { 0xFFDD, 0xFFDF} /* Cn */,
1029f7cf2976SLionel Sambuc { 0xFFE7, 0xFFE7} /* Cn */, { 0xFFEF, 0xFFF8} /* Cn */,
1030f7cf2976SLionel Sambuc { 0xFFF9, 0xFFFB} /* Cf */,
1031f7cf2976SLionel Sambuc { 0xFFFE, 0xFFFF} /* Cn */, { 0x1000C, 0x1000C} /* Cn */,
1032f7cf2976SLionel Sambuc { 0x10027, 0x10027} /* Cn */, { 0x1003B, 0x1003B} /* Cn */,
1033f7cf2976SLionel Sambuc { 0x1003E, 0x1003E} /* Cn */, { 0x1004E, 0x1004F} /* Cn */,
1034f7cf2976SLionel Sambuc { 0x1005E, 0x1007F} /* Cn */, { 0x100FB, 0x100FF} /* Cn */,
1035f7cf2976SLionel Sambuc { 0x10103, 0x10106} /* Cn */, { 0x10134, 0x10136} /* Cn */,
1036f7cf2976SLionel Sambuc { 0x1018B, 0x102FF} /* Cn */, { 0x1031F, 0x1031F} /* Cn */,
1037f7cf2976SLionel Sambuc { 0x10324, 0x1032F} /* Cn */, { 0x1034B, 0x1037F} /* Cn */,
1038f7cf2976SLionel Sambuc { 0x1039E, 0x1039E} /* Cn */, { 0x103C4, 0x103C7} /* Cn */,
1039f7cf2976SLionel Sambuc { 0x103D6, 0x103FF} /* Cn */,
1040f7cf2976SLionel Sambuc { 0x1049E, 0x1049F} /* Cn */, { 0x104AA, 0x107FF} /* Cn */,
1041f7cf2976SLionel Sambuc { 0x10806, 0x10807} /* Cn */, { 0x10809, 0x10809} /* Cn */,
1042f7cf2976SLionel Sambuc { 0x10836, 0x10836} /* Cn */, { 0x10839, 0x1083B} /* Cn */,
1043f7cf2976SLionel Sambuc { 0x1083D, 0x1083E} /* Cn */, { 0x10840, 0x108FF} /* Cn */,
1044f7cf2976SLionel Sambuc { 0x1091A, 0x1091E} /* Cn */, { 0x10920, 0x109FF} /* Cn */,
1045f7cf2976SLionel Sambuc { 0x10A04, 0x10A04} /* Cn */, { 0x10A07, 0x10A0B} /* Cn */,
1046f7cf2976SLionel Sambuc { 0x10A14, 0x10A14} /* Cn */, { 0x10A18, 0x10A18} /* Cn */,
1047f7cf2976SLionel Sambuc { 0x10A34, 0x10A37} /* Cn */, { 0x10A3B, 0x10A3E} /* Cn */,
1048f7cf2976SLionel Sambuc { 0x10A48, 0x10A4F} /* Cn */, { 0x10A59, 0x11FFF} /* Cn */,
1049f7cf2976SLionel Sambuc { 0x1236F, 0x123FF} /* Cn */, { 0x12463, 0x1246F} /* Cn */,
1050f7cf2976SLionel Sambuc { 0x12474, 0x1CFFF} /* Cn */, { 0x1D0F6, 0x1D0FF} /* Cn */,
1051f7cf2976SLionel Sambuc { 0x1D127, 0x1D129} /* Cn */,
1052f7cf2976SLionel Sambuc { 0x1D173, 0x1D17A} /* Cf */,
1053f7cf2976SLionel Sambuc { 0x1D1DE, 0x1D1FF} /* Cn */, { 0x1D246, 0x1D2FF} /* Cn */,
1054f7cf2976SLionel Sambuc { 0x1D357, 0x1D35F} /* Cn */, { 0x1D372, 0x1D3FF} /* Cn */,
1055f7cf2976SLionel Sambuc { 0x1D455, 0x1D455} /* Cn */, { 0x1D49D, 0x1D49D} /* Cn */,
1056f7cf2976SLionel Sambuc { 0x1D4A0, 0x1D4A1} /* Cn */, { 0x1D4A3, 0x1D4A4} /* Cn */,
1057f7cf2976SLionel Sambuc { 0x1D4A7, 0x1D4A8} /* Cn */, { 0x1D4AD, 0x1D4AD} /* Cn */,
1058f7cf2976SLionel Sambuc { 0x1D4BA, 0x1D4BA} /* Cn */, { 0x1D4BC, 0x1D4BC} /* Cn */,
1059f7cf2976SLionel Sambuc { 0x1D4C4, 0x1D4C4} /* Cn */, { 0x1D506, 0x1D506} /* Cn */,
1060f7cf2976SLionel Sambuc { 0x1D50B, 0x1D50C} /* Cn */, { 0x1D515, 0x1D515} /* Cn */,
1061f7cf2976SLionel Sambuc { 0x1D51D, 0x1D51D} /* Cn */, { 0x1D53A, 0x1D53A} /* Cn */,
1062f7cf2976SLionel Sambuc { 0x1D53F, 0x1D53F} /* Cn */, { 0x1D545, 0x1D545} /* Cn */,
1063f7cf2976SLionel Sambuc { 0x1D547, 0x1D549} /* Cn */, { 0x1D551, 0x1D551} /* Cn */,
1064f7cf2976SLionel Sambuc { 0x1D6A6, 0x1D6A7} /* Cn */, { 0x1D7CC, 0x1D7CD} /* Cn */,
1065f7cf2976SLionel Sambuc { 0x1D800, 0x1FFFF} /* Cn */, { 0x2A6D7, 0x2F7FF} /* Cn */,
1066f7cf2976SLionel Sambuc { 0x2FA1E, 0xE0000} /* Cn */,
1067f7cf2976SLionel Sambuc { 0xE0001, 0xE0001} /* Cf */,
1068f7cf2976SLionel Sambuc { 0xE0002, 0xE001F} /* Cn */,
1069f7cf2976SLionel Sambuc { 0xE0020, 0xE007F} /* Cf */,
1070f7cf2976SLionel Sambuc { 0xE0080, 0xE00FF} /* Cn */, { 0xE01F0, 0xEFFFF} /* Cn */,
1071f7cf2976SLionel Sambuc { 0xF0000, 0xFFFFD} /* Co */,
1072f7cf2976SLionel Sambuc { 0xFFFFE, 0xFFFFF} /* Cn */,
1073f7cf2976SLionel Sambuc {0x100000,0x10FFFD} /* Co */,
1074f7cf2976SLionel Sambuc {0x10FFFE,0x10FFFF} /* Cn */,
1075f7cf2976SLionel Sambuc {0x110000,0x7FFFFFFF} /* ISO 10646?? */
1076f7cf2976SLionel Sambuc };
1077f7cf2976SLionel Sambuc
1078f7cf2976SLionel Sambuc /*
1079f7cf2976SLionel Sambuc * Double width characters
1080f7cf2976SLionel Sambuc * W: East Asian Wide
1081f7cf2976SLionel Sambuc * F: East Asian Full-width
1082f7cf2976SLionel Sambuc * Unassigned code points may be included when they allow ranges to be merged.
1083f7cf2976SLionel Sambuc * Last synched with
1084f7cf2976SLionel Sambuc * <http://www.unicode.org/Public/5.0.0/ucd/EastAsianWidth-5.0.0d2.txt>
1085f7cf2976SLionel Sambuc * dated 2005-11-08T01:32:56Z
1086f7cf2976SLionel Sambuc */
1087f7cf2976SLionel Sambuc static struct wchar_range wide_table[] = {
1088f7cf2976SLionel Sambuc { 0x1100, 0x115F} /* W */, { 0x2329, 0x232A} /* W */,
1089f7cf2976SLionel Sambuc { 0x2E80, 0x2FFB} /* W */,
1090f7cf2976SLionel Sambuc { 0x3000, 0x3000} /* F */,
1091f7cf2976SLionel Sambuc { 0x3001, 0x303E} /* W */, { 0x3041, 0x4DB5} /* W */,
1092f7cf2976SLionel Sambuc { 0x4E00, 0x9FBB} /* W */, { 0xA000, 0xA4C6} /* W */,
1093f7cf2976SLionel Sambuc { 0xAC00, 0xD7A3} /* W */, { 0xF900, 0xFAD9} /* W */,
1094f7cf2976SLionel Sambuc { 0xFE10, 0xFE19} /* W */, { 0xFE30, 0xFE6B} /* W */,
1095f7cf2976SLionel Sambuc { 0xFF01, 0xFF60} /* F */, { 0xFFE0, 0xFFE6} /* F */,
1096f7cf2976SLionel Sambuc { 0x20000, 0x2FFFD} /* W */, { 0x30000, 0x3FFFD} /* W */,
1097f7cf2976SLionel Sambuc };
1098f7cf2976SLionel Sambuc
1099f7cf2976SLionel Sambuc static int
is_in_table(ch,table,tsize)1100f7cf2976SLionel Sambuc is_in_table(ch, table, tsize)
1101f7cf2976SLionel Sambuc LWCHAR ch;
1102f7cf2976SLionel Sambuc struct wchar_range table[];
1103f7cf2976SLionel Sambuc int tsize;
1104f7cf2976SLionel Sambuc {
1105f7cf2976SLionel Sambuc int hi;
1106f7cf2976SLionel Sambuc int lo;
1107f7cf2976SLionel Sambuc
1108f7cf2976SLionel Sambuc /* Binary search in the table. */
1109f7cf2976SLionel Sambuc if (ch < table[0].first)
1110f7cf2976SLionel Sambuc return 0;
1111f7cf2976SLionel Sambuc lo = 0;
1112f7cf2976SLionel Sambuc hi = tsize - 1;
1113f7cf2976SLionel Sambuc while (lo <= hi)
1114f7cf2976SLionel Sambuc {
1115f7cf2976SLionel Sambuc int mid = (lo + hi) / 2;
1116f7cf2976SLionel Sambuc if (ch > table[mid].last)
1117f7cf2976SLionel Sambuc lo = mid + 1;
1118f7cf2976SLionel Sambuc else if (ch < table[mid].first)
1119f7cf2976SLionel Sambuc hi = mid - 1;
1120f7cf2976SLionel Sambuc else
1121f7cf2976SLionel Sambuc return 1;
1122f7cf2976SLionel Sambuc }
1123f7cf2976SLionel Sambuc return 0;
1124f7cf2976SLionel Sambuc }
1125f7cf2976SLionel Sambuc
1126f7cf2976SLionel Sambuc /*
1127f7cf2976SLionel Sambuc * Is a character a UTF-8 composing character?
1128f7cf2976SLionel Sambuc * If a composing character follows any char, the two combine into one glyph.
1129f7cf2976SLionel Sambuc */
1130f7cf2976SLionel Sambuc public int
is_composing_char(ch)1131f7cf2976SLionel Sambuc is_composing_char(ch)
1132f7cf2976SLionel Sambuc LWCHAR ch;
1133f7cf2976SLionel Sambuc {
1134f7cf2976SLionel Sambuc return is_in_table(ch, comp_table, (sizeof(comp_table) / sizeof(*comp_table)));
1135f7cf2976SLionel Sambuc }
1136f7cf2976SLionel Sambuc
1137f7cf2976SLionel Sambuc /*
1138f7cf2976SLionel Sambuc * Should this UTF-8 character be treated as binary?
1139f7cf2976SLionel Sambuc */
1140f7cf2976SLionel Sambuc public int
is_ubin_char(ch)1141f7cf2976SLionel Sambuc is_ubin_char(ch)
1142f7cf2976SLionel Sambuc LWCHAR ch;
1143f7cf2976SLionel Sambuc {
1144f7cf2976SLionel Sambuc return is_in_table(ch, ubin_table, (sizeof(ubin_table) / sizeof(*ubin_table)));
1145f7cf2976SLionel Sambuc }
1146f7cf2976SLionel Sambuc
1147f7cf2976SLionel Sambuc /*
1148f7cf2976SLionel Sambuc * Is this a double width UTF-8 character?
1149f7cf2976SLionel Sambuc */
1150f7cf2976SLionel Sambuc public int
is_wide_char(ch)1151f7cf2976SLionel Sambuc is_wide_char(ch)
1152f7cf2976SLionel Sambuc LWCHAR ch;
1153f7cf2976SLionel Sambuc {
1154f7cf2976SLionel Sambuc return is_in_table(ch, wide_table, (sizeof(wide_table) / sizeof(*wide_table)));
1155f7cf2976SLionel Sambuc }
1156f7cf2976SLionel Sambuc
1157f7cf2976SLionel Sambuc /*
1158f7cf2976SLionel Sambuc * Is a character a UTF-8 combining character?
1159f7cf2976SLionel Sambuc * A combining char acts like an ordinary char, but if it follows
1160f7cf2976SLionel Sambuc * a specific char (not any char), the two combine into one glyph.
1161f7cf2976SLionel Sambuc */
1162f7cf2976SLionel Sambuc public int
is_combining_char(ch1,ch2)1163f7cf2976SLionel Sambuc is_combining_char(ch1, ch2)
1164f7cf2976SLionel Sambuc LWCHAR ch1;
1165f7cf2976SLionel Sambuc LWCHAR ch2;
1166f7cf2976SLionel Sambuc {
1167f7cf2976SLionel Sambuc /* The table is small; use linear search. */
1168f7cf2976SLionel Sambuc int i;
1169f7cf2976SLionel Sambuc for (i = 0; i < sizeof(comb_table)/sizeof(*comb_table); i++)
1170f7cf2976SLionel Sambuc {
1171f7cf2976SLionel Sambuc if (ch1 == comb_table[i].first &&
1172f7cf2976SLionel Sambuc ch2 == comb_table[i].last)
1173f7cf2976SLionel Sambuc return 1;
1174f7cf2976SLionel Sambuc }
1175f7cf2976SLionel Sambuc return 0;
1176f7cf2976SLionel Sambuc }
1177f7cf2976SLionel Sambuc
1178