nlib
StringView.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_STRINGVIEW_H_
17 #define INCLUDE_NN_NLIB_STRINGVIEW_H_
18 
19 #include <algorithm>
20 #include <iterator>
21 #include <utility>
22 
23 #include "nn/nlib/Config.h"
24 #include "nn/nlib/UniquePtr.h"
25 #include "nn/nlib/Cstring.h"
26 
27 NLIB_NAMESPACE_BEGIN
28 
30  public:
31  // types
32  typedef char charT;
33  typedef charT value_type;
34  typedef const charT* pointer;
35  typedef const charT* const_pointer;
36  typedef const charT& reference;
37  typedef const charT& const_reference;
38  typedef const_pointer const_iterator;
39  typedef const_iterator iterator;
40  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
41  typedef const_reverse_iterator reverse_iterator;
42  typedef size_t size_type;
43  typedef ptrdiff_t difference_type;
44  static const size_type npos = size_type(-1);
45 
46  // [string.view.cons], construct/copy
47  NLIB_CEXPR StringView() NLIB_NOEXCEPT : len_(0), base_("") {}
48  // this ctor calls strlen(), use StringView(str, len) if you know the the length of the string.
49  explicit StringView(const charT* str) NLIB_NOEXCEPT : len_(nlib_strlen(str)), base_(str) {
50  NLIB_ASSERT(this->IsValid_());
51  }
52  StringView(const charT* str, size_type len) NLIB_NOEXCEPT : len_(len), base_(str) {
53  NLIB_ASSERT(this->IsValid_());
54  }
55 
56  // [string.view.iterators], iterators
57  const_iterator begin() const NLIB_NOEXCEPT {
58  NLIB_ASSERT(this->IsValid_());
59  return base_;
60  }
61  const_iterator end() const NLIB_NOEXCEPT { return begin() + len_; }
62  const_iterator cbegin() const NLIB_NOEXCEPT { return begin(); }
63  const_iterator cend() const NLIB_NOEXCEPT { return cbegin() + len_; }
64 
65  const_reverse_iterator rbegin() const NLIB_NOEXCEPT { return const_reverse_iterator(end()); }
66  const_reverse_iterator rend() const NLIB_NOEXCEPT { return const_reverse_iterator(begin()); }
67  const_reverse_iterator crbegin() const NLIB_NOEXCEPT { return const_reverse_iterator(end()); }
68  const_reverse_iterator crend() const NLIB_NOEXCEPT { return const_reverse_iterator(begin()); }
69 
70  // [string.view.capacity], capacity
71  size_type size() const NLIB_NOEXCEPT {
72  NLIB_ASSERT(this->IsValid_());
73  return len_;
74  }
75  size_type length() const NLIB_NOEXCEPT {
76  NLIB_ASSERT(this->IsValid_());
77  return len_;
78  }
79  size_type max_size() const NLIB_NOEXCEPT { return static_cast<size_type>(-1) / sizeof(charT); }
80  bool empty() const NLIB_NOEXCEPT { return this->size() == 0; }
81 
82  // [string.view.access], element access
83  const charT& operator[](size_type pos) const {
84  NLIB_ASSERT(this->IsValid_());
85  return base_[pos];
86  }
87  const charT& at(size_type pos) const {
88  NLIB_ASSERT(this->IsValid_());
89  return base_[pos];
90  }
91  const charT& front() const { return (*this)[0]; }
92  const charT& back() const { return (*this)[this->length() - 1]; }
93  const charT* data() const NLIB_NOEXCEPT { return base_; }
94 
95  // [string.view.modifiers], modifiers:
97  len_ = 0;
98  base_ = "";
99  }
100  void remove_prefix(size_type n) NLIB_NOEXCEPT {
101  if (n >= len_) {
102  base_ += len_;
103  len_ = 0;
104  } else {
105  base_ += n;
106  len_ -= n;
107  }
108  }
109  void remove_suffix(size_type n) NLIB_NOEXCEPT {
110  if (n >= len_) {
111  len_ = 0;
112  } else {
113  len_ -= n;
114  }
115  }
116 
117  // [string.view.ops], string operations:
118  StringView substr(size_type pos, size_type n = npos) const NLIB_NOEXCEPT {
119  NLIB_ASSERT(this->IsValid_());
120  if (pos >= len_) return StringView(base_ + len_, 0);
121  const charT* new_base = base_ + pos;
122  size_type r = static_cast<size_type>(len_ - pos);
123  size_type new_len = r > n ? n : r;
124  return StringView(new_base, new_len);
125  }
126  int compare(const StringView& s) const NLIB_NOEXCEPT;
127  int compare(const charT* s) const NLIB_NOEXCEPT { return this->compare(StringView(s)); }
128  bool starts_with(const StringView& s) const NLIB_NOEXCEPT {
129  NLIB_ASSERT(this->IsValid_());
130  if (s.length() > this->length()) return false;
131  return nlib_memcmp(s.data(), base_, sizeof(*base_) * s.length()) == 0;
132  }
133  bool starts_with(charT c) const NLIB_NOEXCEPT { return front() == c; }
134  NLIB_DEPRECATED bool starts_with(const charT* s) const NLIB_NOEXCEPT {
135  return this->starts_with(StringView(s));
136  }
137  bool ends_with(const StringView& s) const NLIB_NOEXCEPT {
138  NLIB_ASSERT(this->IsValid_());
139  if (s.length() > len_) return false;
140  return nlib_memcmp(s.data(), base_ + len_ - s.length(), sizeof(*base_) * s.length()) ==
141  0;
142  }
143  NLIB_DEPRECATED bool ends_with(charT c) const NLIB_NOEXCEPT { return back() == c; }
144  NLIB_DEPRECATED bool ends_with(const charT* s) const NLIB_NOEXCEPT {
145  return this->ends_with(StringView(s));
146  }
147  bool ToCstring(charT* str, size_type buf_size) const NLIB_NOEXCEPT;
148  template <size_type N>
149  NLIB_DEPRECATED bool ToCstring(charT (&str)[N]) const NLIB_NOEXCEPT {
150  return ToCstring(str, N);
151  }
152 #ifdef NLIB_CXX11_DEFAULT_TEMPLATE_ARGUMENT_FOR_FUNCTION_TEMPLATES
153  template<class DUMMY = void>
154 #endif
155  NLIB_DEPRECATED bool ToCstring(UniquePtr<charT[]>& str) const NLIB_NOEXCEPT { // NOLINT
156  // to avoid crossing the DLL boundary
157  NLIB_ASSERT(this->IsValid_());
158  str.reset(new (std::nothrow) charT[len_ + 1]);
159  if (!str) return false;
160  return ToCstring(str.get(), len_ + 1);
161  }
162 #ifdef __cpp_rvalue_references
163  NLIB_DEPRECATED UniquePtr<charT[]> ToCstring() const NLIB_NOEXCEPT {
164  NLIB_ASSERT(this->IsValid_());
165  charT* p = new (std::nothrow) charT[len_ + 1];
166  if (!p) return nullptr;
167  (void)ToCstring(p, len_ + 1);
168  return UniquePtr<char[]>(p);
169  }
170 #endif
171 
172  errno_t ToInteger(int32_t* v, size_type* idx = nullptr, int base = 10) const NLIB_NOEXCEPT;
173  NLIB_DEPRECATED errno_t ToInteger(int64_t* v, size_type* idx = nullptr, int base = 10) const NLIB_NOEXCEPT; // NOLINT
174  errno_t ToInteger(uint32_t* v, size_type* idx = nullptr, int base = 10) const NLIB_NOEXCEPT;
175  NLIB_DEPRECATED errno_t ToInteger(uint64_t* v, size_type* idx = nullptr, int base = 10) const NLIB_NOEXCEPT; // NOLINT
176  NLIB_DEPRECATED errno_t ToInteger(int8_t* v, size_type* idx = nullptr, int base = 10) const NLIB_NOEXCEPT; // NOLINT
177  NLIB_DEPRECATED errno_t ToInteger(int16_t* v, size_type* idx = nullptr, int base = 10) const NLIB_NOEXCEPT; // NOLINT
178  NLIB_DEPRECATED errno_t ToInteger(uint8_t* v, size_type* idx = nullptr, int base = 10) const NLIB_NOEXCEPT; // NOLINT
179  NLIB_DEPRECATED errno_t ToInteger(uint16_t* v, size_type* idx = nullptr, int base = 10) const NLIB_NOEXCEPT; // NOLINT
180  NLIB_DEPRECATED errno_t ToFloat(float* v, size_type* idx = nullptr) const NLIB_NOEXCEPT;
181  NLIB_DEPRECATED errno_t ToDouble(double* v, size_type* idx = nullptr) const NLIB_NOEXCEPT;
182 
183  bool TrimLeft() NLIB_NOEXCEPT;
184  bool TrimRight() NLIB_NOEXCEPT;
185  NLIB_DEPRECATED void Trim() NLIB_NOEXCEPT {
186  TrimLeft();
187  TrimRight();
188  }
190  bool Proceed(const StringView& kwd) NLIB_NOEXCEPT {
191  if (!this->starts_with(kwd)) return false;
192  base_ += kwd.length();
193  len_ -= kwd.length();
194  return true;
195  }
196  NLIB_DEPRECATED bool Proceed(const charT* kwd) NLIB_NOEXCEPT { return this->Proceed(StringView(kwd)); } // NOLINT
197  NLIB_DEPRECATED bool Proceed(charT ch) NLIB_NOEXCEPT;
199  /*
200  size_type find(const StringView& s) const {
201  StringView::iterator it = std::search(
202  begin(), end(), s.begin(), s.end());
203  return it == end() ? npos : it - begin();
204  }
205  size_type find(charT c) const;
206  size_type find(const charT* s) const;
207  size_type rfind(const StringView& s) const {
208  StringView::iterator it = std::find_end(
209  begin(), end(), s.begin(), s.end());
210  return it == end() ? npos : it - begin();
211  }
212  size_type rfind(charT c) const;
213  size_type rfind(const charT* s) const;
214  size_type find_first_of(const StringView& s) const {
215  StringView::iterator it = std::find_first_of(
216  begin(), end(), s.begin(), s.end());
217  return it == end() ? npos : it - begin();
218  }
219  size_type find_first_of(charT c) const;
220  size_type find_first_of(const charT* s) const;
221  size_type find_last_of(const StringView& s) const {
222  StringView::reverse_iterator it = std::find_first_of(
223  rbegin(), rend(), s.begin(), s.end());
224  return it == rend() ? std::string::npos : it.base() - 1 - begin();
225  }
226  size_type find_last_of(charT c) const;
227  size_type find_last_of(const charT* s) const;
228  size_type find_first_not_of(const StringView& s) const;
229  size_type find_first_not_of(charT c) const;
230  size_type find_first_not_of(const charT* s) const;
231  size_type find_last_not_of(const StringView& s) const;
232  size_type find_last_not_of(charT c) const;
233  size_type find_last_not_of(const charT* s) const;
234  */
235 
236  private:
237  bool IsValid_() const NLIB_NOEXCEPT {
238  if (!base_) return false;
239  return true;
240  }
241  size_type len_;
242  const charT* base_;
243 };
244 
245 
246 inline errno_t StringView::ToInteger(int8_t* v, size_type* idx, int base) const NLIB_NOEXCEPT {
247  int32_t tmp;
248  errno_t e = ToInteger(&tmp, idx, base);
249  if (e != 0) return e;
250  if (tmp > 127 || tmp < -128) return ERANGE;
251  *v = static_cast<int8_t>(tmp);
252  return 0;
253 }
254 
255 
256 inline errno_t StringView::ToInteger(int16_t* v, size_type* idx, int base) const NLIB_NOEXCEPT {
257  int32_t tmp;
258  errno_t e = ToInteger(&tmp, idx, base);
259  if (e != 0) return e;
260  if (tmp > 32767 || tmp < -32768) return ERANGE;
261  *v = static_cast<int16_t>(tmp);
262  return 0;
263 }
264 
265 
266 inline errno_t StringView::ToInteger(uint8_t* v, size_type* idx, int base) const NLIB_NOEXCEPT {
267  uint32_t tmp;
268  errno_t e = ToInteger(&tmp, idx, base);
269  if (e != 0) return e;
270  if (tmp > 255) return ERANGE;
271  *v = static_cast<uint8_t>(tmp);
272  return 0;
273 }
274 
275 
276 inline errno_t StringView::ToInteger(uint16_t* v, size_type* idx, int base) const NLIB_NOEXCEPT {
277  uint32_t tmp;
278  errno_t e = ToInteger(&tmp, idx, base);
279  if (e != 0) return e;
280  if (tmp > 65535) return ERANGE;
281  *v = static_cast<uint16_t>(tmp);
282  return 0;
283 }
284 
285 inline bool StringView::Proceed(charT ch) NLIB_NOEXCEPT {
286  if (this->starts_with(ch)) {
287  ++base_;
288  --len_;
289  return true;
290  } else {
291  return false;
292  }
293 }
294 
295 inline StringView StringView::GetName() NLIB_NOEXCEPT {
296  // isalpha()[isalnum()]*
297  NLIB_ASSERT(this->IsValid_());
298  const charT* s = base_;
299  const charT* s_end = base_ + len_;
300  charT c = (s != s_end) ? *s : '\0';
301  if (!nlib_isalpha(c) && c != '_') return *this;
302  for (;;) {
303  ++s;
304  c = (s != s_end) ? *s : '\0';
305  if (!nlib_isalnum(c) && c != '_') break;
306  }
307  size_type len = s - base_;
308  StringView rval(base_, len);
309  base_ = s;
310  len_ = len_ - len;
311  return rval;
312 }
313 
314 // [string.view.comparison], non-member StringView comparison functions
315 inline bool operator==(const StringView& lhs, const StringView& rhs) NLIB_NOEXCEPT {
316  return lhs.compare(rhs) == 0;
317 }
318 NLIB_EQUAL_OPERATOR(StringView)
319 inline bool operator<(const StringView& lhs, const StringView& rhs) NLIB_NOEXCEPT {
320  return lhs.compare(rhs) < 0;
321 }
322 NLIB_COMPARE_OPERATOR(StringView)
323 
324 // Free functions
325 inline bool StartsWith(const StringView& str, const StringView& prefix) NLIB_NOEXCEPT {
326  if (prefix.length() > str.length()) return false;
327  return nlib_memcmp(prefix.data(), str.data(), prefix.length()) == 0;
328 }
329 inline bool StartsWith(const StringView& str, char c) NLIB_NOEXCEPT { return str.front() == c; }
330 inline bool StartsWith(const StringView& str, const char* prefix) NLIB_NOEXCEPT {
331  return StartsWith(str, StringView(prefix));
332 }
333 inline bool EndsWith(const StringView& str, const StringView& suffix) NLIB_NOEXCEPT {
334  if (suffix.length() > str.length()) return false;
335  return nlib_memcmp(suffix.data(), str.end() - suffix.length(), suffix.length()) == 0;
336 }
337 inline bool EndsWith(const StringView& str, char c) NLIB_NOEXCEPT { return str.back() == c; }
338 inline bool EndsWith(const StringView& str, const char* suffix) NLIB_NOEXCEPT {
339  return EndsWith(str, StringView(suffix));
340 }
341 inline bool ToCstring(char* buf, size_t buf_size, const StringView& str) NLIB_NOEXCEPT {
342  if (!buf || buf_size == 0) return false;
343  size_t len = str.length();
344  errno_t e = nlib_memcpy(buf, buf_size - 1, str.begin(), len);
345  if (e == 0) {
346  buf[len] = '\0';
347  return true;
348  } else {
349  return false;
350  }
351 }
352 template<size_t N>
353 inline bool ToCstring(char (&buf)[N], const StringView& str) NLIB_NOEXCEPT {
354  return ToCstring(&buf[0], N, str);
355 }
356 #ifdef __cpp_rvalue_references
358  size_t buf_size = str.length() + 1;
359  char* p = new (std::nothrow) char[buf_size];
360  if (!p) return nullptr;
361  (void)ToCstring(p, buf_size, str);
362  return UniquePtr<char[]>(p);
363 }
364 #endif
365 inline std::pair<errno_t, size_t>
366 ToInteger(int8_t* v, const StringView& str, int base) NLIB_NOEXCEPT {
367  const char* eptr;
368  errno_t e = nlib_int8_from_chars(v, &eptr, str.begin(), str.end(), base);
369  return std::make_pair(e, eptr - str.begin());
370 }
371 inline std::pair<errno_t, size_t>
372 ToInteger(int16_t* v, const StringView& str, int base) NLIB_NOEXCEPT {
373  const char* eptr;
374  errno_t e = nlib_int16_from_chars(v, &eptr, str.begin(), str.end(), base);
375  return std::make_pair(e, eptr - str.begin());
376 }
377 inline std::pair<errno_t, size_t>
378 ToInteger(int32_t* v, const StringView& str, int base) NLIB_NOEXCEPT {
379  const char* eptr;
380  errno_t e = nlib_int32_from_chars(v, &eptr, str.begin(), str.end(), base);
381  return std::make_pair(e, eptr - str.begin());
382 }
383 inline std::pair<errno_t, size_t>
384 ToInteger(int64_t* v, const StringView& str, int base) NLIB_NOEXCEPT {
385  const char* eptr;
386  errno_t e = nlib_int64_from_chars(v, &eptr, str.begin(), str.end(), base);
387  return std::make_pair(e, eptr - str.begin());
388 }
389 inline std::pair<errno_t, size_t>
390 ToInteger(uint8_t* v, const StringView& str, int base) NLIB_NOEXCEPT {
391  const char* eptr;
392  errno_t e = nlib_uint8_from_chars(v, &eptr, str.begin(), str.end(), base);
393  return std::make_pair(e, eptr - str.begin());
394 }
395 inline std::pair<errno_t, size_t>
396 ToInteger(uint16_t* v, const StringView& str, int base) NLIB_NOEXCEPT {
397  const char* eptr;
398  errno_t e = nlib_uint16_from_chars(v, &eptr, str.begin(), str.end(), base);
399  return std::make_pair(e, eptr - str.begin());
400 }
401 inline std::pair<errno_t, size_t>
402 ToInteger(uint32_t* v, const StringView& str, int base) NLIB_NOEXCEPT {
403  const char* eptr;
404  errno_t e = nlib_uint32_from_chars(v, &eptr, str.begin(), str.end(), base);
405  return std::make_pair(e, eptr - str.begin());
406 }
407 inline std::pair<errno_t, size_t>
408 ToInteger(uint64_t* v, const StringView& str, int base) NLIB_NOEXCEPT {
409  const char* eptr;
410  errno_t e = nlib_uint64_from_chars(v, &eptr, str.begin(), str.end(), base);
411  return std::make_pair(e, eptr - str.begin());
412 }
413 inline std::pair<errno_t, size_t>
414 ToFloat(float* v, const StringView& str) NLIB_NOEXCEPT {
415  const char* eptr;
416  errno_t e = nlib_float_from_chars(v, &eptr, str.begin(), str.end());
417  return std::make_pair(e, eptr - str.begin());
418 }
419 inline std::pair<errno_t, size_t>
420 ToDouble(double* v, const StringView& str) NLIB_NOEXCEPT {
421  const char* eptr;
422  errno_t e = nlib_double_from_chars(v, &eptr, str.begin(), str.end());
423  return std::make_pair(e, eptr - str.begin());
424 }
425 template<class T>
426 inline std::pair<errno_t, size_t>
427 ToInteger(T* v, const StringView& str) NLIB_NOEXCEPT {
428  return ToInteger(v, str, 10);
429 }
430 inline bool TrimLeft(StringView& str) NLIB_NOEXCEPT { // NOLINT
431  StringView::iterator it = str.begin();
432  StringView::iterator itend = str.end();
433  for (; it != itend; ++it) {
434  if (!nlib_isspace(*it)) break;
435  }
436  ptrdiff_t cnt = std::distance(str.begin(), it);
437  if (cnt == 0) return false;
438  str.remove_prefix(cnt);
439  return true;
440 }
441 inline bool TrimRight(StringView& str) NLIB_NOEXCEPT { // NOLINT
442  StringView::reverse_iterator it = str.rbegin();
443  StringView::reverse_iterator itend = str.rend();
444  for (; it != itend; ++it) {
445  if (!nlib_isspace(*it)) break;
446  }
447  ptrdiff_t cnt = std::distance(str.rbegin(), it);
448  if (cnt == 0) return false;
449  str.remove_suffix(cnt);
450  return true;
451 }
452 inline void Trim(StringView& str) NLIB_NOEXCEPT { // NOLINT
453  TrimLeft(str);
454  TrimRight(str);
455 }
456 inline StringView GetLine(StringView& str) NLIB_NOEXCEPT { // NOLINT
457  const char* beg = str.begin();
458  const char* p = static_cast<const char*>(nlib_memchr(beg, '\n', str.length()));
459  if (!p) {
460  StringView rval(str);
461  str.remove_prefix(str.length());
462  return rval;
463  }
464  size_t width = p - beg;
465  if (width > 0 && *(p - 1) == '\r') --width;
466  StringView rval(beg, width);
467  str.remove_prefix(p - beg + 1);
468  return rval;
469 }
470 inline bool Proceed(StringView& str, const StringView& prefix) NLIB_NOEXCEPT { // NOLINT
471  if (!str.starts_with(prefix)) return false;
472  str.remove_prefix(prefix.length());
473  return true;
474 }
475 inline bool Proceed(StringView& str, const char* prefix) NLIB_NOEXCEPT { // NOLINT
476  return Proceed(str, StringView(prefix));
477 }
478 inline bool Proceed(StringView& str, char c) NLIB_NOEXCEPT { // NOLINT
479  if (!str.starts_with(c)) return false;
480  str.remove_prefix(1);
481  return true;
482 }
483 inline StringView GetName(StringView& str) NLIB_NOEXCEPT { // NOLINT
484  StringView::iterator it = str.begin();
485  StringView::iterator it_end = str.end();
486  if (it != it_end) {
487  if (!nlib_isalpha(*it) && *it != '_') return str;
488  while (++it != it_end) {
489  if (!nlib_isalnum(*it) && *it != '_') break;
490  }
491  }
492  ptrdiff_t len = std::distance(str.begin(), it);
493  StringView rval(str.begin(), len);
494  str.remove_prefix(len);
495  return rval;
496 }
497 
498 NLIB_NAMESPACE_END
499 
500 #endif // INCLUDE_NN_NLIB_STRINGVIEW_H_
void remove_prefix(size_type n) noexcept
最初のn 文字を取り除きます。
Definition: StringView.h:100
std::pair< errno_t, size_t > ToInteger(T *v, const StringView &str) noexcept
ToInteger(v, str, 10)を返します。つまり10進数として文字列を数値に変換します。
Definition: StringView.h:427
bool ends_with(const StringView &s) const noexcept
文字列がs をサフィックスとして持つかをチェックします。
Definition: StringView.h:137
std::reverse_iterator< const_iterator > const_reverse_iterator
文字列の逆方向イテレータです
Definition: StringView.h:40
const charT * data() const noexcept
最初の文字へのポインタを返します。
Definition: StringView.h:93
size_t size_type
非負整数型で、現在はsize_tにtypedefされています。
Definition: StringView.h:42
void clear() noexcept
空文字列を設定します。
Definition: StringView.h:96
static int nlib_isalpha(int ch)
chがASCII文字の&#39;A&#39;-&#39;Z&#39;, または&#39;a&#39;-&#39;z&#39;である場合に非0、そうでない場合に0を返します。 ...
Definition: Platform.h:2409
ptrdiff_t difference_type
イテレータの差分をとったときに返される型です。
Definition: StringView.h:43
errno_t nlib_uint64_from_chars(uint64_t *result, const char **endptr, const char *first, const char *last, int base)
文字列をuint64_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。 ...
bool empty() const noexcept
空文字列であるかどうかをチェックします。
Definition: StringView.h:80
int nlib_memcmp(const void *buf1, const void *buf2, size_t n)
buf1 とbuf2 を先頭からn バイト分unsigned charとして比較します。
StringView substr(size_type pos, size_type n=npos) const noexcept
部分文字列[pos, pos + n)を返します。
Definition: StringView.h:118
std::pair< errno_t, size_t > ToFloat(float *v, const StringView &str) noexcept
内部でnlib_float_from_chars()を呼び出して、文字列を数値に変換します。戻り値はエラー値と読み込んだ文字...
Definition: StringView.h:414
errno_t nlib_float_from_chars(float *result, const char **endptr, const char *first, const char *last)
文字列をfloat型に変換します。詳しくはnlib_double_from_chars()の項目を御覧ください。 ...
bool ends_with(charT c) const noexcept
末尾が文字c であるかどうかをチェックします。
Definition: StringView.h:143
const_reverse_iterator crbegin() const noexcept
最後の文字への逆反復子を返します。
Definition: StringView.h:67
size_type length() const noexcept
文字列長を返します。
Definition: StringView.h:75
UniquePtrはポインタの所有権を保持し、UniquePtrがスコープから出るときにデストラクタでポインタをDELで指...
Definition: UniquePtr.h:109
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価ならば、trueを返します。
Definition: NMalloc.h:149
std::unique_ptrに相当するクラスが定義されています。
char charT
現在はchar型専用のクラスです。
Definition: StringView.h:32
#define NLIB_DEPRECATED
関数等がdeprecatedになったことを示します。
Definition: Config.h:109
bool starts_with(charT c) const noexcept
文字c で始まるかどうかをチェックします。
Definition: StringView.h:133
UniquePtr< char[]> ToCstring(const StringView &str) noexcept
メモリを割り当ててヌル終端文字列として文字列をコピーします。コピーできた場合はtrueを返します。 ...
Definition: StringView.h:357
const charT & operator[](size_type pos) const
pos 番目の文字を取得します。
Definition: StringView.h:83
errno_t nlib_uint8_from_chars(uint8_t *result, const char **endptr, const char *first, const char *last, int base)
文字列をuint8_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。 ...
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
bool EndsWith(const StringView &str, const char *suffix) noexcept
suffixがstrのサフィックスである場合trueを返します。
Definition: StringView.h:338
bool starts_with(const StringView &s) const noexcept
文字列がs をプレフィックスとして持つかをチェックします。
Definition: StringView.h:128
const charT & back() const
最後の文字を取得します。
Definition: StringView.h:92
bool ends_with(const charT *s) const noexcept
文字列がs をサフィックスとして持つかをチェックします。
Definition: StringView.h:144
constexpr StringView() noexcept
デフォルトコンストラクタです。空文字列で初期化されます。
Definition: StringView.h:47
bool TrimRight(StringView &str) noexcept
文字列の末尾の空白を切り詰めます。
Definition: StringView.h:441
const void * nlib_memchr(const void *s, int c, size_t n)
メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc があるポインタを返します。 ...
const_iterator end() const noexcept
最後の文字に続く文字への反復子を返します。
Definition: StringView.h:61
const charT * pointer
文字へのポインタ型ですが、const_pointerと同一です。
Definition: StringView.h:34
size_type max_size() const noexcept
文字列長の最大値を返します。
Definition: StringView.h:79
errno_t nlib_int32_from_chars(int32_t *result, const char **endptr, const char *first, const char *last, int base)
文字列をint32_t型に変換します。
const_iterator cend() const noexcept
最後の文字に続く文字への反復子を返します。
Definition: StringView.h:63
const_iterator iterator
文字列のイテレータですが、const_iteratorと同一です。
Definition: StringView.h:39
int compare(const charT *s) const noexcept
文字列を比較します。
Definition: StringView.h:127
const charT & at(size_type pos) const
pos 番目の文字を取得します。
Definition: StringView.h:87
errno_t nlib_int8_from_chars(int8_t *result, const char **endptr, const char *first, const char *last, int base)
文字列をint8_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。 ...
errno_t nlib_int64_from_chars(int64_t *result, const char **endptr, const char *first, const char *last, int base)
文字列をint64_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。 ...
static int nlib_isalnum(int ch)
chがASCII文字の&#39;0&#39;-&#39;9&#39;, &#39;A&#39;-&#39;Z&#39;, または&#39;a&#39;-&#39;z&#39;である場合に非0、そうでない場合に0を返します。 ...
Definition: Platform.h:2406
static errno_t nlib_memcpy(void *s1, size_t s1max, const void *s2, size_t n)
N1078のmemcpy_sに相当する実装です。
Definition: Platform.h:2437
const_reverse_iterator reverse_iterator
文字列の逆方向イテレータですが、const_reverse_iteratorと同一です。
Definition: StringView.h:41
static int nlib_isspace(int ch)
chがASCII文字の&#39; &#39;, &#39;\t&#39;, または&#39;\n&#39;である場合に非0、そうでない場合に0を返します。 ...
Definition: Platform.h:2419
const_iterator begin() const noexcept
最初のキャラクタへの反復子を返します。
Definition: StringView.h:57
bool Proceed(StringView &str, char c) noexcept
strがcで始まっていればその文字列長だけ進めます。
Definition: StringView.h:478
bool StartsWith(const StringView &str, const char *prefix) noexcept
prefixがstrのプレフィックスである場合trueを返します。
Definition: StringView.h:330
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
const_iterator cbegin() const noexcept
最初のキャラクタへの反復子を返します。
Definition: StringView.h:62
StringView(const charT *str, size_type len) noexcept
(計算済みの)文字列長を与えて初期化します。
Definition: StringView.h:52
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
開発環境別の設定が書かれるファイルです。
const_reverse_iterator crend() const noexcept
最初の文字の前の文字への逆反復子を返します。
Definition: StringView.h:68
const_pointer const_iterator
文字列のイテレータです。
Definition: StringView.h:38
StringView GetName(StringView &str) noexcept
一般に変数名とされるような文字列を取得します。自身のオブジェクト(str)は取得した文字列の次に移動します...
Definition: StringView.h:483
std::stringが持つメソッドをstd::stringを構築せずに利用するためのクラスです。 C++17のstring_viewにtype...
Definition: StringView.h:29
bool starts_with(const charT *s) const noexcept
文字列がs をプレフィックスとして持つかをチェックします。
Definition: StringView.h:134
std::pair< errno_t, size_t > ToDouble(double *v, const StringView &str) noexcept
内部でnlib_double_from_chars()を呼び出して、文字列を数値に変換します。戻り値はエラー値と読み込んだ文...
Definition: StringView.h:420
void Trim(StringView &str) noexcept
文字列の先頭と末尾の空白を切り詰めます。
Definition: StringView.h:452
bool Proceed(const StringView &kwd) noexcept
プレフィックスがkwd と一致していればkwd の文字列長だけ前に進みます。
Definition: StringView.h:190
void remove_suffix(size_type n) noexcept
最後のn 文字を取り除きます。
Definition: StringView.h:109
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
const charT * const_pointer
文字へのポインタ型です。
Definition: StringView.h:35
const charT & const_reference
文字への参照です。
Definition: StringView.h:37
errno_t nlib_int16_from_chars(int16_t *result, const char **endptr, const char *first, const char *last, int base)
文字列をint16_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。 ...
strlen, strcpy等を安全に使えるようにラップしています。
const_reverse_iterator rbegin() const noexcept
最後の文字への逆反復子を返します。
Definition: StringView.h:65
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
bool ToCstring(charT(&str)[N]) const noexcept
Definition: StringView.h:149
charT value_type
文字の型です。
Definition: StringView.h:33
StringView(const charT *str) noexcept
str を参照するように初期化されます。内部で文字列長が計算されます。
Definition: StringView.h:49
bool TrimLeft(StringView &str) noexcept
文字列の先頭の空白を切り詰めます。
Definition: StringView.h:430
const charT & front() const
最初の文字を取得します。
Definition: StringView.h:91
size_type size() const noexcept
文字列長を返します。
Definition: StringView.h:71
const_reverse_iterator rend() const noexcept
最初の文字の前の文字への逆反復子を返します。
Definition: StringView.h:66
bool ToCstring(UniquePtr< charT[]> &str) const noexcept
Definition: StringView.h:155
errno_t nlib_double_from_chars(double *result, const char **endptr, const char *first, const char *last)
文字列をdouble型に変換します。
bool Proceed(const charT *kwd) noexcept
プレフィックスがkwd と一致していればkwd の文字列長だけ前に進みます。
Definition: StringView.h:196
void Trim() noexcept
文字列の先頭と末尾の空白を切り詰めます。
Definition: StringView.h:185
errno_t nlib_uint16_from_chars(uint16_t *result, const char **endptr, const char *first, const char *last, int base)
文字列をuint16_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。 ...
errno_t nlib_uint32_from_chars(uint32_t *result, const char **endptr, const char *first, const char *last, int base)
文字列をuint32_t型に変換します。詳しくはnlib_int32_from_chars()の項目を御覧ください。 ...
const charT & reference
文字への参照ですが、const_referenceと同一です。
Definition: StringView.h:36
StringView GetLine(StringView &str) noexcept
先頭から行末までの文字列を取得します。自身のオブジェクト(str)は次の行の行頭に移動します。 ...
Definition: StringView.h:456
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37