diff options
author | Werner Koch <[email protected]> | 2007-01-25 10:26:55 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-01-25 10:26:55 +0000 |
commit | 0d4b2056307ebb9ff2b938c1518014fbdf2c8f49 (patch) | |
tree | 5e17e51e33b0844372f8c0523e6e512ab485837f /jnlib/stringhelp.c | |
parent | agent/ (diff) | |
download | gnupg-0d4b2056307ebb9ff2b938c1518014fbdf2c8f49.tar.gz gnupg-0d4b2056307ebb9ff2b938c1518014fbdf2c8f49.zip |
jnlib/
* stringhelp.c (utf8_charcount): New.
agent/
* genkey.c (check_passphrase_constraints): Use UTF-8 aware strlen.
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 **************** ****************************************************/ |