]> mj.ucw.cz Git - libucw.git/blob - charset/strlen.c
added utf8_strlen()
[libucw.git] / charset / strlen.c
1 /*
2  *      The UniCode Library -- String Length
3  *
4  *      (c) 1997 Martin Mares <mj@ucw.cz>
5  *      (c) 2003 Robert Spalek <robert@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #include "lib/lib.h"
12 #include "charset/unicode.h"
13
14 uns
15 Ustrlen(word *w)
16 {
17   word *z = w;
18
19   while (*z)
20     z++;
21   return z - w;
22 }
23
24 uns
25 utf8_strlen(byte *str)
26 {
27   uns len = 0;
28   while (1)
29   {
30     uns c;
31     GET_UTF8(str, c);
32     if (!c)
33       return len;
34     len++;
35   }
36 }
37