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