summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-03-30 22:13:14 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-03-30 22:13:14 +0200
commitbb00b6b8fb895e85d2959bebba9d49fe9de61438 (patch)
treef751d79ce8c49eedc7164916349d14be6ec638b5
parentf0c8da2f05a4b463cbc7d03341ee8a7a6db45f61 (diff)
downloadweechat-bb00b6b8fb895e85d2959bebba9d49fe9de61438.zip
core: add ${re:#} to get the index of last group captured in evaluation of expressions
-rw-r--r--doc/en/weechat_plugin_api.en.adoc15
-rw-r--r--doc/fr/weechat_plugin_api.fr.adoc15
-rw-r--r--doc/it/weechat_plugin_api.it.adoc15
-rw-r--r--doc/ja/weechat_plugin_api.ja.adoc16
-rw-r--r--src/core/wee-eval.c6
-rw-r--r--tests/unit/core/test-eval.cpp7
6 files changed, 62 insertions, 12 deletions
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc
index d4e1e9630..ec48f67a5 100644
--- a/doc/en/weechat_plugin_api.en.adoc
+++ b/doc/en/weechat_plugin_api.en.adoc
@@ -2058,9 +2058,18 @@ expanded to last):
| `+${re:N}+` |
Regex captured group: `0` = whole string matching, `1` to `99` = group
- captured, `+++` = last group captured. |
- `+${re:1}+` |
- `+test+`
+ captured, `+++` = last group captured,
+ `#` = index of last group captured (_WeeChat ≥ 1.8_). |
+ `+${re:0}+` +
+ `+${re:1}+` +
+ `+${re:2}+` +
+ `+${re:+++}+` +
+ `+${re:#}+` |
+ `+test1 test2+` +
+ `+test1+` +
+ `+test2+` +
+ `+test2+` +
+ `+2+`
| `+${color:name}+` |
WeeChat color code (the name of color has optional attributes),
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc
index a2fea8a0d..4b1761935 100644
--- a/doc/fr/weechat_plugin_api.fr.adoc
+++ b/doc/fr/weechat_plugin_api.fr.adoc
@@ -2101,9 +2101,18 @@ première étendue à la dernière) :
| `+${re:N}+` |
Groupe regex capturé : `0` = toute la chaîne correspondante,
- `1` à `99` = groupe capturé, `+++` = dernier groupe capturé. |
- `+${re:1}+` |
- `+test+`
+ `1` à `99` = groupe capturé, `+++` = dernier groupe capturé,
+ `#` = index du dernier groupe capturé (_WeeChat ≥ 1.8_). |
+ `+${re:0}+` +
+ `+${re:1}+` +
+ `+${re:2}+` +
+ `+${re:+++}+` +
+ `+${re:#}+` |
+ `+test1 test2+` +
+ `+test1+` +
+ `+test2+` +
+ `+test2+` +
+ `+2+`
| `+${color:nom}+` |
Code couleur WeeChat (le nom de couleur a des attributs facultatifs),
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc
index 31e610f08..8f70f1402 100644
--- a/doc/it/weechat_plugin_api.it.adoc
+++ b/doc/it/weechat_plugin_api.it.adoc
@@ -2136,9 +2136,18 @@ expanded to last):
| `+${re:N}+` |
Regex captured group: `0` = whole string matching, `1` to `99` = group
- captured, `+++` = last group captured. |
- `+${re:1}+` |
- `+test+`
+ captured, `+++` = last group captured,
+ `#` = index of last group captured (_WeeChat ≥ 1.8_). |
+ `+${re:0}+` +
+ `+${re:1}+` +
+ `+${re:2}+` +
+ `+${re:+++}+` +
+ `+${re:#}+` |
+ `+test1 test2+` +
+ `+test1+` +
+ `+test2+` +
+ `+test2+` +
+ `+2+`
| `+${color:name}+` |
WeeChat color code (the name of color has optional attributes),
diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc
index 12e89b394..feee8826f 100644
--- a/doc/ja/weechat_plugin_api.ja.adoc
+++ b/doc/ja/weechat_plugin_api.ja.adoc
@@ -2064,11 +2064,21 @@ char *weechat_string_eval_expression (const char *expr,
`+this…+` +
`+こ>>+`
+// TRANSLATION MISSING
| `+${re:N}+` |
正規表現のキャプチャグループ: `0` = マッチするすべての文字列、`1` から `99` =
- キャプチャされたグループ、`+++` = 最後にキャプチャされたグループ |
- `+${re:1}+` |
- `+test+`
+ キャプチャされたグループ、`+++` = 最後にキャプチャされたグループ、
+ `#` = index of last group captured (_WeeChat ≥ 1.8_). |
+ `+${re:0}+` +
+ `+${re:1}+` +
+ `+${re:2}+` +
+ `+${re:+++}+` +
+ `+${re:#}+` |
+ `+test1 test2+` +
+ `+test1+` +
+ `+test2+` +
+ `+test2+` +
+ `+2+`
| `+${color:name}+` |
WeeChat 色コード (色名部分はオプション属性をとることも可能です),
diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c
index 62dc6981b..016d99c2d 100644
--- a/src/core/wee-eval.c
+++ b/src/core/wee-eval.c
@@ -464,6 +464,12 @@ eval_replace_vars_cb (void *data, const char *text)
{
if (strcmp (text + 3, "+") == 0)
number = eval_regex->last_match;
+ else if (strcmp (text + 3, "#") == 0)
+ {
+ snprintf (str_value, sizeof (str_value),
+ "%d", eval_regex->last_match);
+ return strdup (str_value);
+ }
else
{
number = strtol (text + 3, &error, 10);
diff --git a/tests/unit/core/test-eval.cpp b/tests/unit/core/test-eval.cpp
index 4f2a92e8e..e0bd236b7 100644
--- a/tests/unit/core/test-eval.cpp
+++ b/tests/unit/core/test-eval.cpp
@@ -402,6 +402,13 @@ TEST(Eval, EvalReplaceRegex)
"password=abc password=def");
regfree (&regex);
+ /* regex groups */
+ hashtable_remove (pointers, "regex");
+ hashtable_set (options, "regex", "([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+)");
+ hashtable_set (options, "regex_replace",
+ "${re:0} -- ${re:1} ${re:+} (${re:#})");
+ WEE_CHECK_EVAL("abc def ghi jkl -- abc jkl (4)", "abc def ghi jkl");
+
hashtable_free (pointers);
hashtable_free (extra_vars);
hashtable_free (options);