arabica/include/io/uri.hpp
2007-09-10 15:58:45 +00:00

78 lines
1.8 KiB
C++

#ifndef ARABICA_IO_URI_HPP
#define ARABICA_IO_URI_HPP
#include <string>
namespace Arabica
{
namespace io
{
class URI
{
public:
URI() { }
URI(const std::string& URI);
URI(const URI& base, const std::string& relativeURI);
URI(const URI& rhs) :
scheme_(rhs.scheme_),
host_(rhs.host_),
path_(rhs.path_),
port_(rhs.port_)
{
} // URI
URI& operator=(const URI& rhs)
{
URI t(rhs);
swap(t);
return *this;
} // operator=
bool operator==(const URI& rhs) const
{
return scheme_ == rhs.scheme_ &&
host_ == rhs.host_ &&
path_ == rhs.path_ &&
port_ == rhs.port_;
} // operator==
bool operator!=(const URI& rhs) const
{
return !(operator==(rhs));
} // operator!=
~URI() { }
void swap(URI& rhs)
{
std::swap(scheme_, rhs.scheme_);
std::swap(host_, rhs.host_);
std::swap(path_, rhs.path_);
std::swap(port_, rhs.port_);
} // swap
const std::string& scheme() const { return scheme_; }
const std::string& host() const { return host_; }
const std::string& port() const;
const std::string& path() const { return path_; }
std::string as_string() const;
private:
void parse(const std::string& URI);
void parseAuthority(std::string::const_iterator& u, std::string::const_iterator& ue);
void absolutise(URI& relURI);
void combinePath(const std::string& path);
std::string scheme_;
std::string host_;
std::string path_;
std::string port_;
}; // class URI
} // namespace io
} // namespace Arabica
#endif