MCPcopy Create free account
hub / github.com/cuberite/cuberite / EscapeString

Function EscapeString

src/StringUtils.cpp:587–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

585
586
587AString EscapeString(const AString & a_Message)
588{
589 AString EscapedMsg;
590 size_t len = a_Message.size();
591 size_t last = 0;
592 EscapedMsg.reserve(len);
593 for (size_t i = 0; i < len; i++)
594 {
595 char ch = a_Message[i];
596 switch (ch)
597 {
598 case '\'':
599 case '\"':
600 case '\\':
601 {
602 if (i > last)
603 {
604 EscapedMsg.append(a_Message, last, i - last);
605 }
606 EscapedMsg.push_back('\\');
607 EscapedMsg.push_back(ch);
608 last = i + 1;
609 break;
610 }
611 } // switch (ch)
612 } // for i - a_Message[]
613 if (len > last)
614 {
615 EscapedMsg.append(a_Message, last, len - last);
616 }
617 return EscapedMsg;
618}
619
620
621

Callers 3

SendChatMethod · 0.85
SendChatMethod · 0.85
SendDisconnectMethod · 0.85

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected