api: add function string_match_list

v2.8-utf8proc
Sébastien Helleu 2019-02-26 20:02:07 +01:00
parent e473161c9f
commit c2859096cb
29 changed files with 566 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -627,6 +627,48 @@ string_match (const char *string, const char *mask, int case_sensitive)
return 0;
}
/*
* 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.
*

View File

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

View File

@ -350,6 +350,24 @@ weechat_guile_api_string_match (SCM string, SCM mask, SCM case_sensitive)
API_RETURN_INT(value);
}
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)
{
@ -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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -47,6 +47,35 @@ plugin_script_api_charset_set (struct t_plugin_script *script,
script->charset = (charset) ? strdup (charset) : NULL;
}
/*
* 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.
*

View File

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

View File

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

View File

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

View File

@ -339,6 +339,33 @@ weechat_ruby_api_string_match (VALUE class, VALUE string, VALUE mask,
API_RETURN_INT(value);
}
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);

View File

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

View File

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

View File

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

View File

@ -491,6 +491,67 @@ TEST(CoreString, Match)
LONGS_EQUAL(1, string_match ("aabaabaabaa", "aa*", 1));
}
/*
* 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