AbstractEditorSupport: Simplify licenseheader handling

Change-Id: I6bad3870b14066716fff5adc2a03b18f1840b6c7
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2015-10-14 13:02:53 +02:00
parent fe8e14eb4c
commit a447645422

View File

@@ -35,6 +35,7 @@
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/macroexpander.h> #include <utils/macroexpander.h>
#include <utils/templateengine.h>
namespace CppTools { namespace CppTools {
@@ -63,30 +64,7 @@ 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; });
QString out = expander.expand(license); return Utils::TemplateEngine::processText(&expander, license, 0);
// 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