1 /* Utility functions for UTF-8
2 Copyright (C) 2001, 2002 Peter Verthez
4 Permission granted to do anything with this file that you want, as long
5 as the above copyright is retained in all copies.
6 THERE IS NO WARRANTY - USE AT YOUR OWN RISK
14 int is_utf8_string(const char* str)
21 if ((*str & 0x80) == 0) {
22 /* Looks like an ASCII character */
24 /* byte of UTF-8 character expected */
27 /* OK, ASCII character expected */
32 /* Looks like byte of an UTF-8 character */
34 /* expect_bytes already set: first byte of UTF-8 char already seen */
35 if ((*str & 0xC0) == 0x80) {
36 /* OK, next byte of UTF-8 character */
37 /* Decrement number of expected bytes */
42 /* again first byte ?!?! */
47 /* First byte of the UTF-8 character */
48 /* count initial one bits and set expect_bytes to 1 less */
52 ch = (ch & 0x7f) << 1;
60 return (expect_bytes == 0);
63 int utf8_strlen(const char* str)
70 if ((*str & 0x80) == 0 || (*str & 0xC0) == 0xC0)