1 /* Utility functions for UTF-8
2 Copyright (C) 2001, 2002 Peter Verthez
4 The UTF8 tools library is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The Gedcom parser library is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the Gedcom parser library; if not, write to the
16 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include "utf8tools.h"
25 int is_utf8_string(const char* str)
32 if ((*str & 0x80) == 0) {
33 /* Looks like an ASCII character */
35 /* byte of UTF-8 character expected */
38 /* OK, ASCII character expected */
43 /* Looks like byte of an UTF-8 character */
45 /* expect_bytes already set: first byte of UTF-8 char already seen */
46 if ((*str & 0xC0) == 0x80) {
47 /* OK, next byte of UTF-8 character */
48 /* Decrement number of expected bytes */
53 /* again first byte ?!?! */
58 /* First byte of the UTF-8 character */
59 /* count initial one bits and set expect_bytes to 1 less */
63 ch = (ch & 0x7f) << 1;
71 return (expect_bytes == 0);
74 int utf8_strlen(const char* str)
81 if ((*str & 0x80) == 0 || (*str & 0xC0) == 0xC0)