2 /* Copyright (C) 2002, 2009
3 Free Software Foundation, Inc.
4 Written by Werner Lemberg <wl@gnu.org>
6 This file is part of groff.
8 groff is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "stringclass.h"
27 const char *check_unicode_name(const char *u)
34 const char *start = p;
36 // only uppercase hex digits allowed
40 val = val*0x10 + (*p-'0');
42 val = val*0x10 + (*p-'A'+10);
45 // biggest Unicode value is U+10FFFF
49 if (*p == '\0' || *p == '_')
52 // surrogates not allowed
53 if ((val >= 0xD800 && val <= 0xDBFF) || (val >= 0xDC00 && val <= 0xDFFF))
56 if (*start == '0') // no leading zeros allowed if > 0xFFFF
59 else if (p - start != 4) // otherwise, check for exactly 4 hex digits