]> mj.ucw.cz Git - libucw.git/blob - charset/strlen.c
upgraded from ftp.unicode.org and also renamed
[libucw.git] / charset / strlen.c
1 /*
2  *      The UniCode Library -- String Length
3  *
4  *      (c) 1997--2003 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 (*str)
29     {
30       UTF8_SKIP(str);
31       len++;
32     }
33   return len;
34 }
35
36 uns
37 utf8_strnlen(byte *str, uns n)
38 {
39   uns len = 0;
40   byte *end = str + n;
41   while (str < end)
42     {
43       UTF8_SKIP(str);
44       len++;
45     }
46   return len;
47 }