From 53a8cbbec1a6c9c644b35da86bc26a33ff1279e0 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 19 Jan 2019 17:49:05 +0100 Subject: Add support for spaces in grid name parameters (fixes #1152) --- src/iso19111/io.cpp | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'src/iso19111/io.cpp') diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index bac42d5b..4c417585 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -5208,8 +5208,9 @@ const std::string &PROJStringFormatter::toString() const { d->appendToResult("+"); d->result_ += paramValue.key; if (!paramValue.value.empty()) { - d->result_ += "="; - d->result_ += paramValue.value; + d->result_ += '='; + d->result_ += + pj_double_quote_string_param_if_needed(paramValue.value); } } } @@ -5229,8 +5230,9 @@ const std::string &PROJStringFormatter::toString() const { d->appendToResult("+"); d->result_ += paramValue.key; if (!paramValue.value.empty()) { - d->result_ += "="; - d->result_ += paramValue.value; + d->result_ += '='; + d->result_ += + pj_double_quote_string_param_if_needed(paramValue.value); } } } @@ -5273,8 +5275,39 @@ static void PROJStringSyntaxParser(const std::string &projString, std::vector &steps, std::vector &globalParamValues, std::string &title) { - std::string word; - std::istringstream iss(projString, std::istringstream::in); + const char *c_str = projString.c_str(); + std::vector tokens; + + size_t i = 0; + while (true) { + for (; isspace(c_str[i]); i++) { + } + std::string token; + bool in_string = false; + for (; c_str[i]; i++) { + if (in_string) { + if (c_str[i] == '"' && c_str[i + 1] == '"') { + i++; + } else if (c_str[i] == '"') { + in_string = false; + continue; + } + } else if (c_str[i] == '=' && c_str[i + 1] == '"') { + in_string = true; + token += c_str[i]; + i++; + continue; + } else if (isspace(c_str[i])) { + break; + } + token += c_str[i]; + } + if (token.empty()) { + break; + } + tokens.emplace_back(token); + } + bool prevWasTitle = false; if (projString.find("proj=pipeline") == std::string::npos) { @@ -5290,7 +5323,7 @@ PROJStringSyntaxParser(const std::string &projString, std::vector &steps, steps.push_back(Step()); } - while (iss >> word) { + for (auto &word : tokens) { if (word[0] == '+') { word = word.substr(1); } else if (prevWasTitle && word.find('=') == std::string::npos) { @@ -5334,7 +5367,7 @@ PROJStringSyntaxParser(const std::string &projString, std::vector &steps, bool inPipeline = false; bool invGlobal = false; - while (iss >> word) { + for (auto &word : tokens) { if (word[0] == '+') { word = word.substr(1); } else if (prevWasTitle && word.find('=') == std::string::npos) { -- cgit v1.2.3