summaryrefslogtreecommitdiffstats
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-08-18 12:29:54 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2017-08-18 12:29:54 +0200
commitb8dda388e0cf300f573d411dc670099e56c2e3c3 (patch)
tree6c3f40beb7a652f9c5afa560954e68a53db54401 /src/StringUtils.cpp
parentChanged type of FastRandom in monster drop calculation. (#3920) (diff)
downloadcuberite-b8dda388e0cf300f573d411dc670099e56c2e3c3.tar
cuberite-b8dda388e0cf300f573d411dc670099e56c2e3c3.tar.gz
cuberite-b8dda388e0cf300f573d411dc670099e56c2e3c3.tar.bz2
cuberite-b8dda388e0cf300f573d411dc670099e56c2e3c3.tar.lz
cuberite-b8dda388e0cf300f573d411dc670099e56c2e3c3.tar.xz
cuberite-b8dda388e0cf300f573d411dc670099e56c2e3c3.tar.zst
cuberite-b8dda388e0cf300f573d411dc670099e56c2e3c3.zip
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r--src/StringUtils.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 42d736a8c..b7e446d53 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -228,6 +228,42 @@ AStringVector StringSplitWithQuotes(const AString & str, const AString & delim)
+
+AString StringJoin(const AStringVector & a_Strings, const AString & a_Delimeter)
+{
+ if (a_Strings.empty())
+ {
+ return {};
+ }
+
+ // Do a dry run to gather the size
+ const auto DelimSize = a_Delimeter.size();
+ size_t ResultSize = a_Strings[0].size();
+ std::for_each(a_Strings.begin() + 1, a_Strings.end(),
+ [&](const AString & a_String)
+ {
+ ResultSize += DelimSize;
+ ResultSize += a_String.size();
+ }
+ );
+
+ // Now do the actual join
+ AString Result;
+ Result.reserve(ResultSize);
+ Result.append(a_Strings[0]);
+ std::for_each(a_Strings.begin() + 1, a_Strings.end(),
+ [&](const AString & a_String)
+ {
+ Result += a_Delimeter;
+ Result += a_String;
+ }
+ );
+ return Result;
+}
+
+
+
+
AStringVector StringSplitAndTrim(const AString & str, const AString & delim)
{
AStringVector results;