Add functions string_match, string_has_highlight and string_mask_to_regex in script plugin API
parent
2801b8437c
commit
9d96090d7d
|
@ -1,7 +1,7 @@
|
|||
WeeChat ChangeLog
|
||||
=================
|
||||
FlashCode <flashcode@flashtux.org>
|
||||
v0.3.2-dev, 2010-03-17
|
||||
v0.3.2-dev, 2010-03-20
|
||||
|
||||
|
||||
Version 0.3.2 (under dev!)
|
||||
|
@ -28,8 +28,10 @@ Version 0.3.2 (under dev!)
|
|||
* gui: fix bug with cursor when position is last char of terminal
|
||||
* api: add "version_number" for function info_get to get WeeChat version as
|
||||
number
|
||||
* api: add functions "string_encode_base64" and "string_decode_base64",, fix
|
||||
* api: add functions "string_encode_base64" and "string_decode_base64", fix
|
||||
bug with base64 encoding
|
||||
* api: add functions "string_match", "string_has_highlight" and
|
||||
"string_mask_to_regex" in script plugin API
|
||||
* api: add missing infos in functions buffer_get_integer / buffer_get_string
|
||||
and in buffer infolist
|
||||
* api: add description of arguments for functions hook_info and hook_infolist
|
||||
|
|
|
@ -681,6 +681,20 @@ int match3 = weechat_string_match ("abcdef", "*def", 0); /* == 1 */
|
|||
int match4 = weechat_string_match ("abcdef", "*de*", 0); /* == 1 */
|
||||
----------------------------------------
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
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
|
||||
----------------------------------------
|
||||
|
||||
weechat_string_replace
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -809,6 +823,17 @@ C example:
|
|||
int hl = weechat_string_has_highlight ("my test string", "test,word2"); /* == 1 */
|
||||
----------------------------------------
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
highlight = weechat.string_has_highlight(string, highlight_words)
|
||||
|
||||
# example
|
||||
highlight = weechat.string_has_highlight("my test string", "test,word2") # 1
|
||||
----------------------------------------
|
||||
|
||||
weechat_string_mask_to_regex
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -840,6 +865,17 @@ char *str_regex = weechat_string_mask_to_regex ("test*mask");
|
|||
free (str_regex);
|
||||
----------------------------------------
|
||||
|
||||
Script (Python):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
regex = weechat.string_mask_to_regex(mask)
|
||||
|
||||
# example
|
||||
regex = weechat.string_mask_to_regex("test*mask") # "test.*mask"
|
||||
----------------------------------------
|
||||
|
||||
weechat_string_split
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -1204,7 +1240,7 @@ Script (Python):
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.string_is_command_char(string)
|
||||
is_cmdchar = weechat.string_is_command_char(string)
|
||||
|
||||
# examples
|
||||
command_char1 = weechat.string_is_command_char("/test") # == 1
|
||||
|
@ -3509,7 +3545,7 @@ Script (Python):
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.config_option_is_null(option)
|
||||
is_null = weechat.config_option_is_null(option)
|
||||
|
||||
# example
|
||||
if weechat.config_option_is_null(option):
|
||||
|
@ -3556,7 +3592,7 @@ Script (Python):
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.config_option_default_is_null(option)
|
||||
is_null = weechat.config_option_default_is_null(option)
|
||||
|
||||
# example
|
||||
if weechat.config_option_default_is_null(option):
|
||||
|
@ -9134,9 +9170,9 @@ Prototype:
|
|||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_upgrade_file *weechat_upgrade_write_object (struct t_upgrade_file *upgrade_file,
|
||||
int object_id,
|
||||
struct t_infolist *infolist);
|
||||
int weechat_upgrade_write_object (struct t_upgrade_file *upgrade_file,
|
||||
int object_id,
|
||||
struct t_infolist *infolist);
|
||||
----------------------------------------
|
||||
|
||||
Arguments:
|
||||
|
@ -9168,7 +9204,7 @@ Script (Python):
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.upgrade_write_object(upgrade_file, object_id, infolist)
|
||||
rc = weechat.upgrade_write_object(upgrade_file, object_id, infolist)
|
||||
|
||||
# example
|
||||
weechat.upgrade_write_object(upgrade_file, 1, infolist)
|
||||
|
@ -9183,12 +9219,12 @@ Prototype:
|
|||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_upgrade_file *weechat_upgrade_read (struct t_upgrade_file *upgrade_file,
|
||||
int (*callback_read)(void *data,
|
||||
struct t_upgrade_file *upgrade_file,
|
||||
int object_id,
|
||||
struct t_infolist *infolist),
|
||||
void *callback_read_data);
|
||||
int weechat_upgrade_read (struct t_upgrade_file *upgrade_file,
|
||||
int (*callback_read)(void *data,
|
||||
struct t_upgrade_file *upgrade_file,
|
||||
int object_id,
|
||||
struct t_infolist *infolist),
|
||||
void *callback_read_data);
|
||||
----------------------------------------
|
||||
|
||||
Arguments:
|
||||
|
@ -9223,7 +9259,7 @@ Script (Python):
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.upgrade_read(upgrade_file, callback_read, callback_read_data)
|
||||
rc = weechat.upgrade_read(upgrade_file, callback_read, callback_read_data)
|
||||
|
||||
# example
|
||||
def my_upgrade_read_cb(upgrade_file, object_id, infolist):
|
||||
|
|
|
@ -242,10 +242,9 @@ List of functions in script API:
|
|||
| plugins |
|
||||
plugin_get_name
|
||||
| strings |
|
||||
charset_set, iconv_to_internal, iconv_from_internal, +
|
||||
gettext, ngettext,
|
||||
string_remove_color, +
|
||||
string_is_command_char, string_input_for_buffer
|
||||
charset_set, iconv_to_internal, iconv_from_internal, gettext, ngettext, +
|
||||
string_match, string_has_highlight, string_mask_to_regex,
|
||||
string_remove_color, string_is_command_char, string_input_for_buffer
|
||||
| directories |
|
||||
mkdir_home, mkdir, mkdir_parents
|
||||
| sorted lists |
|
||||
|
|
|
@ -688,6 +688,20 @@ int match3 = weechat_string_match ("abcdef", "*def", 0); /* == 1 */
|
|||
int match4 = weechat_string_match ("abcdef", "*de*", 0); /* == 1 */
|
||||
----------------------------------------
|
||||
|
||||
Script (Python) :
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
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
|
||||
----------------------------------------
|
||||
|
||||
weechat_string_replace
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -818,6 +832,17 @@ Exemple en C :
|
|||
int hl = weechat_string_has_highlight ("my test string", "test,word2"); /* == 1 */
|
||||
----------------------------------------
|
||||
|
||||
Script (Python) :
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
highlight = weechat.string_has_highlight(string, highlight_words)
|
||||
|
||||
# exemple
|
||||
highlight = weechat.string_has_highlight("my test string", "test,word2") # 1
|
||||
----------------------------------------
|
||||
|
||||
weechat_string_mask_to_regex
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -851,6 +876,17 @@ char *str_regex = weechat_string_mask_to_regex ("test*mask");
|
|||
free (str_regex);
|
||||
----------------------------------------
|
||||
|
||||
Script (Python) :
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
regex = weechat.string_mask_to_regex(mask)
|
||||
|
||||
# exemple
|
||||
regex = weechat.string_mask_to_regex("test*mask") # "test.*mask"
|
||||
----------------------------------------
|
||||
|
||||
weechat_string_split
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -1219,7 +1255,7 @@ Script (Python) :
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.string_is_command_char(string)
|
||||
is_cmdchar = weechat.string_is_command_char(string)
|
||||
|
||||
# exemples
|
||||
command_char1 = weechat.string_is_command_char("/test") # == 1
|
||||
|
@ -3553,7 +3589,7 @@ Script (Python) :
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.config_option_is_null(option)
|
||||
is_null = weechat.config_option_is_null(option)
|
||||
|
||||
# exemple
|
||||
if weechat.config_option_is_null(option):
|
||||
|
@ -3600,7 +3636,7 @@ Script (Python) :
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.config_option_default_is_null(option)
|
||||
is_null = weechat.config_option_default_is_null(option)
|
||||
|
||||
# exemple
|
||||
if weechat.config_option_default_is_null(option):
|
||||
|
@ -9273,9 +9309,9 @@ Prototype :
|
|||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_upgrade_file *weechat_upgrade_write_object (struct t_upgrade_file *upgrade_file,
|
||||
int object_id,
|
||||
struct t_infolist *infolist);
|
||||
int weechat_upgrade_write_object (struct t_upgrade_file *upgrade_file,
|
||||
int object_id,
|
||||
struct t_infolist *infolist);
|
||||
----------------------------------------
|
||||
|
||||
Paramètres :
|
||||
|
@ -9307,7 +9343,7 @@ Script (Python) :
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.upgrade_write_object(upgrade_file, object_id, infolist)
|
||||
rc = weechat.upgrade_write_object(upgrade_file, object_id, infolist)
|
||||
|
||||
# exemple
|
||||
weechat.upgrade_write_object(upgrade_file, 1, infolist)
|
||||
|
@ -9322,12 +9358,12 @@ Prototype :
|
|||
|
||||
[source,C]
|
||||
----------------------------------------
|
||||
struct t_upgrade_file *weechat_upgrade_read (struct t_upgrade_file *upgrade_file,
|
||||
int (*callback_read)(void *data,
|
||||
struct t_upgrade_file *upgrade_file,
|
||||
int object_id,
|
||||
struct t_infolist *infolist),
|
||||
void *callback_read_data);
|
||||
int weechat_upgrade_read (struct t_upgrade_file *upgrade_file,
|
||||
int (*callback_read)(void *data,
|
||||
struct t_upgrade_file *upgrade_file,
|
||||
int object_id,
|
||||
struct t_infolist *infolist),
|
||||
void *callback_read_data);
|
||||
----------------------------------------
|
||||
|
||||
Paramètres :
|
||||
|
@ -9363,7 +9399,7 @@ Script (Python) :
|
|||
[source,python]
|
||||
----------------------------------------
|
||||
# prototype
|
||||
weechat.upgrade_read(upgrade_file, callback_read, callback_read_data)
|
||||
rc = weechat.upgrade_read(upgrade_file, callback_read, callback_read_data)
|
||||
|
||||
# exemple
|
||||
def my_upgrade_read_cb(upgrade_file, object_id, infolist):
|
||||
|
|
|
@ -251,10 +251,9 @@ Liste des fonctions de l'API script :
|
|||
| extensions |
|
||||
plugin_get_name
|
||||
| chaînes |
|
||||
charset_set, iconv_to_internal, iconv_from_internal, +
|
||||
gettext, ngettext,
|
||||
string_remove_color, +
|
||||
string_is_command_char, string_input_for_buffer
|
||||
charset_set, iconv_to_internal, iconv_from_internal, gettext, ngettext, +
|
||||
string_match, string_has_highlight, string_mask_to_regex,
|
||||
string_remove_color, string_is_command_char, string_input_for_buffer
|
||||
| répertoires |
|
||||
mkdir_home, mkdir, mkdir_parents
|
||||
| listes triées |
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -33,6 +33,11 @@ struct t_infolist;
|
|||
struct t_weelist;
|
||||
struct timeval;
|
||||
|
||||
/*
|
||||
* IMPORTANT NOTE for WeeChat developers: if you update, add or remove
|
||||
* some functions in this file, then please update API version below.
|
||||
*/
|
||||
|
||||
/* API version (used to check that plugin has same API and can be loaded) */
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20100302-01"
|
||||
|
||||
|
@ -131,12 +136,6 @@ struct t_weechat_plugin
|
|||
|
||||
/* plugin functions (API) */
|
||||
|
||||
/*
|
||||
* IMPORTANT NOTE for WeeChat developers: always add new API functions
|
||||
* at the END of functions, for keeping backward compatibility with
|
||||
* existing plugins
|
||||
*/
|
||||
|
||||
/* plugins */
|
||||
const char *(*plugin_get_name) (struct t_weechat_plugin *plugin);
|
||||
|
||||
|
|
Loading…
Reference in New Issue