summaryrefslogtreecommitdiffstats
path: root/source/StringUtils.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-14 10:52:57 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-14 10:52:57 +0100
commitff403fdbf0b4c372057fc8369797ddf652cfd727 (patch)
tree0f9f22c6a8ea41e879cbd49011ccd2c9f25d2604 /source/StringUtils.cpp
parentChanged DelayedFluidSimulatorData to be a vector rather than a list, performance doubled :) (diff)
downloadcuberite-ff403fdbf0b4c372057fc8369797ddf652cfd727.tar
cuberite-ff403fdbf0b4c372057fc8369797ddf652cfd727.tar.gz
cuberite-ff403fdbf0b4c372057fc8369797ddf652cfd727.tar.bz2
cuberite-ff403fdbf0b4c372057fc8369797ddf652cfd727.tar.lz
cuberite-ff403fdbf0b4c372057fc8369797ddf652cfd727.tar.xz
cuberite-ff403fdbf0b4c372057fc8369797ddf652cfd727.tar.zst
cuberite-ff403fdbf0b4c372057fc8369797ddf652cfd727.zip
Diffstat (limited to '')
-rw-r--r--source/StringUtils.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/StringUtils.cpp b/source/StringUtils.cpp
index dc128e61d..e98830f00 100644
--- a/source/StringUtils.cpp
+++ b/source/StringUtils.cpp
@@ -118,6 +118,26 @@ AStringVector StringSplit(const AString & str, const AString & delim)
+AStringVector StringSplitAndTrim(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)
+ {
+ results.push_back(TrimString(str.substr(Prev, cutAt - Prev)));
+ Prev = cutAt + delim.length();
+ }
+ if (Prev < str.length())
+ {
+ results.push_back(TrimString(str.substr(Prev)));
+ }
+ return results;
+}
+
+
+
+
AString TrimString(const AString & str)
{
size_t len = str.length();
@@ -506,7 +526,11 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_
k = a_LineLength;
}
memset(line, ' ', sizeof(line));
+ #ifdef _MSC_VER // MSVC provides a "secure" version of sprintf()
+ line[sprintf_s(line, sizeof(line), "%08x:", i)] = 32; // Remove the terminating NULL that sprintf puts there
+ #else
line[sprintf(line, "%08x:", i)] = 32; // Remove the terminating NULL that sprintf puts there
+ #endif
p = line + 10;
q = p + 2 + a_LineLength * 3 + 1;
for (int j = 0; j < k; j++)