From 4a75bc8f1ce56720517b9c6d174da6bfd81fae8b Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Wed, 7 Oct 2015 15:44:37 +0200 Subject: Allow string config values to be enclosed in quotes to include spaces at the beginning or the end --- src/CRSMConfig.hpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/CRSMConfig.hpp b/src/CRSMConfig.hpp index c8750dd..b25b809 100644 --- a/src/CRSMConfig.hpp +++ b/src/CRSMConfig.hpp @@ -60,13 +60,38 @@ using Boolean = bool; template<> class CRSMConfigValue : public CRSMConfigValueBase { String& config; + bool trimmedQuotes = false; public: CRSMConfigValue(String& config) : config(config) { } - virtual void setValue(const QString& value) { config = value; } - virtual QString value() { return config; } + virtual void setValue(const QString& value) { config = trimQuotes(QString(value), trimmedQuotes); } + virtual QString value() + { + if(trimmedQuotes) + { + return "\"" + config + "\""; + } + else + { + return config; + } + } virtual CRSMConfigValueType::Type type() { return CRSMConfigValueType::Type::String; } + +private: + QString& trimQuotes(QString&& string, bool& trimmed) + { + trimmed = false; + if(string.length() >= 2 && string.at(0) == '"' && string.at(string.length() - 1) == '"') + { + string.remove(0, 1); + string.remove(string.length() - 1, 1); + trimmed = true; + } + return string; + } + }; template -- cgit v1.2.3-54-g00ecf