summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc1
-rw-r--r--doc/en/weechat_plugin_api.en.adoc71
-rw-r--r--doc/fr/weechat_plugin_api.fr.adoc71
-rw-r--r--doc/it/weechat_plugin_api.it.adoc79
-rw-r--r--doc/ja/weechat_plugin_api.ja.adoc77
-rw-r--r--doc/sr/weechat_plugin_api.sr.adoc79
-rw-r--r--src/core/wee-string.c61
-rw-r--r--src/core/wee-string.h2
-rw-r--r--src/plugins/plugin.c2
-rw-r--r--src/plugins/weechat-plugin.h8
-rw-r--r--tests/unit/core/test-core-string.cpp44
11 files changed, 494 insertions, 1 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index da21a1a33..3e961c2d6 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: add functions string_strcmp and string_strncmp
* api: rename char comparison functions "utf8_char*" to "string_char*"
* api: return arithmetic difference between chars in functions string_charcmp, string_charcasecmp, string_charcasecmp_range, string_strcasecmp, string_strcasecmp_range, string_strncasecmp, string_strncasecmp_range, string_strcmp_ignore_chars
* api: return newly allocated string in 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 6b558350e..9467a53d0 100644
--- a/doc/en/weechat_plugin_api.en.adoc
+++ b/doc/en/weechat_plugin_api.en.adoc
@@ -768,6 +768,77 @@ int diff = weechat_string_charcasecmp ("aaa", "CCC"); /* == -2 */
[NOTE]
This function is not available in scripting API.
+==== strcmp
+
+_WeeChat ≥ 3.8._
+
+Case sensitive string comparison.
+
+Prototype:
+
+[source,c]
+----
+int weechat_strcmp (const char *string1, const char *string2);
+----
+
+Arguments:
+
+* _string1_: first string for comparison
+* _string2_: second string for comparison
+
+Return value: arithmetic result of subtracting the last compared UTF-8 char in
+_string2_ from the last compared UTF-8 char in _string1_:
+
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
+
+C example:
+
+[source,c]
+----
+int diff = weechat_strcmp ("aaa", "ccc"); /* == -2 */
+----
+
+[NOTE]
+This function is not available in scripting API.
+
+==== strncmp
+
+_WeeChat ≥ 3.8._
+
+Case sensitive string comparison, for _max_ chars.
+
+Prototype:
+
+[source,c]
+----
+int weechat_strncmp (const char *string1, const char *string2, int max);
+----
+
+Arguments:
+
+* _string1_: first string for comparison
+* _string2_: second string for comparison
+* _max_: max chars to compare
+
+Return value: arithmetic result of subtracting the last compared UTF-8 char in
+_string2_ from the last compared UTF-8 char in _string1_:
+
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
+
+C example:
+
+[source,c]
+----
+int diff = weechat_strncmp ("aabb", "aacc", 2); /* == 0 */
+----
+
+[NOTE]
+This function is not available in scripting API.
+
==== strcasecmp
_Updated in 1.0, 3.8._
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc
index fbe5ebdf7..44fb3d81d 100644
--- a/doc/fr/weechat_plugin_api.fr.adoc
+++ b/doc/fr/weechat_plugin_api.fr.adoc
@@ -782,6 +782,77 @@ int diff = weechat_string_charcasecmp ("aaa", "CCC"); /* == -2 */
[NOTE]
Cette fonction n'est pas disponible dans l'API script.
+==== strcmp
+
+_WeeChat ≥ 3.8._
+
+Comparer deux chaînes.
+
+Prototype :
+
+[source,c]
+----
+int weechat_strcmp (const char *string1, const char *string2);
+----
+
+Paramètres :
+
+* _string1_ : première chaîne à comparer
+* _string2_ : seconde chaîne à comparer
+
+Valeur de retour : résultat de la soustraction du dernier caractère UTF-8 comparé
+dans _string2_ du dernier caractère UTF-8 comparé dans _string1_ :
+
+* < 0 si string1 < string2
+* 0 si string1 == string2
+* > 0 si string1 > string2
+
+Exemple en C :
+
+[source,c]
+----
+int diff = weechat_strcmp ("aaa", "ccc"); /* == -2 */
+----
+
+[NOTE]
+Cette fonction n'est pas disponible dans l'API script.
+
+==== strncmp
+
+_WeeChat ≥ 3.8._
+
+Comparer deux chaînes, pour _max_ caractères.
+
+Prototype :
+
+[source,c]
+----
+int weechat_strncmp (const char *string1, const char *string2, int max);
+----
+
+Paramètres :
+
+* _string1_ : première chaîne à comparer
+* _string2_ : seconde chaîne à comparer
+* _max_ : nombre maximum de caractères à comparer
+
+Valeur de retour : résultat de la soustraction du dernier caractère UTF-8 comparé
+dans _string2_ du dernier caractère UTF-8 comparé dans _string1_ :
+
+* < 0 si string1 < string2
+* 0 si string1 == string2
+* > 0 si string1 > string2
+
+Exemple en C :
+
+[source,c]
+----
+int diff = weechat_strncmp ("aabb", "aacc", 2); /* == 0 */
+----
+
+[NOTE]
+Cette fonction n'est pas disponible dans l'API script.
+
==== strcasecmp
_Mis à jour dans la 1.0, 3.8._
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc
index 3f0b750de..c9a71831f 100644
--- a/doc/it/weechat_plugin_api.it.adoc
+++ b/doc/it/weechat_plugin_api.it.adoc
@@ -816,6 +816,85 @@ int diff = weechat_string_charcasecmp ("aaa", "CCC"); /* == -2 */
[NOTE]
Questa funzione non è disponibile nelle API per lo scripting.
+==== strcmp
+
+// TRANSLATION MISSING
+_WeeChat ≥ 3.8._
+
+// TRANSLATION MISSING
+Case sensitive string comparison.
+
+Prototipo:
+
+[source,c]
+----
+int weechat_strcmp (const char *string1, const char *string2);
+----
+
+Argomenti:
+
+* _string1_: prima stringa da comparare
+* _string2_: seconda stringa da comparare
+
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared UTF-8 char in
+_string2_ from the last compared UTF-8 char in _string1_:
+
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
+
+Esempio in C:
+
+[source,c]
+----
+int diff = weechat_strcmp ("aaa", "ccc"); /* == -2 */
+----
+
+[NOTE]
+Questa funzione non è disponibile nelle API per lo scripting.
+
+==== strncmp
+
+// TRANSLATION MISSING
+_WeeChat ≥ 3.8._
+
+// TRANSLATION MISSING
+Case sensitive string comparison, for _max_ chars.
+
+Prototipo:
+
+[source,c]
+----
+int weechat_strncmp (const char *string1, const char *string2, int max);
+----
+
+Argomenti:
+
+* _string1_: prima stringa da comparare
+* _string2_: seconda stringa da comparare
+* _max_: numero massimo di caratteri da comparare
+
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared UTF-8 char in
+_string2_ from the last compared UTF-8 char in _string1_:
+
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
+
+Esempio in C:
+
+[source,c]
+----
+int diff = weechat_strncmp ("aabb", "aacc", 2); /* == 0 */
+----
+
+[NOTE]
+Questa funzione non è disponibile nelle API per lo scripting.
+
==== strcasecmp
// TRANSLATION MISSING
diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc
index d58e2b20c..cc83d8565 100644
--- a/doc/ja/weechat_plugin_api.ja.adoc
+++ b/doc/ja/weechat_plugin_api.ja.adoc
@@ -791,6 +791,83 @@ int diff = weechat_string_charcasecmp ("aaa", "CCC"); /* == -2 */
[NOTE]
スクリプト API ではこの関数を利用できません。
+==== strcmp
+
+_WeeChat ≥ 3.8_
+
+// TRANSLATION MISSING
+Case sensitive string comparison.
+
+プロトタイプ:
+
+[source,c]
+----
+int weechat_strcmp (const char *string1, const char *string2);
+----
+
+引数:
+
+* _string1_: 1 番目の比較対象の文字列
+* _string2_: 2 番目の比較対象の文字列
+
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared UTF-8 char in
+_string2_ from the last compared UTF-8 char in _string1_:
+
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
+
+C 言語での使用例:
+
+[source,c]
+----
+int diff = weechat_strcmp ("aaa", "ccc"); /* == -2 */
+----
+
+[NOTE]
+スクリプト API ではこの関数を利用できません。
+
+==== strncmp
+
+_WeeChat ≥ 3.8_
+
+// TRANSLATION MISSING
+Case sensitive string comparison, for _max_ chars.
+
+プロトタイプ:
+
+[source,c]
+----
+int weechat_strncmp (const char *string1, const char *string2, int max);
+----
+
+引数:
+
+* _string1_: 1 番目の比較対象の文字列
+* _string2_: 2 番目の比較対象の文字列
+* _max_: 比較する文字数の最大値
+
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared UTF-8 char in
+_string2_ from the last compared UTF-8 char in _string1_:
+
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
+
+C 言語での使用例:
+
+[source,c]
+----
+int diff = weechat_strncmp ("aabb", "aacc", 2); /* == 0 */
+----
+
+[NOTE]
+スクリプト API ではこの関数を利用できません。
+
==== strcasecmp
_WeeChat バージョン 1.0, 3.8 で更新。_
diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc
index f7f511c53..a7a40c5a8 100644
--- a/doc/sr/weechat_plugin_api.sr.adoc
+++ b/doc/sr/weechat_plugin_api.sr.adoc
@@ -752,6 +752,85 @@ int diff = weechat_string_charcasecmp ("aaa", "CCC"); /* == -2 */
[NOTE]
Ова функција није доступна у API скриптовања.
+==== strcmp
+
+_WeeChat ≥ 3.8._
+
+// TRANSLATION MISSING
+Case sensitive string comparison.
+
+Прототип:
+
+[source,c]
+----
+int weechat_strcmp (const char *string1, const char *string2);
+----
+
+Аргументи:
+
+* _string1_: први стринг за поређење
+* _string2_: други стринг за поређење
+
+Повратна вредност:
+
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared UTF-8 char in
+_string2_ from the last compared UTF-8 char in _string1_:
+
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
+
+C пример:
+
+[source,c]
+----
+int diff = weechat_strcmp ("aaa", "ccc"); /* == -2 */
+----
+
+[NOTE]
+Ова функција није доступна у API скриптовања.
+
+==== strncmp
+
+_WeeChat ≥ 3.8._
+
+// TRANSLATION MISSING
+Case sensitive string comparison, for _max_ chars.
+
+Прототип:
+
+[source,c]
+----
+int weechat_strncmp (const char *string1, const char *string2, int max);
+----
+
+Аргументи:
+
+* _string1_: први стринг за поређење
+* _string2_: други стринг за поређење
+* _max_: максимални број карактера који се пореде
+
+// TRANSLATION MISSING
+Return value: arithmetic result of subtracting the last compared UTF-8 char in
+_string2_ from the last compared UTF-8 char in _string1_:
+
+// TRANSLATION MISSING
+* < 0 if string1 < string2
+* 0 if string1 == string2
+* > 0 if string1 > string2
+
+C пример:
+
+[source,c]
+----
+int diff = weechat_strncmp ("aabb", "aacc", 2); /* == 0 */
+----
+
+[NOTE]
+Ова функција није доступна у API скриптовања.
+
==== strcasecmp
_Ажурирано у верзији 1.0, 3.8._
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 64ee364b1..ed0880495 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -485,6 +485,67 @@ string_charcasecmp_range (const char *string1, const char *string2, int range)
}
/*
+ * Compares two strings (case sensitive).
+ *
+ * Returns: arithmetic result of subtracting the last compared UTF-8 char in
+ * string2 from the last compared UTF-8 char in string1:
+ * < 0: string1 < string2
+ * 0: string1 == string2
+ * > 0: string1 > string2
+ */
+
+int
+string_strcmp (const char *string1, const char *string2)
+{
+ int diff;
+
+ while (string1 && string1[0] && string2 && string2[0])
+ {
+ diff = string_charcmp (string1, string2);
+ if (diff != 0)
+ return diff;
+
+ string1 = utf8_next_char (string1);
+ string2 = utf8_next_char (string2);
+ }
+
+ return string_charcmp (string1, string2);
+}
+
+/*
+ * Compares two strings with max length (case sensitive).
+ *
+ * Returns: arithmetic result of subtracting the last compared UTF-8 char in
+ * string2 from the last compared UTF-8 char in string1:
+ * < 0: string1 < string2
+ * 0: string1 == string2
+ * > 0: string1 > string2
+ */
+
+int
+string_strncmp (const char *string1, const char *string2, int max)
+{
+ int count, diff;
+
+ count = 0;
+ while ((count < max) && string1 && string1[0] && string2 && string2[0])
+ {
+ diff = string_charcmp (string1, string2);
+ if (diff != 0)
+ return diff;
+
+ string1 = utf8_next_char (string1);
+ string2 = utf8_next_char (string2);
+ count++;
+ }
+
+ if (count >= max)
+ return 0;
+ else
+ return string_charcmp (string1, string2);
+}
+
+/*
* Compares two strings (case insensitive).
*
* Returns: arithmetic result of subtracting the last compared UTF-8 char in
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index 303238d8f..1b57fa41b 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -48,6 +48,8 @@ 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_strcmp (const char *string1, const char *string2);
+extern int string_strncmp (const char *string1, const char *string2, int max);
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/plugins/plugin.c b/src/plugins/plugin.c
index 6013c20ec..34e6f3e16 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -607,6 +607,8 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->string_toupper = &string_toupper;
new_plugin->string_charcmp = &string_charcmp;
new_plugin->string_charcasecmp = &string_charcasecmp;
+ new_plugin->strcmp = &string_strcmp;
+ new_plugin->strncmp = &string_strncmp;
new_plugin->strcasecmp = &string_strcasecmp;
new_plugin->strcasecmp_range = &string_strcasecmp_range;
new_plugin->strncasecmp = &string_strncasecmp;
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index dc1439d50..207b35de2 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 "20221224-01"
+#define WEECHAT_PLUGIN_API_VERSION "20221224-02"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -291,6 +291,8 @@ struct t_weechat_plugin
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 (*strcmp) (const char *string1, const char *string2);
+ int (*strncmp) (const char *string1, const char *string2, int max);
int (*strcasecmp) (const char *string1, const char *string2);
int (*strcasecmp_range) (const char *string1, const char *string2,
int range);
@@ -1233,6 +1235,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->string_charcmp)(__string1, __string2)
#define weechat_string_charcasecmp(__string1, __string2) \
(weechat_plugin->string_charcasecmp)(__string1, __string2)
+#define weechat_strcmp(__string1, __string2) \
+ (weechat_plugin->strcmp)(__string1, __string2)
+#define weechat_strncmp(__string1, __string2, __max) \
+ (weechat_plugin->strncmp)(__string1, __string2, __max)
#define weechat_strcasecmp(__string1, __string2) \
(weechat_plugin->strcasecmp)(__string1, __string2)
#define weechat_strcasecmp_range(__string1, __string2, __range) \
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 78670cc2c..a06cd9ed9 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -511,6 +511,8 @@ TEST(CoreString, CharComparison)
/*
* Tests functions:
+ * string_strcmp
+ * string_strncmp
* string_strcasecmp
* string_strncasecmp
* string_strcasecmp_range
@@ -520,6 +522,48 @@ TEST(CoreString, CharComparison)
TEST(CoreString, StringComparison)
{
+ /* case-sensitive comparison */
+ LONGS_EQUAL(0, string_strcmp (NULL, NULL));
+ LONGS_EQUAL(-97, string_strcmp (NULL, "abc"));
+ LONGS_EQUAL(97, string_strcmp ("abc", NULL));
+ LONGS_EQUAL(-98, string_strcmp ("", "b"));
+ LONGS_EQUAL(98, string_strcmp ("b", ""));
+ LONGS_EQUAL(0, string_strcmp ("abc", "abc"));
+ LONGS_EQUAL(32, string_strcmp ("abc", "ABC"));
+ LONGS_EQUAL(0, string_strcmp ("ABC", "ABC"));
+ LONGS_EQUAL(-3, string_strcmp ("abc", "def"));
+ LONGS_EQUAL(29, string_strcmp ("abc", "DEF"));
+ LONGS_EQUAL(-35, string_strcmp ("ABC", "def"));
+ LONGS_EQUAL(-3, string_strcmp ("ABC", "DEF"));
+ LONGS_EQUAL(3, string_strcmp ("def", "abc"));
+ LONGS_EQUAL(35, string_strcmp ("def", "ABC"));
+ LONGS_EQUAL(-29, string_strcmp ("DEF", "abc"));
+ LONGS_EQUAL(3, string_strcmp ("DEF", "ABC"));
+
+ /* case-sensitive comparison with max length */
+ LONGS_EQUAL(0, string_strncmp (NULL, NULL, 3));
+ LONGS_EQUAL(-97, string_strncmp (NULL, "abc", 3));
+ LONGS_EQUAL(97, string_strncmp ("abc", NULL, 3));
+ LONGS_EQUAL(-98, string_strncmp ("", "b", 3));
+ LONGS_EQUAL(98, string_strncmp ("b", "", 3));
+ LONGS_EQUAL(0, string_strncmp ("abc", "abc", 3));
+ LONGS_EQUAL(0, string_strncmp ("abcabc", "abcdef", 3));
+ LONGS_EQUAL(-3, string_strncmp ("abcabc", "abcdef", 6));
+ LONGS_EQUAL(32, string_strncmp ("abc", "ABC", 3));
+ LONGS_EQUAL(32, string_strncmp ("abcabc", "ABCDEF", 3));
+ LONGS_EQUAL(32, string_strncmp ("abcabc", "ABCDEF", 6));
+ LONGS_EQUAL(0, string_strncmp ("ABC", "ABC", 3));
+ LONGS_EQUAL(0, string_strncmp ("ABCABC", "ABCDEF", 3));
+ LONGS_EQUAL(-3, string_strncmp ("ABCABC", "ABCDEF", 6));
+ LONGS_EQUAL(-3, string_strncmp ("abc", "def", 3));
+ LONGS_EQUAL(29, string_strncmp ("abc", "DEF", 3));
+ LONGS_EQUAL(-35, string_strncmp ("ABC", "def", 3));
+ LONGS_EQUAL(-3, string_strncmp ("ABC", "DEF", 3));
+ LONGS_EQUAL(3, string_strncmp ("def", "abc", 3));
+ LONGS_EQUAL(35, string_strncmp ("def", "ABC", 3));
+ LONGS_EQUAL(-29, string_strncmp ("DEF", "abc", 3));
+ LONGS_EQUAL(3, string_strncmp ("DEF", "ABC", 3));
+
/* case-insensitive comparison */
LONGS_EQUAL(0, string_strcasecmp (NULL, NULL));
LONGS_EQUAL(-97, string_strcasecmp (NULL, "abc"));