From: Robert Spalek Date: Thu, 13 Feb 2003 12:42:10 +0000 (+0000) Subject: added utf8_strlen() X-Git-Tag: holmes-import~1281 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=b38db3d370fbd9c6830d50dad2155910b9685dd6;p=libucw.git added utf8_strlen() --- diff --git a/charset/strlen.c b/charset/strlen.c index ae682db5..39c1cb5b 100644 --- a/charset/strlen.c +++ b/charset/strlen.c @@ -2,6 +2,7 @@ * The UniCode Library -- String Length * * (c) 1997 Martin Mares + * (c) 2003 Robert Spalek * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -19,3 +20,18 @@ Ustrlen(word *w) z++; return z - w; } + +uns +utf8_strlen(byte *str) +{ + uns len = 0; + while (1) + { + uns c; + GET_UTF8(str, c); + if (!c) + return len; + len++; + } +} + diff --git a/charset/unicode.h b/charset/unicode.h index c0afc17a..1e11e0f7 100644 --- a/charset/unicode.h +++ b/charset/unicode.h @@ -118,5 +118,6 @@ uns ucs2_to_utf8(byte *, word *); uns utf8_to_ucs2(word *, byte *); byte *static_ucs2_to_utf8(word *); uns Ustrlen(word *); +uns utf8_strlen(byte *str); #endif