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 © 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 Fit allocated size to string's actual size
294  **/
295  void shrink_to_fit() noexcept;
296 
297  /**
298  @brief Clear string and free allocated memory
299  **/
300  void free() noexcept;
301 
302  /**
303  @brief Get substring
304  @param nPos - start index
305  @param nSymbols - string size (npos - to the end)
306  @retval - substring view
307  **/
308  string_view substr(size_type nPos, size_type nSymbols = npos) const noexcept;
309 
310  /**
311  @brief Convert string to lowercase
312  **/
313  void to_lower() noexcept;
314 
315  /**
316  @brief Convert string to uppercase
317  **/
318  void to_upper() noexcept;
319 
320  /**
321  @brief Get first char of the string
322  @retval - first char of the string
323  **/
324  value_type front() const noexcept;
325 
326  /**
327  @brief Get last char of the string
328  @retval - last char of the string
329  **/
330  value_type back() const noexcept;
331 
332  /**
333  @brief Get string length
334  @brief Same as size()
335  @retval - string length
336  **/
337  size_type length() const noexcept;
338 
339  /**
340  @brief Get pointer to string zero terminated
341  @retval - pointer to string zero terminated
342  **/
343  const_pointer c_str() const noexcept;
344 
345  /**
346  @brief Get allocated memory size (including null terminator)
347  @retval - allocated memory size
348  **/
349  size_type capacity() const noexcept;
350 
351  /**
352  @brief Get the theoretical maximum of string size
353  @retval - theoretical maximum of string size
354  **/
355  static constexpr size_type max_size() noexcept;
356 
357  /**
358  @brief Convert string to specified type
359  @warning This function currently uses unsafe scanf functions from the c library,
360  since the current implementation of the standard library
361  does not have an implementation of fmt::scan (https://github.com/fmtlib/fmt/blob/master/test/scan.h).
362  Status: https://github.com/cplusplus/papers/issues/493
363  This will be fixed in the future when possible.
364  @tparam to_t - type to convert
365  @param pszFormat - format string (according to https://en.cppreference.com/w/c/io/fscanf)
366  @retval - converted value or std::nullopt
367  **/
368  template<class to_t>
369  std::optional<to_t> to(const_pointer pszFormat = nullptr) const noexcept;
370 
371  /**
372  @brief Copies a substring [nPos, nPos + nCount) to character string pointed to by pDest
373  @param pDest - pointer to the destination character string
374  @param nCount - length of the substring
375  @param nPos - position of the first character to include
376  @retval - number of characters copied
377  **/
378  size_type copy(pointer pDest, size_type nCount, size_type nPos = 0) const noexcept;
379 
380  /**
381  @brief Construct string from custom type
382  @tparam from_t - type to convert from
383  @param data - data of type from_type
384  **/
385  template<class from_t>
386  void from(const from_t& data);
387 
388  /**
389  @brief Construct string from custom type and get it
390  @tparam from_t - type to convert from
391  @param data - data of type from_type
392  @retval - constructed string
393  **/
394  template<class from_t>
395  static basic_string static_from(const from_t& data);
396 
397  /**
398  @brief Append char
399  @param chSymbol - char to append
400  **/
401  void append(value_type chSymbol) noexcept;
402 
403  /**
404  @brief Append string
405  @param pszStr - source string
406  @param nStrSize - source string size
407  **/
408  void append(const_pointer pszStr, size_type nStrSize = npos) noexcept;
409 
410  /**
411  @brief Append string
412  @param sStr - source string
413  **/
414  void append(const basic_string& sStr) noexcept;
415 
416  /**
417  @brief Append string
418  @tparam fwd_it_t - forward iterator type
419  @param itBegin - other string begin iterator
420  @param itEnd - other end begin iterator
421  **/
422  template<class fwd_it_t>
423  void append(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
424 
425  /**
426  @brief Append string
427  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
428  @param sStr - source char container
429  **/
430  template<range_of_t_c<char_t> string_t>
431  void append(const string_t& sStr) noexcept;
432 
433  /**
434  @brief Insert substring
435  @param nPos - first char index
436  @param chSymbol - symbol to insert
437  @retval - pos of char after last char of inserted string or npos
438  **/
439  size_type insert(size_type nPos, value_type chSymbol) noexcept;
440 
441  /**
442  @brief Insert substring
443  @param nPos - first char index
444  @param pszWhat - source string
445  @param nSymbols - number of symbols to insert
446  @retval - pos of char after last char of inserted string or npos
447  **/
448  size_type insert(size_type nPos, const_pointer pszWhat, size_type nSymbols = npos) noexcept;
449 
450  /**
451  @brief Insert substring
452  @param nPos - first char index
453  @param sWhat - string to insert
454  @retval - pos of char after last char of inserted string or npos
455  **/
456  size_type insert(size_type nPos, const basic_string& sWhat) noexcept;
457 
458  /**
459  @brief Insert substring
460  @tparam fwd_it_t - forward iterator type
461  @param nPos - first char index
462  @param itWhatBegin - source first iterator
463  @param itWhatEnd - source last iterator
464  @retval - pos of char after last char of inserted string or npos
465  **/
466  template<class fwd_it_t>
467  size_type insert(size_type nPos, fwd_it_t itWhatBegin, fwd_it_t itWhatEnd) noexcept;
468 
469  /**
470  @brief Insert substring
471  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
472  @param nPos - first char index
473  @param sWhat - source string
474  @retval - pos of char after last char of inserted string or npos
475  **/
476  template<range_of_t_c<char_t> string_t>
477  size_type insert(size_type nPos, string_t sWhat) noexcept;
478 
479  /**
480  @brief Insert char
481  @param itPos - first char iterator
482  @param chSymbol - char to insert
483  @retval - pos of char after last char of inserted string or npos
484  **/
485  size_type insert(const_iterator itPos, value_type chSymbol) noexcept;
486 
487  /**
488  @brief Insert substring
489  @param itPos - first char iterator
490  @param pszWhat - source string
491  @param nSymbols - number of symbols to insert
492  @retval - pos of char after last char of inserted string or npos
493  **/
494  size_type insert(const_iterator itPos, const_pointer pszWhat, size_type nSymbols = npos) noexcept;
495 
496  /**
497  @brief Insert substring
498  @param itPos - first char iterator
499  @param sWhat - string to insert
500  @retval - pos of char after last char of inserted string or npos
501  **/
502  size_type insert(const_iterator itPos, const basic_string& sWhat) noexcept;
503 
504  /**
505  @brief Insert substring
506  @tparam fwd_it_t - forward iterator type
507  @param itPos - first char iterator
508  @param itWhatBegin - source string first iterator
509  @param itWhatEnd - source string last iterator
510  @retval - pos of char after last char of inserted string or npos
511  **/
512  template<class fwd_it_t>
513  size_type insert(const_iterator itPos, fwd_it_t itWhatBegin, fwd_it_t itWhatEnd) noexcept;
514 
515  /**
516  @brief Insert substring
517  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
518  @param itPos - first char iterator
519  @param sWhat - source string
520  @retval - pos of char after last char of inserted string or npos
521  **/
522  template<range_of_t_c<char_t> string_t>
523  size_type insert(const_iterator itPos, string_t sWhat) noexcept;
524 
525  /**
526  @brief Insert char in the end of the string
527  @param chSymbol - char to insert
528  **/
529  void push_back(value_type chSymbol) noexcept;
530 
531  /**
532  @brief Insert char in the beginning of the string
533  @param chSymbol - char to insert
534  **/
535  void push_front(value_type chSymbol) noexcept;
536 
537  /**
538  @brief Erase substring
539  @param itFirst - first substr char iterator
540  @param itLast - last substr char iterator (excluded)
541  **/
542  void erase(iterator itFirst, iterator itLast) noexcept;
543 
544  /**
545  @brief Erase on iterator
546  @param itPos - iterator where to erase
547  **/
548  void erase(iterator itPos) noexcept;
549 
550  /**
551  @brief Erase on position
552  @param nPos - index where to erase
553  **/
554  void erase(size_type nPos) noexcept;
555 
556  /**
557  @brief Erase substring
558  @param nPos - start position
559  @param nSymbols - number of symbols
560  **/
561  void erase(size_type nPos, size_type nSymbols) noexcept;
562 
563  /**
564  @brief Erase last char and return it
565  @retval - last char
566  **/
567  value_type pop_back() noexcept;
568 
569  /**
570  @brief Erase first char and return it
571  @retval - first char
572  **/
573  value_type pop_front() noexcept;
574 
575  /**
576  @brief Trim the string to the left (whitespace characters)
577  @retval - number of deleted symbols
578  **/
579  size_type trim_left() noexcept;
580 
581  /**
582  @brief Trim the string to the left
583  @param chSymbol - symbol to delete
584  @retval - number of deleted symbols
585  **/
586  size_type trim_left(value_type chSymbol) noexcept;
587 
588  /**
589  @brief Trim the string to the left
590  @param pszStr - string with symbols to delete
591  @retval - number of deleted symbols
592  **/
593  size_type trim_left(const_pointer pszStr) noexcept;
594 
595  /**
596  @brief Trim the string to the left
597  @param pszStr - string with symbols to delete
598  @param nStrSize - string size
599  @retval - number of deleted symbols
600  **/
601  size_type trim_left(const_pointer pszStr, size_type nStrSize) noexcept;
602 
603  /**
604  @brief Trim the string to the left
605  @param sStr - string with symbols to delete
606  @retval - number of deleted symbols
607  **/
608  size_type trim_left(const basic_string& sStr) noexcept;
609 
610  /**
611  @brief Trim the string to the left
612  @tparam fwd_it_t - forward iterator type
613  @param itBegin - begin it of string with symbols to delete
614  @param itEnd - begin it of string with symbols to delete
615  @retval - number of deleted symbols
616  **/
617  template<class fwd_it_t>
618  size_type trim_left(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
619 
620  /**
621  @brief Trim the string to the left
622  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
623  @param sStr - string with symbols to delete
624  @retval - number of deleted symbols
625  **/
626  template<range_of_t_c<char_t> string_t>
627  size_type trim_left(const string_t& sStr) noexcept;
628 
629  /**
630  @brief Trim the string to the right (whitespace characters)
631  @retval - number of deleted symbols
632  **/
633  size_type trim_right() noexcept;
634 
635  /**
636  @brief Trim the string to the right
637  @param chSymbol - symbol to delete
638  @retval - number of deleted symbols
639  **/
640  size_type trim_right(value_type chSymbol) noexcept;
641 
642  /**
643  @brief Trim the string to the right
644  @param pszStr - string with symbols to delete
645  @retval - number of deleted symbols
646  **/
647  size_type trim_right(const_pointer pszStr) noexcept;
648 
649  /**
650  @brief Trim the string to the right
651  @param pszStr - string with symbols to delete
652  @param nStrSize - string size
653  @retval - number of deleted symbols
654  **/
655  size_type trim_right(const_pointer pszStr, size_type nStrSize) noexcept;
656 
657  /**
658  @brief Trim the string to the right
659  @param sStr - string with symbols to delete
660  @retval - number of deleted symbols
661  **/
662  size_type trim_right(const basic_string& sStr) noexcept;
663 
664  /**
665  @brief Trim the string to the right
666  @tparam fwd_it_t - forward iterator type
667  @param itBegin - begin it of string with symbols to delete
668  @param itEnd - begin it of string with symbols to delete
669  @retval - number of deleted symbols
670  **/
671  template<class fwd_it_t>
672  size_type trim_right(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
673 
674  /**
675  @brief Trim the string to the right
676  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
677  @param sStr - string with symbols to delete
678  @retval - number of deleted symbols
679  **/
680  template<range_of_t_c<char_t> string_t>
681  size_type trim_right(const string_t& sStr) noexcept;
682 
683  /**
684  @brief Trim the string to the both sides (whitespace characters)
685  @retval - number of deleted symbols
686  **/
687  size_type trim() noexcept;
688 
689  /**
690  @brief Trim the string to the both sides
691  @param chSymbol - symbol to delete
692  @retval - number of deleted symbols
693  **/
694  size_type trim(value_type chSymbol) noexcept;
695 
696  /**
697  @brief Trim the string to the both sides
698  @param pszStr - string with symbols to delete
699  @retval - number of deleted symbols
700  **/
701  size_type trim(const_pointer pszStr) noexcept;
702 
703  /**
704  @brief Trim the string to the both sides
705  @param pszStr - string with symbols to delete
706  @param nStrSize - string size
707  @retval - number of deleted symbols
708  **/
709  size_type trim(const_pointer pszStr, size_type nStrSize) noexcept;
710 
711  /**
712  @brief Trim the string to the both sides
713  @param sStr - string with symbols to delete
714  @retval - number of deleted symbols
715  **/
716  size_type trim(const basic_string& sStr) noexcept;
717 
718  /**
719  @brief Trim the string to the both sides
720  @tparam fwd_it_t - forward iterator type
721  @param itBegin - begin it of string with symbols to delete
722  @param itEnd - begin it of string with symbols to delete
723  @retval - number of deleted symbols
724  **/
725  template<class fwd_it_t>
726  size_type trim(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
727 
728  /**
729  @brief Trim the string to the both sides
730  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
731  @param sStr - string with symbols to delete
732  @retval - number of deleted symbols
733  **/
734  template<range_of_t_c<char_t> string_t>
735  size_type trim(const string_t& sStr) noexcept;
736 
737  /**
738  @brief Remove the first occurrence of a substring in a string
739  @param chSymbol - char to remove
740  @param nBegin - start searching index
741  @param nEnd - end searching index
742  @retval - position where the first occurrence was or npos
743  **/
744  size_type remove(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) noexcept;
745 
746  /**
747  @brief Remove the first occurrence of a substring in a string
748  @param pszStr - c-string to remove
749  @param nBegin - start searching index
750  @param nEnd - end searching index
751  @param nStrSize - c-string size
752  @retval - position where the first occurrence was or npos
753  **/
754  size_type remove(
755  const_pointer pszStr,
756  size_type nBegin = 0,
757  size_type nEnd = npos,
758  size_type nStrSize = npos) noexcept;
759 
760  /**
761  @brief Remove the first occurrence of a substring in a string
762  @param sStr - string to remove
763  @param nBegin - start searching index
764  @param nEnd - end searching index
765  @retval - position where the first occurrence was or npos
766  **/
767  size_type remove(const basic_string& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
768 
769  /**
770  @brief Remove the first occurrence of a substring in a string
771  @tparam fwd_it_t - forward iterator type
772  @param itBegin - string begin iterator
773  @param itEnd - string end iterator
774  @param nBegin - start searching index
775  @param nEnd - end searching index
776  @retval - position where the first occurrence was or npos
777  **/
778  template<class fwd_it_t>
779  size_type remove(fwd_it_t itBegin, fwd_it_t itEnd, size_type nBegin = 0, size_type nEnd = npos) noexcept;
780 
781  /**
782  @brief Remove the first occurrence of a substring in a string
783  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
784  @param sStr - string to remove
785  @param nBegin - start searching index
786  @param nEnd - end searching index
787  @retval - position where the first occurrence was or npos
788  **/
789  template<range_of_t_c<char_t> string_t>
790  size_type remove(const string_t& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
791 
792  /**
793  @brief Remove string prefix if matches
794  @param chSymbol - char to remove
795  @retval - true if removed
796  **/
797  bool remove_prefix(value_type chSymbol) noexcept;
798 
799  /**
800  @brief Remove string prefix if matches
801  @param pszStr - string to remove
802  @param nStrSize - string size
803  @retval - true if removed
804  **/
805  bool remove_prefix(const_pointer pszStr, size_type nStrSize = npos) noexcept;
806 
807  /**
808  @brief Remove string prefix if matches
809  @param sStr - string to remove
810  @retval - true if removed
811  **/
812  bool remove_prefix(const basic_string& sStr) noexcept;
813 
814  /**
815  @brief Remove string prefix if matches
816  @tparam fwd_it_t - forward iterator type
817  @param itBegin - string to remove begin iterator
818  @param itEnd - string to remove end iterator
819  @retval - true if removed
820  **/
821  template<class fwd_it_t>
822  bool remove_prefix(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
823 
824  /**
825  @brief Remove string prefix if matches
826  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
827  @param sStr - string to remove
828  @retval - true if removed
829  **/
830  template<range_of_t_c<char_t> string_t>
831  bool remove_prefix(const string_t& sStr) noexcept;
832 
833  /**
834  @brief Remove string suffix if matches
835  @param chSymbol - char to remove
836  @retval - true if removed
837  **/
838  bool remove_suffix(value_type chSymbol) noexcept;
839 
840  /**
841  @brief Remove string suffix if matches
842  @param pszStr - string to remove
843  @param nStrSize - string size
844  @retval - true if removed
845  **/
846  bool remove_suffix(const_pointer pszStr, size_type nStrSize = npos) noexcept;
847 
848  /**
849  @brief Remove string suffix if matches
850  @param sStr - string to remove
851  @retval - true if removed
852  **/
853  bool remove_suffix(const basic_string& sStr) noexcept;
854 
855  /**
856  @brief Remove string suffix if matches
857  @tparam fwd_it_t - forward iterator type
858  @param itBegin - string to remove begin iterator
859  @param itEnd - string to remove end iterator
860  @retval - true if removed
861  **/
862  template<class fwd_it_t>
863  bool remove_suffix(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
864 
865  /**
866  @brief Remove string suffix if matches
867  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
868  @param sStr - string to remove
869  @retval - true if removed
870  **/
871  template<range_of_t_c<char_t> string_t>
872  bool remove_suffix(const string_t& sStr) noexcept;
873 
874  /**
875  @brief Remove all occurrences of a substring in a string
876  @param chSymbol - char to remove
877  @param nBegin - start searching index
878  @param nEnd - end searching index
879  @retval - number of deleted occurrences
880  **/
881  size_type remove_all(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) noexcept;
882 
883  /**
884  @brief Remove all occurrences of a substring in a string
885  @param pszStr - string to remove
886  @param nBegin - start searching index
887  @param nEnd - end searching index
888  @param nStrSize - string size
889  @retval - number of deleted occurrences
890  **/
891  size_type remove_all(
892  const_pointer pszStr,
893  size_type nBegin = 0,
894  size_type nEnd = npos,
895  size_type nStrSize = npos) noexcept;
896 
897  /**
898  @brief Remove all occurrences of a substring in a string
899  @param sStr - string to remove
900  @param nBegin - start searching index
901  @param nEnd - end searching index
902  @retval - number of deleted occurrences
903  **/
904  size_type remove_all(const basic_string& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
905 
906  /**
907  @brief Remove all occurrences of a substring in a string
908  @tparam fwd_it_t - forward iterator type
909  @param itFirst - string begin iterator
910  @param itLast - string end iterator
911  @param nBegin - start searching index
912  @param nEnd - end searching index
913  @retval - number of deleted occurrences
914  **/
915  template<class fwd_it_t>
916  size_type remove_all(fwd_it_t itFirst, fwd_it_t itLast, size_type nBegin = 0, size_type nEnd = npos) noexcept;
917 
918  /**
919  @brief Remove all occurrences of a substring in a string
920  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
921  @param sStr - string to remove
922  @param nBegin - start searching index
923  @param nEnd - end searching index
924  @retval - number of deleted occurrences
925  **/
926  template<range_of_t_c<char_t> string_t>
927  size_type remove_all(const string_t& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
928 
929  /**
930  @brief Replace a substring with a given string
931  @todo tests
932  @param nBegin - substring start index
933  @param nSize - substring size
934  @param pszReplace - new substring pointer
935  @param nReplaceSize - new substring suze
936  @retval - pos of char after last char of replaced string or npos
937  **/
938  size_type replace(size_type nBegin, size_type nSize, const_pointer pszReplace, size_t nReplaceSize) noexcept;
939 
940  /**
941  @brief Replace a substring with a given string
942  @todo tests
943  @tparam replace_string_t - new substring type
944  @param nBegin - substring start index
945  @param nSize - substring size
946  @param sReplace - new substring
947  @retval - pos of char after last char of replaced string or npos
948  **/
949  template<class replace_string_t>
950  size_type replace(size_type nBegin, size_type nSize, const replace_string_t& sReplace) noexcept;
951 
952  /**
953  @brief Replace first occurrence of sFind with sReplace
954  @tparam find_string_t - find string type
955  @tparam replace_string_t - replace string type
956  @param sFind - string to find and replace
957  @param sReplace - string to replace with
958  @param nBegin - start searching index
959  @param nEnd - end searching index
960  @retval - pos of char after last char of replaced string or npos
961  **/
962  template<class find_string_t, class replace_string_t>
963  size_type replace(
964  const find_string_t& sFind,
965  const replace_string_t& sReplace,
966  size_type nBegin = 0,
967  size_type nEnd = npos) noexcept;
968 
969  /**
970  @brief Replace all occurrences of sFind with sReplace
971  @tparam find_string_t - find string type
972  @tparam replace_string_t - replace string type
973  @param sFind - string to find and replace
974  @param sReplace - string to replace with
975  @param nBegin - start searching index
976  @param nEnd - end searching index
977  @retval - number of replaced occurrences
978  **/
979  template<class find_string_t, class replace_string_t>
980  size_type replace_all(
981  const find_string_t& sFind,
982  const replace_string_t& sReplace,
983  size_type nBegin = 0,
984  size_type nEnd = npos) noexcept;
985 
986  /**
987  @brief Performs a binary comparison of the characters
988  @param chSymbol - symbol to compare
989  @retval - < 0 the first character that does not match has
990  a lower value in this than in chSymbol
991  = 0 the contents of both strings are equal
992  > 0 the first character that does not match has
993  a greater value in this than in chSymbol
994  **/
995  int compare(value_type chSymbol) const noexcept;
996 
997  /**
998  @brief Performs a binary comparison of the characters
999  @param pszStr - string to compare. must not be nullptr
1000  @retval - < 0 the first character that does not match has
1001  a lower value in this than in chSymbol
1002  = 0 the contents of both strings are equal
1003  > 0 the first character that does not match has
1004  a greater value in this than in chSymbol
1005  **/
1006  int compare(const_pointer pszStr) const noexcept;
1007 
1008  /**
1009  @brief Performs a binary comparison of the characters
1010  @param pStr - string to compare. must not be nullptr
1011  @param nStrSize - number of symbols to compare
1012  @retval - < 0 the first character that does not match has
1013  a lower value in this than in chSymbol
1014  = 0 the contents of both strings are equal
1015  > 0 the first character that does not match has
1016  a greater value in this than in chSymbol
1017  **/
1018  int compare(const_pointer pStr, size_type nStrSize) const noexcept;
1019 
1020  /**
1021  @brief Performs a binary comparison of the characters
1022  @param sStr - string to compare
1023  @retval - < 0 the first character that does not match has
1024  a lower value in this than in chSymbol
1025  = 0 the contents of both strings are equal
1026  > 0 the first character that does not match has
1027  a greater value in this than in chSymbol
1028  **/
1029  int compare(const basic_string& sStr) const noexcept;
1030 
1031  /**
1032  @brief Performs a binary comparison of the characters
1033  @tparam fwd_it_t - forward iterator type
1034  @param itBegin - string to compare begin iterator
1035  @param itEnd - string to compare end iterator
1036  @retval - < 0 the first character that does not match has
1037  a lower value in this than in chSymbol
1038  = 0 the contents of both strings are equal
1039  > 0 the first character that does not match has
1040  a greater value in this than in chSymbol
1041  **/
1042  template<class fwd_it_t>
1043  int compare(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1044 
1045  /**
1046  @brief Performs a binary comparison of the characters
1047  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1048  @param sStr - string to compare
1049  @retval - < 0 the first character that does not match has
1050  a lower value in this than in chSymbol
1051  = 0 the contents of both strings are equal
1052  > 0 the first character that does not match has
1053  a greater value in this than in chSymbol
1054  **/
1055  template<range_of_t_c<char_t> string_t>
1056  int compare(const string_t& sStr) const noexcept;
1057 
1058  /**
1059  @brief Find substring
1060  @param chSymbol - char to find
1061  @param nBegin - start searching index
1062  @param nEnd - end searching index (npos - to the end)
1063  @retval - substring index or npos if not found
1064  **/
1065  size_type find(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1066 
1067  /**
1068  @brief Find substring
1069  @param pszWhat - string to find
1070  @param nBegin - start searching index
1071  @param nWhatSize - string length (npos - string is zero terminated)
1072  @param nEnd - end searching index (npos - to the end).
1073  @retval - substring index
1074  **/
1075  size_type find(const_pointer pszWhat, size_type nBegin = 0, size_type nWhatSize = npos, size_type nEnd = npos)
1076  const noexcept;
1077 
1078  /**
1079  @brief Find substring
1080  @param sWhat - string to find
1081  @param nBegin - start searching index
1082  @param nEnd - end searching index
1083  @retval - substring index or npos if not found
1084  **/
1085  size_type find(const basic_string& sWhat, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1086 
1087  /**
1088  @brief Find substring
1089  @tparam fwd_it_t - forward iterator type
1090  @param itWhatBegin - substring begin iterator
1091  @param itWhatEnd - substring end iterator
1092  @param nBegin - start searching index
1093  @param nEnd - end searching index
1094  @retval - substring index or npos if not found
1095  **/
1096  template<class fwd_it_t>
1097  size_type find(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0, size_type nEnd = npos)
1098  const noexcept;
1099 
1100  /**
1101  @brief Find substring
1102  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1103  @param sWhat - substring
1104  @param nBegin - start searching index
1105  @param nEnd - end searching index
1106  @retval - substring index or npos if not found
1107  **/
1108  template<range_of_t_c<char_t> string_t>
1109  size_type find(string_t sWhat, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1110 
1111  /**
1112  @brief Find substring (reverse direction)
1113  @param chSymbol - char to find
1114  @param nBegin - start searching index
1115  @param nEnd - end searching index
1116  (if nBegin < end, result is equivalent of find(...))
1117  @retval - substring index or npos if not found
1118  **/
1119  size_type rfind(value_type chSymbol, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1120 
1121  /**
1122  @brief Find substring (reverse direction)
1123  @param pszWhat - c-string to find
1124  @param nBegin - start searching index
1125  @param nWhatSize - c-string length
1126  @param nEnd - end searching index
1127  (if nBegin < end, result is equivalent of find(...))
1128  @retval - substring index or npos if not found
1129  **/
1130  size_type rfind(const_pointer pszWhat, size_type nBegin = npos, size_type nWhatSize = npos, size_type nEnd = 0)
1131  const noexcept;
1132 
1133  /**
1134  @brief Find substring (reverse direction)
1135  @param sWhat - string to find
1136  @param nBegin - start searching index
1137  @param nEnd - end searching index
1138  (if nBegin < end, result is equivalent of find(...))
1139  @retval - substring index or npos if not found
1140  **/
1141  size_type rfind(const basic_string& sWhat, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1142 
1143  /**
1144  @brief Find substring (reverse direction)
1145  @tparam fwd_it_t - forward iterator type
1146  @param itWhatBegin - substring begin iterator
1147  @param itWhatEnd - substring end iterator
1148  @param nBegin - start searching index
1149  @param nEnd - end searching index
1150  (if nBegin < end, result is equivalent of find(...))
1151  @retval - substring index or npos if not found
1152  **/
1153  template<class fwd_it_t>
1154  size_type rfind(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = npos, size_type nEnd = 0)
1155  const noexcept;
1156 
1157  /**
1158  @brief Find substring (reverse direction)
1159  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1160  @param sWhat - substring
1161  @param nBegin - start searching index
1162  @param nEnd - end searching index
1163  (if nBegin < end, result is equivalent of find(...))
1164  @retval - substring index or npos if not found
1165  **/
1166  template<range_of_t_c<char_t> string_t>
1167  size_type rfind(string_t sWhat, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1168 
1169  /**
1170  @brief Find first position of character
1171  @param chSymbol - char to find
1172  @param nBegin - position at which the search is to begin
1173  @retval - symbol index or npos
1174  **/
1175  size_type find_first_of(value_type chSymbol, size_type nBegin = 0) const noexcept;
1176 
1177  /**
1178  @brief Finds the first character equal to one of characters in the given character sequence
1179  @param pszWhat - string identifying characters to search for
1180  @param nBegin - position at which the search is to begin
1181  @param nWhatSize - length of character string identifying characters to search for
1182  @retval - symbol index or npos
1183  **/
1184  size_type find_first_of(const_pointer pszWhat, size_type nBegin, size_type nWhatSize) const noexcept;
1185 
1186  /**
1187  @brief Finds the first character equal to one of characters in the given character sequence
1188  @param pszWhat - null terminated string identifying characters to search for
1189  @param nBegin - position at which the search is to begin
1190  @retval - symbol index or npos
1191  **/
1192  size_type find_first_of(const_pointer pszWhat, size_type nBegin = 0) const noexcept;
1193 
1194  /**
1195  @brief Finds the first character equal to one of characters in the given character sequence
1196  @param sWhat - 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 basic_string& sWhat, 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  @tparam fwd_it_t - forward iterator type
1205  @param itWhatBegin - begin it of string identifying characters to search for
1206  @param itWhatEnd - end it of string identifying characters to search for
1207  @param nBegin - position at which the search is to begin
1208  @retval - symbol index or npos
1209  **/
1210  template<class fwd_it_t>
1211  size_type find_first_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0) const noexcept;
1212 
1213  /**
1214  @brief Finds the first character equal to one of characters in the given character sequence
1215  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1216  @param sWhat - string identifying characters to search for
1217  @param nBegin - position at which the search is to begin
1218  @retval - symbol index or npos
1219  **/
1220  template<range_of_t_c<char_t> string_t>
1221  size_type find_first_of(string_t sWhat, size_type nBegin = 0) const noexcept;
1222 
1223  /**
1224  @brief Find last position of character
1225  @param chSymbol - char to find
1226  @param nEnd - position at which the search is to finish
1227  @retval - symbol index or npos
1228  **/
1229  size_type find_last_of(value_type chSymbol, size_type nEnd = 0) const noexcept;
1230 
1231  /**
1232  @brief Finds the last character equal to one of characters in the given character sequence
1233  @param pszWhat - string identifying characters to search for
1234  @param nEnd - position at which the search is to finish
1235  @param nWhatSize - length of character string identifying characters to search for
1236  @retval - symbol index or npos
1237  **/
1238  size_type find_last_of(const_pointer pszWhat, size_type nEnd, size_type nWhatSize) const noexcept;
1239 
1240  /**
1241  @brief Finds the last character equal to one of characters in the given character sequence
1242  @param pszWhat - null terminated string identifying characters to search for
1243  @param nEnd - position at which the search is to finish
1244  @retval - symbol index or npos
1245  **/
1246  size_type find_last_of(const_pointer pszWhat, size_type nEnd = 0) const noexcept;
1247 
1248  /**
1249  @brief Finds the last character equal to one of characters in the given character sequence
1250  @param sWhat - 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 basic_string& sWhat, 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  @tparam fwd_it_t - forward iterator type
1259  @param itWhatBegin - begin it of string identifying characters to search for
1260  @param itWhatEnd - end it of string identifying characters to search for
1261  @param nEnd - position at which the search is to finish
1262  @retval - symbol index or npos
1263  **/
1264  template<class fwd_it_t>
1265  size_type find_last_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nEnd = 0) const noexcept;
1266 
1267  /**
1268  @brief Finds the last character equal to one of characters in the given character sequence
1269  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1270  @param sWhat - string identifying characters to search for
1271  @param nEnd - position at which the search is to finish
1272  @retval - symbol index or npos
1273  **/
1274  template<range_of_t_c<char_t> string_t>
1275  size_type find_last_of(string_t sWhat, size_type nEnd = 0) const noexcept;
1276 
1277  /**
1278  @brief Finds the first character not equal to chSymbol
1279  @param chSymbol - char to find
1280  @param nBegin - position at which the search is to begin
1281  @retval - symbol index or npos
1282  **/
1283  size_type find_first_not_of(value_type chSymbol, size_type nBegin = 0) const noexcept;
1284 
1285  /**
1286  @brief Finds the first character equal to none of the characters in the given character sequence
1287  @param pszWhat - string identifying characters to search for
1288  @param nBegin - position at which the search is to begin
1289  @param nWhatSize - length of character string identifying characters to search for
1290  @retval - symbol index or npos
1291  **/
1292  size_type find_first_not_of(const_pointer pszWhat, size_type nBegin, size_type nWhatSize) const noexcept;
1293 
1294  /**
1295  @brief Finds the first character equal to none of the characters in the given character sequence
1296  @param pszWhat - null terminated string identifying characters to search for
1297  @param nBegin - position at which the search is to begin
1298  @retval - symbol index or npos
1299  **/
1300  size_type find_first_not_of(const_pointer pszWhat, size_type nBegin = 0) const noexcept;
1301 
1302  /**
1303  @brief Finds the first character equal to none of the characters in the given character sequence
1304  @param sWhat - 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 basic_string& sWhat, 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  @tparam fwd_it_t - forward iterator type
1313  @param itWhatBegin - begin it of string identifying characters to search for
1314  @param itWhatEnd - end it of string identifying characters to search for
1315  @param nBegin - position at which the search is to begin
1316  @retval - symbol index or npos
1317  **/
1318  template<class fwd_it_t>
1319  size_type find_first_not_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0) const noexcept;
1320 
1321  /**
1322  @brief Finds the first character equal to none of the characters in the given character sequence
1323  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1324  @param sWhat - string identifying characters to search for
1325  @param nBegin - position at which the search is to begin
1326  @retval - symbol index or npos
1327  **/
1328  template<range_of_t_c<char_t> string_t>
1329  size_type find_first_not_of(string_t sWhat, size_type nBegin = 0) const noexcept;
1330 
1331  /**
1332  @brief Finds the last character not equal to chSymbol
1333  @param chSymbol - char to find
1334  @param nEnd - position at which the search is to finish
1335  @retval - symbol index or npos
1336  **/
1337  size_type find_last_not_of(value_type chSymbol, size_type nEnd = 0) const noexcept;
1338 
1339  /**
1340  @brief Finds the last character equal to none of the characters in the given character sequence
1341  @param pszWhat - string identifying characters to search for
1342  @param nEnd - position at which the search is to finish
1343  @param nWhatSize - length of character string identifying characters to search for
1344  @retval - symbol index or npos
1345  **/
1346  size_type find_last_not_of(const_pointer pszWhat, size_type nEnd, size_type nWhatSize) const noexcept;
1347 
1348  /**
1349  @brief Finds the last character equal to none of the characters in the given character sequence
1350  @param pszWhat - null terminated string identifying characters to search for
1351  @param nEnd - position at which the search is to finish
1352  @retval - symbol index or npos
1353  **/
1354  size_type find_last_not_of(const_pointer pszWhat, size_type nEnd = 0) const noexcept;
1355 
1356  /**
1357  @brief Finds the last character equal to none of the characters in the given character sequence
1358  @param sWhat - 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 basic_string& sWhat, 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  @tparam fwd_it_t - forward iterator type
1367  @param itWhatBegin - begin it of string identifying characters to search for
1368  @param itWhatEnd - end it of string identifying characters to search for
1369  @param nEnd - position at which the search is to finish
1370  @retval - symbol index or npos
1371  **/
1372  template<class fwd_it_t>
1373  size_type find_last_not_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nEnd = 0) const noexcept;
1374 
1375  /**
1376  @brief Finds the last character equal to none of the characters in the given character sequence
1377  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1378  @param sWhat - string identifying characters to search for
1379  @param nEnd - position at which the search is to finish
1380  @retval - symbol index or npos
1381  **/
1382  template<range_of_t_c<char_t> string_t>
1383  size_type find_last_not_of(string_t sWhat, size_type nEnd = 0) const noexcept;
1384 
1385  /**
1386  @brief Split string by separator
1387  @param chSeparator - char separator
1388  @retval - string_view container
1389  **/
1390  views split(const value_type chSeparator) const noexcept;
1391 
1392  /**
1393  @brief Split string by separator
1394  @param pszSeparator - separator string
1395  @param nSepLen - separator string length (npos if str is null terminated)
1396  @retval - string_view container
1397  **/
1398  views split(const_pointer pszSeparator, size_type nSepLen = npos) const noexcept;
1399 
1400  /**
1401  @brief Split string by separator
1402  @param sSeparator - separator string
1403  @retval - string_view container
1404  **/
1405  views split(const basic_string& sSeparator) const noexcept;
1406 
1407  /**
1408  @brief Split string by separator
1409  @tparam fwd_it_t - forward iterator type
1410  @param itSepFirst - separator begin iterator
1411  @param itSepLast - separator end iterator
1412  @retval - string_view container
1413  **/
1414  template<class fwd_it_t>
1415  views split(fwd_it_t itSepFirst, fwd_it_t itSepLast) const noexcept;
1416 
1417  /**
1418  @brief Split string by separator
1419  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1420  @param sSeparator - separator string
1421  @retval - string_view container
1422  **/
1423  template<range_of_t_c<char_t> string_t>
1424  views split(const string_t& sSeparator) const noexcept;
1425 
1426  /**
1427  @brief Check if current string starts with char
1428  @param chSymbol - char for comparison
1429  @retval - true if starts with char
1430  **/
1431  bool starts_with(value_type chSymbol) const noexcept;
1432 
1433  /**
1434  @brief Check if current string starts with string
1435  @param pszStr - const pointer to string
1436  @param nStrSize - string length
1437  @retval - true if starts with string
1438  **/
1439  bool starts_with(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1440 
1441  /**
1442  @brief Check if current string starts with string
1443  @param sStr - string to check
1444  @retval - true if starts with string
1445  **/
1446  bool starts_with(const basic_string& sStr) const noexcept;
1447 
1448  /**
1449  @brief Check if current string starts with string
1450  @tparam fwd_it_t - forward iterator type
1451  @param itBegin - string begin iterator
1452  @param itEnd - string end iterator
1453  @retval - true if starts with string
1454  **/
1455  template<class fwd_it_t>
1456  bool starts_with(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1457 
1458  /**
1459  @brief Check if current string starts with string
1460  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1461  @param sStr - string container to check
1462  @retval - true if starts with string
1463  **/
1464  template<range_of_t_c<char_t> string_t>
1465  bool starts_with(const string_t& sStr) const noexcept;
1466 
1467  /**
1468  @brief Check if current string ends with char
1469  @param chSymbol - char for comparison
1470  @retval - true if ends with char
1471  **/
1472  bool ends_with(value_type chSymbol) const noexcept;
1473 
1474  /**
1475  @brief Check if current string ends with string
1476  @param pszStr - const pointer to string
1477  @param nStrSize - string length
1478  @retval - true if ends with string
1479  **/
1480  bool ends_with(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1481 
1482  /**
1483  @brief Check if current string ends with string
1484  @param sStr - string to check
1485  @retval - true if starts with string
1486  **/
1487  bool ends_with(const basic_string& sStr) const noexcept;
1488 
1489  /**
1490  @brief Check if current string ends with string
1491  @tparam fwd_it_t - forward iterator type
1492  @param itBegin - string begin iterator
1493  @param itEnd - string end iterator
1494  @retval - true if ends with string
1495  **/
1496  template<class fwd_it_t>
1497  bool ends_with(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1498 
1499  /**
1500  @brief Check if current string ends with string
1501  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1502  @param sStr - string container to check
1503  @retval - true if starts with string
1504  **/
1505  template<range_of_t_c<char_t> string_t>
1506  bool ends_with(const string_t& sStr) const noexcept;
1507 
1508  /**
1509  @brief Check if string contains char
1510  @details Equal to find != npos
1511  @param chSymbol - char to check
1512  @retval - true if this string contains substring
1513  **/
1514  bool contains(value_type chSymbol) const noexcept;
1515 
1516  /**
1517  @brief Check if string contains substring
1518  @details Equal to find != npos
1519  @param pszStr - substring to check
1520  @param nStrSize - substring size
1521  @retval - true if this string contains substring
1522  **/
1523  bool contains(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1524 
1525  /**
1526  @brief Check if string contains substring
1527  @details Equal to find != npos
1528  @param sStr - string to check
1529  @retval - true if this string contains substring
1530  **/
1531  bool contains(const basic_string& sStr) const noexcept;
1532 
1533  /**
1534  @brief Check if string contains substring
1535  @details Equal to find != npos
1536  @tparam fwd_it_t - forward iterator type
1537  @param itBegin - substring begin iterator
1538  @param itEnd - substring end iterator
1539  @retval - true if this string contains substring
1540  **/
1541  template<class fwd_it_t>
1542  bool contains(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1543 
1544  /**
1545  @brief Check if string contains substring
1546  @details Equal to find != npos
1547  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1548  @param sStr - string to check
1549  @retval - true if this string contains substring
1550  **/
1551  template<range_of_t_c<char_t> string_t>
1552  bool contains(const string_t& sStr) const noexcept;
1553 
1554  basic_string& operator=(const_pointer pszSource) noexcept;
1555  basic_string& operator=(basic_string&& sStr) noexcept;
1556  basic_string& operator=(const basic_string& sStr) noexcept;
1557  template<range_of_t_c<char_t> string_t>
1558  basic_string& operator=(const string_t& sStr) noexcept;
1559 
1560  basic_string& operator+=(value_type chSymbol) noexcept;
1561  basic_string& operator+=(const_pointer pszSource) noexcept;
1562  basic_string& operator+=(const basic_string& sStr) noexcept;
1563  template<range_of_t_c<char_t> string_t>
1564  basic_string& operator+=(const string_t& sStr) noexcept;
1565 
1566  bool operator==(value_type chSymbol) const noexcept;
1567  bool operator==(const_pointer pszSource) const noexcept;
1568  bool operator==(const basic_string& sStr) const noexcept;
1569  template<range_of_t_c<char_t> string_t>
1570  bool operator==(const string_t& sStr) const noexcept;
1571 
1572  bool operator!=(value_type chSymbol) const noexcept;
1573  bool operator!=(const_pointer pszSource) const noexcept;
1574  bool operator!=(const basic_string& sStr) const noexcept;
1575  template<range_of_t_c<char_t> string_t>
1576  bool operator!=(const string_t& sStr) const noexcept;
1577 
1578  bool operator<(value_type chSymbol) const noexcept;
1579  bool operator<(const_pointer pszSource) const noexcept;
1580  bool operator<(const basic_string& sStr) const noexcept;
1581  template<range_of_t_c<char_t> string_t>
1582  bool operator<(const string_t& sStr) const noexcept;
1583 
1584  bool operator<=(value_type chSymbol) const noexcept;
1585  bool operator<=(const_pointer pszSource) const noexcept;
1586  bool operator<=(const basic_string& sStr) const noexcept;
1587  template<range_of_t_c<char_t> string_t>
1588  bool operator<=(const string_t& sStr) const noexcept;
1589 
1590  bool operator>(value_type chSymbol) const noexcept;
1591  bool operator>(const_pointer pszSource) const noexcept;
1592  bool operator>(const basic_string& sStr) const noexcept;
1593  template<range_of_t_c<char_t> string_t>
1594  bool operator>(const string_t& sStr) const noexcept;
1595 
1596  bool operator>=(value_type chSymbol) const noexcept;
1597  bool operator>=(const_pointer pszSource) const noexcept;
1598  bool operator>=(const basic_string& sStr) const noexcept;
1599  template<range_of_t_c<char_t> string_t>
1600  bool operator>=(const string_t& sStr) const noexcept;
1601 
1602  reference operator[](size_type nSymbol) noexcept;
1603  const_reference operator[](size_type nSymbol) const noexcept;
1604 
1605  operator string_view() const noexcept;
1606 
1607  explicit operator bool() const noexcept;
1608 
1609 private:
1610  /**
1611  @brief Resize string
1612  @details If new size is smaller, string will be truncated
1613  @param nSymbols - new size
1614  @retval - true if memory alloc is successful
1615  **/
1616  bool _resize(size_type nSymbols) noexcept;
1617 
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:578
void erase(iterator itFirst, iterator itLast) noexcept
Erase substring.
Definition: string.inl:592
size_type find(value_type chSymbol, size_type nBegin=0, size_type nEnd=npos) const noexcept
Find substring.
Definition: string.inl:1298
bool remove_prefix(value_type chSymbol) noexcept
Remove string prefix if matches.
Definition: string.inl:1023
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:1100
std::optional< to_t > to(const_pointer pszFormat=nullptr) const noexcept
Convert string to specified type.
Definition: string.inl:282
int compare(value_type chSymbol) const noexcept
Performs a binary comparison of the characters.
Definition: string.inl:1260
size_type find_last_of(value_type chSymbol, size_type nEnd=0) const noexcept
Find last position of character.
Definition: string.inl:1549
void push_front(value_type chSymbol) noexcept
Insert char in the beginning of the string.
Definition: string.inl:586
size_type capacity() const noexcept
Get allocated memory size (including null terminator)
Definition: string.inl:268
value_type pop_back() noexcept
Erase last char and return it.
Definition: string.inl:630
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:345
views split(const value_type chSeparator) const noexcept
Split string by separator.
Definition: string.inl:1822
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:1380
size_type length() const noexcept
Get string length.
Definition: string.inl:256
void free() noexcept
Clear string and free allocated memory.
Definition: string.inl:215
void from(const from_t &data)
Construct string from custom type.
Definition: string.inl:363
size_type trim_right() noexcept
Trim the string to the right (whitespace characters)
Definition: string.inl:746
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:1240
bool ends_with(value_type chSymbol) const noexcept
Check if current string ends with char.
Definition: string.inl:1958
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:638
void append(value_type chSymbol) noexcept
Append char.
Definition: string.inl:402
size_type trim() noexcept
Trim the string to the both sides (whitespace characters)
Definition: string.inl:846
void to_upper() noexcept
Convert string to uppercase.
Definition: string.inl:237
void shrink_to_fit() noexcept
Fit allocated size to string's actual size.
Definition: string.inl:209
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:1729
size_type trim_left() noexcept
Trim the string to the left (whitespace characters)
Definition: string.inl:646
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:222
void to_lower() noexcept
Convert string to lowercase.
Definition: string.inl:230
size_type insert(size_type nPos, value_type chSymbol) noexcept
Insert substring.
Definition: string.inl:449
bool remove_suffix(value_type chSymbol) noexcept
Remove string suffix if matches.
Definition: string.inl:1056
const_pointer c_str() const noexcept
Get pointer to string zero terminated.
Definition: string.inl:262
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:946
static constexpr size_type max_size() noexcept
Get the theoretical maximum of string size.
Definition: string.inl:274
bool starts_with(value_type chSymbol) const noexcept
Check if current string starts with char.
Definition: string.inl:1910
value_type front() const noexcept
Get first char of the string.
Definition: string.inl:244
value_type back() const noexcept
Get last char of the string.
Definition: string.inl:250
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:1183
size_type find_first_of(value_type chSymbol, size_type nBegin=0) const noexcept
Find first position of character.
Definition: string.inl:1462
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:1636
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:30
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.