]> mj.ucw.cz Git - libucw.git/blob - lib/unicode-utf8.c
5a9d1bfc9ff3531fba8d30760c647fd0a9facae2
[libucw.git] / lib / unicode-utf8.c
1 /*
2  *      Sherlock Library -- UTF-8 Functions
3  *
4  *      (c) 1997--2004 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 "lib/unicode.h"
13
14 uns
15 utf8_strlen(byte *str)
16 {
17   uns len = 0;
18   while (*str)
19     {
20       UTF8_SKIP(str);
21       len++;
22     }
23   return len;
24 }
25
26 uns
27 utf8_strnlen(byte *str, uns n)
28 {
29   uns len = 0;
30   byte *end = str + n;
31   while (str < end)
32     {
33       UTF8_SKIP(str);
34       len++;
35     }
36   return len;
37 }