nlib
Uri.h
[詳解]
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_URI_H_
17 #define INCLUDE_NN_NLIB_URI_H_
18 
19 #include <utility>
20 
21 #include "nn/nlib/Config.h"
22 #include "nn/nlib/Nlist.h"
23 #include "nn/nlib/Swap.h"
24 
25 NLIB_NAMESPACE_BEGIN
26 
27 class InputStream;
28 class OutputStream;
29 class MemoryOutputStream;
30 
31 template<size_t N = 1024>
33  public:
34  UriQueryEncoder() NLIB_NOEXCEPT { cur_ = &buf_[0]; }
35  errno_t Append(const char* key, const char* value) NLIB_NOEXCEPT;
36  const char* c_str() const NLIB_NOEXCEPT {
37  *cur_ = '\0';
38  return &buf_[0];
39  }
40  operator const char*() const NLIB_NOEXCEPT { return c_str(); }
41  std::pair<const char*, const char*> GetData() const NLIB_NOEXCEPT {
42  return std::make_pair(&buf_[0], cur_);
43  }
44 
45  private:
46  char* cur_;
47  char buf_[N];
48 };
49 
50 struct UriPrivate;
52  public:
53  static bool IsHostName(const nlib_utf8_t* first,
55  static bool IsHostName(const nlib_utf8_t* str) NLIB_NOEXCEPT {
56  return IsHostName(str, str + nlib_strlen(str));
57  }
58  static bool IsIpv4(const nlib_utf8_t* first,
60  static bool IsIpv4(const nlib_utf8_t* str) NLIB_NOEXCEPT {
61  return IsIpv4(str, str + nlib_strlen(str));
62  }
63  static bool IsIpv6(const nlib_utf8_t* first,
65  static bool IsIpv6(const nlib_utf8_t* str) NLIB_NOEXCEPT {
66  return IsIpv6(str, str + nlib_strlen(str));
67  }
68  static bool IsEmailAddress(const nlib_utf8_t* first,
70  static bool IsEmailAddress(const nlib_utf8_t* str) NLIB_NOEXCEPT {
71  return IsEmailAddress(str, str + nlib_strlen(str));
72  }
73  static bool IsUri(const nlib_utf8_t* first,
75  static bool IsUri(const nlib_utf8_t* str) NLIB_NOEXCEPT {
76  return IsUri(str, str + nlib_strlen(str));
77  }
78  static bool IsUriReference(const nlib_utf8_t* first,
80  static bool IsUriReference(const nlib_utf8_t* str) NLIB_NOEXCEPT {
81  return IsUriReference(str, str + nlib_strlen(str));
82  }
83 
84  // reserved = gen-delims / sub-delims
85  // gen - delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
86  // sub - delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
87  static bool IsReserved(int c) NLIB_NOEXCEPT;
88  // unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
89  static bool IsUnreserved(int c) NLIB_NOEXCEPT;
90  // 0-9 / A-F / a-f
91  static bool IsHexDigit(int c) NLIB_NOEXCEPT;
92 
93  static errno_t DecodeUriComponent(size_t* written, char* buf, size_t n, const char* first,
94  const char* last) NLIB_NOEXCEPT;
95  template <size_t N>
96  static errno_t DecodeUriComponent(size_t* written, char (&buf)[N],
97  const char* s) NLIB_NOEXCEPT {
98  return DecodeUriComponent(written, buf, N, s);
99  }
100  static errno_t DecodeUriComponent(size_t* written, char* buf, size_t n,
101  const char* s) NLIB_NOEXCEPT {
102  return DecodeUriComponent(written, buf, n, s, s + nlib_strlen(s));
103  }
104  template <size_t N>
105  static errno_t DecodeUriComponent(size_t* written, char (&buf)[N], const char* first,
106  const char* last) NLIB_NOEXCEPT {
107  return DecodeUriComponent(written, buf, N, first, last);
108  }
109  static std::pair<errno_t, size_t>
110  DecodeUriComponent(char* buf, size_t n, const char* first, const char* last) NLIB_NOEXCEPT {
111  size_t written;
112  errno_t e = DecodeUriComponent(&written, buf, n, first, last);
113  return std::make_pair(e, written);
114  }
115  template<size_t N>
116  static std::pair<errno_t, size_t>
117  DecodeUriComponent(char (&buf)[N], const char* first, const char* last) NLIB_NOEXCEPT {
118  return DecodeUriComponent(buf, N, first, last);
119  }
120  static std::pair<errno_t, size_t>
121  DecodeUriComponent(char* buf, size_t n, const char* s) NLIB_NOEXCEPT {
122  return DecodeUriComponent(buf, n, s, s + nlib_strlen(s));
123  }
124  template<size_t N>
125  static std::pair<errno_t, size_t>
126  DecodeUriComponent(char(&buf)[N], const char* s) NLIB_NOEXCEPT {
127  return DecodeUriComponent(buf, N, s, s + nlib_strlen(s));
128  }
129 
130  static errno_t EncodeUriComponent(size_t* written, char* buf, size_t n, const char* first,
131  const char* last, bool fragment_mode) NLIB_NOEXCEPT;
132  template <size_t N>
133  static errno_t EncodeUriComponent(size_t* written, char (&buf)[N], const char* first,
134  const char* last, bool fragment_mode) NLIB_NOEXCEPT {
135  return EncodeUriComponent(written, buf, N, first, last, fragment_mode);
136  }
137  static errno_t EncodeUriComponent(size_t* written, char* buf, size_t n, const char* s,
138  bool fragment_mode) NLIB_NOEXCEPT {
139  return EncodeUriComponent(written, buf, n, s, s + nlib_strlen(s), fragment_mode);
140  }
141  template <size_t N>
142  static errno_t EncodeUriComponent(size_t* written, char (&buf)[N], const char* s,
143  bool fragment_mode) NLIB_NOEXCEPT {
144  return EncodeUriComponent(written, buf, N, s, fragment_mode);
145  }
146  static std::pair<errno_t, size_t>
147  EncodeUriComponent(char* buf, size_t n, const char* first,
148  const char* last, bool fragment_mode) NLIB_NOEXCEPT {
149  size_t written;
150  errno_t e = EncodeUriComponent(&written, buf, n, first, last, fragment_mode);
151  return std::make_pair(e, written);
152  }
153  template <size_t N>
154  static std::pair<errno_t, size_t>
155  EncodeUriComponent(char (&buf)[N], const char* first, const char* last,
156  bool fragment_mode) NLIB_NOEXCEPT {
157  return EncodeUriComponent(buf, N, first, last, fragment_mode);
158  }
159  static std::pair<errno_t, size_t>
160  EncodeUriComponent(char* buf, size_t n, const char* s, bool fragment_mode) {
161  return EncodeUriComponent(buf, n, s, s + nlib_strlen(s), fragment_mode);
162  }
163  template <size_t N>
164  static std::pair<errno_t, size_t>
165  EncodeUriComponent(char(&buf)[N], const char* s, bool fragment_mode) {
166  return EncodeUriComponent(buf, N, s, s + nlib_strlen(s), fragment_mode);
167  }
168 
169  static errno_t DecodePath(size_t* written, char* buf, size_t n, const char* s) NLIB_NOEXCEPT;
170  template <size_t N>
171  static errno_t DecodePath(size_t* written, char (&buf)[N], const char* s) NLIB_NOEXCEPT {
172  return DecodePath(written, buf, N, s);
173  }
174  static std::pair<errno_t, size_t>
175  DecodePath(char* buf, size_t n, const char* s) NLIB_NOEXCEPT {
176  size_t written;
177  errno_t e = DecodePath(&written, buf, n, s);
178  return std::make_pair(e, written);
179  }
180  template <size_t N>
181  static std::pair<errno_t, size_t>
182  DecodePath(char (&buf)[N], const char* s) NLIB_NOEXCEPT { return DecodePath(buf, N, s); }
183 
184  static errno_t EncodePath(size_t* written, char* buf, size_t n, const char* s) NLIB_NOEXCEPT;
185  template <size_t N>
186  static errno_t EncodePath(size_t* written, char (&buf)[N], const char* s) NLIB_NOEXCEPT {
187  return EncodePath(written, buf, N, s);
188  }
189  static std::pair<errno_t, size_t>
190  EncodePath(char* buf, size_t n, const char* s) NLIB_NOEXCEPT {
191  size_t written;
192  errno_t e = EncodePath(&written, buf, n, s);
193  return std::make_pair(e, written);
194  }
195  template <size_t N>
196  static std::pair<errno_t, size_t>
197  EncodePath(char (&buf)[N], const char* s) NLIB_NOEXCEPT { return EncodePath(buf, N, s); }
198 
199  public:
200  NLIB_CEXPR Uri() NLIB_NOEXCEPT : prv_(nullptr) {}
201  ~Uri() NLIB_NOEXCEPT { Reset(); }
202  NLIB_DEFMOVE_PIMPL(Uri);
203  NLIB_DEPRECATED void swap(Uri& rhs) NLIB_NOEXCEPT {
204  using std::swap;
205  swap(prv_, rhs.prv_);
206  }
207  bool Parse(const char* first, const char* last) NLIB_NOEXCEPT;
208  bool Parse(const char* str) NLIB_NOEXCEPT { return Parse(str, str + nlib_strlen(str)); }
209  // for example:
210  // http://foobar:pass@www.example.com:80/my/dir/index.html?var=value#frag
211  // scheme = "http"
212  // userinfo = "foobar:pass"
213  // host = "www.example.com"
214  // port = "80"
215  // path = "/my/dir/index.html"
216  // query = "var=value"
217  // fragment = "frag"
218  bool SetUri(const char* scheme, const char* userinfo, const char* host,
219  const char* port, const char* path, const char* query,
220  const char* fragment) NLIB_NOEXCEPT;
221  bool IsAbsolute() const NLIB_NOEXCEPT { return GetScheme() != nullptr; }
222  bool ComposeString(char* buf, size_t size) const NLIB_NOEXCEPT;
223  template <size_t N>
224  bool ComposeString(char (&buf)[N]) const NLIB_NOEXCEPT {
225  return this->ComposeString(buf, N);
226  }
227 
228  // AddBaseUri("g/", "http://a/b/c/d;p?q") -> http://a/b/c/g/
229  // AddBaseUri("/g", "http://a/b/c/d;p?q") -> http://a/g
230  // AddBaseUri("//g", "http://a/b/c/d;p?q") -> http://g
231  bool AddBaseUri(const Uri& relative, const Uri& base) NLIB_NOEXCEPT;
232  // "http" from "http://foobar:pass@www.example.com:80/my/dir/index.html?var=value#frag"
233  const char* GetScheme() const NLIB_NOEXCEPT;
234  // "foobar:pass" from "http://foobar:pass@www.example.com:80/my/dir/index.html?var=value#frag"
235  const char* GetUserInfo() const NLIB_NOEXCEPT;
236  // "www.example.com" from "http://foobar:pass@www.example.com:80/my/dir/index.html?var=value#frag"
237  const char* GetHost() const NLIB_NOEXCEPT;
238  // "80" from "http://foobar:pass@www.example.com:80/my/dir/index.html?var=value#frag"
239  const char* GetPort() const NLIB_NOEXCEPT;
240  int GetPortNumber() const NLIB_NOEXCEPT;
241  // "/my/dir/index.html" from "http://foobar:pass@www.example.com:80/my/dir/index.html?var=value#frag"
242  const char* GetPath() const NLIB_NOEXCEPT;
243  // "var=value" from "http://foobar:pass@www.example.com:80/my/dir/index.html?var=value#frag"
244  const char* GetQuery() const NLIB_NOEXCEPT;
245  // "frag" from "http://foobar:pass@www.example.com:80/my/dir/index.html?var=value#frag"
246  const char* GetFragment() const NLIB_NOEXCEPT;
247 
248  bool SetScheme(const char* first, const char* last) NLIB_NOEXCEPT;
249  bool SetUserInfo(const char* first, const char* last) NLIB_NOEXCEPT;
250  bool SetHost(const char* first, const char* last) NLIB_NOEXCEPT;
251  bool SetPort(const char* first, const char* last) NLIB_NOEXCEPT;
252  bool SetPath(const char* first, const char* last) NLIB_NOEXCEPT;
253  bool SetQuery(const char* first, const char* last) NLIB_NOEXCEPT;
254  bool SetFragment(const char* first, const char* last) NLIB_NOEXCEPT;
255  bool SetScheme(const char* scheme) NLIB_NOEXCEPT {
256  return scheme ? SetScheme(scheme, scheme + nlib_strlen(scheme))
257  : SetScheme(nullptr, nullptr);
258  }
259  bool SetUserInfo(const char* userinfo) NLIB_NOEXCEPT {
260  return userinfo ? SetUserInfo(userinfo, userinfo + nlib_strlen(userinfo))
261  : SetUserInfo(nullptr, nullptr);
262  }
263  bool SetHost(const char* host) NLIB_NOEXCEPT {
264  return host ? SetHost(host, host + nlib_strlen(host)) : SetHost(nullptr, nullptr);
265  }
266  bool SetPort(const char* port) NLIB_NOEXCEPT {
267  return port ? SetPort(port, port + nlib_strlen(port)) : SetPort(nullptr, nullptr);
268  }
269  bool SetPortNumber(int port) NLIB_NOEXCEPT {
270  size_t cnt;
271  char buf[16];
272  nlib_snprintf(&cnt, buf, "%d", port);
273  return SetPort(&buf[0], &buf[0] + cnt);
274  }
275  bool SetPath(const char* path) NLIB_NOEXCEPT {
276  return path ? SetPath(path, path + nlib_strlen(path)) : SetPath(nullptr, nullptr);
277  }
278  bool SetQuery(const char* query) NLIB_NOEXCEPT {
279  return query ? SetQuery(query, query + nlib_strlen(query)) : SetQuery(nullptr, nullptr);
280  }
281  bool SetFragment(const char* fragment) NLIB_NOEXCEPT {
282  return fragment ? SetFragment(fragment, fragment + nlib_strlen(fragment))
283  : SetFragment(nullptr, nullptr);
284  }
285  template<size_t N>
286  bool SetQuery(const UriQueryEncoder<N>& encoder) NLIB_NOEXCEPT {
287  std::pair<const char*, const char*> x = encoder.GetData();
288  return SetQueryByQueryEncoder_(x.first, x.second);
289  }
290 
291  void Reset() NLIB_NOEXCEPT;
292  enum Error {
293  kOk = 0,
301  kBufferSizeNotEnough
302  };
303  Error GetError() const NLIB_NOEXCEPT;
304  NLIB_SAFE_BOOL(Uri, GetError() == kOk);
305 
306  private:
307  bool SetQueryByQueryEncoder_(const char* first, const char* last) NLIB_NOEXCEPT;
308  UriPrivate* prv_;
310  friend bool operator==(const Uri& lhs, const Uri& rhs) NLIB_NOEXCEPT;
311  friend bool operator<(const Uri& lhs, const Uri& rhs) NLIB_NOEXCEPT;
312 };
313 
314 bool operator==(const Uri& lhs, const Uri& rhs) NLIB_NOEXCEPT;
315 NLIB_EQUAL_OPERATOR(Uri)
316 bool operator<(const Uri& lhs, const Uri& rhs) NLIB_NOEXCEPT;
317 NLIB_COMPARE_OPERATOR(Uri)
318 
319 template<size_t N>
320 errno_t UriQueryEncoder<N>::Append(const char* key, const char* value) NLIB_NOEXCEPT {
321  // cur_ unchanged if not successful
322  char* p = cur_;
323  if (p != &buf_[0]) {
324  if (p == &buf_[N - 1]) return ERANGE;
325  *p++ = '&';
326  }
327  errno_t e;
328  size_t written;
329  if (key) {
330  e = Uri::EncodeUriComponent(&written, p, &buf_[N] - p, key, false);
331  if (e != 0) return e;
332  p += written;
333  }
334  if (p == &buf_[N - 1]) return ERANGE;
335  *p++ = '=';
336  if (value) {
337  e = Uri::EncodeUriComponent(&written, p, &buf_[N] - p, value, false);
338  if (e != 0) return e;
339  p += written;
340  }
341  cur_ = p;
342  return 0;
343 }
344 
345 template<size_t K = 64, size_t V = 192>
347  public:
349  : ptr_beg_(nullptr), ptr_end_(nullptr), ptr_key_(nullptr), ptr_eq_(nullptr),
350  ptr_and_(nullptr), buf_key_valid_(false), buf_value_valid_(false) {
351  buf_key_[0] = '\0';
352  buf_value_[0] = '\0';
353  }
354  errno_t Init(const Uri& uri) NLIB_NOEXCEPT;
355  void Reset() NLIB_NOEXCEPT;
356  bool HasNext() NLIB_NOEXCEPT;
357  errno_t MoveNext() NLIB_NOEXCEPT;
358  std::pair<errno_t, const char*> GetKey() NLIB_NOEXCEPT;
359  std::pair<errno_t, const char*> GetValue() NLIB_NOEXCEPT;
360  std::pair<errno_t, const char*> GetFirstValueByName(const char* key) NLIB_NOEXCEPT;
361  void Rewind() NLIB_NOEXCEPT;
362 
363  private:
364  static std::pair<errno_t, const char*> Error(errno_t e) NLIB_NOEXCEPT {
365  return std::make_pair(e, static_cast<const char*>(nullptr));
366  }
367  errno_t GetKeyWithCompare_(const char* key) NLIB_NOEXCEPT {
368  std::pair<errno_t, const char*> x = GetKey();
369  if (x.first != 0) return x.first;
370  if (strcmp(key, x.second) == 0) return 0;
371  return ESRCH;
372  }
373  void SpotKeyValue() NLIB_NOEXCEPT;
374 
375  const char* ptr_beg_;
376  const char* ptr_end_;
377  const char* ptr_key_; // key or p_end_ or nullptr
378  const char* ptr_eq_; // '=' or ptr_and_
379  const char* ptr_and_; // '&' or p_end_ or nullptr
380  bool buf_key_valid_;
381  bool buf_value_valid_;
382  char buf_key_[K];
383  char buf_value_[V];
384 };
385 
386 template<size_t K, size_t V>
387 errno_t UriQueryDecoder<K, V>::Init(const Uri& uri) NLIB_NOEXCEPT {
388  if (!uri) return EINVAL;
389  const char* p = uri.GetQuery();
390  if (p) {
391  ptr_beg_ = ptr_key_ = p;
392  ptr_end_ = p + nlib_strlen(p);
393  } else {
394  ptr_beg_ = ptr_end_ = &buf_key_[0];
395  }
396  ptr_eq_ = ptr_and_ = nullptr;
397  buf_key_valid_ = buf_value_valid_ = false;
398  return 0;
399 }
400 
401 template<size_t K, size_t V>
402 void UriQueryDecoder<K, V>::Reset() NLIB_NOEXCEPT {
403  ptr_beg_ = ptr_end_ = ptr_key_ = ptr_eq_ = ptr_and_ = nullptr;
404  buf_key_valid_ = buf_value_valid_ = false;
405 }
406 
407 template<size_t K, size_t V>
408 bool UriQueryDecoder<K, V>::HasNext() NLIB_NOEXCEPT {
409  if (ptr_key_ == ptr_end_) return false;
410  if (NLIB_LIKELY(*ptr_key_ != '&')) return true;
411  ptr_eq_ = ptr_and_ = nullptr;
412  buf_key_valid_ = buf_value_valid_ = false;
413  do {
414  ++ptr_key_;
415  } while (ptr_key_ != ptr_end_ && *ptr_key_ == '&');
416  return ptr_key_ != ptr_end_;
417 }
418 
419 template<size_t K, size_t V>
421  if (!HasNext()) return ENOENT;
422  if (ptr_and_) {
423  ptr_key_ = (ptr_and_ != ptr_end_) ? ptr_and_ + 1 : ptr_end_;
424  } else {
425  const void* p = nlib_memchr(ptr_key_, '&', std::distance(ptr_key_, ptr_end_));
426  ptr_key_ = (p != nullptr) ? static_cast<const char*>(p) + 1 : ptr_end_;
427  }
428  ptr_eq_ = ptr_and_ = nullptr;
429  buf_key_valid_ = buf_value_valid_ = false;
430  return 0;
431 }
432 
433 template<size_t K, size_t V>
434 std::pair<errno_t, const char*>
436  if (buf_key_valid_) return std::make_pair(0, &buf_key_[0]);
437  if (!ptr_key_) return Error(EBADF);
438  if (!HasNext()) return Error(ENOENT);
439  if (!ptr_eq_) SpotKeyValue();
440  size_t w;
441  errno_t e = Uri::DecodeUriComponent(&w, buf_key_, K, ptr_key_, ptr_eq_);
442  if (e != 0) return Error(e);
443  buf_key_valid_ = true;
444  return std::make_pair(0, &buf_key_[0]);
445 }
446 
447 template<size_t K, size_t V>
448 std::pair<errno_t, const char*>
450  if (buf_value_valid_) return std::make_pair(0, &buf_value_[0]);
451  if (!ptr_key_) return Error(EBADF);
452  if (!HasNext()) return Error(ENOENT);
453  if (!ptr_eq_) SpotKeyValue();
454  if (ptr_eq_ != ptr_and_) {
455  size_t w;
456  errno_t e = Uri::DecodeUriComponent(&w, buf_value_, V, ptr_eq_ + 1, ptr_and_);
457  if (e != 0) return Error(e);
458  } else {
459  buf_value_[0] = '\0';
460  }
461  buf_value_valid_ = true;
462  return std::make_pair(0, &buf_value_[0]);
463 }
464 
465 template<size_t K, size_t V>
466 std::pair<errno_t, const char*>
467 UriQueryDecoder<K, V>::GetFirstValueByName(const char* key) NLIB_NOEXCEPT {
468  errno_t e;
469  do {
470  e = GetKeyWithCompare_(key);
471  if (e == 0) return std::make_pair(0, &buf_key_[0]);
472  if (e != ESRCH) return Error(e);
473  } while (MoveNext() == 0);
474  return Error(ESRCH);
475 }
476 
477 template<size_t K, size_t V>
478 void UriQueryDecoder<K, V>::Rewind() NLIB_NOEXCEPT {
479  ptr_key_ = ptr_beg_;
480  ptr_eq_ = ptr_and_ = nullptr;
481  buf_key_valid_ = buf_value_valid_ = false;
482 }
483 
484 template<size_t K, size_t V>
485 void UriQueryDecoder<K, V>::SpotKeyValue() NLIB_NOEXCEPT {
486  const void* p_and = nlib_memchr(ptr_key_, '&', std::distance(ptr_key_, ptr_end_));
487  ptr_and_ = p_and ? static_cast<const char*>(p_and) : ptr_end_;
488  const void* p_eq = nlib_memchr(ptr_key_, '=', std::distance(ptr_key_, ptr_and_));
489  ptr_eq_ = p_eq ? static_cast<const char*>(p_eq) : ptr_and_;
490 }
491 
492 NLIB_NAMESPACE_END
493 #ifndef __cpp_rvalue_references
494 NLIB_DEFINE_STD_SWAP(::nlib_ns::Uri)
495 #endif
496 #endif // INCLUDE_NN_NLIB_URI_H_
static errno_t DecodeUriComponent(size_t *written, char *buf, size_t n, const char *s) noexcept
%エンコードされた文字列をデコードします。
Definition: Uri.h:100
bool SetQuery(const char *query) noexcept
クエリ文字列(先頭の?は含まない)を設定します。
Definition: Uri.h:278
bool SetPath(const char *path) noexcept
パスを設定します。
Definition: Uri.h:275
static errno_t EncodeUriComponent(size_t *written, char *buf, size_t n, const char *s, bool fragment_mode) noexcept
文字列を%エンコードします。
Definition: Uri.h:137
static errno_t DecodePath(size_t *written, char(&buf)[N], const char *s) noexcept
DecodePath(written, buf, N, s)を呼び出します。
Definition: Uri.h:171
static errno_t DecodeUriComponent(size_t *written, char(&buf)[N], const char *s) noexcept
DecodeUriComponent(written, buf, N, s)を呼び出します。
Definition: Uri.h:96
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:194
static bool IsIpv4(const nlib_utf8_t *str) noexcept
IsIpv4(str, str + strlen(str))を返します。
Definition: Uri.h:60
bool SetFragment(const char *fragment) noexcept
フラグメント文字列(先頭の::は含まない)を設定します。
Definition: Uri.h:281
#define NLIB_CEXPR14
C++14のconstexprが利用可能であればconstexprが定義されます。そうでない場合は空文字列です。 ...
Definition: Config.h:108
static errno_t EncodePath(size_t *written, char(&buf)[N], const char *s) noexcept
EncodePath(written, buf, N, s)を呼び出します。
Definition: Uri.h:186
#define NLIB_DEPRECATED
関数等がdeprecatedになったことを示します。
Definition: Config.h:109
constexpr Uri() noexcept
デフォルトコンストラクタです。オブジェクトを初期化します。
Definition: Uri.h:200
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
static errno_t DecodeUriComponent(size_t *written, char(&buf)[N], const char *first, const char *last) noexcept
DecodeUriComponent(written, buf, N, first, last)を呼び出します。
Definition: Uri.h:105
const void * nlib_memchr(const void *s, int c, size_t n)
メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc があるポインタを返します。 ...
errno_t nlib_snprintf(size_t *count, char(&buf)[N], const char *fmt,...) noexcept
nlib_snprintf() の関数テンプレート版です。
Definition: Config.h:480
引数が無効です。
Definition: Uri.h:294
constexpr UriQueryDecoder() noexcept
デフォルトコンストラクタです。
Definition: Uri.h:348
オブジェクトが初期化されていない状態です。
Definition: Uri.h:296
std::vectorに似ていますが、コピーできないオブジェクトを格納可能なクラスが定義されています。 ...
bool IsAbsolute() const noexcept
URIが絶対URIであればtrueを返します。この関数ではschemeが指定されていれば絶対URIであると判断しています...
Definition: Uri.h:221
bool SetPortNumber(int port) noexcept
ポート番号を設定します。
Definition: Uri.h:269
絶対URIを指定する必要があります。
Definition: Uri.h:298
メモリの確保に失敗しました。
Definition: Uri.h:295
bool SetHost(const char *host) noexcept
ホスト名を設定します。
Definition: Uri.h:263
#define NLIB_LIKELY(x)
条件xが真になる傾向が高いことをコンパイラに示します。
Definition: Platform_unix.h:99
static errno_t EncodeUriComponent(size_t *written, char(&buf)[N], const char *first, const char *last, bool fragment_mode) noexcept
EncodeUriComponent(written, buf, N, first, last, fragment_mode)を呼び出します。
Definition: Uri.h:133
static bool IsEmailAddress(const nlib_utf8_t *str) noexcept
IsEmailAddress(str, str + strlen(str))を返します。
Definition: Uri.h:70
const char * c_str() const noexcept
エンコードされたクエリ文字列を返します。
Definition: Uri.h:36
static errno_t EncodeUriComponent(size_t *written, char(&buf)[N], const char *s, bool fragment_mode) noexcept
EncodeUriComponent(written, buf, N, s, fragment_mode)を呼び出します。
Definition: Uri.h:142
bool ComposeString(char(&buf)[N]) const noexcept
URI文字列を書き出します。
Definition: Uri.h:224
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
開発環境別の設定が書かれるファイルです。
(絶対)パスの正規化に失敗しました。
Definition: Uri.h:299
bool SetPort(const char *port) noexcept
ポート番号の文字列(:は含まない)を設定します。
Definition: Uri.h:266
static bool IsUriReference(const nlib_utf8_t *str) noexcept
IsUriReference(str, str + strlen(str))を返します。
Definition: Uri.h:80
一般的なURIをパースしたり構築したりするためのクラスです。
Definition: Uri.h:51
static bool IsHostName(const nlib_utf8_t *str) noexcept
IsHostName(str, str + strlen(str))を返します。
Definition: Uri.h:55
URIが無効です。
Definition: Uri.h:297
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
static bool IsIpv6(const nlib_utf8_t *str) noexcept
IsIpv6(str, str + strlen(str))を返します。
Definition: Uri.h:65
bool Parse(const char *str) noexcept
Parse(str, str + strlen(str))を返します。
Definition: Uri.h:208
bool SetScheme(const char *scheme) noexcept
スキームの文字列(末尾の:は含まない)を設定します。
Definition: Uri.h:255
URIのクエリをパースするためのクラステンプレートです。
Definition: Uri.h:346
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
bool SetQuery(const UriQueryEncoder< N > &encoder) noexcept
クエリ文字列(先頭の?は含まない)を設定します。
Definition: Uri.h:286
UriQueryEncoder() noexcept
デフォルトコンストラクタです。
Definition: Uri.h:34
std::pair< const char *, const char * > GetData() const noexcept
エンコードされたクエリ文字列の先頭と末尾を返します。
Definition: Uri.h:41
URIのクエリを作成するためのクラスです。
Definition: Uri.h:32
static bool IsUri(const nlib_utf8_t *str) noexcept
IsUri(str, str + strlen(str))を返します。
Definition: Uri.h:75
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
URIが長すぎます。
Definition: Uri.h:300
bool SetUserInfo(const char *userinfo) noexcept
指定した URI に関連付けられているユーザー名、パスワードなどのユーザー固有の情報を設定します。 ...
Definition: Uri.h:259
char nlib_utf8_t
charのtypedefです。文字列がUTF-8であることを示します。
Definition: Platform.h:308
Error
GetError()で取得することのできるエラー値の列挙型です。
Definition: Uri.h:292
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37