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