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