From b38a954521358b35bbb3ca371513e80c7469ee2d Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 15 Sep 2015 16:37:54 +0200 Subject: [PATCH] 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 --- .../cpptools/abstracteditorsupport.cpp | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/plugins/cpptools/abstracteditorsupport.cpp b/src/plugins/cpptools/abstracteditorsupport.cpp index c1e49a4a1b0..3733f668cc5 100644 --- a/src/plugins/cpptools/abstracteditorsupport.cpp +++ b/src/plugins/cpptools/abstracteditorsupport.cpp @@ -63,7 +63,30 @@ QString AbstractEditorSupport::licenseTemplate(const QString &file, const QStrin expander.registerVariable("Cpp:License:ClassName", tr("The class name"), [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