Commit 869c7770 authored by Tobias Hunger's avatar Tobias Hunger

JsonWizard: Allow for more control of line layout in templates

Expand "\n", "\\" and "\t" in the templates to a linebreak/single '\'
character/tab respectively. Also enable line continuation with a '\'
character followed by a line break.

This allows for nicer output from the templates, avoiding spurious
blank lines in places.

Change-Id: I224b49e799f306dcb8fb8aa8ab2ea52733aecfa4
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 6568d9fb
......@@ -56,9 +56,32 @@ static QString processTextFileContents(Utils::AbstractMacroExpander *expander,
if (input.isEmpty())
return input;
QString result;
if (!customWizardPreprocess(Utils::expandMacros(input, expander), &result, errorMessage))
QString tmp;
if (!customWizardPreprocess(Utils::expandMacros(input, expander), &tmp, errorMessage))
return QString();
// Expand \n, \t and handle line continuation:
QString result;
result.reserve(tmp.count());
bool isEscaped = false;
for (int i = 0; i < tmp.count(); ++i) {
const QChar c = tmp.at(i);
if (isEscaped) {
if (c == QLatin1Char('n'))
result.append(QLatin1Char('\n'));
else if (c == QLatin1Char('t'))
result.append(QLatin1Char('\t'));
else if (c != QLatin1Char('\n'))
result.append(c);
isEscaped = false;
} else {
if (c == QLatin1Char('\\'))
isEscaped = true;
else
result.append(c);
}
}
return result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment