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