Macro expander: Allow alternative substitution character

The forward slash is a poor choice on Windows for fields containing file
paths, as it gets auto-converted to a backslash when used in a path
chooser.

Fixes: QTCREATORBUG-22276
Change-Id: I1d22d2031909b24c72aad4781995418efd394039
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2019-07-09 16:24:12 +02:00
parent 61b4ef6bfa
commit 14aa0122e6
2 changed files with 10 additions and 3 deletions

View File

@@ -141,6 +141,11 @@
backreferences. For example, if \c %{variable} is \c my123var, then
\c %{variable/(..)(\d+)/\2\1} is expanded to \c {123myvar}.
Instead of the forward slash, you can also use the pound sign (\c #) as
the substitution character. This can be helpful if the value is supposed
to be a file path, in which case forward slashes might get translated
to backslashes on Windows hosts.
To use the default value if the variable is not set, use:
\badcode

View File

@@ -136,6 +136,7 @@ bool AbstractMacroExpander::expandNestedMacros(const QString &str, int *pos, QSt
QString *currArg = &varName;
QChar prev;
QChar c;
QChar replacementChar;
bool replaceAll = false;
int i = *pos;
@@ -192,13 +193,14 @@ bool AbstractMacroExpander::expandNestedMacros(const QString &str, int *pos, QSt
} else if (currArg == &varName && c == '-' && prev == ':' && validateVarName(varName)) {
varName.chop(1);
currArg = &defaultValue;
} else if (currArg == &varName && c == '/' && validateVarName(varName)) {
} else if (currArg == &varName && (c == '/' || c == '#') && validateVarName(varName)) {
replacementChar = c;
currArg = &pattern;
if (i < strLen && str.at(i) == '/') {
if (i < strLen && str.at(i) == replacementChar) {
++i;
replaceAll = true;
}
} else if (currArg == &pattern && c == '/') {
} else if (currArg == &pattern && c == replacementChar) {
currArg = &replace;
} else {
*currArg += c;