From 3a0b0e0699c2617bdb090bc9e67e040aa10a0ed4 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Wed, 18 Oct 2023 18:31:13 +0200 Subject: [PATCH] Add support for vector configs This is the first step for arbitrary widget position --- src/Config.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Config.cpp b/src/Config.cpp index 275ec53..c4eb680 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -96,6 +96,35 @@ void ApplyProperty(std::pair& propertyToSet, const std::string_vi ApplyProperty(propertyToSet.second, after); } +template +void ApplyProperty(std::vector& propertyToSet, const std::string_view& value) +{ + propertyToSet.clear(); + // Delete [] + size_t beginBracket = value.find('['); + size_t endBracket = value.find(']'); + if (beginBracket == std::string::npos || endBracket == std::string::npos) + { + LOG("Error: Missing [ or ] for vector property!"); + return; + } + std::string_view elems = value.substr(beginBracket, endBracket - beginBracket + 1); + size_t beginString = 0; + while (true) + { + // Find first not whitespace + beginString = elems.find_first_not_of("[ \t", beginString); + size_t endString = elems.find_first_of(",]", beginString); + if (beginString == std::string::npos || endString == std::string::npos) + break; + + // Append to property + std::string_view elem = elems.substr(beginString, endString - beginString); + propertyToSet.push_back(std::string(elem)); + beginString = ++endString; + } +} + template, bool> = true> void AddConfigVar(const std::string& propertyName, T& propertyToSet, std::string_view line, bool& setConfig) {