diff options
author | Remko Tronçon <git@el-tramo.be> | 2012-09-15 11:10:20 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2012-09-15 12:05:19 (GMT) |
commit | ab402e9e044e6f141a318c9b082671c828b915f3 (patch) | |
tree | 06194776a0102007b9a5fa5a6650f60b648d813b /Swiften/Base/URL.h | |
parent | e94541a7156f4ccceaf1a3f7135b9c89c067883b (diff) | |
download | swift-contrib-ab402e9e044e6f141a318c9b082671c828b915f3.zip swift-contrib-ab402e9e044e6f141a318c9b082671c828b915f3.tar.bz2 |
Added URL parser.
Diffstat (limited to 'Swiften/Base/URL.h')
-rw-r--r-- | Swiften/Base/URL.h | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/Swiften/Base/URL.h b/Swiften/Base/URL.h index 94dc4cb..9821ed5 100644 --- a/Swiften/Base/URL.h +++ b/Swiften/Base/URL.h @@ -8,32 +8,27 @@ #include <string> #include <boost/lexical_cast.hpp> +#include <boost/optional.hpp> namespace Swift { class URL { public: - URL() : scheme(""), user(""), password(""), host(""), port(-1), path(""), isEmpty(true) { + URL() : scheme(""), user(""), password(""), host(""), path(""), empty(true) { } - URL(const std::string& urlString) { - host = urlString; - port = 80; - scheme = "http"; - isEmpty = false; - //FIXME - } - - URL(const std::string& scheme, const std::string& host, int port, const std::string& path) : scheme(scheme), user(), password(), host(host), port(port), path(path), isEmpty(false) { + URL(const std::string& scheme, const std::string& host, int port, const std::string& path) : scheme(scheme), user(), password(), host(host), port(port), path(path), empty(false) { + } + URL(const std::string& scheme, const std::string& host, const std::string& path) : scheme(scheme), user(), password(), host(host), path(path), empty(false) { } /** * Whether the URL is empty. */ - bool empty() const { - return isEmpty; + bool isEmpty() const { + return empty; } /** @@ -53,7 +48,7 @@ class URL { /** * Port number */ - int getPort() const { + boost::optional<int> getPort() const { return port; } @@ -65,7 +60,7 @@ class URL { } const std::string toString() const { - if (isEmpty) { + if (empty) { return ""; } std::string result = scheme + "://"; @@ -86,13 +81,18 @@ class URL { return result; } + static int getPortOrDefaultPort(const URL& url); + static URL fromString(const std::string&); + static std::string unescape(const std::string&); + + private: std::string scheme; std::string user; std::string password; std::string host; - int port; + boost::optional<int> port; std::string path; - bool isEmpty; + bool empty; }; } |