From: Martin Mares Date: Fri, 14 Feb 2003 09:27:35 +0000 (+0000) Subject: Sped up utf8_strlen(), introduced utf8_strnlen(). X-Git-Tag: holmes-import~1280 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=0f448197aa5c08a75e91d56ed2f9acde3e132f64;p=libucw.git Sped up utf8_strlen(), introduced utf8_strnlen(). --- diff --git a/charset/strlen.c b/charset/strlen.c index 39c1cb5b..1fb0f756 100644 --- a/charset/strlen.c +++ b/charset/strlen.c @@ -1,7 +1,7 @@ /* * The UniCode Library -- String Length * - * (c) 1997 Martin Mares + * (c) 1997--2003 Martin Mares * (c) 2003 Robert Spalek * * This software may be freely distributed and used according to the terms @@ -25,13 +25,23 @@ uns utf8_strlen(byte *str) { uns len = 0; - while (1) - { - uns c; - GET_UTF8(str, c); - if (!c) - return len; - len++; - } + while (*str) + { + UTF8_SKIP(str); + len++; + } + return len; } +uns +utf8_strnlen(byte *str, uns n) +{ + uns len = 0; + byte *end = str + n; + while (str < end) + { + UTF8_SKIP(str); + len++; + } + return len; +} diff --git a/charset/unicode.h b/charset/unicode.h index 1e11e0f7..80c4ff88 100644 --- a/charset/unicode.h +++ b/charset/unicode.h @@ -1,7 +1,7 @@ /* * The UniCode Library * - * (c) 1997 Martin Mares + * (c) 1997--2003 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -119,5 +119,6 @@ uns utf8_to_ucs2(word *, byte *); byte *static_ucs2_to_utf8(word *); uns Ustrlen(word *); uns utf8_strlen(byte *str); +uns utf8_strnlen(byte *str, uns n); #endif