From d130696e95f83a2b7cd38258034cebf7edb890f3 Mon Sep 17 00:00:00 2001 From: flx5 Date: Wed, 11 Mar 2015 04:14:17 +0100 Subject: Fixes #493 and #490 --- src/StringUtils.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 4eb2d48b6..db406369b 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -140,6 +140,45 @@ AStringVector StringSplit(const AString & str, const AString & delim) +AStringVector StringSplitWithQuotes(const AString & str, const AString & delim) +{ + AStringVector results; + + size_t cutAt = 0; + size_t Prev = 0; + + while ((cutAt = str.find_first_of(delim, Prev)) != str.npos) + { + AString current = str.substr(Prev, cutAt - Prev); + if (current.at(0) == '"' || current.at(0) == '\'') { + Prev += 1; + cutAt = str.find_first_of(current.at(0), Prev); + if (cutAt != str.npos) { + current = str.substr(Prev, cutAt - Prev); + cutAt += 1; + } + } + + results.push_back(current); + Prev = cutAt + 1; + } + + if (Prev < str.length()) + { + AString current = str.substr(Prev); + + if (current.length() >= 2 && (current.front() == '"' || current.front() == '\'') && current.front() == current.back()) { + current = current.substr(1, current.length() - 2); + } + + results.push_back(current); + } + + return results; +} + + + AStringVector StringSplitAndTrim(const AString & str, const AString & delim) { -- cgit v1.2.3 From 451ab6860fcdf53f4e4057465acd8712aea48bce Mon Sep 17 00:00:00 2001 From: flx5 Date: Wed, 11 Mar 2015 04:33:17 +0100 Subject: Fixed some markup issues --- src/StringUtils.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index db406369b..084a42280 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -150,10 +150,12 @@ AStringVector StringSplitWithQuotes(const AString & str, const AString & delim) while ((cutAt = str.find_first_of(delim, Prev)) != str.npos) { AString current = str.substr(Prev, cutAt - Prev); - if (current.at(0) == '"' || current.at(0) == '\'') { + if ((current.at(0) == '"') || (current.at(0) == '\'')) + { Prev += 1; cutAt = str.find_first_of(current.at(0), Prev); - if (cutAt != str.npos) { + if (cutAt != str.npos) + { current = str.substr(Prev, cutAt - Prev); cutAt += 1; } @@ -167,7 +169,7 @@ AStringVector StringSplitWithQuotes(const AString & str, const AString & delim) { AString current = str.substr(Prev); - if (current.length() >= 2 && (current.front() == '"' || current.front() == '\'') && current.front() == current.back()) { + if ((current.length() >= 2) && ((current.front() == '"') || (current.front() == '\'')) && (current.front() == current.back())) { current = current.substr(1, current.length() - 2); } -- cgit v1.2.3 From 76012ee090c7e500ef47c3b4114a386cad176bd9 Mon Sep 17 00:00:00 2001 From: flx5 Date: Wed, 11 Mar 2015 04:38:15 +0100 Subject: Fixed some markup issues --- src/StringUtils.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 084a42280..343f93ce3 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -150,11 +150,11 @@ AStringVector StringSplitWithQuotes(const AString & str, const AString & delim) while ((cutAt = str.find_first_of(delim, Prev)) != str.npos) { AString current = str.substr(Prev, cutAt - Prev); - if ((current.at(0) == '"') || (current.at(0) == '\'')) + if ((current.at(0) == '"') || (current.at(0) == '\'')) { Prev += 1; cutAt = str.find_first_of(current.at(0), Prev); - if (cutAt != str.npos) + if (cutAt != str.npos) { current = str.substr(Prev, cutAt - Prev); cutAt += 1; @@ -169,7 +169,8 @@ AStringVector StringSplitWithQuotes(const AString & str, const AString & delim) { AString current = str.substr(Prev); - if ((current.length() >= 2) && ((current.front() == '"') || (current.front() == '\'')) && (current.front() == current.back())) { + if ((current.length() >= 2) && ((current.front() == '"') || (current.front() == '\'')) && (current.front() == current.back())) + { current = current.substr(1, current.length() - 2); } -- cgit v1.2.3 From d8ab99e944f90dffcaa597b030c6475a675679b2 Mon Sep 17 00:00:00 2001 From: flx5 Date: Wed, 11 Mar 2015 19:52:49 +0100 Subject: Fixed issue with quotes not appearing in pairs --- src/StringUtils.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 343f93ce3..47fb6e5a1 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -146,6 +146,7 @@ AStringVector StringSplitWithQuotes(const AString & str, const AString & delim) size_t cutAt = 0; size_t Prev = 0; + size_t cutAtQuote = 0; while ((cutAt = str.find_first_of(delim, Prev)) != str.npos) { @@ -153,11 +154,11 @@ AStringVector StringSplitWithQuotes(const AString & str, const AString & delim) if ((current.at(0) == '"') || (current.at(0) == '\'')) { Prev += 1; - cutAt = str.find_first_of(current.at(0), Prev); - if (cutAt != str.npos) + cutAtQuote = str.find_first_of(current.at(0), Prev); + if (cutAtQuote != str.npos) { - current = str.substr(Prev, cutAt - Prev); - cutAt += 1; + current = str.substr(Prev, cutAtQuote - Prev); + cutAt = cutAtQuote + 1; } } -- cgit v1.2.3 From f6912bd01c80a1031c1d0f69a87eca4f0990da66 Mon Sep 17 00:00:00 2001 From: flx5 Date: Wed, 11 Mar 2015 20:02:11 +0100 Subject: Fixed coding conventions for Pull Request #1807 --- src/StringUtils.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 47fb6e5a1..95b3c7400 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -170,7 +170,12 @@ AStringVector StringSplitWithQuotes(const AString & str, const AString & delim) { AString current = str.substr(Prev); - if ((current.length() >= 2) && ((current.front() == '"') || (current.front() == '\'')) && (current.front() == current.back())) + // If the remant is wrapped in matching quotes, remove them: + if ( + (current.length() >= 2) && + ((current.front() == '"') || (current.front() == '\'')) && + (current.front() == current.back()) + ) { current = current.substr(1, current.length() - 2); } -- cgit v1.2.3