mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 17:53:13 +02:00
api: add function string_match_list
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) \
|
||||
|
||||
Reference in New Issue
Block a user