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 | |
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')
-rw-r--r-- | jnlib/ChangeLog | 4 | ||||
-rw-r--r-- | jnlib/stringhelp.c | 17 | ||||
-rw-r--r-- | jnlib/stringhelp.h | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index e120319cd..3f9ef1539 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,7 @@ +2007-01-25 Werner Koch <[email protected]> + + * stringhelp.c (utf8_charcount): New. + 2006-11-29 Werner Koch <[email protected]> * utf8conv.c (set_native_charset) [HAVE_W32_SYSTEM]: Fixed typo in 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 **************** ****************************************************/ diff --git a/jnlib/stringhelp.h b/jnlib/stringhelp.h index adbd9bf02..869b0f00e 100644 --- a/jnlib/stringhelp.h +++ b/jnlib/stringhelp.h @@ -57,6 +57,9 @@ size_t print_sanitized_utf8_string (FILE *fp, const char *string, int delim); char *sanitize_buffer (const void *p, size_t n, int delim); +size_t utf8_charcount (const char *s); + + #ifdef HAVE_W32_SYSTEM const char *w32_strerror (int ec); #endif |