diff options
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 |