summaryrefslogtreecommitdiffstats
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-03-11 22:43:52 +0100
committerMattes D <github@xoft.cz>2015-03-11 22:43:52 +0100
commit439eb8d6cb111fdc336c95aec497a8eb9ddf2df1 (patch)
treea8ceefb71e807fa5b0acba588e07737086ea8d1c /src/StringUtils.cpp
parentMerge pull request #1804 from mc-server/streamlinetravis (diff)
parentFixed coding conventions for Pull Request #1807 (diff)
downloadcuberite-439eb8d6cb111fdc336c95aec497a8eb9ddf2df1.tar
cuberite-439eb8d6cb111fdc336c95aec497a8eb9ddf2df1.tar.gz
cuberite-439eb8d6cb111fdc336c95aec497a8eb9ddf2df1.tar.bz2
cuberite-439eb8d6cb111fdc336c95aec497a8eb9ddf2df1.tar.lz
cuberite-439eb8d6cb111fdc336c95aec497a8eb9ddf2df1.tar.xz
cuberite-439eb8d6cb111fdc336c95aec497a8eb9ddf2df1.tar.zst
cuberite-439eb8d6cb111fdc336c95aec497a8eb9ddf2df1.zip
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r--src/StringUtils.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 4eb2d48b6..95b3c7400 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -140,6 +140,54 @@ 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;
+ size_t cutAtQuote = 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;
+ cutAtQuote = str.find_first_of(current.at(0), Prev);
+ if (cutAtQuote != str.npos)
+ {
+ current = str.substr(Prev, cutAtQuote - Prev);
+ cutAt = cutAtQuote + 1;
+ }
+ }
+
+ results.push_back(current);
+ Prev = cutAt + 1;
+ }
+
+ if (Prev < str.length())
+ {
+ AString current = str.substr(Prev);
+
+ // 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);
+ }
+
+ results.push_back(current);
+ }
+
+ return results;
+}
+
+
+
AStringVector StringSplitAndTrim(const AString & str, const AString & delim)
{