From 2ec82a2a933bb5e6ea2ff33d8785e88f19194f99 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 26 Jun 2016 16:51:11 +0300 Subject: Utils: Support pattern substitution in macro expansion Syntax is similar to bash substitution: %{variable/pattern/replacement} takes the expansion of variable, and replaces the regular expression pattern with replacement once. %{variable//pattern/replacement} replaces all occurrences. Capture groups are supported for both forms. Change-Id: I67ff91e2dad4dd8be81573ea446cd1093a05ccf6 Reviewed-by: Oswald Buddenhagen Reviewed-by: hjk --- tests/auto/utils/stringutils/tst_stringutils.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/auto/utils/stringutils/tst_stringutils.cpp') diff --git a/tests/auto/utils/stringutils/tst_stringutils.cpp b/tests/auto/utils/stringutils/tst_stringutils.cpp index 314bf1391d..972d0b35d5 100644 --- a/tests/auto/utils/stringutils/tst_stringutils.cpp +++ b/tests/auto/utils/stringutils/tst_stringutils.cpp @@ -50,6 +50,18 @@ public: *ret = QLatin1String("bar"); return true; } + if (name == "slash") { + *ret = "foo/bar"; + return true; + } + if (name == "sl/sh") { + *ret = "slash"; + return true; + } + if (name == "JS:foo") { + *ret = "bar"; + return true; + } return false; } }; @@ -129,6 +141,18 @@ void tst_StringUtils::testMacroExpander_data() { "%{%{a}}}post", "ho}post" }, { "%{hi%{a}}", "bar" }, { "%{hi%{%{foo}}}", "bar" }, + { "%{hihi/b/c}", "car" }, + { "%{hihi/a/}", "br" }, // empty replacement + { "%{hihi/b}", "bar" }, // incomplete substitution + { "%{hihi/./c}", "car" }, + { "%{hihi//./c}", "ccc" }, + { "%{hihi/(.)(.)r/\\2\\1c}", "abc" }, // no escape for capture groups + { "%{hihi/b/c/d}", "c/dar" }, + { "%{hihi/a/e{\\}e}", "be{}er" }, // escape closing brace + { "%{slash/o\\/b/ol's c}", "fool's car" }, + { "%{sl\\/sh/(.)(a)(.)/\\2\\1\\3as}", "salsash" }, // escape in variable name + { "%{JS:foo/b/c}", "%{JS:foo/b/c}" }, // No replacement for JS (all considered varName) + { "%{%{a}%{a}/b/c}", "car" }, }; for (unsigned i = 0; i < sizeof(vals)/sizeof(vals[0]); i++) -- cgit v1.2.1