11#include <boost/algorithm/string.hpp>
12#include <boost/tokenizer.hpp>
19void appendKeyValuePair(
const std::pair<std::string, std::string> &kvp,
const bool quoteValues,
20 std::ostringstream &resultStream) {
22 resultStream << kvp.first <<
"='" << kvp.second <<
'\'';
24 resultStream << kvp.first <<
"=" << kvp.second;
33void trimQuotes(QString &
value,
const char quote,
const char escape) {
41 if (
value.startsWith(quote) &&
value.endsWith(quote)) {
62 const auto valueIn =
value;
68 trimQuotes(
value,
'"',
'\\');
69 trimQuotes(
value,
'\'',
'\\');
82 for (
auto &
value : values)
96std::map<std::string, std::string>
parseKeyValueString(
const std::string &str,
const std::string &separator) {
107 boost::tokenizer<boost::escaped_list_separator<char>> tok(
108 str, boost::escaped_list_separator<char>(
"\\", separator,
"\"'"));
109 std::map<std::string, std::string> kvp;
111 for (
const auto &it : tok) {
112 std::vector<std::string> valVec;
113 boost::split(valVec, it, boost::is_any_of(
"="));
115 if (valVec.size() > 1) {
118 std::string key = valVec[0];
120 valVec.begin() = valVec.erase(valVec.begin());
122 std::string
value = boost::algorithm::join(valVec,
"=");
128 if (key.empty() ||
value.empty())
129 throw std::runtime_error(
"Invalid key value pair, '" + it +
"'");
133 throw std::runtime_error(
"Invalid key value pair, '" + it +
"'");
158 auto str = qstr.toStdString();
159 boost::tokenizer<boost::escaped_list_separator<char>> tok(
160 str, boost::escaped_list_separator<char>(
"\\", separator,
"\"'"));
161 std::map<QString, QString> kvp;
163 for (
const auto &it : tok) {
164 auto keyValueString = QString::fromStdString(it);
165 auto valVec = keyValueString.split(
"=");
167 if (valVec.size() > 1) {
170 auto key = valVec[0].trimmed();
172 valVec.removeFirst();
174 auto value = valVec.join(
"=").trimmed();
176 if (key.isEmpty() ||
value.isEmpty())
177 throw std::runtime_error(
"Invalid key value pair, '" + it +
"'");
181 throw std::runtime_error(
"Invalid key value pair, '" + it +
"'");
189QString
convertMapToString(
const std::map<QString, QString> &optionsMap,
const char separator,
const bool quoteValues) {
193 for (
auto &kvp : optionsMap) {
194 if (kvp.second.isEmpty())
202 const auto key = kvp.first;
203 auto value = kvp.second;
208 result += key +
"=" +
value;
216std::string
convertMapToString(
const std::map<std::string, std::string> &optionsMap,
const char separator,
217 const bool quoteValues) {
221 for (
auto &kvp : optionsMap) {
222 if (kvp.second.empty())
230 const auto key = kvp.first;
231 auto value = kvp.second;
236 result += key +
"=" +
value;
242std::string
optionsToString(std::map<std::string, std::string>
const &options,
const bool quoteValues,
243 const std::string &separator) {
244 if (!options.empty()) {
245 std::ostringstream resultStream;
246 auto optionsKvpIt = options.cbegin();
248 auto const &firstKvp = (*optionsKvpIt);
249 appendKeyValuePair(firstKvp, quoteValues, resultStream);
252 for (; optionsKvpIt != options.cend(); ++optionsKvpIt) {
253 auto kvp = (*optionsKvpIt);
254 resultStream << separator;
255 appendKeyValuePair(kvp, quoteValues, resultStream);
258 return resultStream.str();
260 return std::string();
267 return std::string();
269 auto result = std::string(props[0] + std::string(
"=") + options.
getPropertyValue(props[0]));
270 return std::accumulate(++props.cbegin(), props.cend(), result, [&options](
auto const &result,
auto const &prop) {
271 return result + std::string(
";") + prop + std::string(
"=") + options.getPropertyValue(prop);
double value
The value of the point.
virtual std::vector< std::string > getDeclaredPropertyNames() const noexcept=0
Get the list of managed property names.
virtual std::string getPropertyValue(const std::string &name) const =0
Get the value of a property as a string.