diff options
author | Remko Tronçon <git@el-tramo.be> | 2013-08-25 16:39:06 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2013-08-27 19:47:48 (GMT) |
commit | 1bb607f96e79845ce30dd5590b0d53cc394ac150 (patch) | |
tree | 6156622ddd1b3238aec73536e0dc25b632965a71 /Swiften/JID | |
parent | c4431ee90f3f1daac0a12b35bfa3378d5c570eaa (diff) | |
download | swift-1bb607f96e79845ce30dd5590b0d53cc394ac150.zip swift-1bb607f96e79845ce30dd5590b0d53cc394ac150.tar.bz2 |
PubSub implementation & Sluift refactoring.
Change-Id: I04ff7111b73565c00bff6db183451774a633344f
Diffstat (limited to 'Swiften/JID')
-rw-r--r-- | Swiften/JID/JID.cpp | 6 | ||||
-rw-r--r-- | Swiften/JID/JID.h | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index e1502f1..0f2d8d1 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -18,6 +18,7 @@ #include <boost/assign/list_of.hpp> #include <boost/algorithm/string/find_format.hpp> #include <boost/algorithm/string/finder.hpp> +#include <boost/optional.hpp> #include <iostream> #include <sstream> @@ -317,4 +318,9 @@ std::ostream& operator<<(std::ostream& os, const JID& j) { return os; } +boost::optional<JID> JID::parse(const std::string& s) { + JID jid(s); + return jid.isValid() ? jid : boost::optional<JID>(); +} + } diff --git a/Swiften/JID/JID.h b/Swiften/JID/JID.h index eac1e2a..126a7b1 100644 --- a/Swiften/JID/JID.h +++ b/Swiften/JID/JID.h @@ -10,7 +10,7 @@ #include <iosfwd> #include <Swiften/Base/API.h> - +#include <boost/optional/optional_fwd.hpp> namespace Swift { class IDNConverter; @@ -160,6 +160,11 @@ namespace Swift { return a.compare(b, Swift::JID::WithResource) != 0; } + /** + * Returns an empty optional if the JID is invalid, and an + * optional with a value if the JID is valid. + */ + static boost::optional<JID> parse(const std::string&); /** * If Swiften was compiled with SWIFTEN_JID_NO_DEFAULT_IDN_CONVERTER (not default), use this method at |