mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 00:03:12 +02:00
core: improve the string_replace_regex function (add reference char, change syntax for match refs)
The reference char is now an argument for the function. The references are now $0 .. $99 and $+ was added (last match, with highest number). The syntax to replace a match with one char is now: $.cN or $.c+ (for example: "$.*3").
This commit is contained in:
@@ -114,7 +114,8 @@ trigger_callback_replace_regex (struct t_trigger *trigger,
|
||||
|
||||
value = weechat_string_replace_regex (ptr_value,
|
||||
trigger->regex[i].regex,
|
||||
trigger->regex[i].replace_eval);
|
||||
trigger->regex[i].replace_eval,
|
||||
'$');
|
||||
if (!value)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -618,12 +618,12 @@ trigger_command_init ()
|
||||
" replace password with '*' in /oper command (in command line and "
|
||||
"command history):\n"
|
||||
" /trigger add oper modifier input_text_display;history_add "
|
||||
"\"\" \"==^(/oper +\\S+ +)(.*)==\\1\\*2\"\n"
|
||||
"\"\" \"==^(/oper +\\S+ +)(.*)==$1$.*2\"\n"
|
||||
" add text attributes in *bold*, _underline_ and /italic/:\n"
|
||||
" /trigger add effects modifier weechat_print \"\" "
|
||||
"\"==\\*(\\S+)\\*==*${color:bold}\\1${color:-bold}*== "
|
||||
"==_(\\S+)_==_${color:underline}\\1${color:-underline}_== "
|
||||
"==/(\\S+)/==/${color:italic}\\1${color:-italic}/\"\n"
|
||||
"\"==\\*(\\S+)\\*==*${color:bold}$1${color:-bold}*== "
|
||||
"==_(\\S+)_==_${color:underline}$1${color:-underline}_== "
|
||||
"==/(\\S+)/==/${color:italic}$1${color:-italic}/\"\n"
|
||||
" silently save config each hour:\n"
|
||||
" /trigger add cfgsave timer 3600000;0;0 \"\" \"\" \"/mute /save\""),
|
||||
"list|listfull"
|
||||
|
||||
@@ -221,7 +221,9 @@ trigger_config_create_option (const char *trigger_name, int index_option,
|
||||
"many regex can be separated by a space, for example: "
|
||||
"\"/regex1/replace1/var1 /regex2/replace2/var2\"; the "
|
||||
"separator \"/\" can be replaced by any char (one or more "
|
||||
"identical chars), except '\\' and parentheses"),
|
||||
"identical chars), except '\\' and parentheses; matching "
|
||||
"groups can be used in replace: $0 to $99, $+ for last "
|
||||
"match and $.cN to replace all chars of group N by char c"),
|
||||
NULL, 0, 0, value, NULL, 0,
|
||||
NULL, NULL, &trigger_config_change_regex, NULL, NULL, NULL);
|
||||
break;
|
||||
|
||||
@@ -57,7 +57,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 "20140131-01"
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20140208-01"
|
||||
|
||||
/* macros for defining plugin infos */
|
||||
#define WEECHAT_PLUGIN_NAME(__name) \
|
||||
@@ -248,7 +248,8 @@ struct t_weechat_plugin
|
||||
const char *highlight_words);
|
||||
int (*string_has_highlight_regex) (const char *string, const char *regex);
|
||||
char *(*string_replace_regex) (const char *string, void *regex,
|
||||
const char *replace);
|
||||
const char *replace,
|
||||
const char reference_char);
|
||||
char **(*string_split) (const char *string, const char *separators,
|
||||
int keep_eol, int num_items_max, int *num_items);
|
||||
char **(*string_split_shell) (const char *string, int *num_items);
|
||||
@@ -1012,8 +1013,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
weechat_plugin->string_has_highlight(__string, __highlight_words)
|
||||
#define weechat_string_has_highlight_regex(__string, __regex) \
|
||||
weechat_plugin->string_has_highlight_regex(__string, __regex)
|
||||
#define weechat_string_replace_regex(__string, __regex, __replace) \
|
||||
weechat_plugin->string_replace_regex(__string, __regex, __replace)
|
||||
#define weechat_string_replace_regex(__string, __regex, __replace, \
|
||||
__reference_char) \
|
||||
weechat_plugin->string_replace_regex(__string, __regex, __replace, \
|
||||
__reference_char)
|
||||
#define weechat_string_split(__string, __separator, __eol, __max, \
|
||||
__num_items) \
|
||||
weechat_plugin->string_split(__string, __separator, __eol, \
|
||||
|
||||
Reference in New Issue
Block a user