summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc1
-rw-r--r--ReleaseNotes.adoc29
-rw-r--r--doc/en/weechat_plugin_api.en.adoc68
-rw-r--r--doc/fr/weechat_plugin_api.fr.adoc69
-rw-r--r--doc/it/weechat_plugin_api.it.adoc92
-rw-r--r--doc/ja/weechat_plugin_api.ja.adoc100
-rw-r--r--doc/sr/weechat_plugin_api.sr.adoc94
-rw-r--r--src/core/wee-string.c118
-rw-r--r--src/core/wee-utf8.c74
-rw-r--r--tests/unit/core/test-core-string.cpp132
-rw-r--r--tests/unit/core/test-core-utf8.cpp48
-rw-r--r--tests/unit/plugins/irc/test-irc-join.cpp4
12 files changed, 475 insertions, 354 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 027c17385..73e923a0e 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -26,6 +26,7 @@ New features::
* core: add signals "buffer_user_input_xxx" and "buffer_user_closing_xxx" for buffers created with `/buffer add` (issue #1848)
* core: add identifier in buffer lines (issue #901)
* core: add option `unicode` in command `/debug`
+ * api: return arithmetic difference between chars in functions string_strcasecmp, string_strcasecmp_range, string_strncasecmp, string_strncasecmp_range, string_strcmp_ignore_chars, utf8_charcmp, utf8_charcasecmp, utf8_charcasecmp_range
* api: return newly allocated string in functions string_tolower and string_toupper
* api: add function utf8_strncpy
* trigger: add regex command "y" to translate chars, set default regex command to "s" (regex replace) (issue #1510)
diff --git a/ReleaseNotes.adoc b/ReleaseNotes.adoc
index 1be4a54b3..3ac46d248 100644
--- a/ReleaseNotes.adoc
+++ b/ReleaseNotes.adoc
@@ -20,6 +20,35 @@ https://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog]
[[v3.8]]
== Version 3.8 (under dev)
+[[v3.8_return_code_string_comparison_functions]]
+=== Return code of string comparison functions
+
+The following functions now return arithmetic result of subtracting the last
+compared char in string2 from the last compared char in string1:
+
+* string_strcasecmp
+* string_strcasecmp_range
+* string_strncasecmp
+* string_strncasecmp_range
+* string_strcmp_ignore_chars
+* utf8_charcmp
+* utf8_charcasecmp
+* utf8_charcasecmp_range
+
+Example with WeeChat 3.8:
+
+[source,c]
+----
+int diff = string_strcasecmp ("aaa", "CCC"); /* == -2 */
+----
+
+With older releases:
+
+[source,c]
+----
+int diff = string_strcasecmp ("aaa", "CCC"); /* == -1 */
+----
+
[[v3.8_api_string_lower_upper]]
=== API functions string_tolower and string_toupper
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc
index 991d0d997..9000d55d3 100644
--- a/doc/en/weechat_plugin_api.en.adoc
+++ b/doc/en/weechat_plugin_api.en.adoc
@@ -715,18 +715,20 @@ Arguments:
* _string1_: first string for comparison
* _string2_: second string for comparison
-Return value:
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 if string1 < string2
+* < 0 if string1 < string2
* 0 if string1 == string2
-* 1 if string1 > string2
+* > 0 if string1 > string2
C example:
[source,c]
----
int diff;
-diff = weechat_strcasecmp ("aaa", "CCC"); /* == -1 */
+diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */
diff = weechat_strcasecmp ("noël", "NOËL"); /* == 0 */
----
@@ -735,7 +737,7 @@ This function is not available in scripting API.
==== strcasecmp_range
-_WeeChat ≥ 0.3.7, updated in 1.0._
+_WeeChat ≥ 0.3.7, updated in 1.0, 3.8._
Locale and case independent string comparison, using a range for case
comparison.
@@ -759,11 +761,13 @@ Arguments:
[NOTE]
Values 29 and 30 are used by some protocols like IRC.
-Return value:
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 if string1 < string2
+* < 0 if string1 < string2
* 0 if string1 == string2
-* 1 if string1 > string2
+* > 0 if string1 > string2
C example:
@@ -799,17 +803,19 @@ Arguments:
* _string2_: second string for comparison
* _max_: max chars to compare
-Return value:
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 if string1 < string2
+* < 0 if string1 < string2
* 0 if string1 == string2
-* 1 if string1 > string2
+* > 0 if string1 > string2
C example:
[source,c]
----
-int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */
+int diff = weechat_strncasecmp ("aabb", "AACC", 2); /* == 0 */
----
[NOTE]
@@ -817,7 +823,7 @@ This function is not available in scripting API.
==== strncasecmp_range
-_WeeChat ≥ 0.3.7, updated in 1.0._
+_WeeChat ≥ 0.3.7, updated in 1.0, 3.8._
Locale and case independent string comparison, for _max_ chars, using a range
for case comparison.
@@ -842,11 +848,13 @@ Arguments:
[NOTE]
Values 29 and 30 are used by some protocols like IRC.
-Return value:
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 if string1 < string2
+* < 0 if string1 < string2
* 0 if string1 == string2
-* 1 if string1 > string2
+* > 0 if string1 > string2
C example:
@@ -885,11 +893,13 @@ Behavior has changed in version 3.8 when _case_sensitive_ is set to 0: now all
uppercase letters are properly converted to lowercase (by calling function
`towlower`), in addition to the range `A` to `Z`.
-Return value:
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase if _case_sentitive_ is set to 0) from the last
+compared char in _string1_ (converted to lowercase if _case_sensitive_ is set to 0):
-* -1 if string1 < string2
+* < 0 if string1 < string2
* 0 if string1 == string2
-* 1 if string1 > string2
+* > 0 if string1 > string2
C example:
@@ -3629,7 +3639,7 @@ This function is not available in scripting API.
==== utf8_charcmp
-_Updated in 1.0._
+_Updated in 1.0, 3.8._
Compare two UTF-8 chars.
@@ -3645,11 +3655,12 @@ Arguments:
* _string1_: first string for comparison
* _string2_: second string for comparison
-Return value:
+Return value: arithmetic result of subtracting the first char in _string2_ from
+the first char in _string1_:
-* -1 if string1 < string2
-* 0 if string1 == string2
-* 1 if string1 > string2
+* < 0 if char1 < char2
+* 0 if char1 == char2
+* > 0 if char1 > char2
C example:
@@ -3684,11 +3695,12 @@ Arguments:
* _string1_: first string for comparison
* _string2_: second string for comparison
-Return value:
+Return value: arithmetic result of subtracting the first char in _string2_
+(converted to lowercase) from the first char in _string1_ (converted to lowercase):
-* -1 if string1 < string2
-* 0 if string1 == string2
-* 1 if string1 > string2
+* < 0 if char1 < char2
+* 0 if char1 == char2
+* > 0 if char1 > char2
C example:
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc
index ca52b4977..b07389d15 100644
--- a/doc/fr/weechat_plugin_api.fr.adoc
+++ b/doc/fr/weechat_plugin_api.fr.adoc
@@ -729,18 +729,20 @@ Paramètres :
* _string1_ : première chaîne à comparer
* _string2_ : seconde chaîne à comparer
-Valeur de retour :
+Valeur de retour : résultat de la soustraction du dernier caractère comparé
+dans _string2_ (converti en minuscule) du dernier caractère comparé dans
+_string1_ (converti en minuscule) :
-* -1 si string1 < string2
+* < 0 si string1 < string2
* 0 si string1 == string2
-* 1 si string1 > string2
+* > 0 si string1 > string2
Exemple en C :
[source,c]
----
int diff;
-diff = weechat_strcasecmp ("aaa", "CCC"); /* == -1 */
+diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */
diff = weechat_strcasecmp ("noël", "NOËL"); /* == 0 */
----
@@ -749,7 +751,7 @@ Cette fonction n'est pas disponible dans l'API script.
==== strcasecmp_range
-_WeeChat ≥ 0.3.7, mis à jour dans la 1.0._
+_WeeChat ≥ 0.3.7, mis à jour dans la 1.0, 3.8._
Comparer deux chaînes indépendemment de la locale et de la casse, avec un
intervalle pour comparer la casse.
@@ -773,11 +775,13 @@ Paramètres :
[NOTE]
Les valeurs 29 et 30 sont utilisés par quelques protocoles comme IRC.
-Valeur de retour :
+Valeur de retour : résultat de la soustraction du dernier caractère comparé
+dans _string2_ (converti en minuscule) du dernier caractère comparé dans
+_string1_ (converti en minuscule) :
-* -1 si string1 < string2
+* < 0 si string1 < string2
* 0 si string1 == string2
-* 1 si string1 > string2
+* > 0 si string1 > string2
Exemple en C :
@@ -813,17 +817,19 @@ Paramètres :
* _string2_ : seconde chaîne à comparer
* _max_ : nombre maximum de caractères à comparer
-Valeur de retour :
+Valeur de retour : résultat de la soustraction du dernier caractère comparé
+dans _string2_ (converti en minuscule) du dernier caractère comparé dans
+_string1_ (converti en minuscule) :
-* -1 si string1 < string2
+* < 0 si string1 < string2
* 0 si string1 == string2
-* 1 si string1 > string2
+* > 0 si string1 > string2
Exemple en C :
[source,c]
----
-int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */
+int diff = weechat_strncasecmp ("aabb", "AACC", 2); /* == 0 */
----
[NOTE]
@@ -831,7 +837,7 @@ Cette fonction n'est pas disponible dans l'API script.
==== strncasecmp_range
-_WeeChat ≥ 0.3.7, mis à jour dans la 1.0._
+_WeeChat ≥ 0.3.7, mis à jour dans la 1.0, 3.8._
Comparer deux chaînes indépendemment de la locale et de la casse, pour _max_
caractères, avec un intervalle pour comparer la casse.
@@ -856,11 +862,13 @@ Paramètres :
[NOTE]
Les valeurs 29 et 30 sont utilisés par quelques protocoles comme IRC.
-Valeur de retour :
+Valeur de retour : résultat de la soustraction du dernier caractère comparé
+dans _string2_ (converti en minuscule) du dernier caractère comparé dans
+_string1_ (converti en minuscule) :
-* -1 si string1 < string2
+* < 0 si string1 < string2
* 0 si string1 == string2
-* 1 si string1 > string2
+* > 0 si string1 > string2
Exemple en C :
@@ -900,11 +908,14 @@ positionné à 0 : désormais toutes les lettres en majuscules sont correctemen
converties en minuscules (par appel à la fonction `towlower`), en plus de
l'intervalle de `A` à `Z`.
-Valeur de retour :
+Valeur de retour : résultat de la soustraction du dernier caractère comparé
+dans _string2_ (converti en minuscule si _case_sensitive_ est positionné à 0)
+du dernier caractère comparé dans _string1_ (converti en minuscule si
+_case_sensitive_ est positionné à 0) :
-* -1 si string1 < string2
+* < 0 si string1 < string2
* 0 si string1 == string2
-* 1 si string1 > string2
+* > 0 si string1 > string2
Exemple en C :
@@ -3694,7 +3705,7 @@ Cette fonction n'est pas disponible dans l'API script.
==== utf8_charcmp
-_Mis à jour dans la 1.0._
+_Mis à jour dans la 1.0, 3.8._
Comparer deux caractères UTF-8.
@@ -3710,11 +3721,12 @@ Paramètres :
* _string1_ : première chaîne pour la comparaison
* _string2_ : seconde chaîne pour la comparaison
-Valeur de retour :
+Valeur de retour : résultat de la soustraction du premier caractère dans _string2_
+du premier caractère dans _string1_ :
-* -1 si string1 < string2
-* 0 si string1 == string2
-* 1 si string1 > string2
+* < 0 si char1 < char2
+* 0 si char1 == char2
+* > 0 si char1 > char2
Exemple en C :
@@ -3749,11 +3761,12 @@ Paramètres :
* _string1_ : première chaîne pour la comparaison
* _string2_ : seconde chaîne pour la comparaison
-Valeur de retour :
+Valeur de retour : résultat de la soustraction du premier caractère dans _string2_
+(converti en minuscule) du premier caractère dans _string1_ (converti en minuscule) :
-* -1 si string1 < string2
-* 0 si string1 == string2
-* 1 si string1 > string2
+* < 0 si char1 < char2
+* 0 si char1 == char2
+* > 0 si char1 > char2
Exemple en C :
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc
index 8b226a562..afbf3b5bf 100644
--- a/doc/it/weechat_plugin_api.it.adoc
+++ b/doc/it/weechat_plugin_api.it.adoc
@@ -760,18 +760,22 @@ Argomenti:
* _string1_: prima stringa da comparare
* _string2_: seconda stringa da comparare
-Valore restituito:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 se stringa1 < stringa2
-* 0 se stringa1 == stringa1
-* 1 se stringa1 > stringa2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
Esempio in C:
[source,c]
----
int diff;
-diff = weechat_strcasecmp ("aaa", "CCC"); /* == -1 */
+diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */
diff = weechat_strcasecmp ("noël", "NOËL"); /* == 0 */
----
@@ -781,7 +785,7 @@ Questa funzione non è disponibile nelle API per lo scripting.
==== strcasecmp_range
// TRANSLATION MISSING
-_WeeChat ≥ 0.3.7, updated in 1.0._
+_WeeChat ≥ 0.3.7, updated in 1.0, 3.8._
Confronta stringa non sensibile alle maiuscole e alla localizzazione, usando una
serie per il confronto.
@@ -805,11 +809,15 @@ Argomenti:
[NOTE]
I valori 29 e 30 vengono usati da alcuni protocolli come IRC.
-Valore restituito:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 se stringa1 < stringa2
-* 0 se stringa1 == stringa1
-* 1 se stringa1 > stringa2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
Esempio in C:
@@ -848,17 +856,21 @@ Argomenti:
* _string2_: seconda stringa da comparare
* _max_: numero massimo di caratteri da comparare
-Valore restituito:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 se stringa1 < stringa2
-* 0 se stringa1 == stringa1
-* 1 se stringa1 > stringa2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
Esempio in C:
[source,c]
----
-int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */
+int diff = weechat_strncasecmp ("aabb", "AACC", 2); /* == 0 */
----
[NOTE]
@@ -867,7 +879,7 @@ Questa funzione non è disponibile nelle API per lo scripting.
==== strncasecmp_range
// TRANSLATION MISSING
-_WeeChat ≥ 0.3.7, updated in 1.0._
+_WeeChat ≥ 0.3.7, updated in 1.0, 3.8._
Confronta una stringa non sensibile alle maiuscole e alla localizzazione, per un
numero _max_ di caratteri, usando una serie per il confronto.
@@ -892,11 +904,15 @@ Argomenti:
[NOTE]
I valori 29 e 30 vengono usati da alcuni protocolli come IRC.
-Valore restituito:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 se stringa1 < stringa2
-* 0 se stringa1 == stringa1
-* 1 se stringa1 > stringa2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
Esempio in C:
@@ -938,11 +954,15 @@ Behavior has changed in version 3.8 when _case_sensitive_ is set to 0: now all
uppercase letters are properly converted to lowercase (by calling function
`towlower`), in addition to the range `A` to `Z`.
-Valore restituito:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase if _case_sentitive_ is set to 0) from the last
+compared char in _string1_ (converted to lowercase if _case_sensitive_ is set to 0):
-* -1 se stringa1 < stringa2
-* 0 se stringa1 == stringa1
-* 1 se stringa1 > stringa2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
Esempio in C:
@@ -3786,7 +3806,7 @@ Questa funzione non è disponibile nelle API per lo scripting.
==== utf8_charcmp
// TRANSLATION MISSING
-_Updated in 1.0._
+_Updated in 1.0, 3.8._
Confronta due caratteri UTF-8.
@@ -3802,11 +3822,14 @@ Argomenti:
* _string1_: prima stringa da comparare
* _string2_: seconda stringa da comparare
-Valore restituito:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the first char in _string2_ from
+the first char in _string1_:
-* -1 se string1 < string2
-* 0 se string1 == string2
-* 1 se string1 > string2
+// TRANSLATION MISSING
+* < 0 if char1 < char2
+* 0 if char1 == char2
+* > 0 if char1 > char2
Esempio in C:
@@ -3843,11 +3866,14 @@ Argomenti:
* _string1_: prima stringa da comparare
* _string2_: seconda stringa da comparare
-Valore restituito:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the first char in _string2_
+(converted to lowercase) from the first char in _string1_ (converted to lowercase):
-* -1 se string1 < string2
-* 0 se string1 == string2
-* 1 se string1 > string2
+// TRANSLATION MISSING
+* < 0 if char1 < char2
+* 0 if char1 == char2
+* > 0 if char1 > char2
Esempio in C:
diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc
index c9dd3152b..2de5fdf9c 100644
--- a/doc/ja/weechat_plugin_api.ja.adoc
+++ b/doc/ja/weechat_plugin_api.ja.adoc
@@ -727,9 +727,7 @@ range `A` to `Z`.
[source,c]
----
-int diff;
-diff = weechat_strcasecmp ("aaa", "CCC"); /* == -1 */
-diff = weechat_strcasecmp ("noël", "NOËL"); /* == 0 */
+int weechat_strcasecmp (const char *string1, const char *string2);
----
引数:
@@ -737,17 +735,23 @@ diff = weechat_strcasecmp ("noël", "NOËL"); /* == 0 */
* _string1_: 1 番目の比較対象の文字列
* _string2_: 2 番目の比較対象の文字列
-戻り値:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* string1 < string2 の場合は -1
-* string1 == string2 の場合は 0
-* string1 > string2 の場合は 1
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C 言語での使用例:
[source,c]
----
-int diff = weechat_strcasecmp ("aaa", "CCC"); /* == -1 */
+int diff;
+diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */
+diff = weechat_strcasecmp ("noël", "NOËL"); /* == 0 */
----
[NOTE]
@@ -755,7 +759,7 @@ int diff = weechat_strcasecmp ("aaa", "CCC"); /* == -1 */
==== strcasecmp_range
-_WeeChat バージョン 0.3.7 以上で利用可、バージョン 1.0 で更新。_
+_WeeChat バージョン 0.3.7 以上で利用可、バージョン 1.0, 3.8 で更新。_
大文字小文字を無視する文字範囲の幅を使い、ロケールと大文字小文字を無視して文字列を比較。
@@ -778,11 +782,15 @@ int weechat_strcasecmp_range (const char *string1, const char *string2, int rang
[NOTE]
29 と 30 は IRC など一部のプロトコルで使います。
-戻り値:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* string1 < string2 の場合は -1
-* string1 == string2 の場合は 0
-* string1 > string2 の場合は 1
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C 言語での使用例:
@@ -796,7 +804,7 @@ int diff = weechat_strcasecmp_range ("nick{away}", "NICK[away]", 29); /* == 0 *
==== strncasecmp
-_WeeChat バージョン 1.0 で更新。_
+_WeeChat バージョン 1.0, 3.8 で更新。_
// TRANSLATION MISSING
Case insensitive string comparison, for _max_ chars.
@@ -820,17 +828,21 @@ int weechat_strncasecmp (const char *string1, const char *string2, int max);
* _string2_: 2 番目の比較対象の文字列
* _max_: 比較する文字数の最大値
-戻り値:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* string1 < string2 の場合は -1
-* string1 == string2 の場合は 0
-* string1 > string2 の場合は 1
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C 言語での使用例:
[source,c]
----
-int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */
+int diff = weechat_strncasecmp ("aabb", "AACC", 2); /* == 0 */
----
[NOTE]
@@ -838,7 +850,7 @@ int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */
==== strncasecmp_range
-_WeeChat バージョン 0.3.7 以上で利用可、バージョン 1.0 で更新。_
+_WeeChat バージョン 0.3.7 以上で利用可、バージョン 1.0, 3.8 で更新。_
大文字小文字を無視する文字範囲の幅を使い、ロケールと大文字小文字を無視して
_max_ 文字だけ文字列を比較。
@@ -863,11 +875,15 @@ int weechat_strncasecmp_range (const char *string1, const char *string2, int max
[NOTE]
29 と 30 は IRC など一部のプロトコルで使います。
-戻り値:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* string1 < string2 の場合は -1
-* string1 == string2 の場合は 0
-* string1 > string2 の場合は 1
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C 言語での使用例:
@@ -908,11 +924,15 @@ Behavior has changed in version 3.8 when _case_sensitive_ is set to 0: now all
uppercase letters are properly converted to lowercase (by calling function
`towlower`), in addition to the range `A` to `Z`.
-戻り値:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase if _case_sentitive_ is set to 0) from the last
+compared char in _string1_ (converted to lowercase if _case_sensitive_ is set to 0):
-* string1 < string2 の場合は -1
-* string1 == string2 の場合は 0
-* string1 > string2 の場合は 1
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C 言語での使用例:
@@ -3713,7 +3733,7 @@ int length_on_screen = weechat_utf8_strlen_screen ("é"); /* == 1 */
==== utf8_charcmp
-_WeeChat バージョン 1.0 で更新。_
+_WeeChat バージョン 1.0, 3.8 で更新。_
2 つの UTF-8 文字を比較。
@@ -3729,11 +3749,14 @@ int weechat_utf8_charcmp (const char *string1, const char *string2);
* _string1_: 1 番目の比較文字列
* _string2_: 2 番目の比較文字列
-戻り値:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the first char in _string2_ from
+the first char in _string1_:
-* string1 < string2 の場合は -1
-* string1 == string2 の場合は 0
-* string1 > string2 の場合は 1
+// TRANSLATION MISSING
+* < 0 if char1 < char2
+* 0 if char1 == char2
+* > 0 if char1 > char2
C 言語での使用例:
@@ -3769,11 +3792,14 @@ int weechat_utf8_charcasecmp (const char *string1, const char *string2);
* _string1_: 1 番目の比較文字列
* _string2_: 2 番目の比較文字列
-戻り値:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the first char in _string2_
+(converted to lowercase) from the first char in _string1_ (converted to lowercase):
-* string1 < string2 の場合は -1
-* string1 == string2 の場合は 0
-* string1 > string2 の場合は 1
+// TRANSLATION MISSING
+* < 0 if char1 < char2
+* 0 if char1 == char2
+* > 0 if char1 > char2
C 言語での使用例:
diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc
index c32f7202b..15ef3ba83 100644
--- a/doc/sr/weechat_plugin_api.sr.adoc
+++ b/doc/sr/weechat_plugin_api.sr.adoc
@@ -698,16 +698,22 @@ int weechat_strcasecmp (const char *string1, const char *string2);
Повратна вредност:
-* -1 ако је string1 < string2
-* 0 ако је string1 == string2
-* 1 ако је string1 > string2
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
+
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C пример:
[source,c]
----
int diff;
-diff = weechat_strcasecmp ("aaa", "CCC"); /* == -1 */
+diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */
diff = weechat_strcasecmp ("noël", "NOËL"); /* == 0 */
----
@@ -716,7 +722,7 @@ diff = weechat_strcasecmp ("noël", "NOËL"); /* == 0 */
==== strcasecmp_range
-_WeeChat ≥ 0.3.7, ажурирано у верзији 1.0._
+_WeeChat ≥ 0.3.7, ажурирано у верзији 1.0, 3.8._
Поређење стрингова независно од величине слова и локал подешавања, употребом опсега за поређење величине слова.
@@ -739,11 +745,15 @@ int weechat_strcasecmp_range (const char *string1, const char *string2, int rang
[NOTE]
Вредности 29 и 30 користе неки протоколи, као што је IRC.
-Повратна вредност:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 ако је string1 < string2
-* 0 ако је string1 == string2
-* 1 ако је string1 > string2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C пример:
@@ -757,7 +767,7 @@ int diff = weechat_strcasecmp_range ("nick{away}", "NICK[away]", 29); /* == 0 *
==== strncasecmp
-_Ажурирано у верзији 1.0._
+_Ажурирано у верзији 1.0, 3.8._
// TRANSLATION MISSING
Case insensitive string comparison, for _max_ chars.
@@ -781,17 +791,21 @@ int weechat_strncasecmp (const char *string1, const char *string2, int max);
* _string2_: други стринг за поређење
* _max_: максимални број карактера који се пореде
-Повратна вредност:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 ако је string1 < string2
-* 0 ако је string1 == string2
-* 1 ако је string1 > string2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C пример:
[source,c]
----
-int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */
+int diff = weechat_strncasecmp ("aabb", "AACC", 2); /* == 0 */
----
[NOTE]
@@ -799,7 +813,7 @@ int diff = weechat_strncasecmp ("aabb", "aacc", 2); /* == 0 */
==== strncasecmp_range
-_WeeChat ≥ 0.3.7, ажурирано у верзији 1.0._
+_WeeChat ≥ 0.3.7, ажурирано у верзији 1.0, 3.8._
Поређење стрингова независно од величине слова и локал подешавања, за _max_ карактера, користећи опсег за поређење величине слова.
@@ -823,11 +837,15 @@ int weechat_strncasecmp_range (const char *string1, const char *string2, int max
[NOTE]
Вредности 29 и 30 користе неки протоколи, као што је IRC.
-Повратна вредност:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase) from the last compared char in _string1_
+(converted to lowercase):
-* -1 ако је string1 < string2
-* 0 ако је string1 == string2
-* 1 ако је string1 > string2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C пример:
@@ -868,11 +886,15 @@ Behavior has changed in version 3.8 when _case_sensitive_ is set to 0: now all
uppercase letters are properly converted to lowercase (by calling function
`towlower`), in addition to the range `A` to `Z`.
-Повратна вредност:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared char in
+_string2_ (converted to lowercase if _case_sentitive_ is set to 0) from the last
+compared char in _string1_ (converted to lowercase if _case_sensitive_ is set to 0):
-* -1 ако је string1 < string2
-* 0 ако је string1 == string2
-* 1 ако је string1 > string2
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
C пример:
@@ -3520,7 +3542,7 @@ int length_on_screen = weechat_utf8_strlen_screen ("é"); /* == 1 */
==== utf8_charcmp
-_Ажурирано у верзији 1.0._
+_Ажурирано у верзији 1.0, 3.8._
Пореди два UTF-8 карактера.
@@ -3536,11 +3558,14 @@ int weechat_utf8_charcmp (const char *string1, const char *string2);
* _string1_: први стринг за поређење
* _string2_: други стринг за поређење
-Повратна вредност:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the first char in _string2_ from
+the first char in _string1_:
-* -1 ако је string1 < string2
-* 0 ако је string1 == string2
-* 1 ако је string1 > string2
+// TRANSLATION MISSING
+* < 0 if char1 < char2
+* 0 if char1 == char2
+* > 0 if char1 > char2
C пример:
@@ -3576,11 +3601,14 @@ int weechat_utf8_charcasecmp (const char *string1, const char *string2);
* _string1_: први стринг за поређење
* _string2_: други стринг за поређење
-Повратна вредност:
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the first char in _string2_
+(converted to lowercase) from the first char in _string1_ (converted to lowercase):
-* -1 ако је string1 < string2
-* 0 ако је string1 == string2
-* 1 ако је string1 > string2
+// TRANSLATION MISSING
+* < 0 if char1 < char2
+* 0 if char1 == char2
+* > 0 if char1 > char2
C пример:
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 4bf43094e..3c258ec94 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -394,12 +394,14 @@ string_toupper (const char *string)
}
/*
- * Compares two strings (locale and case independent).
+ * Compares two strings (case insensitive).
*
- * Returns:
- * -1: string1 < string2
- * 0: string1 == string2
- * 1: string1 > string2
+ * 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
@@ -407,24 +409,21 @@ string_strcasecmp (const char *string1, const char *string2)
{
int diff;
- if (!string1 || !string2)
- return (string1) ? 1 : ((string2) ? -1 : 0);
-
- while (string1[0] && string2[0])
+ while (string1 && string1[0] && string2 && string2[0])
{
diff = utf8_charcasecmp (string1, string2);
if (diff != 0)
- return (diff < 0) ? -1 : 1;
+ return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
}
- return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
+ return utf8_charcasecmp (string1, string2);
}
/*
- * Compares two strings (locale and case independent) using a range.
+ * Compares two strings (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.
@@ -435,10 +434,12 @@ string_strcasecmp (const char *string1, const char *string2)
* - range = 30: A-Z [ \ ] ^ ==> a-z { | } ~
* (ranges 29 and 30 are used by some protocols like IRC)
*
- * Returns:
- * -1: string1 < string2
- * 0: string1 == string2
- * 1: string1 > string2
+ * 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
@@ -446,29 +447,28 @@ 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])
+ while (string1 && string1[0] && string2 && string2[0])
{
diff = utf8_charcasecmp_range (string1, string2, range);
if (diff != 0)
- return (diff < 0) ? -1 : 1;
+ return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
}
- return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
+ return utf8_charcasecmp_range (string1, string2, range);
}
/*
- * Compares two strings with max length (locale and case independent).
+ * Compares two strings with max length (case insensitive).
*
- * Returns:
- * -1: string1 < string2
+ * 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
- * 1: string1 > string2
+ * > 0: string1 > string2
*/
int
@@ -476,15 +476,12 @@ string_strncasecmp (const char *string1, const char *string2, int max)
{
int count, diff;
- if (!string1 || !string2)
- return (string1) ? 1 : ((string2) ? -1 : 0);
-
count = 0;
- while ((count < max) && string1[0] && string2[0])
+ while ((count < max) && string1 && string1[0] && string2 && string2[0])
{
diff = utf8_charcasecmp (string1, string2);
if (diff != 0)
- return (diff < 0) ? -1 : 1;
+ return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
@@ -494,12 +491,11 @@ string_strncasecmp (const char *string1, const char *string2, int max)
if (count >= max)
return 0;
else
- return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
+ return utf8_charcasecmp (string1, string2);
}
/*
- * Compares two strings with max length (locale and case independent) using a
- * range.
+ * Compares two strings with max length (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.
@@ -510,10 +506,12 @@ string_strncasecmp (const char *string1, const char *string2, int max)
* - range = 30: A-Z [ \ ] ^ ==> a-z { | } ~
* (ranges 29 and 30 are used by some protocols like IRC)
*
- * Returns:
- * -1: string1 < string2
- * 0: string1 == string2
- * 1: string1 > string2
+ * 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
@@ -522,15 +520,12 @@ string_strncasecmp_range (const char *string1, const char *string2, int max,
{
int count, diff;
- if (!string1 || !string2)
- return (string1) ? 1 : ((string2) ? -1 : 0);
-
count = 0;
- while ((count < max) && string1[0] && string2[0])
+ while ((count < max) && string1 && string1[0] && string2 && string2[0])
{
diff = utf8_charcasecmp_range (string1, string2, range);
if (diff != 0)
- return (diff < 0) ? -1 : 1;
+ return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
@@ -540,16 +535,19 @@ string_strncasecmp_range (const char *string1, const char *string2, int max,
if (count >= max)
return 0;
else
- return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0);
+ return utf8_charcasecmp_range (string1, string2, range);
}
/*
* Compares two strings, ignoring some chars.
*
- * Returns:
- * -1: string1 < string2
- * 0: string1 == string2
- * 1: string1 > string2
+ * Returns: arithmetic result of subtracting the last compared char in string2
+ * (converted to lowercase if case_sensitive is set to 0) from the last
+ * compared char in string1 (converted to lowercase if case_sensitive is set
+ * to 0):
+ * < 0: string1 < string2
+ * 0: string1 == string2
+ * > 0: string1 > string2
*/
int
@@ -558,9 +556,6 @@ string_strcmp_ignore_chars (const char *string1, const char *string2,
{
int diff;
- if (!string1 || !string2)
- return (string1) ? 1 : ((string2) ? -1 : 0);
-
while (string1 && string1[0] && string2 && string2[0])
{
/* skip ignored chars */
@@ -574,18 +569,18 @@ string_strcmp_ignore_chars (const char *string1, const char *string2,
}
/* end of one (or both) string(s) ? */
- if ((!string1 || !string1[0]) && (!string2 || !string2[0]))
- return 0;
- if ((!string1 || !string1[0]) && string2 && string2[0])
- return -1;
- if (string1 && string1[0] && (!string2 || !string2[0]))
- return 1;
+ if (!string1 || !string1[0] || !string2 || !string2[0])
+ {
+ return (case_sensitive) ?
+ utf8_charcmp (string1, string2) :
+ utf8_charcasecmp (string1, string2);
+ }
/* look at diff */
diff = (case_sensitive) ?
utf8_charcmp (string1, string2) : utf8_charcasecmp (string1, string2);
if (diff != 0)
- return (diff < 0) ? -1 : 1;
+ return diff;
string1 = utf8_next_char (string1);
string2 = utf8_next_char (string2);
@@ -600,11 +595,8 @@ string_strcmp_ignore_chars (const char *string1, const char *string2,
string2 = utf8_next_char (string2);
}
}
- if ((!string1 || !string1[0]) && string2 && string2[0])
- return -1;
- if (string1 && string1[0] && (!string2 || !string2[0]))
- return 1;
- return 0;
+ return (case_sensitive) ?
+ utf8_charcmp (string1, string2) : utf8_charcasecmp (string1, string2);
}
/*
diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c
index 8f6a69cff..557fc592d 100644
--- a/src/core/wee-utf8.c
+++ b/src/core/wee-utf8.c
@@ -531,48 +531,28 @@ utf8_strlen_screen (const char *string)
/*
* Compares two UTF-8 chars (case sensitive).
*
- * Returns:
- * -1: string1 < string2
- * 0: string1 == string2
- * 1: string1 > string2
+ * 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)
{
- int length1, length2, i, diff;
-
- if (!string1 || !string2)
- return (string1) ? 1 : ((string2) ? -1 : 0);
-
- length1 = utf8_char_size (string1);
- length2 = utf8_char_size (string2);
-
- i = 0;
- while ((i < length1) && (i < length2))
- {
- diff = (int)((unsigned char) string1[i]) - (int)((unsigned char) string2[i]);
- if (diff != 0)
- return (diff < 0) ? -1 : 1;
- i++;
- }
- /* string1 == string2 ? */
- if ((i == length1) && (i == length2))
- return 0;
- /* string1 < string2 ? */
- if (i == length1)
- return 1;
- /* string1 > string2 */
- return -1;
+ return utf8_char_int (string1) - utf8_char_int (string2);
}
/*
- * Compares two UTF-8 chars (case is ignored).
- *
- * Returns:
- * -1: string1 < string2
- * 0: string1 == string2
- * 1: string1 > 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
@@ -580,15 +560,12 @@ utf8_charcasecmp (const char *string1, const char *string2)
{
wint_t wchar1, wchar2;
- if (!string1 || !string2)
- return (string1) ? 1 : ((string2) ? -1 : 0);
-
/*
* optimization for single-byte chars: only letters A-Z must be converted
* to lowercase; this is faster than calling `towlower`
*/
- if (!((unsigned char)(string1[0]) & 0x80)
- && !((unsigned char)(string2[0]) & 0x80))
+ if (string1 && !((unsigned char)(string1[0]) & 0x80)
+ && string2 && !((unsigned char)(string2[0]) & 0x80))
{
wchar1 = string1[0];
if ((wchar1 >= 'A') && (wchar1 <= 'Z'))
@@ -603,11 +580,11 @@ utf8_charcasecmp (const char *string1, const char *string2)
wchar2 = towlower (utf8_char_int (string2));
}
- return (wchar1 < wchar2) ? -1 : ((wchar1 == wchar2) ? 0 : 1);
+ return wchar1 - wchar2;
}
/*
- * Compares two UTF-8 chars (case is ignored) using a range.
+ * 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.
@@ -618,10 +595,12 @@ utf8_charcasecmp (const char *string1, const char *string2)
* - range = 30: A-Z [ \ ] ^ ==> a-z { | } ~
* (ranges 29 and 30 are used by some protocols like IRC)
*
- * Returns:
- * < 0: char1 < char2
- * 0: char1 == char2
- * > 0: char1 > char2
+ * 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
@@ -629,9 +608,6 @@ utf8_charcasecmp_range (const char *string1, const char *string2, int range)
{
wchar_t wchar1, wchar2;
- if (!string1 || !string2)
- return (string1) ? 1 : ((string2) ? -1 : 0);
-
wchar1 = utf8_char_int (string1);
if ((wchar1 >= (wchar_t)'A') && (wchar1 < (wchar_t)('A' + range)))
wchar1 += ('a' - 'A');
@@ -640,7 +616,7 @@ utf8_charcasecmp_range (const char *string1, const char *string2, int range)
if ((wchar2 >= (wchar_t)'A') && (wchar2 < (wchar_t)('A' + range)))
wchar2 += ('a' - 'A');
- return (wchar1 < wchar2) ? -1 : ((wchar1 == wchar2) ? 0 : 1);
+ return wchar1 - wchar2;
}
/*
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 3dbcfbc78..540e241b5 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -468,107 +468,121 @@ TEST(CoreString, Comparison)
{
/* case-insensitive comparison */
LONGS_EQUAL(0, string_strcasecmp (NULL, NULL));
- LONGS_EQUAL(-1, string_strcasecmp (NULL, "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("abc", NULL));
+ LONGS_EQUAL(-97, string_strcasecmp (NULL, "abc"));
+ LONGS_EQUAL(97, string_strcasecmp ("abc", NULL));
+ LONGS_EQUAL(-98, string_strcasecmp ("", "b"));
+ LONGS_EQUAL(98, string_strcasecmp ("b", ""));
LONGS_EQUAL(0, string_strcasecmp ("abc", "abc"));
LONGS_EQUAL(0, string_strcasecmp ("abc", "ABC"));
LONGS_EQUAL(0, string_strcasecmp ("ABC", "ABC"));
- LONGS_EQUAL(-1, string_strcasecmp ("abc", "def"));
- LONGS_EQUAL(-1, string_strcasecmp ("abc", "DEF"));
- LONGS_EQUAL(-1, string_strcasecmp ("ABC", "def"));
- LONGS_EQUAL(-1, string_strcasecmp ("ABC", "DEF"));
- LONGS_EQUAL(1, string_strcasecmp ("def", "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("def", "ABC"));
- LONGS_EQUAL(1, string_strcasecmp ("DEF", "abc"));
- LONGS_EQUAL(1, string_strcasecmp ("DEF", "ABC"));
+ LONGS_EQUAL(-3, string_strcasecmp ("abc", "def"));
+ LONGS_EQUAL(-3, string_strcasecmp ("abc", "DEF"));
+ LONGS_EQUAL(-3, string_strcasecmp ("ABC", "def"));
+ LONGS_EQUAL(-3, string_strcasecmp ("ABC", "DEF"));
+ LONGS_EQUAL(3, string_strcasecmp ("def", "abc"));
+ LONGS_EQUAL(3, string_strcasecmp ("def", "ABC"));
+ LONGS_EQUAL(3, string_strcasecmp ("DEF", "abc"));
+ LONGS_EQUAL(3, string_strcasecmp ("DEF", "ABC"));
/* case-insensitive comparison with max length */
LONGS_EQUAL(0, string_strncasecmp (NULL, NULL, 3));
- LONGS_EQUAL(-1, string_strncasecmp (NULL, "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("abc", NULL, 3));
+ LONGS_EQUAL(-97, string_strncasecmp (NULL, "abc", 3));
+ LONGS_EQUAL(97, string_strncasecmp ("abc", NULL, 3));
+ LONGS_EQUAL(-98, string_strncasecmp ("", "b", 3));
+ LONGS_EQUAL(98, string_strncasecmp ("b", "", 3));
LONGS_EQUAL(0, string_strncasecmp ("abc", "abc", 3));
LONGS_EQUAL(0, string_strncasecmp ("abcabc", "abcdef", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abcabc", "abcdef", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abcabc", "abcdef", 6));
LONGS_EQUAL(0, string_strncasecmp ("abc", "ABC", 3));
LONGS_EQUAL(0, string_strncasecmp ("abcabc", "ABCDEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abcabc", "ABCDEF", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abcabc", "ABCDEF", 6));
LONGS_EQUAL(0, string_strncasecmp ("ABC", "ABC", 3));
LONGS_EQUAL(0, string_strncasecmp ("ABCABC", "ABCDEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABCABC", "ABCDEF", 6));
- LONGS_EQUAL(-1, string_strncasecmp ("abc", "def", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("abc", "DEF", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABC", "def", 3));
- LONGS_EQUAL(-1, string_strncasecmp ("ABC", "DEF", 3));
- LONGS_EQUAL(1, string_strncasecmp ("def", "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("def", "ABC", 3));
- LONGS_EQUAL(1, string_strncasecmp ("DEF", "abc", 3));
- LONGS_EQUAL(1, string_strncasecmp ("DEF", "ABC", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABCABC", "ABCDEF", 6));
+ LONGS_EQUAL(-3, string_strncasecmp ("abc", "def", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("abc", "DEF", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABC", "def", 3));
+ LONGS_EQUAL(-3, string_strncasecmp ("ABC", "DEF", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("def", "abc", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("def", "ABC", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("DEF", "abc", 3));
+ LONGS_EQUAL(3, string_strncasecmp ("DEF", "ABC", 3));
/* case-insensitive comparison with a range */
LONGS_EQUAL(0, string_strcasecmp_range (NULL, NULL, 30));
- LONGS_EQUAL(-1, string_strcasecmp_range (NULL, "abc", 30));
- LONGS_EQUAL(1, string_strcasecmp_range ("abc", NULL, 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("A", "Z", 30));
- LONGS_EQUAL(1, string_strcasecmp_range ("Z", "A", 30));
+ LONGS_EQUAL(-97, string_strcasecmp_range (NULL, "abc", 30));
+ LONGS_EQUAL(97, string_strcasecmp_range ("abc", NULL, 30));
+ LONGS_EQUAL(-98, string_strcasecmp_range ("", "b", 30));
+ LONGS_EQUAL(98, string_strcasecmp_range ("b", "", 30));
+ LONGS_EQUAL(-2, string_strcasecmp_range ("A", "C", 30));
+ LONGS_EQUAL(2, string_strcasecmp_range ("C", "A", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("A", "a", 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("ë", "€", 30));
+ LONGS_EQUAL(-8129, string_strcasecmp_range ("ë", "€", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("[", "{", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("]", "}", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("\\", "|", 30));
LONGS_EQUAL(0, string_strcasecmp_range ("^", "~", 30));
- LONGS_EQUAL(-1, string_strcasecmp_range ("[", "{", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("]", "}", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("\\", "|", 26));
- LONGS_EQUAL(-1, string_strcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("[", "{", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("{", "[", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("]", "}", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("}", "]", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("\\", "|", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("|", "\\", 26));
+ LONGS_EQUAL(-32, string_strcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(32, string_strcasecmp_range ("~", "^", 26));
/* case-insensitive comparison with max length and a range */
LONGS_EQUAL(0, string_strncasecmp_range (NULL, NULL, 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range (NULL, "abc", 3, 30));
- LONGS_EQUAL(1, string_strncasecmp_range ("abc", NULL, 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("ABC", "ZZZ", 3, 30));
- LONGS_EQUAL(1, string_strncasecmp_range ("ZZZ", "ABC", 3, 30));
+ LONGS_EQUAL(-97, string_strncasecmp_range (NULL, "abc", 3, 30));
+ LONGS_EQUAL(97, string_strncasecmp_range ("abc", NULL, 3, 30));
+ LONGS_EQUAL(-98, string_strncasecmp_range ("", "b", 3, 30));
+ LONGS_EQUAL(98, string_strncasecmp_range ("b", "", 3, 30));
+ LONGS_EQUAL(-2, string_strncasecmp_range ("ABC", "CCC", 3, 30));
+ LONGS_EQUAL(2, string_strncasecmp_range ("CCC", "ABC", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("ABC", "abc", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("ABCABC", "abcdef", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("ABCABC", "abcdef", 6, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("ëëë", "€€€", 3, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("ABCABC", "abcdef", 6, 30));
+ LONGS_EQUAL(-8129, string_strncasecmp_range ("ëëë", "€€€", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("[[[", "{{{", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("[[[abc", "{{{def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("[[[abc", "{{{def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("[[[abc", "{{{def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("]]]", "}}}", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("]]]abc", "}}}def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("]]]abc", "}}}def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("]]]abc", "}}}def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("\\\\\\", "|||", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("\\\\\\abc", "|||def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("\\\\\\abc", "|||def", 6, 30));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("\\\\\\abc", "|||def", 6, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("^^^", "~~~", 3, 30));
LONGS_EQUAL(0, string_strncasecmp_range ("^^^abc", "~~~def", 3, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("^^^abc", "~~~def", 6, 30));
- LONGS_EQUAL(-1, string_strncasecmp_range ("[[[", "{{{", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("]]]", "}}}", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("\\\\\\", "|||", 3, 26));
- LONGS_EQUAL(-1, string_strncasecmp_range ("^^^", "~~~", 3, 26));
+ LONGS_EQUAL(-3, string_strncasecmp_range ("^^^abc", "~~~def", 6, 30));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("[[[", "{{{", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("]]]", "}}}", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("\\\\\\", "|||", 3, 26));
+ LONGS_EQUAL(-32, string_strncasecmp_range ("^^^", "~~~", 3, 26));
/* comparison with chars ignored */
LONGS_EQUAL(0, string_strcmp_ignore_chars (NULL, NULL, "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars (NULL, "abc", "", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc", NULL, "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("ABC", "ZZZ", "", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("ZZZ", "ABC", "", 0));
+ LONGS_EQUAL(-97, string_strcmp_ignore_chars (NULL, "abc", "", 0));
+ LONGS_EQUAL(97, string_strcmp_ignore_chars ("abc", NULL, "", 0));
+ LONGS_EQUAL(-98, string_strcmp_ignore_chars ("", "b", "", 0));
+ LONGS_EQUAL(98, string_strcmp_ignore_chars ("b", "", "", 0));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("ABC", "CCC", "", 0));
+ LONGS_EQUAL(2, string_strcmp_ignore_chars ("CCC", "ABC", "", 0));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("ABC", "abc", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("ABC", "abc", "", 1));
+ LONGS_EQUAL(-32, string_strcmp_ignore_chars ("ABC", "abc", "", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("abc..abc", "abcabc", ".", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc..abc", "ABCABC", ".", 1));
+ LONGS_EQUAL(32, string_strcmp_ignore_chars ("abc..abc", "ABCABC", ".", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars ("abc..abc", "abc-.-.abc",
".-", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc..abc", "ABC-.-.ABC",
- ".-", 1));
+ LONGS_EQUAL(32, string_strcmp_ignore_chars ("abc..abc", "ABC-.-.ABC",
+ ".-", 1));
LONGS_EQUAL(0, string_strcmp_ignore_chars (".abc..abc", "..abcabc", ".", 0));
- LONGS_EQUAL(1, string_strcmp_ignore_chars (".abc..abc", "..", ".", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars (".", "..abcabc", ".", 0));
+ LONGS_EQUAL(97, string_strcmp_ignore_chars (".abc..abc", "..", ".", 0));
+ LONGS_EQUAL(-97, string_strcmp_ignore_chars (".", "..abcabc", ".", 0));
LONGS_EQUAL(0, string_strcmp_ignore_chars (".", ".", ".", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "é", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "É", "", 0));
- LONGS_EQUAL(-1, string_strcmp_ignore_chars ("è", "é", "", 1));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "ê", "", 0));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "Ê", "", 0));
+ LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "ê", "", 1));
}
/*
diff --git a/tests/unit/core/test-core-utf8.cpp b/tests/unit/core/test-core-utf8.cpp
index 7da5482b1..cd330eadf 100644
--- a/tests/unit/core/test-core-utf8.cpp
+++ b/tests/unit/core/test-core-utf8.cpp
@@ -602,43 +602,47 @@ TEST(CoreUtf8, Comparison)
{
/* case-sensitive comparison */
LONGS_EQUAL(0, utf8_charcmp (NULL, NULL));
- LONGS_EQUAL(-1, utf8_charcmp (NULL, "abc"));
- LONGS_EQUAL(1, utf8_charcmp ("abc", NULL));
+ LONGS_EQUAL(-97, utf8_charcmp (NULL, "abc"));
+ LONGS_EQUAL(97, utf8_charcmp ("abc", NULL));
LONGS_EQUAL(0, utf8_charcmp ("axx", "azz"));
- LONGS_EQUAL(-1, utf8_charcmp ("A", "Z"));
- LONGS_EQUAL(1, utf8_charcmp ("Z", "A"));
- LONGS_EQUAL(-1, utf8_charcmp ("A", "a"));
- LONGS_EQUAL(-1, utf8_charcmp ("ë", "€"));
- LONGS_EQUAL(1, utf8_charcmp ("ë", ""));
- LONGS_EQUAL(-1, utf8_charcmp ("", "ë"));
+ LONGS_EQUAL(-2, utf8_charcmp ("A", "C"));
+ LONGS_EQUAL(2, utf8_charcmp ("C", "A"));
+ LONGS_EQUAL(-32, utf8_charcmp ("A", "a"));
+ LONGS_EQUAL(-8129, utf8_charcmp ("ë", "€"));
+ LONGS_EQUAL(235, utf8_charcmp ("ë", ""));
+ LONGS_EQUAL(-235, utf8_charcmp ("", "ë"));
/* case-insensitive comparison */
LONGS_EQUAL(0, utf8_charcasecmp (NULL, NULL));
- LONGS_EQUAL(-1, utf8_charcasecmp (NULL, "abc"));
- LONGS_EQUAL(1, utf8_charcasecmp ("abc", NULL));
+ LONGS_EQUAL(-97, utf8_charcasecmp (NULL, "abc"));
+ LONGS_EQUAL(97, utf8_charcasecmp ("abc", NULL));
LONGS_EQUAL(0, utf8_charcasecmp ("axx", "azz"));
- LONGS_EQUAL(-1, utf8_charcasecmp ("A", "Z"));
- LONGS_EQUAL(1, utf8_charcasecmp ("Z", "A"));
+ LONGS_EQUAL(-2, utf8_charcasecmp ("A", "C"));
+ LONGS_EQUAL(2, utf8_charcasecmp ("C", "A"));
LONGS_EQUAL(0, utf8_charcasecmp ("A", "a"));
- LONGS_EQUAL(-1, utf8_charcasecmp ("ë", "€"));
+ LONGS_EQUAL(-8129, utf8_charcasecmp ("ë", "€"));
/* case-insensitive comparison with a range */
LONGS_EQUAL(0, utf8_charcasecmp_range (NULL, NULL, 30));
- LONGS_EQUAL(-1, utf8_charcasecmp_range (NULL, "abc", 30));
- LONGS_EQUAL(1, utf8_charcasecmp_range ("abc", NULL, 30));
+ LONGS_EQUAL(-97, utf8_charcasecmp_range (NULL, "abc", 30));
+ LONGS_EQUAL(97, utf8_charcasecmp_range ("abc", NULL, 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("axx", "azz", 30));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("A", "Z", 30));
- LONGS_EQUAL(1, utf8_charcasecmp_range ("Z", "A", 30));
+ LONGS_EQUAL(-2, utf8_charcasecmp_range ("A", "C", 30));
+ LONGS_EQUAL(2, utf8_charcasecmp_range ("C", "A", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("A", "a", 30));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("ë", "€", 30));
+ LONGS_EQUAL(-8129, utf8_charcasecmp_range ("ë", "€", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("[", "{", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("]", "}", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("\\", "|", 30));
LONGS_EQUAL(0, utf8_charcasecmp_range ("^", "~", 30));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("[", "{", 26));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("]", "}", 26));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("\\", "|", 26));
- LONGS_EQUAL(-1, utf8_charcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(-32, utf8_charcasecmp_range ("[", "{", 26));
+ LONGS_EQUAL(32, utf8_charcasecmp_range ("{", "[", 26));
+ LONGS_EQUAL(-32, utf8_charcasecmp_range ("]", "}", 26));
+ LONGS_EQUAL(32, utf8_charcasecmp_range ("}", "]", 26));
+ LONGS_EQUAL(-32, utf8_charcasecmp_range ("\\", "|", 26));
+ LONGS_EQUAL(32, utf8_charcasecmp_range ("|", "\\", 26));
+ LONGS_EQUAL(-32, utf8_charcasecmp_range ("^", "~", 26));
+ LONGS_EQUAL(32, utf8_charcasecmp_range ("~", "^", 26));
}
/*
diff --git a/tests/unit/plugins/irc/test-irc-join.cpp b/tests/unit/plugins/irc/test-irc-join.cpp
index 54b8076b0..2ab88910d 100644
--- a/tests/unit/plugins/irc/test-irc-join.cpp
+++ b/tests/unit/plugins/irc/test-irc-join.cpp
@@ -112,7 +112,7 @@ TEST(IrcJoin, CompateJoinChannel)
LONGS_EQUAL(0, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
join_chan1.name = strdup ("#abc");
- LONGS_EQUAL(1, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+ LONGS_EQUAL(35, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
join_chan2.name = strdup ("#abc");
LONGS_EQUAL(0, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
@@ -129,7 +129,7 @@ TEST(IrcJoin, CompateJoinChannel)
free (join_chan2.name);
join_chan2.name = strdup ("#def");
- LONGS_EQUAL(-1, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
+ LONGS_EQUAL(-3, irc_join_compare_join_channel (NULL, &join_chan1, &join_chan2));
free (join_chan1.name);
free (join_chan1.key);