1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 00:03:12 +02:00

api: add argument "length" in function utf8_is_valid()

This commit is contained in:
Sébastien Helleu
2015-08-18 07:36:48 +02:00
parent fd1886e883
commit 46a9d17ac3
13 changed files with 188 additions and 46 deletions
+1 -1
View File
@@ -2307,7 +2307,7 @@ string_iconv_to_internal (const char *charset, const char *string)
if (local_utf8 && (!charset || !charset[0]))
return input;
if (utf8_has_8bits (input) && utf8_is_valid (input, NULL))
if (utf8_has_8bits (input) && utf8_is_valid (input, -1, NULL))
return input;
output = string_iconv (0,
+13 -6
View File
@@ -70,18 +70,24 @@ utf8_has_8bits (const char *string)
/*
* Checks if a string is UTF-8 valid.
*
* If length is <= 0, checks whole string.
* If length is > 0, checks only this number of chars (not bytes).
*
* Returns:
* 1: string is UTF-8 valid
* 0: string it not UTF-8 valid, and then if error is not NULL, it is set with
* first non valid UTF-8 char in string
* 0: string it not UTF-8 valid, and then if error is not NULL, it is set
* with first non valid UTF-8 char in string
*/
int
utf8_is_valid (const char *string, char **error)
utf8_is_valid (const char *string, int length, char **error)
{
int code_point;
int code_point, current_char;
while (string && string[0])
current_char = 0;
while (string && string[0]
&& ((length <= 0) || (current_char < length)))
{
/*
* UTF-8, 2 bytes, should be: 110vvvvv 10vvvvvv
@@ -142,6 +148,7 @@ utf8_is_valid (const char *string, char **error)
goto invalid;
else
string++;
current_char++;
}
if (error)
*error = NULL;
@@ -165,7 +172,7 @@ utf8_normalize (char *string, char replacement)
while (string && string[0])
{
if (utf8_is_valid (string, &error))
if (utf8_is_valid (string, -1, &error))
return;
error[0] = replacement;
string = error + 1;
+1 -1
View File
@@ -30,7 +30,7 @@ extern int local_utf8;
extern void utf8_init ();
extern int utf8_has_8bits (const char *string);
extern int utf8_is_valid (const char *string, char **error);
extern int utf8_is_valid (const char *string, int length, char **error);
extern void utf8_normalize (char *string, char replacement);
extern const char *utf8_prev_char (const char *string_start,
const char *string);