forked from qt-creator/qt-creator
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:
@@ -141,6 +141,11 @@
|
|||||||
backreferences. For example, if \c %{variable} is \c my123var, then
|
backreferences. For example, if \c %{variable} is \c my123var, then
|
||||||
\c %{variable/(..)(\d+)/\2\1} is expanded to \c {123myvar}.
|
\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:
|
To use the default value if the variable is not set, use:
|
||||||
|
|
||||||
\badcode
|
\badcode
|
||||||
|
@@ -136,6 +136,7 @@ bool AbstractMacroExpander::expandNestedMacros(const QString &str, int *pos, QSt
|
|||||||
QString *currArg = &varName;
|
QString *currArg = &varName;
|
||||||
QChar prev;
|
QChar prev;
|
||||||
QChar c;
|
QChar c;
|
||||||
|
QChar replacementChar;
|
||||||
bool replaceAll = false;
|
bool replaceAll = false;
|
||||||
|
|
||||||
int i = *pos;
|
int i = *pos;
|
||||||
@@ -192,13 +193,14 @@ bool AbstractMacroExpander::expandNestedMacros(const QString &str, int *pos, QSt
|
|||||||
} else if (currArg == &varName && c == '-' && prev == ':' && validateVarName(varName)) {
|
} else if (currArg == &varName && c == '-' && prev == ':' && validateVarName(varName)) {
|
||||||
varName.chop(1);
|
varName.chop(1);
|
||||||
currArg = &defaultValue;
|
currArg = &defaultValue;
|
||||||
} else if (currArg == &varName && c == '/' && validateVarName(varName)) {
|
} else if (currArg == &varName && (c == '/' || c == '#') && validateVarName(varName)) {
|
||||||
|
replacementChar = c;
|
||||||
currArg = &pattern;
|
currArg = &pattern;
|
||||||
if (i < strLen && str.at(i) == '/') {
|
if (i < strLen && str.at(i) == replacementChar) {
|
||||||
++i;
|
++i;
|
||||||
replaceAll = true;
|
replaceAll = true;
|
||||||
}
|
}
|
||||||
} else if (currArg == &pattern && c == '/') {
|
} else if (currArg == &pattern && c == replacementChar) {
|
||||||
currArg = &replace;
|
currArg = &replace;
|
||||||
} else {
|
} else {
|
||||||
*currArg += c;
|
*currArg += c;
|
||||||
|
Reference in New Issue
Block a user