Old-style wizards: Handle line continuation in license templates

This is necessary to have the same template work in the old-style
wizards and the JSON wizard, which supports inserting \n, \t as well
as line continuation for everything.

Change-Id: I11c310998b92650003206484de8f1ecfc6000034
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Tobias Hunger
2015-09-15 16:37:54 +02:00
parent bd5becfe18
commit b38a954521

View File

@@ -63,7 +63,30 @@ QString AbstractEditorSupport::licenseTemplate(const QString &file, const QStrin
expander.registerVariable("Cpp:License:ClassName", tr("The class name"), expander.registerVariable("Cpp:License:ClassName", tr("The class name"),
[className]() { return className; }); [className]() { return className; });
return expander.expand(license); QString out = expander.expand(license);
// Expand \n, \t and handle line continuation:
QString result;
result.reserve(out.count());
bool isEscaped = false;
for (int i = 0; i < out.count(); ++i) {
const QChar c = out.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;
} }
} // namespace CppTools } // namespace CppTools