qxLib
string.h
Go to the documentation of this file.
1 /**
2 
3  @file string.h
4  @author Khrapov
5  @date 4.09.2019
6  @copyright (c) Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
15 #include <qx/memory/sbo_bytes.h>
16 #include <qx/meta/type_traits.h>
17 
18 #include <iostream>
19 #include <optional>
20 #include <string_view>
21 #include <vector>
22 
23 namespace qx
24 {
25 
26 template<class char_t, class traits_t = string_traits::traits<char_t>>
27 class basic_string;
28 
29 namespace details
30 {
31 
32 template<class string_traits_t>
34 {
35  using size_type = typename string_traits_t::size_type;
36  static constexpr size_type nSBOSize =
37  sizeof(typename string_traits_t::value_type) * string_traits_t::small_string_size();
38  static constexpr bool bShrinkToFitWhenSmall = string_traits_t::shrink_to_fit_when_small();
39  static constexpr bool bPreserveContents = true;
40 
41  static constexpr size_type growth_strategy(size_type nOldCapacity) noexcept
42  {
43  return nOldCapacity + nOldCapacity / 2;
44  }
45 
46  static_assert(
47  (nSBOSize & (nSBOSize - 1)) == 0,
48  "The buffer size should be such that the final size of the structure is aligned");
49 };
50 
51 template<class char_t>
52 using ostream = std::basic_ostream<char_t>;
53 
54 template<class char_t>
55 using istream = std::basic_istream<char_t>;
56 
57 } // namespace details
58 
59 } // namespace qx
60 
61 template<class char_t, class traits_t>
62 qx::details::istream<char_t>& operator>>(qx::details::istream<char_t>& is, qx::basic_string<char_t, traits_t>& str);
63 
64 namespace qx
65 {
66 
67 /**
68 
69  @class basic_string
70  @brief String class
71  @details A class containing a null-terminated character sequence.
72  Supports small strings optimization, almost completely supports
73  the std::string interface (except for some overloads),
74  has many additional methods for convenient working with strings.
75  @tparam char_t - char type (char, wchar_t, etc)
76  @tparam traits_t - char traits. \see string_traits.h
77  @author Khrapov
78  @date 20.10.2019
79 
80 **/
81 template<class char_t, class traits_t>
83 {
84  template<class _char_t, class _traits_t>
85  friend qx::details::istream<_char_t>& ::operator>>(
86  qx::details::istream<_char_t>& is,
88 
89 public:
90  using traits_type = traits_t;
91  using value_type = typename traits_type::value_type;
92  using pointer = typename traits_type::pointer;
93  using const_pointer = typename traits_type::const_pointer;
94  using reference = typename traits_type::reference;
95  using const_reference = typename traits_type::const_reference;
96  using difference_type = typename traits_type::difference_type;
97  using size_type = typename traits_type::size_type;
98  using string_view = basic_string_view<value_type>;
99  using sstream_type = std::basic_stringstream<value_type>;
100  using views = std::vector<string_view>;
101  template<class... args_t>
102  using format_string_type = typename traits_type::template format_string<args_t...>;
103 
104  static constexpr size_type npos = std::numeric_limits<size_type>::max();
105 
106  QX_IMPL_CONTAINER(basic_string);
107 
108 public:
109  basic_string() noexcept = default;
110 
111  /**
112  @brief basic_string object constructor
113  @param nSymbols - number of same chars
114  @param chSymbol - char to assign
115  **/
116  basic_string(size_type nSymbols, value_type chSymbol) noexcept;
117 
118  /**
119  @brief basic_string object constructor
120  @param pszSource - source string pointer
121  @param nSymbols - source string size
122  **/
123  basic_string(const_pointer pszSource, size_type nSymbols) noexcept;
124 
125  /**
126  @brief basic_string object constructor
127  @param pszSource - source string pointer
128  **/
129  basic_string(const_pointer pszSource) noexcept;
130 
131  /**
132  @brief basic_string object constructor
133  @param sAnother - another string rvalue ref
134  **/
135  basic_string(basic_string&& sAnother) noexcept;
136 
137  /**
138  @brief basic_string object constructor
139  @param sAnother - another string
140  **/
141  basic_string(const basic_string& sAnother) noexcept;
142 
143  /**
144  @brief basic_string object constructor
145  @tparam fwd_it_t - forward iterator type
146  @param itFirst - first source iterator
147  @param itLast - last source iterator
148  **/
149  template<class fwd_it_t>
150  basic_string(fwd_it_t itFirst, fwd_it_t itLast) noexcept;
151 
152  /**
153  @brief basic_string object constructor
154  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
155  @param sAnother - string-ish container
156  **/
157  template<range_of_t_c<char_t> string_t>
158  basic_string(const string_t& sAnother) noexcept;
159 
160  /**
161  @brief Assign by filling
162  @param nSymbols - number of same chars
163  @param chSymbol - char to assign
164  **/
165  void assign(size_type nSymbols, value_type chSymbol) noexcept;
166 
167  /**
168  @brief Assign by char sequence
169  @param pszSource - pointer to char sequence
170  @param nSymbols - num of chars
171  **/
172  void assign(const_pointer pszSource, size_type nSymbols) noexcept;
173 
174  /**
175  @brief Assign by psz
176  @param pszSource - pointer to zero terminated char sequence
177  **/
178  void assign(const_pointer pszSource) noexcept;
179 
180  /**
181  @brief Assign by moving from another string
182  @param sAnother - another string
183  **/
184  void assign(basic_string&& sAnother) noexcept;
185 
186  /**
187  @brief Assign by another string
188  @param sAnother - another string
189  **/
190  void assign(const basic_string& sAnother) noexcept;
191 
192  /**
193  @brief Assign by iterators
194  @tparam fwd_it_t - forward iterator type
195  @param itFirst - first iterator of source
196  @param itLast - last iterator of source
197  **/
198  template<class fwd_it_t>
199  void assign(fwd_it_t itFirst, fwd_it_t itLast) noexcept;
200 
201  /**
202  @brief Assign by char container
203  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
204  @param str - char container
205  **/
206  template<range_of_t_c<char_t> string_t>
207  void assign(const string_t& str) noexcept;
208 
209  /**
210  @brief Clear the string and format it with the format string and the args
211  @details Format string will be checked at compile time
212  @tparam args_t - template parameter pack type
213  @param sFormat - format string
214  @param args - format arguments
215  **/
216  template<class... args_t>
217  requires format_acceptable_args_c<char_t, args_t...>
218  void format(const format_string_type<std::type_identity_t<args_t>...> sFormat, args_t&&... args) noexcept;
219 
220  /**
221  @brief Create a string by formatting it with the format string and the args
222  @details Format string will be checked at compile time
223  @tparam args_t - template parameter pack type
224  @param sFormat - format string
225  @param args - format arguments
226  @retval - formatted string
227  **/
228  template<class... args_t>
229  requires format_acceptable_args_c<char_t, args_t...>
231  const format_string_type<std::type_identity_t<args_t>...> sFormat,
232  args_t&&... args) noexcept;
233 
234  /**
235  @brief Append the formatted string to the current one
236  @details Format string will be checked at compile time
237  @tparam args_t - template parameter pack type
238  @param sFormat - format string
239  @param args - format arguments
240  **/
241  template<class... args_t>
242  requires format_acceptable_args_c<char_t, args_t...>
243  void append_format(const format_string_type<std::type_identity_t<args_t>...> sFormat, args_t&&... args) noexcept;
244 
245  /**
246  @brief Clear the string and format it with the format string and the args
247  @details No compile time checks, method will throw is something is wrong with the format string
248  @tparam args_t - template parameter pack type
249  @param svFormat - format string
250  @param args - format arguments
251  **/
252  template<class... args_t>
253  requires format_acceptable_args_c<char_t, args_t...>
254  void vformat(string_view svFormat, args_t&&... args);
255 
256  /**
257  @brief Create a string by formatting it with the format string and the args
258  @details No compile time checks, method will throw is something is wrong with the format string
259  @tparam args_t - template parameter pack type
260  @param svFormat - format string
261  @param args - format arguments
262  @retval - formatted string
263  **/
264  template<class... args_t>
265  requires format_acceptable_args_c<char_t, args_t...>
266  static basic_string static_vformat(string_view svFormat, args_t&&... args);
267 
268  /**
269  @brief Append the formatted string to the current one
270  @details No compile time checks, method will throw is something is wrong with the format string
271  @tparam args_t - template parameter pack type
272  @param svFormat - format string
273  @param args - format arguments
274  **/
275  template<class... args_t>
276  requires format_acceptable_args_c<char_t, args_t...>
277  void append_vformat(string_view svFormat, args_t&&... args);
278 
279  /**
280  @brief Swap this str and other
281  @param sOther - other str
282  **/
283  void swap(basic_string& sOther) noexcept;
284 
285  /**
286  @brief Reserve memory for the string
287  @param nCapacity - required capacity
288  @retval - new string capacity
289  **/
290  size_type reserve(size_type nCapacity) noexcept;
291 
292  /**
293  @brief Resize string
294  @details If the new size is smaller, the string may be
295  @param nSymbols - new size (symbols without null terminator, not bytes)
296  @retval - true if a memory allocation is successful
297  **/
298  bool resize(size_type nSymbols) noexcept;
299 
300  /**
301  @brief Fit allocated size to string's actual size
302  **/
303  void shrink_to_fit() noexcept;
304 
305  /**
306  @brief Clear string and free allocated memory
307  **/
308  void free() noexcept;
309 
310  /**
311  @brief Get substring
312  @param nPos - start index
313  @param nSymbols - string size (npos - to the end)
314  @retval - substring view
315  **/
316  string_view substr(size_type nPos, size_type nSymbols = npos) const noexcept;
317 
318  /**
319  @brief Convert string to lowercase
320  **/
321  void to_lower() noexcept;
322 
323  /**
324  @brief Convert string to uppercase
325  **/
326  void to_upper() noexcept;
327 
328  /**
329  @brief Get first char of the string
330  @retval - first char of the string
331  **/
332  value_type front() const noexcept;
333 
334  /**
335  @brief Get last char of the string
336  @retval - last char of the string
337  **/
338  value_type back() const noexcept;
339 
340  /**
341  @brief Get string length
342  @brief Same as size()
343  @retval - string length
344  **/
345  size_type length() const noexcept;
346 
347  /**
348  @brief Get pointer to string zero terminated
349  @retval - pointer to string zero terminated
350  **/
351  const_pointer c_str() const noexcept;
352 
353  /**
354  @brief Get allocated memory size (including null terminator)
355  @retval - allocated memory size
356  **/
357  size_type capacity() const noexcept;
358 
359  /**
360  @brief Get the theoretical maximum of string size
361  @retval - theoretical maximum of string size
362  **/
363  static constexpr size_type max_size() noexcept;
364 
365  /**
366  @brief Convert string to specified type
367  @warning This function currently uses unsafe scanf functions from the c library,
368  since the current implementation of the standard library
369  does not have an implementation of fmt::scan (https://github.com/fmtlib/fmt/blob/master/test/scan.h).
370  Status: https://github.com/cplusplus/papers/issues/493
371  This will be fixed in the future when possible.
372  @tparam to_t - type to convert
373  @param pszFormat - format string (according to https://en.cppreference.com/w/c/io/fscanf)
374  @retval - converted value or std::nullopt
375  **/
376  template<class to_t>
377  std::optional<to_t> to(const_pointer pszFormat = nullptr) const noexcept;
378 
379  /**
380  @brief Copies a substring [nPos, nPos + nCount) to character string pointed to by pDest
381  @param pDest - pointer to the destination character string
382  @param nCount - length of the substring
383  @param nPos - position of the first character to include
384  @retval - number of characters copied
385  **/
386  size_type copy(pointer pDest, size_type nCount, size_type nPos = 0) const noexcept;
387 
388  /**
389  @brief Construct string from custom type
390  @tparam from_t - type to convert from
391  @param data - data of type from_type
392  **/
393  template<class from_t>
394  void from(const from_t& data);
395 
396  /**
397  @brief Construct string from custom type and get it
398  @tparam from_t - type to convert from
399  @param data - data of type from_type
400  @retval - constructed string
401  **/
402  template<class from_t>
403  static basic_string static_from(const from_t& data);
404 
405  /**
406  @brief Append char
407  @param chSymbol - char to append
408  **/
409  void append(value_type chSymbol) noexcept;
410 
411  /**
412  @brief Append string
413  @param pszStr - source string
414  @param nStrSize - source string size
415  **/
416  void append(const_pointer pszStr, size_type nStrSize = npos) noexcept;
417 
418  /**
419  @brief Append string
420  @param sStr - source string
421  **/
422  void append(const basic_string& sStr) noexcept;
423 
424  /**
425  @brief Append string
426  @tparam fwd_it_t - forward iterator type
427  @param itBegin - other string begin iterator
428  @param itEnd - other end begin iterator
429  **/
430  template<class fwd_it_t>
431  void append(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
432 
433  /**
434  @brief Append string
435  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
436  @param sStr - source char container
437  **/
438  template<range_of_t_c<char_t> string_t>
439  void append(const string_t& sStr) noexcept;
440 
441  /**
442  @brief Insert substring
443  @param nPos - first char index
444  @param chSymbol - symbol to insert
445  @retval - pos of char after last char of inserted string or npos
446  **/
447  size_type insert(size_type nPos, value_type chSymbol) noexcept;
448 
449  /**
450  @brief Insert substring
451  @param nPos - first char index
452  @param pszWhat - source string
453  @param nSymbols - number of symbols to insert
454  @retval - pos of char after last char of inserted string or npos
455  **/
456  size_type insert(size_type nPos, const_pointer pszWhat, size_type nSymbols = npos) noexcept;
457 
458  /**
459  @brief Insert substring
460  @param nPos - first char index
461  @param sWhat - string to insert
462  @retval - pos of char after last char of inserted string or npos
463  **/
464  size_type insert(size_type nPos, const basic_string& sWhat) noexcept;
465 
466  /**
467  @brief Insert substring
468  @tparam fwd_it_t - forward iterator type
469  @param nPos - first char index
470  @param itWhatBegin - source first iterator
471  @param itWhatEnd - source last iterator
472  @retval - pos of char after last char of inserted string or npos
473  **/
474  template<class fwd_it_t>
475  size_type insert(size_type nPos, fwd_it_t itWhatBegin, fwd_it_t itWhatEnd) noexcept;
476 
477  /**
478  @brief Insert substring
479  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
480  @param nPos - first char index
481  @param sWhat - source string
482  @retval - pos of char after last char of inserted string or npos
483  **/
484  template<range_of_t_c<char_t> string_t>
485  size_type insert(size_type nPos, string_t sWhat) noexcept;
486 
487  /**
488  @brief Insert char
489  @param itPos - first char iterator
490  @param chSymbol - char to insert
491  @retval - pos of char after last char of inserted string or npos
492  **/
493  size_type insert(const_iterator itPos, value_type chSymbol) noexcept;
494 
495  /**
496  @brief Insert substring
497  @param itPos - first char iterator
498  @param pszWhat - source string
499  @param nSymbols - number of symbols to insert
500  @retval - pos of char after last char of inserted string or npos
501  **/
502  size_type insert(const_iterator itPos, const_pointer pszWhat, size_type nSymbols = npos) noexcept;
503 
504  /**
505  @brief Insert substring
506  @param itPos - first char iterator
507  @param sWhat - string to insert
508  @retval - pos of char after last char of inserted string or npos
509  **/
510  size_type insert(const_iterator itPos, const basic_string& sWhat) noexcept;
511 
512  /**
513  @brief Insert substring
514  @tparam fwd_it_t - forward iterator type
515  @param itPos - first char iterator
516  @param itWhatBegin - source string first iterator
517  @param itWhatEnd - source string last iterator
518  @retval - pos of char after last char of inserted string or npos
519  **/
520  template<class fwd_it_t>
521  size_type insert(const_iterator itPos, fwd_it_t itWhatBegin, fwd_it_t itWhatEnd) noexcept;
522 
523  /**
524  @brief Insert substring
525  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
526  @param itPos - first char iterator
527  @param sWhat - source string
528  @retval - pos of char after last char of inserted string or npos
529  **/
530  template<range_of_t_c<char_t> string_t>
531  size_type insert(const_iterator itPos, string_t sWhat) noexcept;
532 
533  /**
534  @brief Insert char in the end of the string
535  @param chSymbol - char to insert
536  **/
537  void push_back(value_type chSymbol) noexcept;
538 
539  /**
540  @brief Insert char in the beginning of the string
541  @param chSymbol - char to insert
542  **/
543  void push_front(value_type chSymbol) noexcept;
544 
545  /**
546  @brief Erase substring
547  @param itFirst - first substr char iterator
548  @param itLast - last substr char iterator (excluded)
549  **/
550  void erase(iterator itFirst, iterator itLast) noexcept;
551 
552  /**
553  @brief Erase on iterator
554  @param itPos - iterator where to erase
555  **/
556  void erase(iterator itPos) noexcept;
557 
558  /**
559  @brief Erase on position
560  @param nPos - index where to erase
561  **/
562  void erase(size_type nPos) noexcept;
563 
564  /**
565  @brief Erase substring
566  @param nPos - start position
567  @param nSymbols - number of symbols
568  **/
569  void erase(size_type nPos, size_type nSymbols) noexcept;
570 
571  /**
572  @brief Erase last char and return it
573  @retval - last char
574  **/
575  value_type pop_back() noexcept;
576 
577  /**
578  @brief Erase first char and return it
579  @retval - first char
580  **/
581  value_type pop_front() noexcept;
582 
583  /**
584  @brief Trim the string to the left (whitespace characters)
585  @retval - number of deleted symbols
586  **/
587  size_type trim_left() noexcept;
588 
589  /**
590  @brief Trim the string to the left
591  @param chSymbol - symbol to delete
592  @retval - number of deleted symbols
593  **/
594  size_type trim_left(value_type chSymbol) noexcept;
595 
596  /**
597  @brief Trim the string to the left
598  @param pszStr - string with symbols to delete
599  @retval - number of deleted symbols
600  **/
601  size_type trim_left(const_pointer pszStr) noexcept;
602 
603  /**
604  @brief Trim the string to the left
605  @param pszStr - string with symbols to delete
606  @param nStrSize - string size
607  @retval - number of deleted symbols
608  **/
609  size_type trim_left(const_pointer pszStr, size_type nStrSize) noexcept;
610 
611  /**
612  @brief Trim the string to the left
613  @param sStr - string with symbols to delete
614  @retval - number of deleted symbols
615  **/
616  size_type trim_left(const basic_string& sStr) noexcept;
617 
618  /**
619  @brief Trim the string to the left
620  @tparam fwd_it_t - forward iterator type
621  @param itBegin - begin it of string with symbols to delete
622  @param itEnd - begin it of string with symbols to delete
623  @retval - number of deleted symbols
624  **/
625  template<class fwd_it_t>
626  size_type trim_left(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
627 
628  /**
629  @brief Trim the string to the left
630  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
631  @param sStr - string with symbols to delete
632  @retval - number of deleted symbols
633  **/
634  template<range_of_t_c<char_t> string_t>
635  size_type trim_left(const string_t& sStr) noexcept;
636 
637  /**
638  @brief Trim the string to the right (whitespace characters)
639  @retval - number of deleted symbols
640  **/
641  size_type trim_right() noexcept;
642 
643  /**
644  @brief Trim the string to the right
645  @param chSymbol - symbol to delete
646  @retval - number of deleted symbols
647  **/
648  size_type trim_right(value_type chSymbol) noexcept;
649 
650  /**
651  @brief Trim the string to the right
652  @param pszStr - string with symbols to delete
653  @retval - number of deleted symbols
654  **/
655  size_type trim_right(const_pointer pszStr) noexcept;
656 
657  /**
658  @brief Trim the string to the right
659  @param pszStr - string with symbols to delete
660  @param nStrSize - string size
661  @retval - number of deleted symbols
662  **/
663  size_type trim_right(const_pointer pszStr, size_type nStrSize) noexcept;
664 
665  /**
666  @brief Trim the string to the right
667  @param sStr - string with symbols to delete
668  @retval - number of deleted symbols
669  **/
670  size_type trim_right(const basic_string& sStr) noexcept;
671 
672  /**
673  @brief Trim the string to the right
674  @tparam fwd_it_t - forward iterator type
675  @param itBegin - begin it of string with symbols to delete
676  @param itEnd - begin it of string with symbols to delete
677  @retval - number of deleted symbols
678  **/
679  template<class fwd_it_t>
680  size_type trim_right(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
681 
682  /**
683  @brief Trim the string to the right
684  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
685  @param sStr - string with symbols to delete
686  @retval - number of deleted symbols
687  **/
688  template<range_of_t_c<char_t> string_t>
689  size_type trim_right(const string_t& sStr) noexcept;
690 
691  /**
692  @brief Trim the string to the both sides (whitespace characters)
693  @retval - number of deleted symbols
694  **/
695  size_type trim() noexcept;
696 
697  /**
698  @brief Trim the string to the both sides
699  @param chSymbol - symbol to delete
700  @retval - number of deleted symbols
701  **/
702  size_type trim(value_type chSymbol) noexcept;
703 
704  /**
705  @brief Trim the string to the both sides
706  @param pszStr - string with symbols to delete
707  @retval - number of deleted symbols
708  **/
709  size_type trim(const_pointer pszStr) noexcept;
710 
711  /**
712  @brief Trim the string to the both sides
713  @param pszStr - string with symbols to delete
714  @param nStrSize - string size
715  @retval - number of deleted symbols
716  **/
717  size_type trim(const_pointer pszStr, size_type nStrSize) noexcept;
718 
719  /**
720  @brief Trim the string to the both sides
721  @param sStr - string with symbols to delete
722  @retval - number of deleted symbols
723  **/
724  size_type trim(const basic_string& sStr) noexcept;
725 
726  /**
727  @brief Trim the string to the both sides
728  @tparam fwd_it_t - forward iterator type
729  @param itBegin - begin it of string with symbols to delete
730  @param itEnd - begin it of string with symbols to delete
731  @retval - number of deleted symbols
732  **/
733  template<class fwd_it_t>
734  size_type trim(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
735 
736  /**
737  @brief Trim the string to the both sides
738  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
739  @param sStr - string with symbols to delete
740  @retval - number of deleted symbols
741  **/
742  template<range_of_t_c<char_t> string_t>
743  size_type trim(const string_t& sStr) noexcept;
744 
745  /**
746  @brief Remove the first occurrence of a substring in a string
747  @param chSymbol - char to remove
748  @param nBegin - start searching index
749  @param nEnd - end searching index
750  @retval - position where the first occurrence was or npos
751  **/
752  size_type remove(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) noexcept;
753 
754  /**
755  @brief Remove the first occurrence of a substring in a string
756  @param pszStr - c-string to remove
757  @param nBegin - start searching index
758  @param nEnd - end searching index
759  @param nStrSize - c-string size
760  @retval - position where the first occurrence was or npos
761  **/
762  size_type remove(
763  const_pointer pszStr,
764  size_type nBegin = 0,
765  size_type nEnd = npos,
766  size_type nStrSize = npos) noexcept;
767 
768  /**
769  @brief Remove the first occurrence of a substring in a string
770  @param sStr - string to remove
771  @param nBegin - start searching index
772  @param nEnd - end searching index
773  @retval - position where the first occurrence was or npos
774  **/
775  size_type remove(const basic_string& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
776 
777  /**
778  @brief Remove the first occurrence of a substring in a string
779  @tparam fwd_it_t - forward iterator type
780  @param itBegin - string begin iterator
781  @param itEnd - string end iterator
782  @param nBegin - start searching index
783  @param nEnd - end searching index
784  @retval - position where the first occurrence was or npos
785  **/
786  template<class fwd_it_t>
787  size_type remove(fwd_it_t itBegin, fwd_it_t itEnd, size_type nBegin = 0, size_type nEnd = npos) noexcept;
788 
789  /**
790  @brief Remove the first occurrence of a substring in a string
791  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
792  @param sStr - string to remove
793  @param nBegin - start searching index
794  @param nEnd - end searching index
795  @retval - position where the first occurrence was or npos
796  **/
797  template<range_of_t_c<char_t> string_t>
798  size_type remove(const string_t& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
799 
800  /**
801  @brief Remove string prefix if matches
802  @param chSymbol - char to remove
803  @retval - true if removed
804  **/
805  bool remove_prefix(value_type chSymbol) noexcept;
806 
807  /**
808  @brief Remove string prefix if matches
809  @param pszStr - string to remove
810  @param nStrSize - string size
811  @retval - true if removed
812  **/
813  bool remove_prefix(const_pointer pszStr, size_type nStrSize = npos) noexcept;
814 
815  /**
816  @brief Remove string prefix if matches
817  @param sStr - string to remove
818  @retval - true if removed
819  **/
820  bool remove_prefix(const basic_string& sStr) noexcept;
821 
822  /**
823  @brief Remove string prefix if matches
824  @tparam fwd_it_t - forward iterator type
825  @param itBegin - string to remove begin iterator
826  @param itEnd - string to remove end iterator
827  @retval - true if removed
828  **/
829  template<class fwd_it_t>
830  bool remove_prefix(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
831 
832  /**
833  @brief Remove string prefix if matches
834  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
835  @param sStr - string to remove
836  @retval - true if removed
837  **/
838  template<range_of_t_c<char_t> string_t>
839  bool remove_prefix(const string_t& sStr) noexcept;
840 
841  /**
842  @brief Remove string suffix if matches
843  @param chSymbol - char to remove
844  @retval - true if removed
845  **/
846  bool remove_suffix(value_type chSymbol) noexcept;
847 
848  /**
849  @brief Remove string suffix if matches
850  @param pszStr - string to remove
851  @param nStrSize - string size
852  @retval - true if removed
853  **/
854  bool remove_suffix(const_pointer pszStr, size_type nStrSize = npos) noexcept;
855 
856  /**
857  @brief Remove string suffix if matches
858  @param sStr - string to remove
859  @retval - true if removed
860  **/
861  bool remove_suffix(const basic_string& sStr) noexcept;
862 
863  /**
864  @brief Remove string suffix if matches
865  @tparam fwd_it_t - forward iterator type
866  @param itBegin - string to remove begin iterator
867  @param itEnd - string to remove end iterator
868  @retval - true if removed
869  **/
870  template<class fwd_it_t>
871  bool remove_suffix(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
872 
873  /**
874  @brief Remove string suffix if matches
875  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
876  @param sStr - string to remove
877  @retval - true if removed
878  **/
879  template<range_of_t_c<char_t> string_t>
880  bool remove_suffix(const string_t& sStr) noexcept;
881 
882  /**
883  @brief Remove all occurrences of a substring in a string
884  @param chSymbol - char to remove
885  @param nBegin - start searching index
886  @param nEnd - end searching index
887  @retval - number of deleted occurrences
888  **/
889  size_type remove_all(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) noexcept;
890 
891  /**
892  @brief Remove all occurrences of a substring in a string
893  @param pszStr - string to remove
894  @param nBegin - start searching index
895  @param nEnd - end searching index
896  @param nStrSize - string size
897  @retval - number of deleted occurrences
898  **/
899  size_type remove_all(
900  const_pointer pszStr,
901  size_type nBegin = 0,
902  size_type nEnd = npos,
903  size_type nStrSize = npos) noexcept;
904 
905  /**
906  @brief Remove all occurrences of a substring in a string
907  @param sStr - string to remove
908  @param nBegin - start searching index
909  @param nEnd - end searching index
910  @retval - number of deleted occurrences
911  **/
912  size_type remove_all(const basic_string& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
913 
914  /**
915  @brief Remove all occurrences of a substring in a string
916  @tparam fwd_it_t - forward iterator type
917  @param itFirst - string begin iterator
918  @param itLast - string end iterator
919  @param nBegin - start searching index
920  @param nEnd - end searching index
921  @retval - number of deleted occurrences
922  **/
923  template<class fwd_it_t>
924  size_type remove_all(fwd_it_t itFirst, fwd_it_t itLast, size_type nBegin = 0, size_type nEnd = npos) noexcept;
925 
926  /**
927  @brief Remove all occurrences of a substring in a string
928  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
929  @param sStr - string to remove
930  @param nBegin - start searching index
931  @param nEnd - end searching index
932  @retval - number of deleted occurrences
933  **/
934  template<range_of_t_c<char_t> string_t>
935  size_type remove_all(const string_t& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
936 
937  /**
938  @brief Replace a substring with a given string
939  @todo tests
940  @param nBegin - substring start index
941  @param nSize - substring size
942  @param pszReplace - new substring pointer
943  @param nReplaceSize - new substring suze
944  @retval - pos of char after last char of replaced string or npos
945  **/
946  size_type replace(size_type nBegin, size_type nSize, const_pointer pszReplace, size_t nReplaceSize) noexcept;
947 
948  /**
949  @brief Replace a substring with a given string
950  @todo tests
951  @tparam replace_string_t - new substring type
952  @param nBegin - substring start index
953  @param nSize - substring size
954  @param sReplace - new substring
955  @retval - pos of char after last char of replaced string or npos
956  **/
957  template<class replace_string_t>
958  size_type replace(size_type nBegin, size_type nSize, const replace_string_t& sReplace) noexcept;
959 
960  /**
961  @brief Replace first occurrence of sFind with sReplace
962  @tparam find_string_t - find string type
963  @tparam replace_string_t - replace string type
964  @param sFind - string to find and replace
965  @param sReplace - string to replace with
966  @param nBegin - start searching index
967  @param nEnd - end searching index
968  @retval - pos of char after last char of replaced string or npos
969  **/
970  template<class find_string_t, class replace_string_t>
971  size_type replace(
972  const find_string_t& sFind,
973  const replace_string_t& sReplace,
974  size_type nBegin = 0,
975  size_type nEnd = npos) noexcept;
976 
977  /**
978  @brief Replace all occurrences of sFind with sReplace
979  @tparam find_string_t - find string type
980  @tparam replace_string_t - replace string type
981  @param sFind - string to find and replace
982  @param sReplace - string to replace with
983  @param nBegin - start searching index
984  @param nEnd - end searching index
985  @retval - number of replaced occurrences
986  **/
987  template<class find_string_t, class replace_string_t>
988  size_type replace_all(
989  const find_string_t& sFind,
990  const replace_string_t& sReplace,
991  size_type nBegin = 0,
992  size_type nEnd = npos) noexcept;
993 
994  /**
995  @brief Performs a binary comparison of the characters
996  @param chSymbol - symbol to compare
997  @retval - < 0 the first character that does not match has
998  a lower value in this than in chSymbol
999  = 0 the contents of both strings are equal
1000  > 0 the first character that does not match has
1001  a greater value in this than in chSymbol
1002  **/
1003  int compare(value_type chSymbol) const noexcept;
1004 
1005  /**
1006  @brief Performs a binary comparison of the characters
1007  @param pszStr - string to compare. must not be nullptr
1008  @retval - < 0 the first character that does not match has
1009  a lower value in this than in chSymbol
1010  = 0 the contents of both strings are equal
1011  > 0 the first character that does not match has
1012  a greater value in this than in chSymbol
1013  **/
1014  int compare(const_pointer pszStr) const noexcept;
1015 
1016  /**
1017  @brief Performs a binary comparison of the characters
1018  @param pStr - string to compare. must not be nullptr
1019  @param nStrSize - number of symbols to compare
1020  @retval - < 0 the first character that does not match has
1021  a lower value in this than in chSymbol
1022  = 0 the contents of both strings are equal
1023  > 0 the first character that does not match has
1024  a greater value in this than in chSymbol
1025  **/
1026  int compare(const_pointer pStr, size_type nStrSize) const noexcept;
1027 
1028  /**
1029  @brief Performs a binary comparison of the characters
1030  @param sStr - string to compare
1031  @retval - < 0 the first character that does not match has
1032  a lower value in this than in chSymbol
1033  = 0 the contents of both strings are equal
1034  > 0 the first character that does not match has
1035  a greater value in this than in chSymbol
1036  **/
1037  int compare(const basic_string& sStr) const noexcept;
1038 
1039  /**
1040  @brief Performs a binary comparison of the characters
1041  @tparam fwd_it_t - forward iterator type
1042  @param itBegin - string to compare begin iterator
1043  @param itEnd - string to compare end iterator
1044  @retval - < 0 the first character that does not match has
1045  a lower value in this than in chSymbol
1046  = 0 the contents of both strings are equal
1047  > 0 the first character that does not match has
1048  a greater value in this than in chSymbol
1049  **/
1050  template<class fwd_it_t>
1051  int compare(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1052 
1053  /**
1054  @brief Performs a binary comparison of the characters
1055  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1056  @param sStr - string to compare
1057  @retval - < 0 the first character that does not match has
1058  a lower value in this than in chSymbol
1059  = 0 the contents of both strings are equal
1060  > 0 the first character that does not match has
1061  a greater value in this than in chSymbol
1062  **/
1063  template<range_of_t_c<char_t> string_t>
1064  int compare(const string_t& sStr) const noexcept;
1065 
1066  /**
1067  @brief Find substring
1068  @param chSymbol - char to find
1069  @param nBegin - start searching index
1070  @param nEnd - end searching index (npos - to the end)
1071  @retval - substring index or npos if not found
1072  **/
1073  size_type find(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1074 
1075  /**
1076  @brief Find substring
1077  @param pszWhat - string to find
1078  @param nBegin - start searching index
1079  @param nWhatSize - string length (npos - string is zero terminated)
1080  @param nEnd - end searching index (npos - to the end).
1081  @retval - substring index
1082  **/
1083  size_type find(const_pointer pszWhat, size_type nBegin = 0, size_type nWhatSize = npos, size_type nEnd = npos)
1084  const noexcept;
1085 
1086  /**
1087  @brief Find substring
1088  @param sWhat - string to find
1089  @param nBegin - start searching index
1090  @param nEnd - end searching index
1091  @retval - substring index or npos if not found
1092  **/
1093  size_type find(const basic_string& sWhat, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1094 
1095  /**
1096  @brief Find substring
1097  @tparam fwd_it_t - forward iterator type
1098  @param itWhatBegin - substring begin iterator
1099  @param itWhatEnd - substring end iterator
1100  @param nBegin - start searching index
1101  @param nEnd - end searching index
1102  @retval - substring index or npos if not found
1103  **/
1104  template<class fwd_it_t>
1105  size_type find(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0, size_type nEnd = npos)
1106  const noexcept;
1107 
1108  /**
1109  @brief Find substring
1110  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1111  @param sWhat - substring
1112  @param nBegin - start searching index
1113  @param nEnd - end searching index
1114  @retval - substring index or npos if not found
1115  **/
1116  template<range_of_t_c<char_t> string_t>
1117  size_type find(string_t sWhat, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1118 
1119  /**
1120  @brief Find substring (reverse direction)
1121  @param chSymbol - char to find
1122  @param nBegin - start searching index
1123  @param nEnd - end searching index
1124  (if nBegin < end, result is equivalent of find(...))
1125  @retval - substring index or npos if not found
1126  **/
1127  size_type rfind(value_type chSymbol, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1128 
1129  /**
1130  @brief Find substring (reverse direction)
1131  @param pszWhat - c-string to find
1132  @param nBegin - start searching index
1133  @param nWhatSize - c-string length
1134  @param nEnd - end searching index
1135  (if nBegin < end, result is equivalent of find(...))
1136  @retval - substring index or npos if not found
1137  **/
1138  size_type rfind(const_pointer pszWhat, size_type nBegin = npos, size_type nWhatSize = npos, size_type nEnd = 0)
1139  const noexcept;
1140 
1141  /**
1142  @brief Find substring (reverse direction)
1143  @param sWhat - string to find
1144  @param nBegin - start searching index
1145  @param nEnd - end searching index
1146  (if nBegin < end, result is equivalent of find(...))
1147  @retval - substring index or npos if not found
1148  **/
1149  size_type rfind(const basic_string& sWhat, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1150 
1151  /**
1152  @brief Find substring (reverse direction)
1153  @tparam fwd_it_t - forward iterator type
1154  @param itWhatBegin - substring begin iterator
1155  @param itWhatEnd - substring end iterator
1156  @param nBegin - start searching index
1157  @param nEnd - end searching index
1158  (if nBegin < end, result is equivalent of find(...))
1159  @retval - substring index or npos if not found
1160  **/
1161  template<class fwd_it_t>
1162  size_type rfind(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = npos, size_type nEnd = 0)
1163  const noexcept;
1164 
1165  /**
1166  @brief Find substring (reverse direction)
1167  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1168  @param sWhat - substring
1169  @param nBegin - start searching index
1170  @param nEnd - end searching index
1171  (if nBegin < end, result is equivalent of find(...))
1172  @retval - substring index or npos if not found
1173  **/
1174  template<range_of_t_c<char_t> string_t>
1175  size_type rfind(string_t sWhat, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1176 
1177  /**
1178  @brief Find first position of character
1179  @param chSymbol - char to find
1180  @param nBegin - position at which the search is to begin
1181  @retval - symbol index or npos
1182  **/
1183  size_type find_first_of(value_type chSymbol, size_type nBegin = 0) const noexcept;
1184 
1185  /**
1186  @brief Finds the first character equal to one of characters in the given character sequence
1187  @param pszWhat - string identifying characters to search for
1188  @param nBegin - position at which the search is to begin
1189  @param nWhatSize - length of character string identifying characters to search for
1190  @retval - symbol index or npos
1191  **/
1192  size_type find_first_of(const_pointer pszWhat, size_type nBegin, size_type nWhatSize) const noexcept;
1193 
1194  /**
1195  @brief Finds the first character equal to one of characters in the given character sequence
1196  @param pszWhat - null terminated string identifying characters to search for
1197  @param nBegin - position at which the search is to begin
1198  @retval - symbol index or npos
1199  **/
1200  size_type find_first_of(const_pointer pszWhat, size_type nBegin = 0) const noexcept;
1201 
1202  /**
1203  @brief Finds the first character equal to one of characters in the given character sequence
1204  @param sWhat - string identifying characters to search for
1205  @param nBegin - position at which the search is to begin
1206  @retval - symbol index or npos
1207  **/
1208  size_type find_first_of(const basic_string& sWhat, size_type nBegin = 0) const noexcept;
1209 
1210  /**
1211  @brief Finds the first character equal to one of characters in the given character sequence
1212  @tparam fwd_it_t - forward iterator type
1213  @param itWhatBegin - begin it of string identifying characters to search for
1214  @param itWhatEnd - end it of string identifying characters to search for
1215  @param nBegin - position at which the search is to begin
1216  @retval - symbol index or npos
1217  **/
1218  template<class fwd_it_t>
1219  size_type find_first_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0) const noexcept;
1220 
1221  /**
1222  @brief Finds the first character equal to one of characters in the given character sequence
1223  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1224  @param sWhat - string identifying characters to search for
1225  @param nBegin - position at which the search is to begin
1226  @retval - symbol index or npos
1227  **/
1228  template<range_of_t_c<char_t> string_t>
1229  size_type find_first_of(string_t sWhat, size_type nBegin = 0) const noexcept;
1230 
1231  /**
1232  @brief Find last position of character
1233  @param chSymbol - char to find
1234  @param nEnd - position at which the search is to finish
1235  @retval - symbol index or npos
1236  **/
1237  size_type find_last_of(value_type chSymbol, size_type nEnd = 0) const noexcept;
1238 
1239  /**
1240  @brief Finds the last character equal to one of characters in the given character sequence
1241  @param pszWhat - string identifying characters to search for
1242  @param nEnd - position at which the search is to finish
1243  @param nWhatSize - length of character string identifying characters to search for
1244  @retval - symbol index or npos
1245  **/
1246  size_type find_last_of(const_pointer pszWhat, size_type nEnd, size_type nWhatSize) const noexcept;
1247 
1248  /**
1249  @brief Finds the last character equal to one of characters in the given character sequence
1250  @param pszWhat - null terminated string identifying characters to search for
1251  @param nEnd - position at which the search is to finish
1252  @retval - symbol index or npos
1253  **/
1254  size_type find_last_of(const_pointer pszWhat, size_type nEnd = 0) const noexcept;
1255 
1256  /**
1257  @brief Finds the last character equal to one of characters in the given character sequence
1258  @param sWhat - string identifying characters to search for
1259  @param nEnd - position at which the search is to finish
1260  @retval - symbol index or npos
1261  **/
1262  size_type find_last_of(const basic_string& sWhat, size_type nEnd = 0) const noexcept;
1263 
1264  /**
1265  @brief Finds the last character equal to one of characters in the given character sequence
1266  @tparam fwd_it_t - forward iterator type
1267  @param itWhatBegin - begin it of string identifying characters to search for
1268  @param itWhatEnd - end it of string identifying characters to search for
1269  @param nEnd - position at which the search is to finish
1270  @retval - symbol index or npos
1271  **/
1272  template<class fwd_it_t>
1273  size_type find_last_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nEnd = 0) const noexcept;
1274 
1275  /**
1276  @brief Finds the last character equal to one of characters in the given character sequence
1277  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1278  @param sWhat - string identifying characters to search for
1279  @param nEnd - position at which the search is to finish
1280  @retval - symbol index or npos
1281  **/
1282  template<range_of_t_c<char_t> string_t>
1283  size_type find_last_of(string_t sWhat, size_type nEnd = 0) const noexcept;
1284 
1285  /**
1286  @brief Finds the first character not equal to chSymbol
1287  @param chSymbol - char to find
1288  @param nBegin - position at which the search is to begin
1289  @retval - symbol index or npos
1290  **/
1291  size_type find_first_not_of(value_type chSymbol, size_type nBegin = 0) const noexcept;
1292 
1293  /**
1294  @brief Finds the first character equal to none of the characters in the given character sequence
1295  @param pszWhat - string identifying characters to search for
1296  @param nBegin - position at which the search is to begin
1297  @param nWhatSize - length of character string identifying characters to search for
1298  @retval - symbol index or npos
1299  **/
1300  size_type find_first_not_of(const_pointer pszWhat, size_type nBegin, size_type nWhatSize) const noexcept;
1301 
1302  /**
1303  @brief Finds the first character equal to none of the characters in the given character sequence
1304  @param pszWhat - null terminated string identifying characters to search for
1305  @param nBegin - position at which the search is to begin
1306  @retval - symbol index or npos
1307  **/
1308  size_type find_first_not_of(const_pointer pszWhat, size_type nBegin = 0) const noexcept;
1309 
1310  /**
1311  @brief Finds the first character equal to none of the characters in the given character sequence
1312  @param sWhat - string identifying characters to search for
1313  @param nBegin - position at which the search is to begin
1314  @retval - symbol index or npos
1315  **/
1316  size_type find_first_not_of(const basic_string& sWhat, size_type nBegin = 0) const noexcept;
1317 
1318  /**
1319  @brief Finds the first character equal to none of the characters in the given character sequence
1320  @tparam fwd_it_t - forward iterator type
1321  @param itWhatBegin - begin it of string identifying characters to search for
1322  @param itWhatEnd - end it of string identifying characters to search for
1323  @param nBegin - position at which the search is to begin
1324  @retval - symbol index or npos
1325  **/
1326  template<class fwd_it_t>
1327  size_type find_first_not_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0) const noexcept;
1328 
1329  /**
1330  @brief Finds the first character equal to none of the characters in the given character sequence
1331  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1332  @param sWhat - string identifying characters to search for
1333  @param nBegin - position at which the search is to begin
1334  @retval - symbol index or npos
1335  **/
1336  template<range_of_t_c<char_t> string_t>
1337  size_type find_first_not_of(string_t sWhat, size_type nBegin = 0) const noexcept;
1338 
1339  /**
1340  @brief Finds the last character not equal to chSymbol
1341  @param chSymbol - char to find
1342  @param nEnd - position at which the search is to finish
1343  @retval - symbol index or npos
1344  **/
1345  size_type find_last_not_of(value_type chSymbol, size_type nEnd = 0) const noexcept;
1346 
1347  /**
1348  @brief Finds the last character equal to none of the characters in the given character sequence
1349  @param pszWhat - string identifying characters to search for
1350  @param nEnd - position at which the search is to finish
1351  @param nWhatSize - length of character string identifying characters to search for
1352  @retval - symbol index or npos
1353  **/
1354  size_type find_last_not_of(const_pointer pszWhat, size_type nEnd, size_type nWhatSize) const noexcept;
1355 
1356  /**
1357  @brief Finds the last character equal to none of the characters in the given character sequence
1358  @param pszWhat - null terminated string identifying characters to search for
1359  @param nEnd - position at which the search is to finish
1360  @retval - symbol index or npos
1361  **/
1362  size_type find_last_not_of(const_pointer pszWhat, size_type nEnd = 0) const noexcept;
1363 
1364  /**
1365  @brief Finds the last character equal to none of the characters in the given character sequence
1366  @param sWhat - string identifying characters to search for
1367  @param nEnd - position at which the search is to finish
1368  @retval - symbol index or npos
1369  **/
1370  size_type find_last_not_of(const basic_string& sWhat, size_type nEnd = 0) const noexcept;
1371 
1372  /**
1373  @brief Finds the last character equal to none of the characters in the given character sequence
1374  @tparam fwd_it_t - forward iterator type
1375  @param itWhatBegin - begin it of string identifying characters to search for
1376  @param itWhatEnd - end it of string identifying characters to search for
1377  @param nEnd - position at which the search is to finish
1378  @retval - symbol index or npos
1379  **/
1380  template<class fwd_it_t>
1381  size_type find_last_not_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nEnd = 0) const noexcept;
1382 
1383  /**
1384  @brief Finds the last character equal to none of the characters in the given character sequence
1385  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1386  @param sWhat - string identifying characters to search for
1387  @param nEnd - position at which the search is to finish
1388  @retval - symbol index or npos
1389  **/
1390  template<range_of_t_c<char_t> string_t>
1391  size_type find_last_not_of(string_t sWhat, size_type nEnd = 0) const noexcept;
1392 
1393  /**
1394  @brief Split string by separator
1395  @param chSeparator - char separator
1396  @retval - string_view container
1397  **/
1398  views split(const value_type chSeparator) const noexcept;
1399 
1400  /**
1401  @brief Split string by separator
1402  @param pszSeparator - separator string
1403  @param nSepLen - separator string length (npos if str is null terminated)
1404  @retval - string_view container
1405  **/
1406  views split(const_pointer pszSeparator, size_type nSepLen = npos) const noexcept;
1407 
1408  /**
1409  @brief Split string by separator
1410  @param sSeparator - separator string
1411  @retval - string_view container
1412  **/
1413  views split(const basic_string& sSeparator) const noexcept;
1414 
1415  /**
1416  @brief Split string by separator
1417  @tparam fwd_it_t - forward iterator type
1418  @param itSepFirst - separator begin iterator
1419  @param itSepLast - separator end iterator
1420  @retval - string_view container
1421  **/
1422  template<class fwd_it_t>
1423  views split(fwd_it_t itSepFirst, fwd_it_t itSepLast) const noexcept;
1424 
1425  /**
1426  @brief Split string by separator
1427  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1428  @param sSeparator - separator string
1429  @retval - string_view container
1430  **/
1431  template<range_of_t_c<char_t> string_t>
1432  views split(const string_t& sSeparator) const noexcept;
1433 
1434  /**
1435  @brief Check if current string starts with char
1436  @param chSymbol - char for comparison
1437  @retval - true if starts with char
1438  **/
1439  bool starts_with(value_type chSymbol) const noexcept;
1440 
1441  /**
1442  @brief Check if current string starts with string
1443  @param pszStr - const pointer to string
1444  @param nStrSize - string length
1445  @retval - true if starts with string
1446  **/
1447  bool starts_with(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1448 
1449  /**
1450  @brief Check if current string starts with string
1451  @param sStr - string to check
1452  @retval - true if starts with string
1453  **/
1454  bool starts_with(const basic_string& sStr) const noexcept;
1455 
1456  /**
1457  @brief Check if current string starts with string
1458  @tparam fwd_it_t - forward iterator type
1459  @param itBegin - string begin iterator
1460  @param itEnd - string end iterator
1461  @retval - true if starts with string
1462  **/
1463  template<class fwd_it_t>
1464  bool starts_with(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1465 
1466  /**
1467  @brief Check if current string starts with string
1468  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1469  @param sStr - string container to check
1470  @retval - true if starts with string
1471  **/
1472  template<range_of_t_c<char_t> string_t>
1473  bool starts_with(const string_t& sStr) const noexcept;
1474 
1475  /**
1476  @brief Check if current string ends with char
1477  @param chSymbol - char for comparison
1478  @retval - true if ends with char
1479  **/
1480  bool ends_with(value_type chSymbol) const noexcept;
1481 
1482  /**
1483  @brief Check if current string ends with string
1484  @param pszStr - const pointer to string
1485  @param nStrSize - string length
1486  @retval - true if ends with string
1487  **/
1488  bool ends_with(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1489 
1490  /**
1491  @brief Check if current string ends with string
1492  @param sStr - string to check
1493  @retval - true if starts with string
1494  **/
1495  bool ends_with(const basic_string& sStr) const noexcept;
1496 
1497  /**
1498  @brief Check if current string ends with string
1499  @tparam fwd_it_t - forward iterator type
1500  @param itBegin - string begin iterator
1501  @param itEnd - string end iterator
1502  @retval - true if ends with string
1503  **/
1504  template<class fwd_it_t>
1505  bool ends_with(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1506 
1507  /**
1508  @brief Check if current string ends with string
1509  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1510  @param sStr - string container to check
1511  @retval - true if starts with string
1512  **/
1513  template<range_of_t_c<char_t> string_t>
1514  bool ends_with(const string_t& sStr) const noexcept;
1515 
1516  /**
1517  @brief Check if string contains char
1518  @details Equal to find != npos
1519  @param chSymbol - char to check
1520  @retval - true if this string contains substring
1521  **/
1522  bool contains(value_type chSymbol) const noexcept;
1523 
1524  /**
1525  @brief Check if string contains substring
1526  @details Equal to find != npos
1527  @param pszStr - substring to check
1528  @param nStrSize - substring size
1529  @retval - true if this string contains substring
1530  **/
1531  bool contains(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1532 
1533  /**
1534  @brief Check if string contains substring
1535  @details Equal to find != npos
1536  @param sStr - string to check
1537  @retval - true if this string contains substring
1538  **/
1539  bool contains(const basic_string& sStr) const noexcept;
1540 
1541  /**
1542  @brief Check if string contains substring
1543  @details Equal to find != npos
1544  @tparam fwd_it_t - forward iterator type
1545  @param itBegin - substring begin iterator
1546  @param itEnd - substring end iterator
1547  @retval - true if this string contains substring
1548  **/
1549  template<class fwd_it_t>
1550  bool contains(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1551 
1552  /**
1553  @brief Check if string contains substring
1554  @details Equal to find != npos
1555  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1556  @param sStr - string to check
1557  @retval - true if this string contains substring
1558  **/
1559  template<range_of_t_c<char_t> string_t>
1560  bool contains(const string_t& sStr) const noexcept;
1561 
1562  basic_string& operator=(const_pointer pszSource) noexcept;
1563  basic_string& operator=(basic_string&& sStr) noexcept;
1564  basic_string& operator=(const basic_string& sStr) noexcept;
1565  template<range_of_t_c<char_t> string_t>
1566  basic_string& operator=(const string_t& sStr) noexcept;
1567 
1568  basic_string& operator+=(value_type chSymbol) noexcept;
1569  basic_string& operator+=(const_pointer pszSource) noexcept;
1570  basic_string& operator+=(const basic_string& sStr) noexcept;
1571  template<range_of_t_c<char_t> string_t>
1572  basic_string& operator+=(const string_t& sStr) noexcept;
1573 
1574  bool operator==(value_type chSymbol) const noexcept;
1575  bool operator==(const_pointer pszSource) const noexcept;
1576  bool operator==(const basic_string& sStr) const noexcept;
1577  template<range_of_t_c<char_t> string_t>
1578  bool operator==(const string_t& sStr) const noexcept;
1579 
1580  bool operator!=(value_type chSymbol) const noexcept;
1581  bool operator!=(const_pointer pszSource) const noexcept;
1582  bool operator!=(const basic_string& sStr) const noexcept;
1583  template<range_of_t_c<char_t> string_t>
1584  bool operator!=(const string_t& sStr) const noexcept;
1585 
1586  bool operator<(value_type chSymbol) const noexcept;
1587  bool operator<(const_pointer pszSource) const noexcept;
1588  bool operator<(const basic_string& sStr) const noexcept;
1589  template<range_of_t_c<char_t> string_t>
1590  bool operator<(const string_t& sStr) const noexcept;
1591 
1592  bool operator<=(value_type chSymbol) const noexcept;
1593  bool operator<=(const_pointer pszSource) const noexcept;
1594  bool operator<=(const basic_string& sStr) const noexcept;
1595  template<range_of_t_c<char_t> string_t>
1596  bool operator<=(const string_t& sStr) const noexcept;
1597 
1598  bool operator>(value_type chSymbol) const noexcept;
1599  bool operator>(const_pointer pszSource) const noexcept;
1600  bool operator>(const basic_string& sStr) const noexcept;
1601  template<range_of_t_c<char_t> string_t>
1602  bool operator>(const string_t& sStr) const noexcept;
1603 
1604  bool operator>=(value_type chSymbol) const noexcept;
1605  bool operator>=(const_pointer pszSource) const noexcept;
1606  bool operator>=(const basic_string& sStr) const noexcept;
1607  template<range_of_t_c<char_t> string_t>
1608  bool operator>=(const string_t& sStr) const noexcept;
1609 
1610  reference operator[](size_type nSymbol) noexcept;
1611  const_reference operator[](size_type nSymbol) const noexcept;
1612 
1613  operator string_view() const noexcept;
1614 
1615  explicit operator bool() const noexcept;
1616 
1617 private:
1618  /**
1619  @brief Common algorithm for trimming string to the left
1620  @tparam searcher_t - "searcher" type
1621  @param searcher - function that returns true if symbol has to be deleted
1622  @retval - number of deleted symbols
1623  **/
1624  template<class searcher_t>
1625  size_type _trim_left(const searcher_t& searcher) noexcept;
1626 
1627  /**
1628  @brief Common algorithm for trimming string to the right
1629  @tparam searcher_t - "searcher" type
1630  @param searcher - function that returns true if symbol has to be deleted
1631  @retval - number of deleted symbols
1632  **/
1633  template<class searcher_t>
1634  size_type _trim_right(const searcher_t& searcher) noexcept;
1635 
1636  /**
1637  @brief Common algorithm for trimming string to the both sides
1638  @tparam searcher_t - "searcher" type
1639  @param searcher - function that returns true if symbol has to be deleted
1640  @retval - number of deleted symbols
1641  **/
1642  template<class searcher_t>
1643  size_type _trim(const searcher_t& searcher) noexcept;
1644 
1645  /**
1646  @brief Common algorithm for finding substring
1647  @tparam comparator_t - "comparator" type
1648  @param nBegin - start searching index
1649  @param nEnd - end searching index (npos - to the end)
1650  @param comparator - comparator function
1651  @retval - substring index or npos if not found
1652  **/
1653  template<class comparator_t>
1654  size_type _find(size_type nBegin, size_type nEnd, const comparator_t& comparator) const noexcept;
1655 
1656  /**
1657  @brief Common algorithm for finding substring, starting from the end
1658  @tparam comparator_t - "comparator" type
1659  @param nBegin - start searching index
1660  @param nEnd - end searching index
1661  @param comparator - comparator function
1662  @retval - substring index or npos if not found
1663  **/
1664  template<class comparator_t>
1665  size_type _rfind(size_type nBegin, size_type nEnd, const comparator_t& comparator) const noexcept;
1666 
1667  /**
1668  @brief Common algorithm for find_first_of
1669  @tparam incrementer_t - "incrementer" type
1670  @tparam fwd_it_t - forward iterator type
1671  @param itBegin - begin it of "of" string
1672  @param itEnd - end it of "of" string
1673  @param nBegin - position at which the search is to begin
1674  @param incrementer - function that increments iterator and returns itEnd when string is over
1675  @retval - symbol index or npos
1676  **/
1677  template<class incrementer_t, class fwd_it_t>
1678  size_type _find_first_of(fwd_it_t itBegin, fwd_it_t itEnd, size_type nBegin, const incrementer_t& incrementer)
1679  const noexcept;
1680 
1681  /**
1682  @brief Common algorithm for find_last_of
1683  @tparam incrementer_t - "incrementer" type
1684  @tparam fwd_it_t - forward iterator type
1685  @param itBegin - begin it of "of" string
1686  @param itEnd - end it of "of" string
1687  @param nEnd - position at which the search is to finish
1688  @param incrementer - function that increments iterator and returns itEnd when string is over
1689  @retval - symbol index or npos
1690  **/
1691  template<class incrementer_t, class fwd_it_t>
1692  size_type _find_last_of(fwd_it_t itBegin, fwd_it_t itEnd, size_type nEnd, const incrementer_t& incrementer)
1693  const noexcept;
1694 
1695  /**
1696  @brief Common algorithm for find_first_not_of
1697  @tparam incrementer_t - "incrementer" type
1698  @tparam fwd_it_t - forward iterator type
1699  @param itBegin - begin it of "of" string
1700  @param itEnd - end it of "of" string
1701  @param nBegin - position at which the search is to begin
1702  @param incrementer - function that increments iterator and returns itEnd when string is over
1703  @retval - symbol index or npos
1704  **/
1705  template<class incrementer_t, class fwd_it_t>
1706  size_type _find_first_not_of(fwd_it_t itBegin, fwd_it_t itEnd, size_type nBegin, const incrementer_t& incrementer)
1707  const noexcept;
1708 
1709  /**
1710  @brief Common algorithm for find_last_not_of
1711  @tparam incrementer_t - "incrementer" type
1712  @tparam fwd_it_t - forward iterator type
1713  @param itBegin - begin it of "of" string
1714  @param itEnd - end it of "of" string
1715  @param nEnd - position at which the search is to finish
1716  @param incrementer - function that increments iterator and returns itEnd when string is over
1717  @retval - symbol index or npos
1718  **/
1719  template<class incrementer_t, class fwd_it_t>
1720  size_type _find_last_not_of(fwd_it_t itBegin, fwd_it_t itEnd, size_type nEnd, const incrementer_t& incrementer)
1721  const noexcept;
1722 
1723  /**
1724  @brief Get the size of a string like type object
1725  @tparam string_view_like_t - string like type
1726  @param sValue - string like type object
1727  @retval - string like type object size
1728  **/
1729  template<class string_view_like_t>
1730  static size_type _get_string_view_like_size(const string_view_like_t& sValue) noexcept;
1731 
1732  /**
1733  @brief Get the data of a string like type object
1734  @tparam string_view_like_t - string like type
1735  @param sValue - string like type object
1736  @retval - string like type object data
1737  **/
1738  template<class string_view_like_t>
1739  static const_pointer _get_string_view_like_data(const string_view_like_t& sValue) noexcept;
1740 
1741 private:
1742  sbo_bytes<details::string_sbo_traits<traits_t>> m_Data;
1743 };
1744 
1745 using cstring = basic_string<char>;
1746 using wstring = basic_string<wchar_t>;
1747 using string = basic_string<char_type>;
1748 
1749 } // namespace qx
1750 
1751 #include <qx/containers/string/string.inl>
String class.
Definition: string.h:83
void push_back(value_type chSymbol) noexcept
Insert char in the end of the string.
Definition: string.inl:589
void erase(iterator itFirst, iterator itLast) noexcept
Erase substring.
Definition: string.inl:603
size_type find(value_type chSymbol, size_type nBegin=0, size_type nEnd=npos) const noexcept
Find substring.
Definition: string.inl:1309
bool remove_prefix(value_type chSymbol) noexcept
Remove string prefix if matches.
Definition: string.inl:1034
size_type remove_all(value_type chSymbol, size_type nBegin=0, size_type nEnd=npos) noexcept
Remove all occurrences of a substring in a string.
Definition: string.inl:1111
std::optional< to_t > to(const_pointer pszFormat=nullptr) const noexcept
Convert string to specified type.
Definition: string.inl:293
int compare(value_type chSymbol) const noexcept
Performs a binary comparison of the characters.
Definition: string.inl:1271
size_type find_last_of(value_type chSymbol, size_type nEnd=0) const noexcept
Find last position of character.
Definition: string.inl:1560
void push_front(value_type chSymbol) noexcept
Insert char in the beginning of the string.
Definition: string.inl:597
size_type capacity() const noexcept
Get allocated memory size (including null terminator)
Definition: string.inl:279
value_type pop_back() noexcept
Erase last char and return it.
Definition: string.inl:641
size_type copy(pointer pDest, size_type nCount, size_type nPos=0) const noexcept
Copies a substring [nPos, nPos + nCount) to character string pointed to by pDest.
Definition: string.inl:356
views split(const value_type chSeparator) const noexcept
Split string by separator.
Definition: string.inl:1833
requires format_acceptable_args_c< char_t, args_t... > void append_format(const format_string_type< std::type_identity_t< args_t >... > sFormat, args_t &&... args) noexcept
Append the formatted string to the current one.
Definition: string.inl:146
size_type rfind(value_type chSymbol, size_type nBegin=npos, size_type nEnd=0) const noexcept
Find substring (reverse direction)
Definition: string.inl:1391
size_type length() const noexcept
Get string length.
Definition: string.inl:267
void free() noexcept
Clear string and free allocated memory.
Definition: string.inl:226
void from(const from_t &data)
Construct string from custom type.
Definition: string.inl:374
size_type trim_right() noexcept
Trim the string to the right (whitespace characters)
Definition: string.inl:757
requires format_acceptable_args_c< char_t, args_t... > void vformat(string_view svFormat, args_t &&... args)
Clear the string and format it with the format string and the args.
Definition: string.inl:156
void assign(size_type nSymbols, value_type chSymbol) noexcept
Assign by filling.
Definition: string.inl:58
size_type replace_all(const find_string_t &sFind, const replace_string_t &sReplace, size_type nBegin=0, size_type nEnd=npos) noexcept
Replace all occurrences of sFind with sReplace.
Definition: string.inl:1251
bool ends_with(value_type chSymbol) const noexcept
Check if current string ends with char.
Definition: string.inl:1969
void swap(basic_string &sOther) noexcept
Swap this str and other.
Definition: string.inl:195
value_type pop_front() noexcept
Erase first char and return it.
Definition: string.inl:649
void append(value_type chSymbol) noexcept
Append char.
Definition: string.inl:413
size_type trim() noexcept
Trim the string to the both sides (whitespace characters)
Definition: string.inl:857
void to_upper() noexcept
Convert string to uppercase.
Definition: string.inl:248
void shrink_to_fit() noexcept
Fit allocated size to string's actual size.
Definition: string.inl:220
static basic_string static_from(const from_t &data)
Construct string from custom type and get it.
size_type find_last_not_of(value_type chSymbol, size_type nEnd=0) const noexcept
Finds the last character not equal to chSymbol.
Definition: string.inl:1740
size_type trim_left() noexcept
Trim the string to the left (whitespace characters)
Definition: string.inl:657
size_type reserve(size_type nCapacity) noexcept
Reserve memory for the string.
Definition: string.inl:201
requires format_acceptable_args_c< char_t, args_t... > void append_vformat(string_view svFormat, args_t &&... args)
Append the formatted string to the current one.
Definition: string.inl:177
string_view substr(size_type nPos, size_type nSymbols=npos) const noexcept
Get substring.
Definition: string.inl:233
void to_lower() noexcept
Convert string to lowercase.
Definition: string.inl:241
size_type insert(size_type nPos, value_type chSymbol) noexcept
Insert substring.
Definition: string.inl:460
bool remove_suffix(value_type chSymbol) noexcept
Remove string suffix if matches.
Definition: string.inl:1067
const_pointer c_str() const noexcept
Get pointer to string zero terminated.
Definition: string.inl:273
requires static format_acceptable_args_c< char_t, args_t... > basic_string static_format(const format_string_type< std::type_identity_t< args_t >... > sFormat, args_t &&... args) noexcept
Create a string by formatting it with the format string and the args.
requires static format_acceptable_args_c< char_t, args_t... > basic_string static_vformat(string_view svFormat, args_t &&... args)
Create a string by formatting it with the format string and the args.
size_type remove(value_type chSymbol, size_type nBegin=0, size_type nEnd=npos) noexcept
Remove the first occurrence of a substring in a string.
Definition: string.inl:957
static constexpr size_type max_size() noexcept
Get the theoretical maximum of string size.
Definition: string.inl:285
bool starts_with(value_type chSymbol) const noexcept
Check if current string starts with char.
Definition: string.inl:1921
value_type front() const noexcept
Get first char of the string.
Definition: string.inl:255
value_type back() const noexcept
Get last char of the string.
Definition: string.inl:261
size_type replace(size_type nBegin, size_type nSize, const_pointer pszReplace, size_t nReplaceSize) noexcept
Replace a substring with a given string.
Definition: string.inl:1194
size_type find_first_of(value_type chSymbol, size_type nBegin=0) const noexcept
Find first position of character.
Definition: string.inl:1473
bool resize(size_type nSymbols) noexcept
Resize string.
Definition: string.inl:209
size_type find_first_not_of(value_type chSymbol, size_type nBegin=0) const noexcept
Finds the first character not equal to chSymbol.
Definition: string.inl:1647
requires format_acceptable_args_c< char_t, args_t... > void format(const format_string_type< std::type_identity_t< args_t >... > sFormat, args_t &&... args) noexcept
Clear the string and format it with the format string and the args.
Definition: string.inl:124
Const random access iterator type.
Definition: iterator.h:74
Non-const random access iterator type.
Definition: iterator.h:35
A type erased small buffer object that works with raw data.
Definition: sbo_bytes.h:31
requires(same_variadic_args_v< args_t... >) const expr auto coalesce(args_t &&... args)
Coalesce function, C# a ?? b analogue.
Definition: coalesce.inl:57
Static assert macros.
Check that tuple type contains T.