You.i Engine
YiUrl.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_URL_H_
3 #define _YI_URL_H_
4 
6 #include "utility/YiString.h"
7 
8 class CYIUrlQuery;
9 
24 class CYIUrl
25 {
26 public:
27  enum class Parts
28  {
29  Scheme = 0x1,
30  Username = 0x2,
31  Password = 0x4,
32  Host = 0x8,
33  Port = 0x10,
34  Path = 0x20,
35  Query = 0x40,
36  Fragment = 0x80,
39  AuthorityAndPath = Authority | Path,
40  Everything = Scheme | AuthorityAndPath | Query | Fragment,
41  NoScheme = Everything & (~Scheme),
42  NoAuthentication = Everything & (~Authentication)
43  };
44 
45  enum class Encoding
46  {
47  Encoded,
48  Decoded
49  };
50 
54  static const CYIUrl &EmptyUrl();
55 
61  CYIUrl();
62 
68  explicit CYIUrl(const CYIString &url, Encoding encoding = Encoding::Encoded);
69 
70  bool operator==(const CYIUrl &other) const;
71  bool operator!=(const CYIUrl &other) const;
72  bool operator<(const CYIUrl &other) const;
73 
81  void SetScheme(const CYIString &scheme);
82 
90  void SetAuthority(const CYIString &authority, Encoding encoding = Encoding::Decoded);
91 
99  void SetAuthentication(const CYIString &authentication, Encoding encoding = Encoding::Decoded);
100 
108  void SetUsername(const CYIString &username, Encoding encoding = Encoding::Decoded);
109 
117  void SetPassword(const CYIString &password, Encoding encoding = Encoding::Decoded);
118 
128  void SetHost(const CYIString &host, Encoding encoding = Encoding::Decoded);
129 
135  void SetPort(int32_t port);
136 
144  void SetPort(const CYIString &port);
145 
155  void SetPath(const CYIString &path, CYIUrl::Encoding encoding = Encoding::Decoded);
156 
166  void SetQuery(const CYIString &query, CYIUrl::Encoding encoding = Encoding::Decoded);
167 
171  void SetQuery(const CYIUrlQuery &query);
172 
180  void SetFragment(const CYIString &fragment, CYIUrl::Encoding encoding = Encoding::Decoded);
181 
189  void SetString(const CYIString &url, Encoding encoding = Encoding::Encoded);
190 
196  const CYIString &GetScheme() const;
197 
208 
219 
228 
237 
245  CYIString GetHost(Encoding encoding = Encoding::Decoded) const;
246 
252  int32_t GetPort() const;
253 
259  const CYIString &GetPortString() const;
260 
272  CYIString GetPath(Encoding encoding = Encoding::Decoded) const;
273 
283  CYIString GetQuery(Encoding encoding = Encoding::Decoded) const;
284 
293 
300 
313 
317  bool IsEmpty() const;
318 
322  void Clear();
323 
333  static CYIString Encode(const CYIString &input);
334 
344  static CYIString Decode(const CYIString &input);
345 
346 private:
347  CYIString m_scheme;
348 
349  CYIString m_username;
350  CYIString m_password;
351  CYIString m_host;
352  CYIString m_port;
353 
354  CYIString m_path;
355  CYIString m_query;
356  CYIString m_fragment;
357 };
358 
363 template<>
365 {
366  static const bool enable = true;
367 };
368 
369 std::ostream &operator<<(std::ostream &stream, const CYIUrl &val);
370 
371 #endif
CYIString GetUsername(Encoding encoding=Encoding::Decoded) const
Parts
Definition: YiUrl.h:27
bool operator<(const CYIUrl &other) const
void SetScheme(const CYIString &scheme)
const CYIString & GetPortString() const
bool operator==(const CYIUrl &other) const
void SetFragment(const CYIString &fragment, CYIUrl::Encoding encoding=Encoding::Decoded)
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
CYIString GetAuthority(Encoding encoding=Encoding::Decoded) const
void Clear()
void SetPassword(const CYIString &password, Encoding encoding=Encoding::Decoded)
bool operator!=(const CYIUrl &other) const
A struct used to enable bitmask operators for an enum class type.
Definition: YiEnumBitmaskOperators.h:26
void SetAuthentication(const CYIString &authentication, Encoding encoding=Encoding::Decoded)
void SetAuthority(const CYIString &authority, Encoding encoding=Encoding::Decoded)
void SetString(const CYIString &url, Encoding encoding=Encoding::Encoded)
int32_t GetPort() const
const CYIString & GetScheme() const
CYIString GetPassword(Encoding encoding=Encoding::Decoded) const
void SetHost(const CYIString &host, Encoding encoding=Encoding::Decoded)
static CYIString Encode(const CYIString &input)
std::ostream & operator<<(std::ostream &stream, const CYIUrl &val)
CYIString GetPath(Encoding encoding=Encoding::Decoded) const
CYIString GetFragment(Encoding encoding=Encoding::Decoded) const
void SetQuery(const CYIString &query, CYIUrl::Encoding encoding=Encoding::Decoded)
An URL query builder.
Definition: YiUrlQuery.h:28
A class used to encapsulate an URL.
Definition: YiUrl.h:24
void SetUsername(const CYIString &username, Encoding encoding=Encoding::Decoded)
void SetPort(int32_t port)
Encoding
Definition: YiUrl.h:45
CYIString GetQuery(Encoding encoding=Encoding::Decoded) const
CYIUrlQuery GetQueryBuilder() const
void SetPath(const CYIString &path, CYIUrl::Encoding encoding=Encoding::Decoded)
bool IsEmpty() const
static const CYIUrl & EmptyUrl()
CYIString ToString(Parts parts=Parts::Everything, Encoding encoding=Encoding::Encoded) const
CYIString GetHost(Encoding encoding=Encoding::Decoded) const
CYIString GetAuthentication(Encoding encoding=Encoding::Decoded) const
static CYIString Decode(const CYIString &input)