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 2, or (at your option) any later
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 along
19 with groff; see the file COPYING. If not, write to the Free Software
20 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
24 #include "stringclass.h"
28 const char *check_unicode_name(const char *u)
35 const char *start = p;
37 // only uppercase hex digits allowed
41 val = val*0x10 + (*p-'0');
43 val = val*0x10 + (*p-'A'+10);
46 // biggest Unicode value is U+10FFFF
50 if (*p == '\0' || *p == '_')
53 // surrogates not allowed
54 if ((val >= 0xD800 && val <= 0xDBFF) || (val >= 0xDC00 && val <= 0xDFFF))
57 if (*start == '0') // no leading zeros allowed if > 0xFFFF
60 else if (p - start != 4) // otherwise, check for exactly 4 hex digits