diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp index 2693271b5c8..57cad839463 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp @@ -34,6 +34,7 @@ #include "../project.h" #include "../projectexplorer.h" +#include "../customwizard/customwizardpreprocessor.h" #include #include @@ -201,6 +202,51 @@ QHash JsonWizard::variables() const return result; } +QString JsonWizard::processText(Utils::MacroExpander *expander, const QString &input, + QString *errorMessage) +{ + errorMessage->clear(); + + if (input.isEmpty()) + return input; + + // Recursively expand macros: + QString in = input; + QString oldIn; + for (int i = 0; i < 5 && in != oldIn; ++i) { + oldIn = in; + in = expander->expand(oldIn); + } + + QString out; + if (!Internal::customWizardPreprocess(in, &out, errorMessage)) + return QString(); + + // 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; +} + void JsonWizard::accept() { auto page = qobject_cast(currentPage()); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h index 7809879b9f4..cbbddaefa5e 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h @@ -86,6 +86,9 @@ public: QHash variables() const override; + static QString processText(Utils::MacroExpander *expander, const QString &input, + QString *errorMessage); + signals: void preGenerateFiles(); // emitted before files are generated (can happen several times!) void postGenerateFiles(const JsonWizard::GeneratorFiles &files); // emitted after commitToFileList was called. diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp index f2822ba859c..b6d2526ed84 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp @@ -30,7 +30,6 @@ #include "jsonwizardfilegenerator.h" -#include "../customwizard/customwizardpreprocessor.h" #include "../projectexplorer.h" #include "jsonwizard.h" #include "jsonwizardfactory.h" @@ -48,51 +47,6 @@ namespace ProjectExplorer { namespace Internal { -static QString processTextFileContents(Utils::MacroExpander *expander, - const QString &input, QString *errorMessage) -{ - errorMessage->clear(); - - if (input.isEmpty()) - return input; - - // Recursively expand macros: - QString in = input; - QString oldIn; - for (int i = 0; i < 5 && in != oldIn; ++i) { - oldIn = in; - in = expander->expand(oldIn); - } - - QString out; - if (!customWizardPreprocess(in, &out, errorMessage)) - return QString(); - - // 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; -} - bool JsonWizardFileGenerator::setup(const QVariant &data, QString *errorMessage) { QVariantList list = JsonWizardFactory::objectOrList(data, errorMessage); @@ -210,7 +164,8 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp }); nested.registerExtraResolver([expander](QString n, QString *ret) { return expander->resolveMacro(n, ret); }); - gf.setContents(processTextFileContents(&nested, QString::fromUtf8(reader.data()), errorMessage)); + gf.setContents(JsonWizard::processText(&nested, QString::fromUtf8(reader.data()), + errorMessage)); if (!errorMessage->isEmpty()) { *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "When processing \"%1\":
%2") .arg(sourcePath, *errorMessage);