X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=charset%2Fstrlen.c;h=1fb0f7562a46657cb34076357945145cb4f54494;hb=2b797fef8d8133e5b1cb40706aabc92718da40bd;hp=39c1cb5bae1a44c39d1a79d1f7435889ab770dc5;hpb=b38db3d370fbd9c6830d50dad2155910b9685dd6;p=libucw.git 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; +}