summaryrefslogtreecommitdiffstats
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
authorflx5 <git@flx5.com>2015-03-11 04:14:17 +0100
committerflx5 <git@flx5.com>2015-03-11 04:14:17 +0100
commitd130696e95f83a2b7cd38258034cebf7edb890f3 (patch)
treeed12a3e1bc7cbe1b777eeecefe79a3fca9bda123 /src/StringUtils.cpp
parentFixed client kick/crash if many block changes happend (diff)
downloadcuberite-d130696e95f83a2b7cd38258034cebf7edb890f3.tar
cuberite-d130696e95f83a2b7cd38258034cebf7edb890f3.tar.gz
cuberite-d130696e95f83a2b7cd38258034cebf7edb890f3.tar.bz2
cuberite-d130696e95f83a2b7cd38258034cebf7edb890f3.tar.lz
cuberite-d130696e95f83a2b7cd38258034cebf7edb890f3.tar.xz
cuberite-d130696e95f83a2b7cd38258034cebf7edb890f3.tar.zst
cuberite-d130696e95f83a2b7cd38258034cebf7edb890f3.zip
Diffstat (limited to '')
-rw-r--r--src/StringUtils.cpp39
1 files changed, 39 insertions, 0 deletions
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)
{