summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-string.c2
-rw-r--r--src/core/wee-utf8.c19
-rw-r--r--src/core/wee-utf8.h2
-rw-r--r--src/gui/curses/gui-curses-key.c2
-rw-r--r--src/gui/curses/gui-curses-mouse.c2
-rw-r--r--src/gui/gui-key.c2
-rw-r--r--src/plugins/weechat-plugin.h8
7 files changed, 22 insertions, 15 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index e27603512..2f1adb7d9 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -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,
diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c
index afa64d951..7cfb8a875 100644
--- a/src/core/wee-utf8.c
+++ b/src/core/wee-utf8.c
@@ -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;
diff --git a/src/core/wee-utf8.h b/src/core/wee-utf8.h
index 8e256c9f7..abdf96b2b 100644
--- a/src/core/wee-utf8.h
+++ b/src/core/wee-utf8.h
@@ -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);
diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c
index b1205b400..d9fd89367 100644
--- a/src/gui/curses/gui-curses-key.c
+++ b/src/gui/curses/gui-curses-key.c
@@ -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);
diff --git a/src/gui/curses/gui-curses-mouse.c b/src/gui/curses/gui-curses-mouse.c
index 16330a76e..dcd9c1070 100644
--- a/src/gui/curses/gui-curses-mouse.c
+++ b/src/gui/curses/gui-curses-mouse.c
@@ -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;
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c
index 209ce061e..97c50c5c3 100644
--- a/src/gui/gui-key.c
+++ b/src/gui/gui-key.c
@@ -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);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 31ed0fcfe..ca3e9f86b 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -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) \