1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 14:56:39 +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);
+1 -1
View File
@@ -378,7 +378,7 @@ gui_key_flush (int paste)
ptr_char = key_str;
while (ptr_char && ptr_char[0])
{
(void) utf8_is_valid (ptr_char, &ptr_error);
(void) utf8_is_valid (ptr_char, -1, &ptr_error);
if (!ptr_error)
break;
next_char = (char *)utf8_next_char (ptr_error);
+1 -1
View File
@@ -265,7 +265,7 @@ gui_mouse_event_code2key (const char *code)
* mouse code must have at least:
* one code (for event) + X + Y == 3 bytes or 3 UTF-8 chars
*/
code_utf8 = utf8_is_valid (code, NULL);
code_utf8 = utf8_is_valid (code, -1, NULL);
length = (code_utf8) ? utf8_strlen (code) : (int)strlen (code);
if (length < 3)
return NULL;
+1 -1
View File
@@ -214,7 +214,7 @@ gui_key_grab_end_timer_cb (void *data, int remaining_calls)
* but some mouse codes can return ISO chars (for coordinates),
* then we will convert them to UTF-8 string
*/
if (!utf8_is_valid (expanded_key, NULL))
if (!utf8_is_valid (expanded_key, -1, NULL))
{
expanded_key2 = string_iconv_to_internal ("iso-8859-1",
expanded_key);
+4 -4
View File
@@ -57,7 +57,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20150704-02"
#define WEECHAT_PLUGIN_API_VERSION "20150818-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -317,7 +317,7 @@ struct t_weechat_plugin
/* UTF-8 strings */
int (*utf8_has_8bits) (const char *string);
int (*utf8_is_valid) (const char *string, char **error);
int (*utf8_is_valid) (const char *string, int length, char **error);
void (*utf8_normalize) (char *string, char replacement);
const char *(*utf8_prev_char) (const char *string_start,
const char *string);
@@ -1110,8 +1110,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
/* UTF-8 strings */
#define weechat_utf8_has_8bits(__string) \
(weechat_plugin->utf8_has_8bits)(__string)
#define weechat_utf8_is_valid(__string, __error) \
(weechat_plugin->utf8_is_valid)(__string, __error)
#define weechat_utf8_is_valid(__string, __length, __error) \
(weechat_plugin->utf8_is_valid)(__string, __length, __error)
#define weechat_utf8_normalize(__string, __char) \
(weechat_plugin->utf8_normalize)(__string, __char)
#define weechat_utf8_prev_char(__start, __string) \