JsonWizard: Make template processing more widely available

Change-Id: I2c6eecc5d2a3c5429ce3a6a564d65f24ae3d23eb
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Tobias Hunger
2015-09-25 11:22:51 +02:00
parent 842578f357
commit cb0128846b
3 changed files with 51 additions and 47 deletions

View File

@@ -34,6 +34,7 @@
#include "../project.h"
#include "../projectexplorer.h"
#include "../customwizard/customwizardpreprocessor.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/messagemanager.h>
@@ -201,6 +202,51 @@ QHash<QString, QVariant> 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<Utils::WizardPage *>(currentPage());