mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 20:36:38 +02:00
Add functions string_match, string_has_highlight and string_mask_to_regex in script plugin API
This commit is contained in:
@@ -364,6 +364,130 @@ weechat_lua_api_ngettext (lua_State *L)
|
||||
LUA_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_string_match: return 1 if string matches a mask
|
||||
* mask can begin or end with "*", no other "*"
|
||||
* are allowed inside mask
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_string_match (lua_State *L)
|
||||
{
|
||||
const char *string, *mask;
|
||||
int n, case_sensitive, value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "string_match");
|
||||
LUA_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = NULL;
|
||||
mask = NULL;
|
||||
case_sensitive = 0;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "string_match");
|
||||
LUA_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = lua_tostring (lua_current_interpreter, -3);
|
||||
mask = lua_tostring (lua_current_interpreter, -2);
|
||||
case_sensitive = lua_tonumber (lua_current_interpreter, -1);
|
||||
|
||||
value = weechat_string_match (string, mask, case_sensitive);
|
||||
|
||||
LUA_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_string_has_highlight: return 1 if string contains a
|
||||
* highlight (using list of words to
|
||||
* highlight)
|
||||
* return 0 if no highlight is found in
|
||||
* string
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_string_has_highlight (lua_State *L)
|
||||
{
|
||||
const char *string, *highlight_words;
|
||||
int n, value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
LUA_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = NULL;
|
||||
highlight_words = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
LUA_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = lua_tostring (lua_current_interpreter, -2);
|
||||
highlight_words = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
value = weechat_string_has_highlight (string, highlight_words);
|
||||
|
||||
LUA_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_string_mask_to_regex: convert a mask (string with only
|
||||
* "*" as joker) to a regex, paying
|
||||
* attention to special chars in a
|
||||
* regex
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_string_mask_to_regex (lua_State *L)
|
||||
{
|
||||
const char *mask;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
mask = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 1)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
mask = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = weechat_string_mask_to_regex (mask);
|
||||
|
||||
LUA_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_string_remove_color: remove WeeChat color codes from string
|
||||
*/
|
||||
@@ -7306,6 +7430,9 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
|
||||
{ "iconv_from_internal", &weechat_lua_api_iconv_from_internal },
|
||||
{ "gettext", &weechat_lua_api_gettext },
|
||||
{ "ngettext", &weechat_lua_api_ngettext },
|
||||
{ "string_match", &weechat_lua_api_string_match },
|
||||
{ "string_has_highlight", &weechat_lua_api_string_has_highlight },
|
||||
{ "string_mask_to_regex", &weechat_lua_api_string_mask_to_regex },
|
||||
{ "string_remove_color", &weechat_lua_api_string_remove_color },
|
||||
{ "string_is_command_char", &weechat_lua_api_string_is_command_char },
|
||||
{ "string_input_for_buffer", &weechat_lua_api_string_input_for_buffer },
|
||||
|
||||
@@ -313,6 +313,102 @@ XS (XS_weechat_api_ngettext)
|
||||
PERL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::string_match: return 1 if string matches a mask
|
||||
* mask can begin or end with "*", no other "*"
|
||||
* are allowed inside mask
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_string_match)
|
||||
{
|
||||
int value;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "string_match");
|
||||
PERL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (items < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "string_match");
|
||||
PERL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
value = weechat_string_match (SvPV (ST (0), PL_na), /* string */
|
||||
SvPV (ST (1), PL_na), /* mask */
|
||||
SvIV (ST (2))); /* case_sensitive */
|
||||
|
||||
PERL_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::string_has_highlight: return 1 if string contains a highlight
|
||||
* (using list of words to highlight)
|
||||
* return 0 if no highlight is found in string
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_string_has_highlight)
|
||||
{
|
||||
int value;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
PERL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
PERL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
value = weechat_string_has_highlight (SvPV (ST (0), PL_na), /* string */
|
||||
SvPV (ST (1), PL_na)); /* highlight_words */
|
||||
|
||||
PERL_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::string_mask_to_regex: convert a mask (string with only "*" as
|
||||
* joker) to a regex, paying attention to
|
||||
* special chars in a regex
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_string_mask_to_regex)
|
||||
{
|
||||
char *result;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = weechat_string_mask_to_regex (SvPV (ST (0), PL_na)); /* mask */
|
||||
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::string_remove_color: remove WeeChat color codes from string
|
||||
*/
|
||||
@@ -5849,6 +5945,9 @@ weechat_perl_api_init (pTHX)
|
||||
newXS ("weechat::iconv_from_internal", XS_weechat_api_iconv_from_internal, "weechat");
|
||||
newXS ("weechat::gettext", XS_weechat_api_gettext, "weechat");
|
||||
newXS ("weechat::ngettext", XS_weechat_api_ngettext, "weechat");
|
||||
newXS ("weechat::string_match", XS_weechat_api_string_match, "weechat");
|
||||
newXS ("weechat::string_has_highlight", XS_weechat_api_string_has_highlight, "weechat");
|
||||
newXS ("weechat::string_mask_to_regex", XS_weechat_api_string_mask_to_regex, "weechat");
|
||||
newXS ("weechat::string_remove_color", XS_weechat_api_string_remove_color, "weechat");
|
||||
newXS ("weechat::string_is_command_char", XS_weechat_api_string_is_command_char, "weechat");
|
||||
newXS ("weechat::string_input_for_buffer", XS_weechat_api_string_input_for_buffer, "weechat");
|
||||
|
||||
@@ -318,7 +318,116 @@ weechat_python_api_ngettext (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_string_remove_color: remove WeeChat color codes from string
|
||||
* weechat_python_api_string_match: return 1 if string matches a mask
|
||||
* mask can begin or end with "*", no other
|
||||
* "*" are allowed inside mask
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_string_match (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *string, *mask;
|
||||
int case_sensitive, value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_match");
|
||||
PYTHON_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = NULL;
|
||||
mask = NULL;
|
||||
case_sensitive = 0;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ssi", &string, &mask, &case_sensitive))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_match");
|
||||
PYTHON_RETURN_INT(0);
|
||||
}
|
||||
|
||||
value = weechat_string_match (string, mask, case_sensitive);
|
||||
|
||||
PYTHON_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_string_has_highlight: return 1 if string contains a
|
||||
* highlight (using list of words to
|
||||
* highlight)
|
||||
* return 0 if no highlight is found
|
||||
* in string
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_string_has_highlight (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *string, *highlight_words;
|
||||
int value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
PYTHON_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = NULL;
|
||||
highlight_words = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &string, &highlight_words))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
PYTHON_RETURN_INT(0);
|
||||
}
|
||||
|
||||
value = weechat_string_has_highlight (string, highlight_words);
|
||||
|
||||
PYTHON_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_string_mask_to_regex: convert a mask (string with only
|
||||
* "*" as joker) to a regex, paying
|
||||
* attention to special chars in a
|
||||
* regex
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_string_mask_to_regex (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *mask, *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
mask = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &mask))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = weechat_string_mask_to_regex (mask);
|
||||
|
||||
PYTHON_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_string_remove_color: remove WeeChat color codes from
|
||||
* string
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
@@ -6147,6 +6256,9 @@ PyMethodDef weechat_python_funcs[] =
|
||||
{ "iconv_from_internal", &weechat_python_api_iconv_from_internal, METH_VARARGS, "" },
|
||||
{ "gettext", &weechat_python_api_gettext, METH_VARARGS, "" },
|
||||
{ "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" },
|
||||
{ "string_match", &weechat_python_api_string_match, METH_VARARGS, "" },
|
||||
{ "string_has_highlight", &weechat_python_api_string_has_highlight, METH_VARARGS, "" },
|
||||
{ "string_mask_to_regex", &weechat_python_api_string_mask_to_regex, METH_VARARGS, "" },
|
||||
{ "string_remove_color", &weechat_python_api_string_remove_color, METH_VARARGS, "" },
|
||||
{ "string_is_command_char", &weechat_python_api_string_is_command_char, METH_VARARGS, "" },
|
||||
{ "string_input_for_buffer", &weechat_python_api_string_input_for_buffer, METH_VARARGS, "" },
|
||||
|
||||
@@ -367,6 +367,134 @@ weechat_ruby_api_ngettext (VALUE class, VALUE single, VALUE plural,
|
||||
RUBY_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_string_match: return 1 if string matches a mask
|
||||
* mask can begin or end with "*", no other "*"
|
||||
* are allowed inside mask
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_string_match (VALUE class, VALUE string, VALUE mask,
|
||||
VALUE case_sensitive)
|
||||
{
|
||||
char *c_string, *c_mask;
|
||||
int c_case_sensitive, value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "string_match");
|
||||
RUBY_RETURN_INT(0);
|
||||
}
|
||||
|
||||
c_string = NULL;
|
||||
c_mask = NULL;
|
||||
c_case_sensitive = 0;
|
||||
|
||||
if (NIL_P (string) || NIL_P (mask) || NIL_P (case_sensitive))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "string_match");
|
||||
RUBY_RETURN_INT(0);
|
||||
}
|
||||
|
||||
Check_Type (string, T_STRING);
|
||||
Check_Type (mask, T_STRING);
|
||||
Check_Type (case_sensitive, T_FIXNUM);
|
||||
|
||||
c_string = STR2CSTR (string);
|
||||
c_mask = STR2CSTR (mask);
|
||||
c_case_sensitive = FIX2INT (case_sensitive);
|
||||
|
||||
value = weechat_string_match (c_string, c_mask, c_case_sensitive);
|
||||
|
||||
RUBY_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_string_has_highlight: return 1 if string contains a
|
||||
* highlight (using list of words to
|
||||
* highlight)
|
||||
* return 0 if no highlight is found in
|
||||
* string
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_string_has_highlight (VALUE class, VALUE string,
|
||||
VALUE highlight_words)
|
||||
{
|
||||
char *c_string, *c_highlight_words;
|
||||
int value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
RUBY_RETURN_INT(0);
|
||||
}
|
||||
|
||||
c_string = NULL;
|
||||
c_highlight_words = NULL;
|
||||
|
||||
if (NIL_P (string) || NIL_P (highlight_words))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
RUBY_RETURN_INT(0);
|
||||
}
|
||||
|
||||
Check_Type (string, T_STRING);
|
||||
Check_Type (highlight_words, T_STRING);
|
||||
|
||||
c_string = STR2CSTR (string);
|
||||
c_highlight_words = STR2CSTR (highlight_words);
|
||||
|
||||
value = weechat_string_has_highlight (c_string, c_highlight_words);
|
||||
|
||||
RUBY_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_string_mask_to_regex: convert a mask (string with only
|
||||
* "*" as joker) to a regex, paying
|
||||
* attention to special chars in a
|
||||
* regex
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_string_mask_to_regex (VALUE class, VALUE mask)
|
||||
{
|
||||
char *c_mask, *result;
|
||||
VALUE return_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
c_mask = NULL;
|
||||
|
||||
if (NIL_P (mask))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (mask, T_STRING);
|
||||
|
||||
c_mask = STR2CSTR (mask);
|
||||
|
||||
result = weechat_string_mask_to_regex (c_mask);
|
||||
|
||||
RUBY_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_string_remove_color: remove WeeChat color codes from string
|
||||
*/
|
||||
@@ -7097,6 +7225,9 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "iconv_from_internal", &weechat_ruby_api_iconv_from_internal, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "gettext", &weechat_ruby_api_gettext, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "string_match", &weechat_ruby_api_string_match, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "string_has_highlight", &weechat_ruby_api_string_has_highlight, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "string_mask_to_regex", &weechat_ruby_api_string_mask_to_regex, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "string_remove_color", &weechat_ruby_api_string_remove_color, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "string_is_command_char", &weechat_ruby_api_string_is_command_char, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "string_input_for_buffer", &weechat_ruby_api_string_input_for_buffer, 1);
|
||||
|
||||
@@ -436,6 +436,127 @@ weechat_tcl_api_ngettext (ClientData clientData, Tcl_Interp *interp,
|
||||
TCL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_string_match: return 1 if string matches a mask
|
||||
* mask can begin or end with "*", no other "*"
|
||||
* are allowed inside mask
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_string_match (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj* objp;
|
||||
char *string, *mask;
|
||||
int case_sensitive, result, i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "string_match");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (objc < 4)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_match");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = Tcl_GetStringFromObj (objv[1], &i);
|
||||
mask = Tcl_GetStringFromObj (objv[2], &i);
|
||||
|
||||
if (Tcl_GetIntFromObj (interp, objv[3], &case_sensitive) != TCL_OK)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_match");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
result = weechat_string_match (string, mask, case_sensitive);
|
||||
|
||||
TCL_RETURN_INT(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_string_has_highlight: return 1 if string contains a
|
||||
* highlight (using list of words to
|
||||
* highlight)
|
||||
* return 0 if no highlight is found in
|
||||
* string
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_string_has_highlight (ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj* objp;
|
||||
char *string, *highlight_words;
|
||||
int result, i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (objc < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_has_highlight");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = Tcl_GetStringFromObj (objv[1], &i);
|
||||
highlight_words = Tcl_GetStringFromObj (objv[2], &i);
|
||||
|
||||
result = weechat_string_has_highlight (string, highlight_words);
|
||||
|
||||
TCL_RETURN_INT(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_string_mask_to_regex: convert a mask (string with only
|
||||
* "*" as joker) to a regex, paying
|
||||
* attention to special chars in a
|
||||
* regex
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_string_mask_to_regex (ClientData clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj* objp;
|
||||
char *result, *mask;
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (objc < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_mask_to_regex");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
mask = Tcl_GetStringFromObj (objv[1], &i);
|
||||
|
||||
result = weechat_string_mask_to_regex (mask);
|
||||
|
||||
TCL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_string_remove_color: remove WeeChat color codes from string
|
||||
*/
|
||||
@@ -6616,6 +6737,12 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
|
||||
weechat_tcl_api_gettext, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::ngettext",
|
||||
weechat_tcl_api_ngettext, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::string_match",
|
||||
weechat_tcl_api_string_match, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::string_has_highlight",
|
||||
weechat_tcl_api_string_has_highlight, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::string_mask_to_regex",
|
||||
weechat_tcl_api_string_mask_to_regex, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::string_remove_color",
|
||||
weechat_tcl_api_string_remove_color, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::string_is_command_char",
|
||||
|
||||
Reference in New Issue
Block a user