libfilezilla
uri.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_URI_HEADER
2 #define LIBFILEZILLA_URI_HEADER
3 
4 #include "libfilezilla.hpp"
5 
6 #include <initializer_list>
7 #include <map>
8 #include <string>
9 
14 namespace fz {
15 
21 class FZ_PUBLIC_SYMBOL uri final
22 {
23 public:
24  uri() noexcept = default;
25  explicit uri(std::string_view const& in);
26 
27  void clear();
28 
35  bool parse(std::string_view in);
36 
43  std::string to_string(bool with_query = true) const;
44 
46  std::string get_request(bool with_query = true) const;
47 
49  std::string get_authority(bool with_userinfo) const;
50 
51  bool empty() const;
52  explicit operator bool() const { return !empty(); }
53 
55  std::string scheme_;
56 
58  std::string user_;
59 
61  std::string pass_;
62 
64  std::string host_;
65 
67  unsigned short port_{};
68 
70  std::string path_;
71 
79  std::string query_;
80 
86  std::string fragment_;
87 
89  bool is_absolute() const { return path_[0] == '/'; }
90 
96  void resolve(uri const& base);
97 
98  bool operator==(uri const& arg) const;
99 
100  bool operator!=(uri const& arg) const { return !(*this == arg); }
101 
102 private:
103  bool FZ_PRIVATE_SYMBOL parse_authority(std::string_view authority);
104 };
105 
111 class FZ_PUBLIC_SYMBOL query_string final
112 {
113 public:
114  explicit query_string() = default;
115  explicit query_string(std::string_view const& raw);
116  explicit query_string(std::pair<std::string, std::string> const& segment);
117  explicit query_string(std::initializer_list<std::pair<std::string, std::string>> const& segments);
118  bool set(std::string_view const& raw);
119 
120  std::string to_string(bool encode_slashes) const;
121 
122  void remove(std::string const& key);
123  std::string& operator[](std::string const& key);
124 
125  std::map<std::string, std::string, less_insensitive_ascii> const& pairs() const { return segments_; }
126 
127  bool empty() const { return segments_.empty(); }
128 
129 private:
130  std::map<std::string, std::string, less_insensitive_ascii> segments_;
131 };
132 
133 }
134 
135 #endif
Class for parsing a URI's query string.
Definition: uri.hpp:112
The uri class is used to decompose URIs into their individual components.
Definition: uri.hpp:22
std::string get_authority(bool with_userinfo) const
Returns [user[:pass]@]host[:port].
bool parse(std::string_view in)
Splits uri into components.
std::string user_
Optional user part of the authority.
Definition: uri.hpp:58
std::string query_
The part of a URI after ? but before #.
Definition: uri.hpp:79
std::string get_request(bool with_query=true) const
Returns path and query, separated by question mark.
std::string pass_
Optional password part of the authority.
Definition: uri.hpp:61
std::string to_string(bool with_query=true) const
Assembles components into string.
std::string scheme_
Often referred to as the protocol prefix, e.g. ftp://.
Definition: uri.hpp:55
std::string path_
Optional path, must start with a slash if set.
Definition: uri.hpp:70
std::string fragment_
The part of a URI after #.
Definition: uri.hpp:86
void resolve(uri const &base)
Resolve a relative URI reference into an absolute URI given a base URL.
bool is_absolute() const
Checks that the URI is absolute, that is the path starting with a slash.
Definition: uri.hpp:89
std::string host_
Hostname, or IP address literal.
Definition: uri.hpp:64
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition: apply.hpp:17
std::string to_string(std::wstring_view const &in)
Converts from std::wstring into std::string in system encoding.
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.