summaryrefslogtreecommitdiffstats
path: root/source/StringUtils.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-07-07 16:13:43 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-07-07 16:13:43 +0200
commit0224a4f7fc17400dd100a2333c7bbf9c898426c4 (patch)
tree5b909dc5b57a6859334591e0c5295547d8e9061f /source/StringUtils.cpp
parentImproved function names for protocol packet sending; alpha-sorted the function lists (diff)
downloadcuberite-0224a4f7fc17400dd100a2333c7bbf9c898426c4.tar
cuberite-0224a4f7fc17400dd100a2333c7bbf9c898426c4.tar.gz
cuberite-0224a4f7fc17400dd100a2333c7bbf9c898426c4.tar.bz2
cuberite-0224a4f7fc17400dd100a2333c7bbf9c898426c4.tar.lz
cuberite-0224a4f7fc17400dd100a2333c7bbf9c898426c4.tar.xz
cuberite-0224a4f7fc17400dd100a2333c7bbf9c898426c4.tar.zst
cuberite-0224a4f7fc17400dd100a2333c7bbf9c898426c4.zip
Diffstat (limited to '')
-rw-r--r--source/StringUtils.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/source/StringUtils.cpp b/source/StringUtils.cpp
index b55ce51e6..2bb6ae76e 100644
--- a/source/StringUtils.cpp
+++ b/source/StringUtils.cpp
@@ -569,3 +569,40 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_
+
+AString EscapeString(const AString & a_Message)
+{
+ AString EscapedMsg;
+ size_t len = a_Message.size();
+ size_t last = 0;
+ EscapedMsg.reserve(len);
+ for (size_t i = 0; i < len; i++)
+ {
+ char ch = a_Message[i];
+ switch (ch)
+ {
+ case '\'':
+ case '\"':
+ case '\\':
+ {
+ if (i > last)
+ {
+ EscapedMsg.append(a_Message, last, i - last);
+ }
+ EscapedMsg.push_back('\\');
+ EscapedMsg.push_back(ch);
+ last = i + 1;
+ break;
+ }
+ }
+ }
+ if (len > last)
+ {
+ EscapedMsg.append(a_Message, last, len - last);
+ }
+ return EscapedMsg;
+}
+
+
+
+