diff options
Diffstat (limited to 'src/url.hh')
| -rw-r--r-- | src/url.hh | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/url.hh b/src/url.hh new file mode 100644 index 0000000..d3b69b7 --- /dev/null +++ b/src/url.hh @@ -0,0 +1,62 @@ +// -*- mode: c++; c-basic-offset: 2; -*- + +#ifndef URL_HH +#define URL_HH + +#include <cstdint> +#include <string> + +// scheme://[userinfo@]host[:port]/path[?query][#fragment] +class Url { +public: + virtual ~Url() {} + + static Url* parse(std::string const& url, Url const* base = nullptr); + + virtual Url* copy() const = 0; + + bool operator==(Url const& url) const; + + // never empty, unescaped + virtual std::string const& scheme() const = 0; + + // may be null, not empty, unescaped + virtual char const* userinfo() const = 0; + + // may be null, not empty + virtual char const* userinfo_escaped() const = 0; + + // may be empty, unescaped + virtual std::string const& host() const = 0; + + // 0 is used for no port set + virtual uint16_t port() const = 0; + + // may be empty, unescaped + virtual std::string path() const = 0; + + // may be empty + virtual std::string path_escaped() const = 0; + + // return true if name was found and value updated, + // value may be empty, unescaped + virtual bool query(std::string const& name, std::string* value) const = 0; + + // may be null or empty, unescaped + virtual char const* full_query() const = 0; + + // may be null or empty + virtual char const* full_query_escaped() const = 0; + + // may be null or empty, unescaped + virtual char const* fragment() const = 0; + + virtual void print(std::ostream& out, bool path = true, bool query = true, + bool fragment = true) const = 0; + +protected: + Url() {} + Url(Url const&) = delete; +}; + +#endif // URL_HH |
