summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-string.c123
-rw-r--r--src/core/wee-string.h4
-rw-r--r--src/core/wee-utf8.c91
-rw-r--r--src/core/wee-utf8.h4
-rw-r--r--src/gui/gui-completion.c8
-rw-r--r--src/gui/gui-key.c2
-rw-r--r--src/plugins/plugin.c4
-rw-r--r--src/plugins/trigger/trigger.c2
-rw-r--r--src/plugins/weechat-plugin.h14
9 files changed, 127 insertions, 125 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 3c258ec94..391d23db3 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -394,6 +394,97 @@ string_toupper (const char *string)
}
/*
+ * Compares two chars (case sensitive).
+ *
+ * Returns: arithmetic result of subtracting the first char in string2
+ * from the first char in string1:
+ * < 0: string1 < string2
+ * 0: string1 == string2
+ * > 0: string1 > string2
+ */
+
+int
+string_charcmp (const char *string1, const char *string2)
+{
+ return utf8_char_int (string1) - utf8_char_int (string2);
+}
+
+/*
+ * Compares two chars (case insensitive).
+ *
+ * Returns: arithmetic result of subtracting the first char in string2
+ * (converted to lowercase) from the first char in string1 (converted
+ * to lowercase):
+ * < 0: string1 < string2
+ * 0: string1 == string2
+ * > 0: string1 > string2
+ */
+
+int
+string_charcasecmp (const char *string1, const char *string2)
+{
+ wint_t wchar1, wchar2;
+
+ /*
+ * optimization for single-byte chars: only letters A-Z must be converted
+ * to lowercase; this is faster than calling `towlower`
+ */
+ if (string1 && !((unsigned char)(string1[0]) & 0x80)
+ && string2 && !((unsigned char)(string2[0]) & 0x80))
+ {
+ wchar1 = string1[0];
+ if ((wchar1 >= 'A') && (wchar1 <= 'Z'))
+ wchar1 += ('a' - 'A');
+ wchar2 = string2[0];
+ if ((wchar2 >= 'A') && (wchar2 <= 'Z'))
+ wchar2 += ('a' - 'A');
+ }
+ else
+ {
+ wchar1 = towlower (utf8_char_int (string1));
+ wchar2 = towlower (utf8_char_int (string2));
+ }
+
+ return wchar1 - wchar2;
+}
+
+/*
+ * Compares two chars (case insensitive using a range).
+ *
+ * The range is the number of chars which can be converted from upper to lower
+ * case. For example 26 = all letters of alphabet, 29 = all letters + 3 chars.
+ *
+ * Examples:
+ * - range = 26: A-Z ==> a-z
+ * - range = 29: A-Z [ \ ] ==> a-z { | }
+ * - range = 30: A-Z [ \ ] ^ ==> a-z { | } ~
+ * (ranges 29 and 30 are used by some protocols like IRC)
+ *
+ * Returns: arithmetic result of subtracting the last compared char in string2
+ * (converted to lowercase) from the last compared char in string1 (converted
+ * to lowercase):
+ * < 0: string1 < string2
+ * 0: string1 == string2
+ * > 0: string1 > string2
+ */
+
+int
+string_charcasecmp_range (const char *string1, const char *string2, int range)
+{
+ wchar_t wchar1, wchar2;
+
+ wchar1 = utf8_char_int (string1);
+ if ((wchar1 >= (wchar_t)'A') && (wchar1 < (wchar_t)('A' + range)))
+ wchar1 += ('a' - 'A');
+
+ wchar2 = utf8_char_int (string2);
+ if ((wchar2 >= (wchar_t)'A') && (wchar2 < (wchar_t)('A' + range)))
+ wchar2 += ('a' - 'A');
+
+ return wchar1 - wchar2;
+}
+
+/*
* Compares two strings (case insensitive).
*
* Returns: arithmetic result of subtracting the last compared char in string2
@@ -411,7 +502,7 @@ string_strcasecmp (const char *string1, const char *string2)
while (string1 && string1[0] && string2 && string2[0])
{
- diff = utf8_charcasecmp (string1, string2);
+ diff = string_charcasecmp (string1, string2);
if (diff != 0)
return diff;
@@ -419,7 +510,7 @@ string_strcasecmp (const char *string1, const char *string2)
string2 = utf8_next_char (string2);
}
- return utf8_charcasecmp (string1, string2);
+ return string_charcasecmp (string1, string2);
}
/*
@@ -449,7 +540,7 @@ string_strcasecmp_range (const char *string1, const char *string2, int range)
while (string1 && string1[0] && string2 && string2[0])
{
- diff = utf8_charcasecmp_range (string1, string2, range);
+ diff = string_charcasecmp_range (string1, string2, range);
if (diff != 0)
return diff;
@@ -457,7 +548,7 @@ string_strcasecmp_range (const char *string1, const char *string2, int range)
string2 = utf8_next_char (string2);
}
- return utf8_charcasecmp_range (string1, string2, range);
+ return string_charcasecmp_range (string1, string2, range);
}
/*
@@ -479,7 +570,7 @@ string_strncasecmp (const char *string1, const char *string2, int max)
count = 0;
while ((count < max) && string1 && string1[0] && string2 && string2[0])
{
- diff = utf8_charcasecmp (string1, string2);
+ diff = string_charcasecmp (string1, string2);
if (diff != 0)
return diff;
@@ -491,7 +582,7 @@ string_strncasecmp (const char *string1, const char *string2, int max)
if (count >= max)
return 0;
else
- return utf8_charcasecmp (string1, string2);
+ return string_charcasecmp (string1, string2);
}
/*
@@ -523,7 +614,7 @@ string_strncasecmp_range (const char *string1, const char *string2, int max,
count = 0;
while ((count < max) && string1 && string1[0] && string2 && string2[0])
{
- diff = utf8_charcasecmp_range (string1, string2, range);
+ diff = string_charcasecmp_range (string1, string2, range);
if (diff != 0)
return diff;
@@ -535,7 +626,7 @@ string_strncasecmp_range (const char *string1, const char *string2, int max,
if (count >= max)
return 0;
else
- return utf8_charcasecmp_range (string1, string2, range);
+ return string_charcasecmp_range (string1, string2, range);
}
/*
@@ -572,13 +663,14 @@ string_strcmp_ignore_chars (const char *string1, const char *string2,
if (!string1 || !string1[0] || !string2 || !string2[0])
{
return (case_sensitive) ?
- utf8_charcmp (string1, string2) :
- utf8_charcasecmp (string1, string2);
+ string_charcmp (string1, string2) :
+ string_charcasecmp (string1, string2);
}
/* look at diff */
diff = (case_sensitive) ?
- utf8_charcmp (string1, string2) : utf8_charcasecmp (string1, string2);
+ string_charcmp (string1, string2) :
+ string_charcasecmp (string1, string2);
if (diff != 0)
return diff;
@@ -596,7 +688,8 @@ string_strcmp_ignore_chars (const char *string1, const char *string2,
}
}
return (case_sensitive) ?
- utf8_charcmp (string1, string2) : utf8_charcasecmp (string1, string2);
+ string_charcmp (string1, string2) :
+ string_charcasecmp (string1, string2);
}
/*
@@ -1984,7 +2077,7 @@ string_translate_chars (const char *string,
ptr_chars2 = chars2;
while (ptr_chars1 && ptr_chars1[0] && ptr_chars2 && ptr_chars2[0])
{
- if (utf8_charcmp (ptr_chars1, ptr_string) == 0)
+ if (string_charcmp (ptr_chars1, ptr_string) == 0)
{
string_dyn_concat (result, ptr_chars2, utf8_char_size (ptr_chars2));
translated = 1;
@@ -3736,7 +3829,7 @@ string_is_command_char (const char *string)
while (ptr_command_chars && ptr_command_chars[0])
{
- if (utf8_charcmp (ptr_command_chars, string) == 0)
+ if (string_charcmp (ptr_command_chars, string) == 0)
return 1;
ptr_command_chars = utf8_next_char (ptr_command_chars);
}
@@ -3798,7 +3891,7 @@ string_input_for_buffer (const char *string)
return string;
/* check if first char is doubled: if yes, then it's not a command */
- if (utf8_charcmp (string, next_char) == 0)
+ if (string_charcmp (string, next_char) == 0)
return next_char;
/* string is a command */
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index 59cb4fb64..303238d8f 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -44,6 +44,10 @@ extern char *string_reverse_screen (const char *string);
extern char *string_repeat (const char *string, int count);
extern char *string_tolower (const char *string);
extern char *string_toupper (const char *string);
+extern int string_charcmp (const char *string1, const char *string2);
+extern int string_charcasecmp (const char *string1, const char *string2);
+extern int string_charcasecmp_range (const char *string1, const char *string2,
+ int range);
extern int string_strcasecmp (const char *string1, const char *string2);
extern int string_strcasecmp_range (const char *string1, const char *string2,
int range);
diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c
index 557fc592d..0cb78405f 100644
--- a/src/core/wee-utf8.c
+++ b/src/core/wee-utf8.c
@@ -529,97 +529,6 @@ utf8_strlen_screen (const char *string)
}
/*
- * Compares two UTF-8 chars (case sensitive).
- *
- * Returns: arithmetic result of subtracting the first char in string2
- * from the first char in string1:
- * < 0: string1 < string2
- * 0: string1 == string2
- * > 0: string1 > string2
- */
-
-int
-utf8_charcmp (const char *string1, const char *string2)
-{
- return utf8_char_int (string1) - utf8_char_int (string2);
-}
-
-/*
- * Compares two UTF-8 chars (case insensitive).
- *
- * Returns: arithmetic result of subtracting the first char in string2
- * (converted to lowercase) from the first char in string1 (converted
- * to lowercase):
- * < 0: string1 < string2
- * 0: string1 == string2
- * > 0: string1 > string2
- */
-
-int
-utf8_charcasecmp (const char *string1, const char *string2)
-{
- wint_t wchar1, wchar2;
-
- /*
- * optimization for single-byte chars: only letters A-Z must be converted
- * to lowercase; this is faster than calling `towlower`
- */
- if (string1 && !((unsigned char)(string1[0]) & 0x80)
- && string2 && !((unsigned char)(string2[0]) & 0x80))
- {
- wchar1 = string1[0];
- if ((wchar1 >= 'A') && (wchar1 <= 'Z'))
- wchar1 += ('a' - 'A');
- wchar2 = string2[0];
- if ((wchar2 >= 'A') && (wchar2 <= 'Z'))
- wchar2 += ('a' - 'A');
- }
- else
- {
- wchar1 = towlower (utf8_char_int (string1));
- wchar2 = towlower (utf8_char_int (string2));
- }
-
- return wchar1 - wchar2;
-}
-
-/*
- * Compares two UTF-8 chars (case insensitive using a range).
- *
- * The range is the number of chars which can be converted from upper to lower
- * case. For example 26 = all letters of alphabet, 29 = all letters + 3 chars.
- *
- * Examples:
- * - range = 26: A-Z ==> a-z
- * - range = 29: A-Z [ \ ] ==> a-z { | }
- * - range = 30: A-Z [ \ ] ^ ==> a-z { | } ~
- * (ranges 29 and 30 are used by some protocols like IRC)
- *
- * Returns: arithmetic result of subtracting the last compared char in string2
- * (converted to lowercase) from the last compared char in string1 (converted
- * to lowercase):
- * < 0: string1 < string2
- * 0: string1 == string2
- * > 0: string1 > string2
- */
-
-int
-utf8_charcasecmp_range (const char *string1, const char *string2, int range)
-{
- wchar_t wchar1, wchar2;
-
- wchar1 = utf8_char_int (string1);
- if ((wchar1 >= (wchar_t)'A') && (wchar1 < (wchar_t)('A' + range)))
- wchar1 += ('a' - 'A');
-
- wchar2 = utf8_char_int (string2);
- if ((wchar2 >= (wchar_t)'A') && (wchar2 < (wchar_t)('A' + range)))
- wchar2 += ('a' - 'A');
-
- return wchar1 - wchar2;
-}
-
-/*
* Moves forward N chars in an UTF-8 string.
*
* Returns pointer to the new position in string.
diff --git a/src/core/wee-utf8.h b/src/core/wee-utf8.h
index 9507ea05d..72f4afe3c 100644
--- a/src/core/wee-utf8.h
+++ b/src/core/wee-utf8.h
@@ -41,10 +41,6 @@ extern int utf8_char_size (const char *string);
extern int utf8_strlen (const char *string);
extern int utf8_strnlen (const char *string, int bytes);
extern int utf8_strlen_screen (const char *string);
-extern int utf8_charcmp (const char *string1, const char *string2);
-extern int utf8_charcasecmp (const char *string1, const char *string2);
-extern int utf8_charcasecmp_range (const char *string1, const char *string2,
- int range);
extern int utf8_char_size_screen (const char *string);
extern const char *utf8_add_offset (const char *string, int offset);
extern int utf8_real_pos (const char *string, int pos);
diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c
index 5e07861f1..2348fdbee 100644
--- a/src/gui/gui-completion.c
+++ b/src/gui/gui-completion.c
@@ -1034,11 +1034,11 @@ gui_completion_common_prefix_size (struct t_arraylist *list,
ptr_completion_word =
(struct t_gui_completion_word *)(list->data[i]);
if (!utf_char
- || (utf8_charcasecmp (utf_char,
- ptr_completion_word->word) == 0))
+ || (string_charcasecmp (utf_char,
+ ptr_completion_word->word) == 0))
{
if ((ptr_completion_word->word[ptr_char - ptr_first_item] == '\0')
- || (utf8_charcasecmp (
+ || (string_charcasecmp (
ptr_char,
ptr_completion_word->word + (ptr_char - ptr_first_item)) != 0))
{
@@ -1112,7 +1112,7 @@ gui_completion_partial_build_list (struct t_gui_completion *completion,
{
ptr_completion_word =
(struct t_gui_completion_word *)list_temp->data[index];
- if (utf8_charcasecmp (utf_char, ptr_completion_word->word) == 0)
+ if (string_charcasecmp (utf_char, ptr_completion_word->word) == 0)
{
arraylist_remove (list_temp, index);
items_count++;
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c
index 4d31716c7..232841083 100644
--- a/src/gui/gui-key.c
+++ b/src/gui/gui-key.c
@@ -731,7 +731,7 @@ gui_key_cmp (const char *key, const char *search, int context)
while (search[0])
{
- diff = utf8_charcmp (key, search);
+ diff = string_charcmp (key, search);
if (diff != 0)
return diff;
key = utf8_next_char (key);
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index b9b7584fb..6013c20ec 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -605,6 +605,8 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->string_cut = &string_cut;
new_plugin->string_tolower = &string_tolower;
new_plugin->string_toupper = &string_toupper;
+ new_plugin->string_charcmp = &string_charcmp;
+ new_plugin->string_charcasecmp = &string_charcasecmp;
new_plugin->strcasecmp = &string_strcasecmp;
new_plugin->strcasecmp_range = &string_strcasecmp_range;
new_plugin->strncasecmp = &string_strncasecmp;
@@ -658,8 +660,6 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->utf8_strlen = &utf8_strlen;
new_plugin->utf8_strnlen = &utf8_strnlen;
new_plugin->utf8_strlen_screen = &utf8_strlen_screen;
- new_plugin->utf8_charcmp = &utf8_charcmp;
- new_plugin->utf8_charcasecmp = &utf8_charcasecmp;
new_plugin->utf8_char_size_screen = &utf8_char_size_screen;
new_plugin->utf8_add_offset = &utf8_add_offset;
new_plugin->utf8_real_pos = &utf8_real_pos;
diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c
index 43518c291..7d3895217 100644
--- a/src/plugins/trigger/trigger.c
+++ b/src/plugins/trigger/trigger.c
@@ -701,7 +701,7 @@ trigger_regex_split (const char *str_regex,
/* search the delimiter (which can be more than one char) */
pos = weechat_utf8_next_char (ptr_regex);
- while (pos[0] && (weechat_utf8_charcmp (ptr_regex, pos) == 0))
+ while (pos[0] && (weechat_string_charcmp (ptr_regex, pos) == 0))
{
pos = weechat_utf8_next_char (pos);
}
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 229c3aba8..dc1439d50 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -68,7 +68,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 "20221218-01"
+#define WEECHAT_PLUGIN_API_VERSION "20221224-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -289,6 +289,8 @@ struct t_weechat_plugin
int screen, const char *cut_suffix);
char *(*string_tolower) (const char *string);
char *(*string_toupper) (const char *string);
+ int (*string_charcmp) (const char *string1, const char *string2);
+ int (*string_charcasecmp) (const char *string1, const char *string2);
int (*strcasecmp) (const char *string1, const char *string2);
int (*strcasecmp_range) (const char *string1, const char *string2,
int range);
@@ -372,8 +374,6 @@ struct t_weechat_plugin
int (*utf8_strlen) (const char *string);
int (*utf8_strnlen) (const char *string, int bytes);
int (*utf8_strlen_screen) (const char *string);
- int (*utf8_charcmp) (const char *string1, const char *string2);
- int (*utf8_charcasecmp) (const char *string1, const char *string2);
int (*utf8_char_size_screen) (const char *string);
const char *(*utf8_add_offset) (const char *string, int offset);
int (*utf8_real_pos) (const char *string, int pos);
@@ -1229,6 +1229,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->string_tolower)(__string)
#define weechat_string_toupper(__string) \
(weechat_plugin->string_toupper)(__string)
+#define weechat_string_charcmp(__string1, __string2) \
+ (weechat_plugin->string_charcmp)(__string1, __string2)
+#define weechat_string_charcasecmp(__string1, __string2) \
+ (weechat_plugin->string_charcasecmp)(__string1, __string2)
#define weechat_strcasecmp(__string1, __string2) \
(weechat_plugin->strcasecmp)(__string1, __string2)
#define weechat_strcasecmp_range(__string1, __string2, __range) \
@@ -1365,10 +1369,6 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->utf8_strnlen)(__string, __bytes)
#define weechat_utf8_strlen_screen(__string) \
(weechat_plugin->utf8_strlen_screen)(__string)
-#define weechat_utf8_charcmp(__string1, __string2) \
- (weechat_plugin->utf8_charcmp)(__string1, __string2)
-#define weechat_utf8_charcasecmp(__string1, __string2) \
- (weechat_plugin->utf8_charcasecmp)(__string1, __string2)
#define weechat_utf8_char_size_screen(__string) \
(weechat_plugin->utf8_char_size_screen)(__string)
#define weechat_utf8_add_offset(__string, __offset) \