From 6d6ccfd24bc247545992279b9c9bb5844ccbc9c9 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 2 Jan 2023 19:22:40 +0000 Subject: Add a method for unescaping tags. --- src/clientprotocol.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/clientprotocol.cpp') diff --git a/src/clientprotocol.cpp b/src/clientprotocol.cpp index 0ad9b1ee8..6ed2deb0e 100644 --- a/src/clientprotocol.cpp +++ b/src/clientprotocol.cpp @@ -99,6 +99,50 @@ std::string ClientProtocol::Message::EscapeTag(const std::string& value) return ret; } +std::string ClientProtocol::Message::UnescapeTag(const std::string& value) +{ + std::string ret; + ret.reserve(value.size()); + for (std::string::const_iterator it = value.begin(); it != value.end(); ++it) + { + char chr = *it; + if (chr != '\\') + { + ret.push_back(chr); + continue; + } + + it++; + if (it != value.end()) + { + chr = *it; + switch (chr) + { + case 's': + ret.push_back(' '); + break; + case ':': + ret.push_back(';'); + break; + case '\\': + ret.push_back('\\'); + break; + case 'n': + ret.push_back('\n'); + break; + case 'r': + ret.push_back('\r'); + break; + default: + ret.push_back(chr); + break; + } + } + } + return ret; +} + + const ClientProtocol::SerializedMessage& ClientProtocol::Message::GetSerialized(const SerializedInfo& serializeinfo) const { // First check if the serialized line they're asking for is in the cache -- cgit v1.3.1-10-gc9f91