mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
jnlib/
* stringhelp.c (utf8_charcount): New. agent/ * genkey.c (check_passphrase_constraints): Use UTF-8 aware strlen.
This commit is contained in:
parent
39fbda4e3c
commit
0d4b205630
6 changed files with 29 additions and 6 deletions
|
@ -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 ****************
|
||||
****************************************************/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue