diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-11-12 10:37:44 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-11-12 10:37:44 +0100 |
commit | 491412b314f6a9db9de5d24daee7196bf5dfbdf5 (patch) | |
tree | c060cb6d2cb15da15aa7811055807d5faaa61aaf | |
parent | 538e8257f6c25c465d171c93552da896e4b09c91 (diff) | |
download | weechat-491412b314f6a9db9de5d24daee7196bf5dfbdf5.zip |
api: add new functions strcasecmp_range and strncasecmp_range
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | doc/en/weechat_plugin_api.en.txt | 89 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.txt | 89 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.txt | 91 | ||||
-rw-r--r-- | src/core/wee-string.c | 68 | ||||
-rw-r--r-- | src/core/wee-string.h | 4 | ||||
-rw-r--r-- | src/core/wee-utf8.c | 29 | ||||
-rw-r--r-- | src/core/wee-utf8.h | 2 | ||||
-rw-r--r-- | src/plugins/plugin.c | 2 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 11 |
10 files changed, 386 insertions, 2 deletions
@@ -1,7 +1,7 @@ WeeChat ChangeLog ================= Sébastien Helleu <flashcode@flashtux.org> -v0.3.7-dev, 2011-11-08 +v0.3.7-dev, 2011-11-12 Version 0.3.7 (under dev!) @@ -22,6 +22,7 @@ Version 0.3.7 (under dev!) * core: fix compilation error with "pid_t" on Mac OS X (bug #34639) * core: enable background process under Cygwin to connect to servers, fix reconnection problem (bug #34626) +* api: add new functions strcasecmp_range and strncasecmp_range * irc: display channel voice notices received in channel buffer (bug #34762), display channel/op notices sent in channel buffer * irc: add option irc.color.mirc_remap to remap mirc colors in messages to diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index 7e04f3333..126f2c7db 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -596,6 +596,50 @@ int diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */ [NOTE] This function is not available in scripting API. +weechat_strcasecmp_range +^^^^^^^^^^^^^^^^^^^^^^^^ + +_New in version 0.3.7._ + +Locale and case independent string comparison, using a range for case +comparison. + +Prototype: + +[source,C] +---------------------------------------- +int weechat_strcasecmp_range (const char *string1, const char *string2, int range); +---------------------------------------- + +Arguments: + +* 'string1': first string for comparison +* 'string2': second string for comparison +* 'range': number of chars in case comparison, for example: +** 26: "A-Z" are lowered to "a-z" +** 29: "A-Z [ \ ]" are lowered to "a-z { | }" +** 30: "A-Z [ \ ] ^" are lowered to "a-z { | } ~" + +[NOTE] +Values 29 and 30 are used by some protocols like IRC. + +Return value: + +* difference between two strings: +** negative if string1 < string2 +** zero if string1 == string2 +** positive if string1 > string2 + +C example: + +[source,C] +---------------------------------------- +int diff = weechat_strcasecmp_range ("nick{away}", "NICK[away]", 29); /* == 0 */ +---------------------------------------- + +[NOTE] +This function is not available in scripting API. + weechat_strncasecmp ^^^^^^^^^^^^^^^^^^^ @@ -631,6 +675,51 @@ int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */ [NOTE] This function is not available in scripting API. +weechat_strncasecmp_range +^^^^^^^^^^^^^^^^^^^^^^^^^ + +_New in version 0.3.7._ + +Locale and case independent string comparison, for 'max' chars, using a range +for case comparison. + +Prototype: + +[source,C] +---------------------------------------- +int weechat_strncasecmp_range (const char *string1, const char *string2, int max, int range); +---------------------------------------- + +Arguments: + +* 'string1': first string for comparison +* 'string2': second string for comparison +* 'max': max chars to compare +* 'range': number of chars in case comparison, for example: +** 26: "A-Z" are lowered to "a-z" +** 29: "A-Z [ \ ]" are lowered to "a-z { | }" +** 30: "A-Z [ \ ] ^" are lowered to "a-z { | } ~" + +[NOTE] +Values 29 and 30 are used by some protocols like IRC. + +Return value: + +* difference between two strings: +** negative if string1 < string2 +** zero if string1 == string2 +** positive if string1 > string2 + +C example: + +[source,C] +---------------------------------------- +int diff = weechat_strncasecmp_range ("nick{away}", "NICK[away]", 6, 29); /* == 0 */ +---------------------------------------- + +[NOTE] +This function is not available in scripting API. + weechat_strcmp_ignore_chars ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index 2117f80b2..6a4981ed6 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -603,6 +603,50 @@ int diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */ [NOTE] Cette fonction n'est pas disponible dans l'API script. +weechat_strcasecmp_range +^^^^^^^^^^^^^^^^^^^^^^^^ + +_Nouveau dans la version 0.3.7._ + +Comparaison de chaînes indépendante de la locale et de la casse, avec un +intervalle pour comparer la casse. + +Prototype : + +[source,C] +---------------------------------------- +int weechat_strcasecmp_range (const char *string1, const char *string2, int range); +---------------------------------------- + +Paramètres : + +* 'string1' : première chaîne à comparer +* 'string2' : seconde chaîne à comparer +* 'range' : nombre de caractères pour la comparaison de casse, par exemple : +** 26 : "A-Z" deviennent en minuscules "a-z" +** 29 : "A-Z [ \ ]" deviennent minuscules "a-z { | }" +** 30 : "A-Z [ \ ] ^" deviennent minuscules "a-z { | } ~" + +[NOTE] +Les valeurs 29 et 30 sont utilisés par quelques protocoles comme IRC. + +Valeur de retour : + +* différence entre les deux chaînes : +** négative si string1 < string2 +** zéro si string1 == string2 +** positive si string1 > string2 + +Exemple en C : + +[source,C] +---------------------------------------- +int diff = weechat_strcasecmp_range ("nick{away}", "NICK[away]", 29); /* == 0 */ +---------------------------------------- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + weechat_strncasecmp ^^^^^^^^^^^^^^^^^^^ @@ -639,6 +683,51 @@ int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */ [NOTE] Cette fonction n'est pas disponible dans l'API script. +weechat_strncasecmp_range +^^^^^^^^^^^^^^^^^^^^^^^^^ + +_Nouveau dans la version 0.3.7._ + +Comparaison de chaînes indépendante de la locale et de la casse, pour 'max' +caractères, avec un intervalle pour comparer la casse. + +Prototype : + +[source,C] +---------------------------------------- +int weechat_strncasecmp_range (const char *string1, const char *string2, int max, int range); +---------------------------------------- + +Paramètres : + +* 'string1' : première chaîne à comparer +* 'string2' : seconde chaîne à comparer +* 'max' : nombre maximum de caractères à comparer +* 'range' : nombre de caractères pour la comparaison de casse, par exemple : +** 26 : "A-Z" deviennent en minuscules "a-z" +** 29 : "A-Z [ \ ]" deviennent minuscules "a-z { | }" +** 30 : "A-Z [ \ ] ^" deviennent minuscules "a-z { | } ~" + +[NOTE] +Les valeurs 29 et 30 sont utilisés par quelques protocoles comme IRC. + +Valeur de retour : + +* différence entre les deux chaînes : +** négative si string1 < string2 +** zéro si string1 == string2 +** positive si string1 > string2 + +Exemple en C : + +[source,C] +---------------------------------------- +int diff = weechat_strncasecmp_range ("nick{away}", "NICK[away]", 6, 29); /* == 0 */ +---------------------------------------- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + weechat_strcmp_ignore_chars ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index d193d6b9f..0465b7e7c 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -613,6 +613,51 @@ int diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */ [NOTE] Questa funzione non è disponibile nelle API per lo scripting. +weechat_strcasecmp_range +^^^^^^^^^^^^^^^^^^^^^^^^ + +// TRANSLATION MISSING +Confronta stringa indipendente da caso (maiuscole +o minuscole) e da locale, using a range for case comparison. + +Prototipo: + +[source,C] +---------------------------------------- +int weechat_strcasecmp_range (const char *string1, const char *string2, int range); +---------------------------------------- + +Argomenti: + +* 'string1': prima stringa da comparare +* 'string2': seconda stringa da comparare +// TRANSLATION MISSING +* 'range': number of chars in case comparison, for example: +** 26: "A-Z" are lowered to "a-z" +** 29: "A-Z [ \ ]" are lowered to "a-z { | }" +** 30: "A-Z [ \ ] ^" are lowered to "a-z { | } ~" + +// TRANSLATION MISSING +[NOTE] +Values 29 and 30 are used by some protocols like IRC. + +Valore restituito: + +* differenze tra le due stringhe: +** negativa se stringa1 < stringa2 +** zero se stringa1 == stringa1 +** positiva se stringa1 > stringa2 + +Esempio in C: + +[source,C] +---------------------------------------- +int diff = weechat_strcasecmp ("nick{away}", "NICK[AWAY]"); /* == 0 */ +---------------------------------------- + +[NOTE] +Questa funzione non è disponibile nelle API per lo scripting. + weechat_strncasecmp ^^^^^^^^^^^^^^^^^^^ @@ -649,6 +694,52 @@ int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */ [NOTE] Questa funzione non è disponibile nelle API per lo scripting. +weechat_strncasecmp_range +^^^^^^^^^^^^^^^^^^^^^^^^^ + +// TRANSLATION MISSING +Confronta stringa indipendente da caso (maiuscole o minuscole) e da locale, per +un numero 'max' di caratteri, using a range for case comparison. + +Prototipo: + +[source,C] +---------------------------------------- +int weechat_strncasecmp_range (const char *string1, const char *string2, int max, int range); +---------------------------------------- + +Argomenti: + +* 'string1': prima stringa da comparare +* 'string2': seconda stringa da comparare +* 'max': numero massimo di caratteri da comparare +// TRANSLATION MISSING +* 'range': number of chars in case comparison, for example: +** 26: "A-Z" are lowered to "a-z" +** 29: "A-Z [ \ ]" are lowered to "a-z { | }" +** 30: "A-Z [ \ ] ^" are lowered to "a-z { | } ~" + +// TRANSLATION MISSING +[NOTE] +Values 29 and 30 are used by some protocols like IRC. + +Valore restituito: + +* differenze tra le due stringhe: +** negativa se stringa1 < stringa2 +** zero se stringa1 == stringa1 +** positiva se stringa1 > stringa2 + +Esempio in C: + +[source,C] +---------------------------------------- +int diff = weechat_strncasecmp_range ("nick{away}", "NICK[away]", 6, 29); /* == 0 */ +---------------------------------------- + +[NOTE] +Questa funzione non è disponibile nelle API per lo scripting. + weechat_strcmp_ignore_chars ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/core/wee-string.c b/src/core/wee-string.c index ad534cbb6..679c0c21a 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -139,6 +139,37 @@ string_strcasecmp (const char *string1, const char *string2) } /* + * string_strcasecmp_range: locale and case independent string comparison + * using range to compare case: + * - 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) + */ + +int +string_strcasecmp_range (const char *string1, const char *string2, int range) +{ + int diff; + + if (!string1 || !string2) + return (string1) ? 1 : ((string2) ? -1 : 0); + + while (string1[0] && string2[0]) + { + diff = utf8_charcasecmp_range (string1, string2, range); + if (diff != 0) + return diff; + + string1 = utf8_next_char (string1); + string2 = utf8_next_char (string2); + } + + return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0); +} + +/* * string_strncasecmp: locale and case independent string comparison * with max length */ @@ -170,6 +201,43 @@ string_strncasecmp (const char *string1, const char *string2, int max) } /* + * string_strncasecmp_range: locale and case independent string comparison + * with max length, using range to compare case: + * - 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) + */ + +int +string_strncasecmp_range (const char *string1, const char *string2, int max, + int range) +{ + int count, diff; + + if (!string1 || !string2) + return (string1) ? 1 : ((string2) ? -1 : 0); + + count = 0; + while ((count < max) && string1[0] && string2[0]) + { + diff = utf8_charcasecmp_range (string1, string2, range); + if (diff != 0) + return diff; + + string1 = utf8_next_char (string1); + string2 = utf8_next_char (string2); + count++; + } + + if (count >= max) + return 0; + else + return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0); +} + +/* * string_strcmp_ignore_chars: compare 2 strings, ignoring ignore some chars */ diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 48832408f..70b38a0b2 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -28,8 +28,12 @@ extern char *string_strndup (const char *string, int length); extern void string_tolower (char *string); extern void string_toupper (char *string); extern int string_strcasecmp (const char *string1, const char *string2); +extern int string_strcasecmp_range (const char *string1, const char *string2, + int range); extern int string_strncasecmp (const char *string1, const char *string2, int max); +extern int string_strncasecmp_range (const char *string1, const char *string2, + int max, int range); extern int string_strcmp_ignore_chars (const char *string1, const char *string2, const char *chars_ignored, diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index d61261f33..0360b43b4 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -471,6 +471,35 @@ utf8_charcasecmp (const char *string1, const char *string2) } /* + * utf8_charcasecmp_range: compare two utf8 chars, case is ignored + * using a range, 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) + */ + +int +utf8_charcasecmp_range (const char *string1, const char *string2, int range) +{ + wint_t wchar1, wchar2; + + if (!string1 || !string2) + return (string1) ? 1 : ((string2) ? -1 : 0); + + wchar1 = utf8_wide_char (string1); + if ((wchar1 >= 'A') && (wchar1 < 'A' + (unsigned int)range)) + wchar1 += ('a' - 'A'); + + wchar2 = utf8_wide_char (string2); + if ((wchar2 >= 'A') && (wchar2 < 'A' + (unsigned int)range)) + wchar2 += ('a' - 'A'); + + return (wchar1 < wchar2) ? -1 : ((wchar1 == wchar2) ? 0 : 1); +} + +/* * utf8_char_size_screen: return number of chars needed on screen to display * UTF-8 char */ diff --git a/src/core/wee-utf8.h b/src/core/wee-utf8.h index 51a721143..07080a3c2 100644 --- a/src/core/wee-utf8.h +++ b/src/core/wee-utf8.h @@ -46,6 +46,8 @@ 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 char *utf8_add_offset (const char *string, int offset); extern int utf8_real_pos (const char *string, int pos); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index a298c830d..fe8782ee1 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -463,7 +463,9 @@ plugin_load (const char *filename, int argc, char **argv) new_plugin->string_tolower = &string_tolower; new_plugin->string_toupper = &string_toupper; new_plugin->strcasecmp = &string_strcasecmp; + new_plugin->strcasecmp_range = &string_strcasecmp_range; new_plugin->strncasecmp = &string_strncasecmp; + new_plugin->strncasecmp_range = &string_strncasecmp_range; new_plugin->strcmp_ignore_chars = &string_strcmp_ignore_chars; new_plugin->strcasestr = &string_strcasestr; new_plugin->string_match = &string_match; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 245cbcfdf..bed5d3c9c 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -46,7 +46,7 @@ struct timeval; */ /* API version (used to check that plugin has same API and can be loaded) */ -#define WEECHAT_PLUGIN_API_VERSION "20110826-01" +#define WEECHAT_PLUGIN_API_VERSION "20111112-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -207,7 +207,11 @@ struct t_weechat_plugin void (*string_tolower) (char *string); void (*string_toupper) (char *string); int (*strcasecmp) (const char *string1, const char *string2); + int (*strcasecmp_range) (const char *string1, const char *string2, + int range); int (*strncasecmp) (const char *string1, const char *string2, int max); + int (*strncasecmp_range) (const char *string1, const char *string2, + int max, int range); int (*strcmp_ignore_chars) (const char *string1, const char *string2, const char *chars_ignored, int case_sensitive); char *(*strcasestr) (const char *string, const char *search); @@ -884,8 +888,13 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->string_toupper(__string) #define weechat_strcasecmp(__string1, __string2) \ weechat_plugin->strcasecmp(__string1, __string2) +#define weechat_strcasecmp_range(__string1, __string2, __range) \ + weechat_plugin->strcasecmp_range(__string1, __string2, __range) #define weechat_strncasecmp(__string1, __string2, __max) \ weechat_plugin->strncasecmp(__string1, __string2, __max) +#define weechat_strncasecmp_range(__string1, __string2, __max, __range) \ + weechat_plugin->strncasecmp_range(__string1, __string2, __max, \ + __range) #define weechat_strcmp_ignore_chars(__string1, __string2, \ __chars_ignored, __case_sensitive) \ weechat_plugin->strcmp_ignore_chars(__string1, __string2, \ |