From f09a87e5ba33652cc84672190bf9989a4d0b3f87 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 27 May 2015 15:10:54 +0200 Subject: [PATCH] JsonWizard: Add helper to deal with string lists Change-Id: I5d30f22367b365a71417c473cba3ce7125567a77 Reviewed-by: Alessandro Portale --- .../projectexplorer/jsonwizard/jsonwizard.cpp | 27 ++++++++++++++----- .../projectexplorer/jsonwizard/jsonwizard.h | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp index a3ddf29f607..8e242260dea 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp @@ -133,12 +133,9 @@ QString JsonWizard::stringValue(const QString &n) const if (v.type() == QVariant::String) return m_expander.expand(v.toString()); - if (v.type() == QVariant::StringList) { - QStringList tmp = Utils::transform(v.toStringList(), [this](const QString &i) -> QString { - return m_expander.expand(i).replace(QLatin1Char('\''), QLatin1String("\\'")); - }); - return QString(QString(QLatin1Char('\'')) + tmp.join(QLatin1String("', '")) + QString(QLatin1Char('\''))); - } + if (v.type() == QVariant::StringList) + return stringListToArrayString(v.toStringList(), &m_expander); + return v.toString(); } @@ -166,6 +163,24 @@ bool JsonWizard::boolFromVariant(const QVariant &v, Utils::MacroExpander *expand return v.toBool(); } +QString JsonWizard::stringListToArrayString(const QStringList &list, const Utils::MacroExpander *expander) +{ + // Todo: Handle ' embedded in the strings better. + if (list.isEmpty()) + return QString(); + + QStringList tmp = Utils::transform(list, [expander](const QString &i) { + return expander->expand(i).replace(QLatin1Char('\''), QLatin1String("\\'")); + }); + + QString result; + result.append(QLatin1Char('\'')); + result.append(tmp.join(QLatin1String("', '"))); + result.append(QLatin1Char('\'')); + + return result; +} + void JsonWizard::removeAttributeFromAllFiles(Core::GeneratedFile::Attribute a) { for (int i = 0; i < m_files.count(); ++i) { diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h index 73fa2300e5c..fba16e66b3a 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h @@ -79,6 +79,8 @@ public: void setValue(const QString &key, const QVariant &value); static bool boolFromVariant(const QVariant &v, Utils::MacroExpander *expander); + static QString stringListToArrayString(const QStringList &list, + const Utils::MacroExpander *expander); void removeAttributeFromAllFiles(Core::GeneratedFile::Attribute a);