diff options
author | Jan Kaluza <hanzz.k@gmail.com> | 2011-04-14 08:50:27 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-04-18 19:11:43 (GMT) |
commit | a4e59529239902ac352e791767db63a31e2e0634 (patch) | |
tree | 8ac3da7c6f63f8a5fe523525f31e08742174f33f /Swiften/JID/JID.cpp | |
parent | 07152630c3a9d04dd86f7b370ee30b553665f5c7 (diff) | |
download | swift-contrib-a4e59529239902ac352e791767db63a31e2e0634.zip swift-contrib-a4e59529239902ac352e791767db63a31e2e0634.tar.bz2 |
Added support for JID Escaping XEP.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/JID/JID.cpp')
-rw-r--r-- | Swiften/JID/JID.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index e4611b3..5fd7524 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -13,6 +13,7 @@ #ifdef SWIFTEN_CACHE_JID_PREP #include <boost/unordered_map.hpp> #endif +#include <boost/algorithm/string/replace.hpp> #include <stringprep.h> #include <Swiften/Base/String.h> @@ -126,5 +127,40 @@ int JID::compare(const Swift::JID& o, CompareType compareType) const { return 0; } +std::string JID::getEscapedNode(const std::string& node) { + std::string escaped = node; + + boost::algorithm::replace_all(escaped, "\\", "\\5c"); + boost::algorithm::replace_all(escaped, " ", "\\20"); + boost::algorithm::replace_all(escaped, "\"", "\\22"); + boost::algorithm::replace_all(escaped, "&", "\\26"); + boost::algorithm::replace_all(escaped, "'", "\\27"); + boost::algorithm::replace_all(escaped, "/", "\\2f"); + boost::algorithm::replace_all(escaped, "<", "\\3c"); + boost::algorithm::replace_all(escaped, ">", "\\3e"); + boost::algorithm::replace_all(escaped, "@", "\\40"); + boost::algorithm::replace_all(escaped, ":", "\\3a"); + + return escaped; +} + +std::string JID::getUnescapedNode() const { + std::string unescaped = node_; + + boost::algorithm::replace_all(unescaped, "\\20", " "); + boost::algorithm::replace_all(unescaped, "\\22", "\""); + boost::algorithm::replace_all(unescaped, "\\26", "&"); + boost::algorithm::replace_all(unescaped, "\\27", "'"); + boost::algorithm::replace_all(unescaped, "\\2f", "/"); + boost::algorithm::replace_all(unescaped, "\\3c", "<"); + boost::algorithm::replace_all(unescaped, "\\3e", ">"); + boost::algorithm::replace_all(unescaped, "\\40", "@"); + boost::algorithm::replace_all(unescaped, "\\3a", ":"); + boost::algorithm::replace_all(unescaped, "\\5c", "\\"); + + + return unescaped; +} + } // namespace Swift |