3 /* This file is based on the GLIB utf8 validation functions. The
4 * original license text follows. */
6 /* gutf8.c - Operations on UTF-8 strings.
8 * Copyright (C) 1999 Tom Tromey
9 * Copyright (C) 2000 Red Hat, Inc.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
35 #define UNICODE_VALID(Char) \
36 ((Char) < 0x110000 && \
37 (((Char) & 0xFFFFF800) != 0xD800) && \
38 ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \
39 ((Char) & 0xFFFE) != 0xFFFE)
42 #define CONTINUATION_CHAR \
44 if ((*(const unsigned char *)p & 0xc0) != 0x80) /* 10xxxxxx */ \
47 val |= (*(const unsigned char *)p) & 0x3f; \
52 avahi_utf8_valid (const char *str)
59 for (p = str; *p; p++)
61 if (*(const unsigned char *)p < 128)
68 if ((*(const unsigned char *)p & 0xe0) == 0xc0) /* 110xxxxx */
70 if ( ((*(const unsigned char *)p & 0x1e) == 0))
73 if ( ((*(const unsigned char *)p & 0xc0) != 0x80)) /* 10xxxxxx */
78 if ((*(const unsigned char *)p & 0xf0) == 0xe0) /* 1110xxxx */
81 val = *(const unsigned char *)p & 0x0f;
84 else if ((*(const unsigned char *)p & 0xf8) == 0xf0) /* 11110xxx */
87 val = *(const unsigned char *)p & 0x07;
103 if ( (!UNICODE_VALID(val)))