diff options
Diffstat (limited to 'jnlib/stringhelp.c')
-rw-r--r-- | jnlib/stringhelp.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c index 1731dd946..b74f84a9c 100644 --- a/jnlib/stringhelp.c +++ b/jnlib/stringhelp.c @@ -547,6 +547,23 @@ sanitize_buffer (const void *p_arg, size_t n, int delim) } +/* Given a string containing an UTF-8 encoded text, return the number + of characters in this string. It differs from strlen in that it + only counts complete UTF-8 characters. Note, that this function + does not take combined characters into account. */ +size_t +utf8_charcount (const char *s) +{ + size_t n; + + for (n=0; *s; s++) + if ( (*s&0xc0) != 0x80 ) /* Exclude continuation bytes: 10xxxxxx */ + n++; + + return n; +} + + /**************************************************** ********** W32 specific functions **************** ****************************************************/ |