summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-02-26 20:02:07 +0100
committerSébastien Helleu <flashcode@flashtux.org>2019-02-27 07:46:22 +0100
commitc2859096cbf2030f977c9838af99bf13c8584625 (patch)
tree8d505344feee0e3e0f4af5ac8978a7527f541983
parente473161c9fc3323a86d1cbf61705dcd24233de2a (diff)
downloadweechat-c2859096cbf2030f977c9838af99bf13c8584625.zip
api: add function string_match_list
-rw-r--r--ChangeLog.adoc1
-rw-r--r--doc/de/weechat_scripting.de.adoc1
-rw-r--r--doc/en/weechat_plugin_api.en.adoc61
-rw-r--r--doc/en/weechat_scripting.en.adoc1
-rw-r--r--doc/fr/weechat_plugin_api.fr.adoc62
-rw-r--r--doc/fr/weechat_scripting.fr.adoc1
-rw-r--r--doc/it/weechat_plugin_api.it.adoc64
-rw-r--r--doc/it/weechat_scripting.it.adoc1
-rw-r--r--doc/ja/weechat_plugin_api.ja.adoc64
-rw-r--r--doc/ja/weechat_scripting.ja.adoc1
-rw-r--r--doc/pl/weechat_scripting.pl.adoc1
-rw-r--r--src/core/wee-string.c42
-rw-r--r--src/core/wee-string.h2
-rw-r--r--src/plugins/guile/weechat-guile-api.c19
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp19
-rw-r--r--src/plugins/lua/weechat-lua-api.c22
-rw-r--r--src/plugins/perl/weechat-perl-api.c19
-rw-r--r--src/plugins/php/weechat-php-api.c23
-rw-r--r--src/plugins/php/weechat-php-api.h1
-rw-r--r--src/plugins/php/weechat-php.c1
-rw-r--r--src/plugins/plugin-script-api.c29
-rw-r--r--src/plugins/plugin-script-api.h4
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/python/weechat-python-api.c21
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c28
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c25
-rw-r--r--src/plugins/weechat-plugin.h7
-rw-r--r--tests/scripts/python/testapi.py5
-rw-r--r--tests/unit/core/test-core-string.cpp61
29 files changed, 566 insertions, 21 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 511920584..01f02c259 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -21,6 +21,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
New features::
* core: add option "addreplace" in command /filter (issue #1055, issue #1312)
+ * api: add function string_match_list
* spell: rename aspell plugin to spell (issue #1299)
Bug fixes::
diff --git a/doc/de/weechat_scripting.de.adoc b/doc/de/weechat_scripting.de.adoc
index b13511e9d..0187722ec 100644
--- a/doc/de/weechat_scripting.de.adoc
+++ b/doc/de/weechat_scripting.de.adoc
@@ -440,6 +440,7 @@ Liste der Skript API Funktionen:
ngettext +
strlen_screen +
string_match +
+ string_match_list +
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc
index af87c375e..00d72ea95 100644
--- a/doc/en/weechat_plugin_api.en.adoc
+++ b/doc/en/weechat_plugin_api.en.adoc
@@ -892,11 +892,62 @@ Script (Python):
match = weechat.string_match(string, mask, case_sensitive)
# examples
-match1 = weechat.string_match("abcdef", "abc*", 0) # 1
-match2 = weechat.string_match("abcdef", "*dd*", 0) # 0
-match3 = weechat.string_match("abcdef", "*def", 0) # 1
-match4 = weechat.string_match("abcdef", "*de*", 0) # 1
-match5 = weechat.string_match("abcdef", "*b*d*", 0) # 1
+match1 = weechat.string_match("abcdef", "abc*", 0) # == 1
+match2 = weechat.string_match("abcdef", "*dd*", 0) # == 0
+match3 = weechat.string_match("abcdef", "*def", 0) # == 1
+match4 = weechat.string_match("abcdef", "*de*", 0) # == 1
+match5 = weechat.string_match("abcdef", "*b*d*", 0) # == 1
+----
+
+==== string_match_list
+
+_WeeChat ≥ 2.5._
+
+Check if a string matches a list of masks where negative mask is allowed
+with the format "!word". A negative mask has higher priority than a standard
+mask.
+
+Prototype:
+
+[source,C]
+----
+int weechat_string_match_list (const char *string, const char **masks,
+ int case_sensitive);
+----
+
+Arguments:
+
+* _string_: string
+* _masks_: list of masks, with a NULL after the last mask in list; each mask
+ is compared to the string with the function <<_string_match,string_match>>
+* _case_sensitive_: 1 for case sensitive comparison, otherwise 0
+
+Return value:
+
+* 1 if string matches list of masks (at least one mask matches and no negative
+ mask matches), otherwise 0
+
+C example:
+
+[source,C]
+----
+const char *masks[3] = { "*", "!abc*", NULL };
+int match1 = weechat_string_match_list ("abc", masks, 0); /* == 0 */
+int match2 = weechat_string_match_list ("abcdef", masks, 0); /* == 0 */
+int match3 = weechat_string_match_list ("def", masks, 0); /* == 1 */
+----
+
+Script (Python):
+
+[source,python]
+----
+# prototype
+match = weechat.string_match_list(string, masks, case_sensitive)
+
+# examples
+match1 = weechat.string_match("abc", "*,!abc*", 0) # == 0
+match2 = weechat.string_match("abcdef", "*,!abc*", 0) # == 0
+match3 = weechat.string_match("def", "*,!abc*", 0) # == 1
----
==== string_expand_home
diff --git a/doc/en/weechat_scripting.en.adoc b/doc/en/weechat_scripting.en.adoc
index 6acadebc6..166416bea 100644
--- a/doc/en/weechat_scripting.en.adoc
+++ b/doc/en/weechat_scripting.en.adoc
@@ -427,6 +427,7 @@ List of functions in script API:
ngettext +
strlen_screen +
string_match +
+ string_match_list +
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc
index 45d77e815..8e8b3f786 100644
--- a/doc/fr/weechat_plugin_api.fr.adoc
+++ b/doc/fr/weechat_plugin_api.fr.adoc
@@ -904,11 +904,63 @@ Script (Python) :
match = weechat.string_match(string, mask, case_sensitive)
# exemples
-match1 = weechat.string_match("abcdef", "abc*", 0) # 1
-match2 = weechat.string_match("abcdef", "*dd*", 0) # 0
-match3 = weechat.string_match("abcdef", "*def", 0) # 1
-match4 = weechat.string_match("abcdef", "*de*", 0) # 1
-match5 = weechat.string_match("abcdef", "*b*d*", 0) # 1
+match1 = weechat.string_match("abcdef", "abc*", 0) # == 1
+match2 = weechat.string_match("abcdef", "*dd*", 0) # == 0
+match3 = weechat.string_match("abcdef", "*def", 0) # == 1
+match4 = weechat.string_match("abcdef", "*de*", 0) # == 1
+match5 = weechat.string_match("abcdef", "*b*d*", 0) # == 1
+----
+
+==== string_match_list
+
+_WeeChat ≥ 2.5._
+
+Vérifier si une chaîne correspond à une liste de masques. Des masques négatifs
+sont autorisés avec le format "!mot". Un masque négatif a une priorité plus
+haute qu'un masque standard.
+
+Prototype :
+
+[source,C]
+----
+int weechat_string_match_list (const char *string, const char **masks,
+ int case_sensitive);
+----
+
+Paramètres :
+
+* _string_ : chaîne
+* _masks_ : liste de masques avec un NULL après le dernier masque de la liste ;
+ chaque masque est comparé à la chaîne avec la fonction
+ <<_string_match,string_match>>
+* _case_sensitive_ : 1 pour une comparaison tenant compte de la casse, sinon 0
+
+Valeur de retour :
+
+* 1 si la chaîne correspond à la liste de masques (au moins un masque correspond
+ et aucun masque négatif ne correspond), sinon 0
+
+Exemple en C :
+
+[source,C]
+----
+const char *masks[3] = { "*", "!abc*", NULL };
+int match1 = weechat_string_match_list ("abc", masks, 0); /* == 0 */
+int match2 = weechat_string_match_list ("abcdef", masks, 0); /* == 0 */
+int match3 = weechat_string_match_list ("def", masks, 0); /* == 1 */
+----
+
+Script (Python) :
+
+[source,python]
+----
+# prototype
+match = weechat.string_match_list(string, masks, case_sensitive)
+
+# exemples
+match1 = weechat.string_match("abc", "*,!abc*", 0) # == 0
+match2 = weechat.string_match("abcdef", "*,!abc*", 0) # == 0
+match3 = weechat.string_match("def", "*,!abc*", 0) # == 1
----
==== string_expand_home
diff --git a/doc/fr/weechat_scripting.fr.adoc b/doc/fr/weechat_scripting.fr.adoc
index 4e4dfef3e..a7c3fb075 100644
--- a/doc/fr/weechat_scripting.fr.adoc
+++ b/doc/fr/weechat_scripting.fr.adoc
@@ -439,6 +439,7 @@ Liste des fonctions de l'API script :
ngettext +
strlen_screen +
string_match +
+ string_match_list +
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc
index ee7846361..f32a72024 100644
--- a/doc/it/weechat_plugin_api.it.adoc
+++ b/doc/it/weechat_plugin_api.it.adoc
@@ -937,11 +937,65 @@ Script (Python):
match = weechat.string_match(string, mask, case_sensitive)
# esempio
-match1 = weechat.string_match("abcdef", "abc*", 0) # 1
-match2 = weechat.string_match("abcdef", "*dd*", 0) # 0
-match3 = weechat.string_match("abcdef", "*def", 0) # 1
-match4 = weechat.string_match("abcdef", "*de*", 0) # 1
-match5 = weechat.string_match("abcdef", "*b*d*", 0) # 1
+match1 = weechat.string_match("abcdef", "abc*", 0) # == 1
+match2 = weechat.string_match("abcdef", "*dd*", 0) # == 0
+match3 = weechat.string_match("abcdef", "*def", 0) # == 1
+match4 = weechat.string_match("abcdef", "*de*", 0) # == 1
+match5 = weechat.string_match("abcdef", "*b*d*", 0) # == 1
+----
+
+==== string_match_list
+
+_WeeChat ≥ 2.5._
+
+// TRANSLATION MISSING
+Check if a string matches a list of masks where negative mask is allowed
+with the format "!word". A negative mask has higher priority than a standard
+mask.
+
+Prototipo:
+
+[source,C]
+----
+int weechat_string_match_list (const char *string, const char **masks,
+ int case_sensitive);
+----
+
+Argomenti:
+
+// TRANSLATION MISSING
+* _string_: string
+* _masks_: list of masks, with a NULL after the last mask in list; each mask
+ is compared to the string with the function <<_string_match,string_match>>
+* _case_sensitive_: 1 for case sensitive comparison, otherwise 0
+
+Valore restituito:
+
+// TRANSLATION MISSING
+* 1 if string matches list of masks (at least one mask matches and no negative
+ mask matches), otherwise 0
+
+Esempio in C:
+
+[source,C]
+----
+const char *masks[3] = { "*", "!abc*", NULL };
+int match1 = weechat_string_match_list ("abc", masks, 0); /* == 0 */
+int match2 = weechat_string_match_list ("abcdef", masks, 0); /* == 0 */
+int match3 = weechat_string_match_list ("def", masks, 0); /* == 1 */
+----
+
+Script (Python):
+
+[source,python]
+----
+# prototipo
+match = weechat.string_match_list(string, masks, case_sensitive)
+
+# esempio
+match1 = weechat.string_match("abc", "*,!abc*", 0) # == 0
+match2 = weechat.string_match("abcdef", "*,!abc*", 0) # == 0
+match3 = weechat.string_match("def", "*,!abc*", 0) # == 1
----
==== string_expand_home
diff --git a/doc/it/weechat_scripting.it.adoc b/doc/it/weechat_scripting.it.adoc
index b128ebdd5..113243d81 100644
--- a/doc/it/weechat_scripting.it.adoc
+++ b/doc/it/weechat_scripting.it.adoc
@@ -444,6 +444,7 @@ Elenco di funzioni nelle API per gli script:
ngettext +
strlen_screen +
string_match +
+ string_match_list +
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc
index e26b99325..3ead632f5 100644
--- a/doc/ja/weechat_plugin_api.ja.adoc
+++ b/doc/ja/weechat_plugin_api.ja.adoc
@@ -897,11 +897,65 @@ int match5 = weechat_string_match ("abcdef", "*b*d*", 0); /* == 1 */
match = weechat.string_match(string, mask, case_sensitive)
# 例
-match1 = weechat.string_match("abcdef", "abc*", 0) # 1
-match2 = weechat.string_match("abcdef", "*dd*", 0) # 0
-match3 = weechat.string_match("abcdef", "*def", 0) # 1
-match4 = weechat.string_match("abcdef", "*de*", 0) # 1
-match5 = weechat.string_match("abcdef", "*b*d*", 0) # 1
+match1 = weechat.string_match("abcdef", "abc*", 0) # == 1
+match2 = weechat.string_match("abcdef", "*dd*", 0) # == 0
+match3 = weechat.string_match("abcdef", "*def", 0) # == 1
+match4 = weechat.string_match("abcdef", "*de*", 0) # == 1
+match5 = weechat.string_match("abcdef", "*b*d*", 0) # == 1
+----
+
+==== string_match_list
+
+_WeeChat ≥ 2.5._
+
+// TRANSLATION MISSING
+Check if a string matches a list of masks where negative mask is allowed
+with the format "!word". A negative mask has higher priority than a standard
+mask.
+
+プロトタイプ:
+
+[source,C]
+----
+int weechat_string_match_list (const char *string, const char **masks,
+ int case_sensitive);
+----
+
+引数:
+
+// TRANSLATION MISSING
+* _string_: 文字列
+* _masks_: list of masks, with a NULL after the last mask in list; each mask
+ is compared to the string with the function <<_string_match,string_match>>
+* _case_sensitive_: 1 for case sensitive comparison, otherwise 0
+
+戻り値:
+
+// TRANSLATION MISSING
+* 1 if string matches list of masks (at least one mask matches and no negative
+ mask matches), otherwise 0
+
+C 言語での使用例:
+
+[source,C]
+----
+const char *masks[3] = { "*", "!abc*", NULL };
+int match1 = weechat_string_match_list ("abc", masks, 0); /* == 0 */
+int match2 = weechat_string_match_list ("abcdef", masks, 0); /* == 0 */
+int match3 = weechat_string_match_list ("def", masks, 0); /* == 1 */
+----
+
+スクリプト (Python) での使用例:
+
+[source,python]
+----
+# プロトタイプ
+match = weechat.string_match_list(string, masks, case_sensitive)
+
+# 例
+match1 = weechat.string_match("abc", "*,!abc*", 0) # == 0
+match2 = weechat.string_match("abcdef", "*,!abc*", 0) # == 0
+match3 = weechat.string_match("def", "*,!abc*", 0) # == 1
----
==== string_expand_home
diff --git a/doc/ja/weechat_scripting.ja.adoc b/doc/ja/weechat_scripting.ja.adoc
index d7529f101..f37cc2595 100644
--- a/doc/ja/weechat_scripting.ja.adoc
+++ b/doc/ja/weechat_scripting.ja.adoc
@@ -435,6 +435,7 @@ link:weechat_plugin_api.ja.html[WeeChat プラグイン API リファレンス]
ngettext +
strlen_screen +
string_match +
+ string_match_list +
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
diff --git a/doc/pl/weechat_scripting.pl.adoc b/doc/pl/weechat_scripting.pl.adoc
index 0ce281da0..148118ab3 100644
--- a/doc/pl/weechat_scripting.pl.adoc
+++ b/doc/pl/weechat_scripting.pl.adoc
@@ -433,6 +433,7 @@ Lista funkcji w API skryptów:
ngettext +
strlen_screen +
string_match +
+ string_match_list +
string_has_highlight +
string_has_highlight_regex +
string_mask_to_regex +
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 5380ec8d4..04308a451 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -628,6 +628,48 @@ string_match (const char *string, const char *mask, int case_sensitive)
}
/*
+ * Checks if a string matches a list of masks. Negative masks are allowed
+ * with "!mask" to exclude this mask and have higher priority than standard
+ * masks.
+ *
+ * Each mask is compared with the function string_match.
+ *
+ * Example of masks to allow anything by default, but "toto" and "abc" are
+ * forbidden:
+ * "*", "!toto", "!abc"
+ *
+ * Returns:
+ * 1: string matches list of masks
+ * 0: string does not match list of masks
+ */
+
+int
+string_match_list (const char *string, const char **masks, int case_sensitive)
+{
+ int match, i;
+ const char *ptr_mask;
+
+ if (!string || !masks)
+ return 0;
+
+ match = 0;
+
+ for (i = 0; masks[i]; i++)
+ {
+ ptr_mask = (masks[i][0] == '!') ? masks[i] + 1 : masks[i];
+ if (string_match (string, ptr_mask, case_sensitive))
+ {
+ if (masks[i][0] == '!')
+ return 0;
+ else
+ match = 1;
+ }
+ }
+
+ return match;
+}
+
+/*
* Expands home in a path.
*
* Example: "~/file.txt" => "/home/xxx/file.txt"
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index dc84c6dc4..eddbf26ad 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -57,6 +57,8 @@ extern int string_strcmp_ignore_chars (const char *string1,
extern const char *string_strcasestr (const char *string, const char *search);
extern int string_match (const char *string, const char *mask,
int case_sensitive);
+extern int string_match_list (const char *string, const char **masks,
+ int case_sensitive);
extern char *string_replace (const char *string, const char *search,
const char *replace);
extern char *string_expand_home (const char *path);
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c
index c49832bb1..29f8fbf78 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -351,6 +351,24 @@ weechat_guile_api_string_match (SCM string, SCM mask, SCM case_sensitive)
}
SCM
+weechat_guile_api_string_match_list (SCM string, SCM masks, SCM case_sensitive)
+{
+ int value;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (!scm_is_string (string) || !scm_is_string (masks)
+ || !scm_is_integer (case_sensitive))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ value = plugin_script_api_string_match_list (weechat_guile_plugin,
+ API_SCM_TO_STRING(string),
+ API_SCM_TO_STRING(masks),
+ scm_to_int (case_sensitive));
+
+ API_RETURN_INT(value);
+}
+
+SCM
weechat_guile_api_string_has_highlight (SCM string, SCM highlight_words)
{
int value;
@@ -4855,6 +4873,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(ngettext, 3);
API_DEF_FUNC(strlen_screen, 1);
API_DEF_FUNC(string_match, 3);
+ API_DEF_FUNC(string_match_list, 3);
API_DEF_FUNC(string_has_highlight, 2);
API_DEF_FUNC(string_has_highlight_regex, 2);
API_DEF_FUNC(string_mask_to_regex, 1);
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index a40f61d57..8f0032bac 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -305,6 +305,24 @@ API_FUNC(string_match)
API_RETURN_INT(value);
}
+API_FUNC(string_match_list)
+{
+ int value;
+
+ API_INIT_FUNC(1, "string_match_list", "ssi", API_RETURN_INT(0));
+
+ v8::String::Utf8Value string(args[0]);
+ v8::String::Utf8Value masks(args[1]);
+ int case_sensitive = args[2]->IntegerValue();
+
+ value = plugin_script_api_string_match_list (weechat_js_plugin,
+ *string,
+ *masks,
+ case_sensitive);
+
+ API_RETURN_INT(value);
+}
+
API_FUNC(string_has_highlight)
{
int value;
@@ -4806,6 +4824,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(ngettext);
API_DEF_FUNC(strlen_screen);
API_DEF_FUNC(string_match);
+ API_DEF_FUNC(string_match_list);
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index 4a943a9c0..a07709fa1 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -338,6 +338,27 @@ API_FUNC(string_match)
API_RETURN_INT(value);
}
+API_FUNC(string_match_list)
+{
+ const char *string, *masks;
+ int case_sensitive, value;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (lua_gettop (L) < 3)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ string = lua_tostring (L, -3);
+ masks = lua_tostring (L, -2);
+ case_sensitive = lua_tonumber (L, -1);
+
+ value = plugin_script_api_string_match_list (weechat_lua_plugin,
+ string,
+ masks,
+ case_sensitive);
+
+ API_RETURN_INT(value);
+}
+
API_FUNC(string_has_highlight)
{
const char *string, *highlight_words;
@@ -5154,6 +5175,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(ngettext),
API_DEF_FUNC(strlen_screen),
API_DEF_FUNC(string_match),
+ API_DEF_FUNC(string_match_list),
API_DEF_FUNC(string_has_highlight),
API_DEF_FUNC(string_has_highlight_regex),
API_DEF_FUNC(string_mask_to_regex),
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index c026f5709..9192bbe97 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -309,6 +309,24 @@ API_FUNC(string_match)
API_RETURN_INT(value);
}
+API_FUNC(string_match_list)
+{
+ int value;
+ dXSARGS;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (items < 3)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ value = plugin_script_api_string_match_list (
+ weechat_perl_plugin,
+ SvPV_nolen (ST (0)), /* string */
+ SvPV_nolen (ST (1)), /* masks */
+ SvIV (ST (2))); /* case_sensitive */
+
+ API_RETURN_INT(value);
+}
+
API_FUNC(string_has_highlight)
{
int value;
@@ -5116,6 +5134,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(ngettext);
API_DEF_FUNC(strlen_screen);
API_DEF_FUNC(string_match);
+ API_DEF_FUNC(string_match_list);
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c
index adad1123c..0f9e1a554 100644
--- a/src/plugins/php/weechat-php-api.c
+++ b/src/plugins/php/weechat-php-api.c
@@ -396,6 +396,29 @@ API_FUNC(string_match)
API_RETURN_INT(result);
}
+API_FUNC(string_match_list)
+{
+ zend_string *z_string, *z_masks;
+ zend_long z_case_sensitive;
+ int case_sensitive, result;
+ char *string, *masks;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSl", &z_string, &z_masks,
+ &z_case_sensitive) == FAILURE)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ string = ZSTR_VAL(z_string);
+ masks = ZSTR_VAL(z_masks);
+ case_sensitive = (int)z_case_sensitive;
+ result = plugin_script_api_string_match_list (weechat_php_plugin,
+ (const char *)string,
+ (const char *)masks,
+ case_sensitive);
+
+ API_RETURN_INT(result);
+}
+
API_FUNC(string_has_highlight)
{
zend_string *z_string, *z_highlight_words;
diff --git a/src/plugins/php/weechat-php-api.h b/src/plugins/php/weechat-php-api.h
index 81772e7b0..ca01f3f02 100644
--- a/src/plugins/php/weechat-php-api.h
+++ b/src/plugins/php/weechat-php-api.h
@@ -54,6 +54,7 @@ PHP_FUNCTION(weechat_gettext);
PHP_FUNCTION(weechat_ngettext);
PHP_FUNCTION(weechat_strlen_screen);
PHP_FUNCTION(weechat_string_match);
+PHP_FUNCTION(weechat_string_match_list);
PHP_FUNCTION(weechat_string_has_highlight);
PHP_FUNCTION(weechat_string_has_highlight_regex);
PHP_FUNCTION(weechat_string_mask_to_regex);
diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c
index 0d37a9f29..f84e49f4f 100644
--- a/src/plugins/php/weechat-php.c
+++ b/src/plugins/php/weechat-php.c
@@ -108,6 +108,7 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_ngettext, NULL)
PHP_FE(weechat_strlen_screen, NULL)
PHP_FE(weechat_string_match, NULL)
+ PHP_FE(weechat_string_match_list, NULL)
PHP_FE(weechat_string_has_highlight, NULL)
PHP_FE(weechat_string_has_highlight_regex, NULL)
PHP_FE(weechat_string_mask_to_regex, NULL)
diff --git a/src/plugins/plugin-script-api.c b/src/plugins/plugin-script-api.c
index 3caecdddc..bb797ced1 100644
--- a/src/plugins/plugin-script-api.c
+++ b/src/plugins/plugin-script-api.c
@@ -48,6 +48,35 @@ plugin_script_api_charset_set (struct t_plugin_script *script,
}
/*
+ * Checks if a string matches a list of masks.
+ *
+ * Returns:
+ * 1: string matches list of masks
+ * 0: string does not match list of masks
+ */
+
+int
+plugin_script_api_string_match_list (struct t_weechat_plugin *weechat_plugin,
+ const char *string, const char *masks,
+ int case_sensitive)
+{
+ char **list_masks;
+ int match;
+
+ list_masks = (masks && masks[0]) ?
+ weechat_string_split (masks, ",", 0, 0, NULL) : NULL;
+
+ match = weechat_string_match_list (string,
+ (const char **)list_masks,
+ case_sensitive);
+
+ if (list_masks)
+ weechat_string_free_split (list_masks);
+
+ return match;
+}
+
+/*
* Creates a new configuration file.
*
* Returns pointer to new configuration file, NULL if error.
diff --git a/src/plugins/plugin-script-api.h b/src/plugins/plugin-script-api.h
index b103961fc..ce7bd285a 100644
--- a/src/plugins/plugin-script-api.h
+++ b/src/plugins/plugin-script-api.h
@@ -25,6 +25,10 @@
extern void plugin_script_api_charset_set (struct t_plugin_script *script,
const char *charset);
+extern int plugin_script_api_string_match_list (struct t_weechat_plugin *weechat_plugin,
+ const char *string,
+ const char *masks,
+ int case_sensitive);
extern struct t_config_file *plugin_script_api_config_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *name,
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index fd76c45ed..d8e82ef25 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -616,6 +616,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->strcasestr = &string_strcasestr;
new_plugin->strlen_screen = &gui_chat_strlen_screen;
new_plugin->string_match = &string_match;
+ new_plugin->string_match_list = &string_match_list;
new_plugin->string_replace = &string_replace;
new_plugin->string_expand_home = &string_expand_home;
new_plugin->string_eval_path_home = &string_eval_path_home;
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index ab829fa02..f27d1e169 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -288,6 +288,26 @@ API_FUNC(string_match)
API_RETURN_INT(value);
}
+API_FUNC(string_match_list)
+{
+ char *string, *masks;
+ int case_sensitive, value;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ string = NULL;
+ masks = NULL;
+ case_sensitive = 0;
+ if (!PyArg_ParseTuple (args, "ssi", &string, &masks, &case_sensitive))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ value = plugin_script_api_string_match_list (weechat_python_plugin,
+ string,
+ masks,
+ case_sensitive);
+
+ API_RETURN_INT(value);
+}
+
API_FUNC(string_has_highlight)
{
char *string, *highlight_words;
@@ -5064,6 +5084,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(ngettext),
API_DEF_FUNC(strlen_screen),
API_DEF_FUNC(string_match),
+ API_DEF_FUNC(string_match_list),
API_DEF_FUNC(string_has_highlight),
API_DEF_FUNC(string_has_highlight_regex),
API_DEF_FUNC(string_mask_to_regex),
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index 21b22b659..dbd7ce278 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -340,6 +340,33 @@ weechat_ruby_api_string_match (VALUE class, VALUE string, VALUE mask,
}
static VALUE
+weechat_ruby_api_string_match_list (VALUE class, VALUE string, VALUE masks,
+ VALUE case_sensitive)
+{
+ char *c_string, *c_masks;
+ int c_case_sensitive, value;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (NIL_P (string) || NIL_P (masks) || NIL_P (case_sensitive))
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ Check_Type (string, T_STRING);
+ Check_Type (masks, T_STRING);
+ Check_Type (case_sensitive, T_FIXNUM);
+
+ c_string = StringValuePtr (string);
+ c_masks = StringValuePtr (masks);
+ c_case_sensitive = FIX2INT (case_sensitive);
+
+ value = plugin_script_api_string_match_list (weechat_ruby_plugin,
+ c_string,
+ c_masks,
+ c_case_sensitive);
+
+ API_RETURN_INT(value);
+}
+
+static VALUE
weechat_ruby_api_string_has_highlight (VALUE class, VALUE string,
VALUE highlight_words)
{
@@ -6218,6 +6245,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(ngettext, 3);
API_DEF_FUNC(strlen_screen, 1);
API_DEF_FUNC(string_match, 3);
+ API_DEF_FUNC(string_match_list, 3);
API_DEF_FUNC(string_has_highlight, 2);
API_DEF_FUNC(string_has_highlight_regex, 2);
API_DEF_FUNC(string_mask_to_regex, 1);
diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c
index ed63f3494..527380e48 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -437,6 +437,30 @@ API_FUNC(string_match)
API_RETURN_INT(result);
}
+API_FUNC(string_match_list)
+{
+ Tcl_Obj *objp;
+ char *string, *masks;
+ int case_sensitive, result, i;
+
+ API_INIT_FUNC(1, "string_match_list", API_RETURN_INT(0));
+ if (objc < 4)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ string = Tcl_GetStringFromObj (objv[1], &i);
+ masks = Tcl_GetStringFromObj (objv[2], &i);
+
+ if (Tcl_GetIntFromObj (interp, objv[3], &case_sensitive) != TCL_OK)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ result = plugin_script_api_string_match_list (weechat_tcl_plugin,
+ string,
+ masks,
+ case_sensitive);
+
+ API_RETURN_INT(result);
+}
+
API_FUNC(string_has_highlight)
{
Tcl_Obj *objp;
@@ -5586,6 +5610,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(ngettext);
API_DEF_FUNC(strlen_screen);
API_DEF_FUNC(string_match);
+ API_DEF_FUNC(string_match_list);
API_DEF_FUNC(string_has_highlight);
API_DEF_FUNC(string_has_highlight_regex);
API_DEF_FUNC(string_mask_to_regex);
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index e93c665c9..da4eda6ba 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -67,7 +67,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 "20190219-01"
+#define WEECHAT_PLUGIN_API_VERSION "20190226-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -289,6 +289,8 @@ struct t_weechat_plugin
int (*strlen_screen) (const char *string);
int (*string_match) (const char *string, const char *mask,
int case_sensitive);
+ int (*string_match_list) (const char *string, const char **masks,
+ int case_sensitive);
char *(*string_replace) (const char *string, const char *search,
const char *replace);
char *(*string_expand_home) (const char *path);
@@ -1172,6 +1174,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->strlen_screen)(__string)
#define weechat_string_match(__string, __mask, __case_sensitive) \
(weechat_plugin->string_match)(__string, __mask, __case_sensitive)
+#define weechat_string_match_list(__string, __masks, __case_sensitive) \
+ (weechat_plugin->string_match_list)(__string, __masks, \
+ __case_sensitive)
#define weechat_string_replace(__string, __search, __replace) \
(weechat_plugin->string_replace)(__string, __search, __replace)
#define weechat_string_expand_home(__path) \
diff --git a/tests/scripts/python/testapi.py b/tests/scripts/python/testapi.py
index 26ff6f27c..5a4c19190 100644
--- a/tests/scripts/python/testapi.py
+++ b/tests/scripts/python/testapi.py
@@ -58,6 +58,11 @@ def test_strings():
check(weechat.ngettext('file', 'files', 2) == 'files')
check(weechat.strlen_screen('abcd') == 4)
check(weechat.string_match('abcdef', 'abc*', 0) == 1)
+ check(weechat.string_match('abcdef', 'abc*', 1) == 1)
+ check(weechat.string_match('ABCDEF', 'abc*', 1) == 0)
+ check(weechat.string_match_list('abcdef', '*,!abc*', 0) == 0)
+ check(weechat.string_match_list('ABCDEF', '*,!abc*', 1) == 1)
+ check(weechat.string_match_list('def', '*,!abc*', 0) == 1)
check(weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) == 'test 123')
check(weechat.string_mask_to_regex('test*mask') == 'test.*mask')
check(weechat.string_has_highlight('my test string', 'test,word2') == 1)
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index ea76b714e..1ccb2fe65 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -493,6 +493,67 @@ TEST(CoreString, Match)
/*
* Tests functions:
+ * string_match
+ */
+
+TEST(CoreString, MatchList)
+{
+ const char *masks_none[1] = { NULL };
+ const char *masks_one_empty[2] = { "", NULL };
+ const char *masks_one[2] = { "toto", NULL };
+ const char *masks_two[3] = { "toto", "abc", NULL };
+ const char *masks_negative[3] = { "*", "!abc", NULL };
+ const char *masks_negative_star[3] = { "*", "!abc*", NULL };
+
+ LONGS_EQUAL(0, string_match_list (NULL, NULL, 0));
+ LONGS_EQUAL(0, string_match_list (NULL, masks_one, 0));
+
+ LONGS_EQUAL(0, string_match_list ("", NULL, 0));
+ LONGS_EQUAL(0, string_match_list ("", masks_none, 0));
+ LONGS_EQUAL(0, string_match_list ("", masks_one_empty, 0));
+ LONGS_EQUAL(0, string_match_list ("", masks_none, 0));
+ LONGS_EQUAL(0, string_match_list ("", masks_one_empty, 0));
+
+ LONGS_EQUAL(0, string_match_list ("toto", NULL, 0));
+ LONGS_EQUAL(0, string_match_list ("toto", masks_none, 0));
+ LONGS_EQUAL(0, string_match_list ("toto", masks_one_empty, 0));
+ LONGS_EQUAL(0, string_match_list ("toto", masks_none, 0));
+ LONGS_EQUAL(0, string_match_list ("toto", masks_one_empty, 0));
+
+ LONGS_EQUAL(0, string_match_list ("test", masks_one, 0));
+ LONGS_EQUAL(0, string_match_list ("to", masks_one, 0));
+ LONGS_EQUAL(1, string_match_list ("toto", masks_one, 0));
+ LONGS_EQUAL(1, string_match_list ("TOTO", masks_one, 0));
+ LONGS_EQUAL(0, string_match_list ("TOTO", masks_one, 1));
+
+ LONGS_EQUAL(0, string_match_list ("test", masks_two, 0));
+ LONGS_EQUAL(1, string_match_list ("toto", masks_two, 0));
+ LONGS_EQUAL(1, string_match_list ("abc", masks_two, 0));
+ LONGS_EQUAL(0, string_match_list ("def", masks_two, 0));
+
+ LONGS_EQUAL(1, string_match_list ("test", masks_negative, 0));
+ LONGS_EQUAL(1, string_match_list ("toto", masks_negative, 0));
+ LONGS_EQUAL(0, string_match_list ("abc", masks_negative, 0));
+ LONGS_EQUAL(0, string_match_list ("ABC", masks_negative, 0));
+ LONGS_EQUAL(1, string_match_list ("ABC", masks_negative, 1));
+ LONGS_EQUAL(1, string_match_list ("abcdef", masks_negative, 0));
+ LONGS_EQUAL(1, string_match_list ("ABCDEF", masks_negative, 0));
+ LONGS_EQUAL(1, string_match_list ("ABCDEF", masks_negative, 1));
+ LONGS_EQUAL(1, string_match_list ("def", masks_negative, 0));
+
+ LONGS_EQUAL(1, string_match_list ("test", masks_negative_star, 0));
+ LONGS_EQUAL(1, string_match_list ("toto", masks_negative_star, 0));
+ LONGS_EQUAL(0, string_match_list ("abc", masks_negative_star, 0));
+ LONGS_EQUAL(0, string_match_list ("ABC", masks_negative_star, 0));
+ LONGS_EQUAL(1, string_match_list ("ABC", masks_negative_star, 1));
+ LONGS_EQUAL(0, string_match_list ("abcdef", masks_negative_star, 0));
+ LONGS_EQUAL(0, string_match_list ("ABCDEF", masks_negative_star, 0));
+ LONGS_EQUAL(1, string_match_list ("ABCDEF", masks_negative_star, 1));
+ LONGS_EQUAL(1, string_match_list ("def", masks_negative_star, 0));
+}
+
+/*
+ * Tests functions:
* string_expand_home
*/