api: add new functions strcasecmp_range and strncasecmp_range

v2.8-utf8proc
Sebastien Helleu 2011-11-12 10:37:44 +01:00
parent 538e8257f6
commit 491412b314
10 changed files with 386 additions and 2 deletions

View File

@ -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

View File

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -138,6 +138,37 @@ string_strcasecmp (const char *string1, const char *string2)
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
}
/*
* 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
@ -169,6 +200,43 @@ string_strncasecmp (const char *string1, const char *string2, int max)
return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
}
/*
* 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
*/

View File

@ -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,

View File

@ -470,6 +470,35 @@ utf8_charcasecmp (const char *string1, const char *string2)
return (wchar1 < wchar2) ? -1 : ((wchar1 == wchar2) ? 0 : 1);
}
/*
* 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

View File

@ -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);

View File

@ -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;

View File

@ -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, \