diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-02-10 16:36:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-02-10 16:36:04 +0300 |
commit | 5a15b718a475f8c2809521ea3166de379bf85b36 (patch) | |
tree | 9b50a62cf5192469dc23448aace0d7ba7996ccf0 /src/utils/paramerers.cpp | |
parent | e19faa6874b92a949703e37e07e912c693545496 (diff) | |
download | plus-5a15b718a475f8c2809521ea3166de379bf85b36.tar.gz plus-5a15b718a475f8c2809521ea3166de379bf85b36.tar.bz2 plus-5a15b718a475f8c2809521ea3166de379bf85b36.tar.xz plus-5a15b718a475f8c2809521ea3166de379bf85b36.zip |
In parameters parsing function add support for multiply separators.
Diffstat (limited to 'src/utils/paramerers.cpp')
-rw-r--r-- | src/utils/paramerers.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/utils/paramerers.cpp b/src/utils/paramerers.cpp index 12c20a18e..418e15ab7 100644 --- a/src/utils/paramerers.cpp +++ b/src/utils/paramerers.cpp @@ -31,22 +31,20 @@ static inline void addToken(StringVect &tokens, std::string str) { - const size_t sz = str.size(); - std::string item; + std::string item = trim(str); + const size_t sz = item.size(); if (sz > 1) { if (str[0] == '\"' && str[sz - 1] == '\"' && str[sz - 2] != '\\') { - str = str.substr(1, sz - 2); - item = trim(str); + item = item.substr(1, sz - 2); replaceAll(item, "\\\"", "\""); tokens.push_back(item); return; } } - item = trim(str); replaceAll(item, "\\\"", "\""); if (!item.empty()) tokens.push_back(item); @@ -57,15 +55,17 @@ static inline size_t findNextQuote(const std::string &str, const size_t pos) { size_t idx = str.find(quote, pos); - if (idx == std::string::npos) - return idx; - while (idx > 0 && str[idx - 1] == '\\') + while (idx > 0 && + idx != std::string::npos && + str[idx - 1] == '\\') + { idx = str.find(quote, idx + 1); + } return idx; } -static inline size_t findNextSplit(std::string &str, - const char separator, +static inline size_t findNextSplit(const std::string &str, + const std::string &separator, const char quote) { size_t pos = 0; @@ -73,7 +73,7 @@ static inline size_t findNextSplit(std::string &str, while (true) { // search for next separator - idx1 = str.find(separator, pos); + idx1 = findAny(str, separator, pos); // search for next open quote, skipping escaped quotes size_t idx2 = findNextQuote(str, quote, pos); if (idx2 == std::string::npos) // not quotes, return next separator @@ -99,7 +99,7 @@ static inline size_t findNextSplit(std::string &str, bool splitParameters(StringVect &tokens, std::string text, - const char separator, + const std::string &separator, const char quote) { size_t idx = findNextSplit(text, separator, quote); |