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 first occurrence of sFind with sReplace
914  @tparam find_string_t - find string type
915  @tparam replace_string_t - replace string type
916  @param sFind - string to find and replace
917  @param sReplace - string to replace with
918  @param nBegin - start searching index
919  @param nEnd - end searching index
920  @retval - pos of char after last char of replaced string or npos
921  **/
922  template<class find_string_t, class replace_string_t>
923  size_type replace(
924  const find_string_t& sFind,
925  const replace_string_t& sReplace,
926  size_type nBegin = 0,
927  size_type nEnd = npos) noexcept;
928 
929  /**
930  @brief Replace all occurrences of sFind with sReplace
931  @tparam find_string_t - find string type
932  @tparam replace_string_t - replace string type
933  @param sFind - string to find and replace
934  @param sReplace - string to replace with
935  @param nBegin - start searching index
936  @param nEnd - end searching index
937  @retval - number of replaced occurrences
938  **/
939  template<class find_string_t, class replace_string_t>
940  size_type replace_all(
941  const find_string_t& sFind,
942  const replace_string_t& sReplace,
943  size_type nBegin = 0,
944  size_type nEnd = npos) noexcept;
945 
946  /**
947  @brief Performs a binary comparison of the characters
948  @param chSymbol - symbol to compare
949  @retval - < 0 the first character that does not match has
950  a lower value in this than in chSymbol
951  = 0 the contents of both strings are equal
952  > 0 the first character that does not match has
953  a greater value in this than in chSymbol
954  **/
955  int compare(value_type chSymbol) const noexcept;
956 
957  /**
958  @brief Performs a binary comparison of the characters
959  @param pszStr - string to compare. must not be nullptr
960  @retval - < 0 the first character that does not match has
961  a lower value in this than in chSymbol
962  = 0 the contents of both strings are equal
963  > 0 the first character that does not match has
964  a greater value in this than in chSymbol
965  **/
966  int compare(const_pointer pszStr) const noexcept;
967 
968  /**
969  @brief Performs a binary comparison of the characters
970  @param pStr - string to compare. must not be nullptr
971  @param nStrSize - number of symbols 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(const_pointer pStr, size_type nStrSize) const noexcept;
979 
980  /**
981  @brief Performs a binary comparison of the characters
982  @param sStr - string 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(const basic_string& sStr) const noexcept;
990 
991  /**
992  @brief Performs a binary comparison of the characters
993  @tparam fwd_it_t - forward iterator type
994  @param itBegin - string to compare begin iterator
995  @param itEnd - string to compare end iterator
996  @retval - < 0 the first character that does not match has
997  a lower value in this than in chSymbol
998  = 0 the contents of both strings are equal
999  > 0 the first character that does not match has
1000  a greater value in this than in chSymbol
1001  **/
1002  template<class fwd_it_t>
1003  int compare(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1004 
1005  /**
1006  @brief Performs a binary comparison of the characters
1007  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1008  @param sStr - string to compare
1009  @retval - < 0 the first character that does not match has
1010  a lower value in this than in chSymbol
1011  = 0 the contents of both strings are equal
1012  > 0 the first character that does not match has
1013  a greater value in this than in chSymbol
1014  **/
1015  template<range_of_t_c<char_t> string_t>
1016  int compare(const string_t& sStr) const noexcept;
1017 
1018  /**
1019  @brief Find substring
1020  @param chSymbol - char to find
1021  @param nBegin - start searching index
1022  @param nEnd - end searching index (npos - to the end)
1023  @retval - substring index or npos if not found
1024  **/
1025  size_type find(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1026 
1027  /**
1028  @brief Find substring
1029  @param pszWhat - string to find
1030  @param nBegin - start searching index
1031  @param nWhatSize - string length (npos - string is zero terminated)
1032  @param nEnd - end searching index (npos - to the end).
1033  @retval - substring index
1034  **/
1035  size_type find(const_pointer pszWhat, size_type nBegin = 0, size_type nWhatSize = npos, size_type nEnd = npos)
1036  const noexcept;
1037 
1038  /**
1039  @brief Find substring
1040  @param sWhat - string to find
1041  @param nBegin - start searching index
1042  @param nEnd - end searching index
1043  @retval - substring index or npos if not found
1044  **/
1045  size_type find(const basic_string& sWhat, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1046 
1047  /**
1048  @brief Find substring
1049  @tparam fwd_it_t - forward iterator type
1050  @param itWhatBegin - substring begin iterator
1051  @param itWhatEnd - substring end iterator
1052  @param nBegin - start searching index
1053  @param nEnd - end searching index
1054  @retval - substring index or npos if not found
1055  **/
1056  template<class fwd_it_t>
1057  size_type find(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0, size_type nEnd = npos)
1058  const noexcept;
1059 
1060  /**
1061  @brief Find substring
1062  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1063  @param sWhat - substring
1064  @param nBegin - start searching index
1065  @param nEnd - end searching index
1066  @retval - substring index or npos if not found
1067  **/
1068  template<range_of_t_c<char_t> string_t>
1069  size_type find(string_t sWhat, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1070 
1071  /**
1072  @brief Find substring (reverse direction)
1073  @param chSymbol - char to find
1074  @param nBegin - start searching index
1075  @param nEnd - end searching index
1076  (if nBegin < end, result is equivalent of find(...))
1077  @retval - substring index or npos if not found
1078  **/
1079  size_type rfind(value_type chSymbol, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1080 
1081  /**
1082  @brief Find substring (reverse direction)
1083  @param pszWhat - c-string to find
1084  @param nBegin - start searching index
1085  @param nWhatSize - c-string length
1086  @param nEnd - end searching index
1087  (if nBegin < end, result is equivalent of find(...))
1088  @retval - substring index or npos if not found
1089  **/
1090  size_type rfind(const_pointer pszWhat, size_type nBegin = npos, size_type nWhatSize = npos, size_type nEnd = 0)
1091  const noexcept;
1092 
1093  /**
1094  @brief Find substring (reverse direction)
1095  @param sWhat - string to find
1096  @param nBegin - start searching index
1097  @param nEnd - end searching index
1098  (if nBegin < end, result is equivalent of find(...))
1099  @retval - substring index or npos if not found
1100  **/
1101  size_type rfind(const basic_string& sWhat, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1102 
1103  /**
1104  @brief Find substring (reverse direction)
1105  @tparam fwd_it_t - forward iterator type
1106  @param itWhatBegin - substring begin iterator
1107  @param itWhatEnd - substring end iterator
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  template<class fwd_it_t>
1114  size_type rfind(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = npos, size_type nEnd = 0)
1115  const noexcept;
1116 
1117  /**
1118  @brief Find substring (reverse direction)
1119  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1120  @param sWhat - substring
1121  @param nBegin - start searching index
1122  @param nEnd - end searching index
1123  (if nBegin < end, result is equivalent of find(...))
1124  @retval - substring index or npos if not found
1125  **/
1126  template<range_of_t_c<char_t> string_t>
1127  size_type rfind(string_t sWhat, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1128 
1129  /**
1130  @brief Find first position of character
1131  @param chSymbol - char to find
1132  @param nBegin - position at which the search is to begin
1133  @retval - symbol index or npos
1134  **/
1135  size_type find_first_of(value_type chSymbol, size_type nBegin = 0) const noexcept;
1136 
1137  /**
1138  @brief Finds the first character equal to one of characters in the given character sequence
1139  @param pszWhat - string identifying characters to search for
1140  @param nBegin - position at which the search is to begin
1141  @param nWhatSize - length of character string identifying characters to search for
1142  @retval - symbol index or npos
1143  **/
1144  size_type find_first_of(const_pointer pszWhat, size_type nBegin, size_type nWhatSize) const noexcept;
1145 
1146  /**
1147  @brief Finds the first character equal to one of characters in the given character sequence
1148  @param pszWhat - null terminated string identifying characters to search for
1149  @param nBegin - position at which the search is to begin
1150  @retval - symbol index or npos
1151  **/
1152  size_type find_first_of(const_pointer pszWhat, size_type nBegin = 0) const noexcept;
1153 
1154  /**
1155  @brief Finds the first character equal to one of characters in the given character sequence
1156  @param sWhat - string identifying characters to search for
1157  @param nBegin - position at which the search is to begin
1158  @retval - symbol index or npos
1159  **/
1160  size_type find_first_of(const basic_string& sWhat, size_type nBegin = 0) const noexcept;
1161 
1162  /**
1163  @brief Finds the first character equal to one of characters in the given character sequence
1164  @tparam fwd_it_t - forward iterator type
1165  @param itWhatBegin - begin it of string identifying characters to search for
1166  @param itWhatEnd - end it of string identifying characters to search for
1167  @param nBegin - position at which the search is to begin
1168  @retval - symbol index or npos
1169  **/
1170  template<class fwd_it_t>
1171  size_type find_first_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0) const noexcept;
1172 
1173  /**
1174  @brief Finds the first character equal to one of characters in the given character sequence
1175  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1176  @param sWhat - string identifying characters to search for
1177  @param nBegin - position at which the search is to begin
1178  @retval - symbol index or npos
1179  **/
1180  template<range_of_t_c<char_t> string_t>
1181  size_type find_first_of(string_t sWhat, size_type nBegin = 0) const noexcept;
1182 
1183  /**
1184  @brief Find last position of character
1185  @param chSymbol - char to find
1186  @param nEnd - position at which the search is to finish
1187  @retval - symbol index or npos
1188  **/
1189  size_type find_last_of(value_type chSymbol, size_type nEnd = 0) const noexcept;
1190 
1191  /**
1192  @brief Finds the last character equal to one of characters in the given character sequence
1193  @param pszWhat - string identifying characters to search for
1194  @param nEnd - position at which the search is to finish
1195  @param nWhatSize - length of character string identifying characters to search for
1196  @retval - symbol index or npos
1197  **/
1198  size_type find_last_of(const_pointer pszWhat, size_type nEnd, size_type nWhatSize) const noexcept;
1199 
1200  /**
1201  @brief Finds the last character equal to one of characters in the given character sequence
1202  @param pszWhat - null terminated string identifying characters to search for
1203  @param nEnd - position at which the search is to finish
1204  @retval - symbol index or npos
1205  **/
1206  size_type find_last_of(const_pointer pszWhat, size_type nEnd = 0) const noexcept;
1207 
1208  /**
1209  @brief Finds the last character equal to one of characters in the given character sequence
1210  @param sWhat - string identifying characters to search for
1211  @param nEnd - position at which the search is to finish
1212  @retval - symbol index or npos
1213  **/
1214  size_type find_last_of(const basic_string& sWhat, size_type nEnd = 0) const noexcept;
1215 
1216  /**
1217  @brief Finds the last character equal to one of characters in the given character sequence
1218  @tparam fwd_it_t - forward iterator type
1219  @param itWhatBegin - begin it of string identifying characters to search for
1220  @param itWhatEnd - end it of string identifying characters to search for
1221  @param nEnd - position at which the search is to finish
1222  @retval - symbol index or npos
1223  **/
1224  template<class fwd_it_t>
1225  size_type find_last_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nEnd = 0) const noexcept;
1226 
1227  /**
1228  @brief Finds the last character equal to one of characters in the given character sequence
1229  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1230  @param sWhat - string identifying characters to search for
1231  @param nEnd - position at which the search is to finish
1232  @retval - symbol index or npos
1233  **/
1234  template<range_of_t_c<char_t> string_t>
1235  size_type find_last_of(string_t sWhat, size_type nEnd = 0) const noexcept;
1236 
1237  /**
1238  @brief Finds the first character not equal to chSymbol
1239  @param chSymbol - char to find
1240  @param nBegin - position at which the search is to begin
1241  @retval - symbol index or npos
1242  **/
1243  size_type find_first_not_of(value_type chSymbol, size_type nBegin = 0) const noexcept;
1244 
1245  /**
1246  @brief Finds the first character equal to none of the characters in the given character sequence
1247  @param pszWhat - string identifying characters to search for
1248  @param nBegin - position at which the search is to begin
1249  @param nWhatSize - length of character string identifying characters to search for
1250  @retval - symbol index or npos
1251  **/
1252  size_type find_first_not_of(const_pointer pszWhat, size_type nBegin, size_type nWhatSize) const noexcept;
1253 
1254  /**
1255  @brief Finds the first character equal to none of the characters in the given character sequence
1256  @param pszWhat - null terminated string identifying characters to search for
1257  @param nBegin - position at which the search is to begin
1258  @retval - symbol index or npos
1259  **/
1260  size_type find_first_not_of(const_pointer pszWhat, size_type nBegin = 0) const noexcept;
1261 
1262  /**
1263  @brief Finds the first character equal to none of the characters in the given character sequence
1264  @param sWhat - string identifying characters to search for
1265  @param nBegin - position at which the search is to begin
1266  @retval - symbol index or npos
1267  **/
1268  size_type find_first_not_of(const basic_string& sWhat, size_type nBegin = 0) const noexcept;
1269 
1270  /**
1271  @brief Finds the first character equal to none of the characters in the given character sequence
1272  @tparam fwd_it_t - forward iterator type
1273  @param itWhatBegin - begin it of string identifying characters to search for
1274  @param itWhatEnd - end it of string identifying characters to search for
1275  @param nBegin - position at which the search is to begin
1276  @retval - symbol index or npos
1277  **/
1278  template<class fwd_it_t>
1279  size_type find_first_not_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nBegin = 0) const noexcept;
1280 
1281  /**
1282  @brief Finds the first character equal to none of the characters in the given character sequence
1283  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1284  @param sWhat - string identifying characters to search for
1285  @param nBegin - position at which the search is to begin
1286  @retval - symbol index or npos
1287  **/
1288  template<range_of_t_c<char_t> string_t>
1289  size_type find_first_not_of(string_t sWhat, size_type nBegin = 0) const noexcept;
1290 
1291  /**
1292  @brief Finds the last character not equal to chSymbol
1293  @param chSymbol - char to find
1294  @param nEnd - position at which the search is to finish
1295  @retval - symbol index or npos
1296  **/
1297  size_type find_last_not_of(value_type chSymbol, size_type nEnd = 0) const noexcept;
1298 
1299  /**
1300  @brief Finds the last character equal to none of the characters in the given character sequence
1301  @param pszWhat - string identifying characters to search for
1302  @param nEnd - position at which the search is to finish
1303  @param nWhatSize - length of character string identifying characters to search for
1304  @retval - symbol index or npos
1305  **/
1306  size_type find_last_not_of(const_pointer pszWhat, size_type nEnd, size_type nWhatSize) const noexcept;
1307 
1308  /**
1309  @brief Finds the last character equal to none of the characters in the given character sequence
1310  @param pszWhat - null terminated string identifying characters to search for
1311  @param nEnd - position at which the search is to finish
1312  @retval - symbol index or npos
1313  **/
1314  size_type find_last_not_of(const_pointer pszWhat, size_type nEnd = 0) const noexcept;
1315 
1316  /**
1317  @brief Finds the last character equal to none of the characters in the given character sequence
1318  @param sWhat - string identifying characters to search for
1319  @param nEnd - position at which the search is to finish
1320  @retval - symbol index or npos
1321  **/
1322  size_type find_last_not_of(const basic_string& sWhat, size_type nEnd = 0) const noexcept;
1323 
1324  /**
1325  @brief Finds the last character equal to none of the characters in the given character sequence
1326  @tparam fwd_it_t - forward iterator type
1327  @param itWhatBegin - begin it of string identifying characters to search for
1328  @param itWhatEnd - end it of string identifying characters to search for
1329  @param nEnd - position at which the search is to finish
1330  @retval - symbol index or npos
1331  **/
1332  template<class fwd_it_t>
1333  size_type find_last_not_of(fwd_it_t itWhatBegin, fwd_it_t itWhatEnd, size_type nEnd = 0) const noexcept;
1334 
1335  /**
1336  @brief Finds the last character equal to none of the characters in the given character sequence
1337  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1338  @param sWhat - string identifying characters to search for
1339  @param nEnd - position at which the search is to finish
1340  @retval - symbol index or npos
1341  **/
1342  template<range_of_t_c<char_t> string_t>
1343  size_type find_last_not_of(string_t sWhat, size_type nEnd = 0) const noexcept;
1344 
1345  /**
1346  @brief Split string by separator
1347  @param chSeparator - char separator
1348  @retval - string_view container
1349  **/
1350  views split(const value_type chSeparator) const noexcept;
1351 
1352  /**
1353  @brief Split string by separator
1354  @param pszSeparator - separator string
1355  @param nSepLen - separator string length (npos if str is null terminated)
1356  @retval - string_view container
1357  **/
1358  views split(const_pointer pszSeparator, size_type nSepLen = npos) const noexcept;
1359 
1360  /**
1361  @brief Split string by separator
1362  @param sSeparator - separator string
1363  @retval - string_view container
1364  **/
1365  views split(const basic_string& sSeparator) const noexcept;
1366 
1367  /**
1368  @brief Split string by separator
1369  @tparam fwd_it_t - forward iterator type
1370  @param itSepFirst - separator begin iterator
1371  @param itSepLast - separator end iterator
1372  @retval - string_view container
1373  **/
1374  template<class fwd_it_t>
1375  views split(fwd_it_t itSepFirst, fwd_it_t itSepLast) const noexcept;
1376 
1377  /**
1378  @brief Split string by separator
1379  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1380  @param sSeparator - separator string
1381  @retval - string_view container
1382  **/
1383  template<range_of_t_c<char_t> string_t>
1384  views split(const string_t& sSeparator) const noexcept;
1385 
1386  /**
1387  @brief Check if current string starts with char
1388  @param chSymbol - char for comparison
1389  @retval - true if starts with char
1390  **/
1391  bool starts_with(value_type chSymbol) const noexcept;
1392 
1393  /**
1394  @brief Check if current string starts with string
1395  @param pszStr - const pointer to string
1396  @param nStrSize - string length
1397  @retval - true if starts with string
1398  **/
1399  bool starts_with(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1400 
1401  /**
1402  @brief Check if current string starts with string
1403  @param sStr - string to check
1404  @retval - true if starts with string
1405  **/
1406  bool starts_with(const basic_string& sStr) const noexcept;
1407 
1408  /**
1409  @brief Check if current string starts with string
1410  @tparam fwd_it_t - forward iterator type
1411  @param itBegin - string begin iterator
1412  @param itEnd - string end iterator
1413  @retval - true if starts with string
1414  **/
1415  template<class fwd_it_t>
1416  bool starts_with(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1417 
1418  /**
1419  @brief Check if current string starts with string
1420  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1421  @param sStr - string container to check
1422  @retval - true if starts with string
1423  **/
1424  template<range_of_t_c<char_t> string_t>
1425  bool starts_with(const string_t& sStr) const noexcept;
1426 
1427  /**
1428  @brief Check if current string ends with char
1429  @param chSymbol - char for comparison
1430  @retval - true if ends with char
1431  **/
1432  bool ends_with(value_type chSymbol) const noexcept;
1433 
1434  /**
1435  @brief Check if current string ends with string
1436  @param pszStr - const pointer to string
1437  @param nStrSize - string length
1438  @retval - true if ends with string
1439  **/
1440  bool ends_with(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1441 
1442  /**
1443  @brief Check if current string ends with string
1444  @param sStr - string to check
1445  @retval - true if starts with string
1446  **/
1447  bool ends_with(const basic_string& sStr) const noexcept;
1448 
1449  /**
1450  @brief Check if current string ends with string
1451  @tparam fwd_it_t - forward iterator type
1452  @param itBegin - string begin iterator
1453  @param itEnd - string end iterator
1454  @retval - true if ends with string
1455  **/
1456  template<class fwd_it_t>
1457  bool ends_with(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1458 
1459  /**
1460  @brief Check if current string ends with string
1461  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1462  @param sStr - string container to check
1463  @retval - true if starts with string
1464  **/
1465  template<range_of_t_c<char_t> string_t>
1466  bool ends_with(const string_t& sStr) const noexcept;
1467 
1468  /**
1469  @brief Check if string contains char
1470  @details Equal to find != npos
1471  @param chSymbol - char to check
1472  @retval - true if this string contains substring
1473  **/
1474  bool contains(value_type chSymbol) const noexcept;
1475 
1476  /**
1477  @brief Check if string contains substring
1478  @details Equal to find != npos
1479  @param pszStr - substring to check
1480  @param nStrSize - substring size
1481  @retval - true if this string contains substring
1482  **/
1483  bool contains(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1484 
1485  /**
1486  @brief Check if string contains substring
1487  @details Equal to find != npos
1488  @param sStr - string to check
1489  @retval - true if this string contains substring
1490  **/
1491  bool contains(const basic_string& sStr) const noexcept;
1492 
1493  /**
1494  @brief Check if string contains substring
1495  @details Equal to find != npos
1496  @tparam fwd_it_t - forward iterator type
1497  @param itBegin - substring begin iterator
1498  @param itEnd - substring end iterator
1499  @retval - true if this string contains substring
1500  **/
1501  template<class fwd_it_t>
1502  bool contains(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1503 
1504  /**
1505  @brief Check if string contains substring
1506  @details Equal to find != npos
1507  @tparam string_t - string-ish type, satisfying the "range_of_t_c" concept
1508  @param sStr - string to check
1509  @retval - true if this string contains substring
1510  **/
1511  template<range_of_t_c<char_t> string_t>
1512  bool contains(const string_t& sStr) const noexcept;
1513 
1514  basic_string& operator=(const_pointer pszSource) noexcept;
1515  basic_string& operator=(basic_string&& sStr) noexcept;
1516  basic_string& operator=(const basic_string& sStr) noexcept;
1517  template<range_of_t_c<char_t> string_t>
1518  basic_string& operator=(const string_t& sStr) noexcept;
1519 
1520  basic_string& operator+=(value_type chSymbol) noexcept;
1521  basic_string& operator+=(const_pointer pszSource) noexcept;
1522  basic_string& operator+=(const basic_string& sStr) noexcept;
1523  template<range_of_t_c<char_t> string_t>
1524  basic_string& operator+=(const string_t& sStr) noexcept;
1525 
1526  bool operator==(value_type chSymbol) const noexcept;
1527  bool operator==(const_pointer pszSource) const noexcept;
1528  bool operator==(const basic_string& sStr) const noexcept;
1529  template<range_of_t_c<char_t> string_t>
1530  bool operator==(const string_t& sStr) const noexcept;
1531 
1532  bool operator!=(value_type chSymbol) const noexcept;
1533  bool operator!=(const_pointer pszSource) const noexcept;
1534  bool operator!=(const basic_string& sStr) const noexcept;
1535  template<range_of_t_c<char_t> string_t>
1536  bool operator!=(const string_t& sStr) const noexcept;
1537 
1538  bool operator<(value_type chSymbol) const noexcept;
1539  bool operator<(const_pointer pszSource) const noexcept;
1540  bool operator<(const basic_string& sStr) const noexcept;
1541  template<range_of_t_c<char_t> string_t>
1542  bool operator<(const string_t& sStr) const noexcept;
1543 
1544  bool operator<=(value_type chSymbol) const noexcept;
1545  bool operator<=(const_pointer pszSource) const noexcept;
1546  bool operator<=(const basic_string& sStr) const noexcept;
1547  template<range_of_t_c<char_t> string_t>
1548  bool operator<=(const string_t& sStr) const noexcept;
1549 
1550  bool operator>(value_type chSymbol) const noexcept;
1551  bool operator>(const_pointer pszSource) const noexcept;
1552  bool operator>(const basic_string& sStr) const noexcept;
1553  template<range_of_t_c<char_t> string_t>
1554  bool operator>(const string_t& sStr) const noexcept;
1555 
1556  bool operator>=(value_type chSymbol) const noexcept;
1557  bool operator>=(const_pointer pszSource) const noexcept;
1558  bool operator>=(const basic_string& sStr) const noexcept;
1559  template<range_of_t_c<char_t> string_t>
1560  bool operator>=(const string_t& sStr) const noexcept;
1561 
1562  reference operator[](size_type nSymbol) noexcept;
1563  const_reference operator[](size_type nSymbol) const noexcept;
1564 
1565  operator string_view() const noexcept;
1566 
1567  explicit operator bool() const noexcept;
1568 
1569 private:
1570  /**
1571  @brief Resize string
1572  @details If new size is smaller, string will be truncated
1573  @param nSymbols - new size
1574  @param eType - resize type
1575  @retval - true if memory alloc is successful
1576  **/
1577  bool _resize(size_type nSymbols, string_resize_type eType = string_resize_type::common) noexcept;
1578 
1579  /**
1580  @brief Common algorithm for trimming string to the left
1581  @tparam searcher_t - "searcher" type
1582  @param searcher - function that returns true if symbol has to be deleted
1583  @retval - number of deleted symbols
1584  **/
1585  template<class searcher_t>
1586  size_type _trim_left(const searcher_t& searcher) noexcept;
1587 
1588  /**
1589  @brief Common algorithm for trimming string to the right
1590  @tparam searcher_t - "searcher" type
1591  @param searcher - function that returns true if symbol has to be deleted
1592  @retval - number of deleted symbols
1593  **/
1594  template<class searcher_t>
1595  size_type _trim_right(const searcher_t& searcher) noexcept;
1596 
1597  /**
1598  @brief Common algorithm for trimming string to the both sides
1599  @tparam searcher_t - "searcher" type
1600  @param searcher - function that returns true if symbol has to be deleted
1601  @retval - number of deleted symbols
1602  **/
1603  template<class searcher_t>
1604  size_type _trim(const searcher_t& searcher) noexcept;
1605 
1606  /**
1607  @brief Common algorithm for finding substring
1608  @tparam comparator_t - "comparator" type
1609  @param nBegin - start searching index
1610  @param nEnd - end searching index (npos - to the end)
1611  @param comparator - comparator function
1612  @retval - substring index or npos if not found
1613  **/
1614  template<class comparator_t>
1615  size_type _find(size_type nBegin, size_type nEnd, const comparator_t& comparator) const noexcept;
1616 
1617  /**
1618  @brief Common algorithm for finding substring, starting from the end
1619  @tparam comparator_t - "comparator" type
1620  @param nBegin - start searching index
1621  @param nEnd - end searching index
1622  @param comparator - comparator function
1623  @retval - substring index or npos if not found
1624  **/
1625  template<class comparator_t>
1626  size_type _rfind(size_type nBegin, size_type nEnd, const comparator_t& comparator) const noexcept;
1627 
1628  /**
1629  @brief Common algorithm for find_first_of
1630  @tparam incrementer_t - "incrementer" type
1631  @tparam fwd_it_t - forward iterator type
1632  @param itBegin - begin it of "of" string
1633  @param itEnd - end it of "of" string
1634  @param nBegin - position at which the search is to begin
1635  @param incrementer - function that increments iterator and returns itEnd when string is over
1636  @retval - symbol index or npos
1637  **/
1638  template<class incrementer_t, class fwd_it_t>
1639  size_type _find_first_of(fwd_it_t itBegin, fwd_it_t itEnd, size_type nBegin, const incrementer_t& incrementer)
1640  const noexcept;
1641 
1642  /**
1643  @brief Common algorithm for find_last_of
1644  @tparam incrementer_t - "incrementer" type
1645  @tparam fwd_it_t - forward iterator type
1646  @param itBegin - begin it of "of" string
1647  @param itEnd - end it of "of" string
1648  @param nEnd - position at which the search is to finish
1649  @param incrementer - function that increments iterator and returns itEnd when string is over
1650  @retval - symbol index or npos
1651  **/
1652  template<class incrementer_t, class fwd_it_t>
1653  size_type _find_last_of(fwd_it_t itBegin, fwd_it_t itEnd, size_type nEnd, const incrementer_t& incrementer)
1654  const noexcept;
1655 
1656  /**
1657  @brief Common algorithm for find_first_not_of
1658  @tparam incrementer_t - "incrementer" type
1659  @tparam fwd_it_t - forward iterator type
1660  @param itBegin - begin it of "of" string
1661  @param itEnd - end it of "of" string
1662  @param nBegin - position at which the search is to begin
1663  @param incrementer - function that increments iterator and returns itEnd when string is over
1664  @retval - symbol index or npos
1665  **/
1666  template<class incrementer_t, class fwd_it_t>
1667  size_type _find_first_not_of(fwd_it_t itBegin, fwd_it_t itEnd, size_type nBegin, const incrementer_t& incrementer)
1668  const noexcept;
1669 
1670  /**
1671  @brief Common algorithm for find_last_not_of
1672  @tparam incrementer_t - "incrementer" type
1673  @tparam fwd_it_t - forward iterator type
1674  @param itBegin - begin it of "of" string
1675  @param itEnd - end it of "of" string
1676  @param nEnd - position at which the search is to finish
1677  @param incrementer - function that increments iterator and returns itEnd when string is over
1678  @retval - symbol index or npos
1679  **/
1680  template<class incrementer_t, class fwd_it_t>
1681  size_type _find_last_not_of(fwd_it_t itBegin, fwd_it_t itEnd, size_type nEnd, const incrementer_t& incrementer)
1682  const noexcept;
1683 
1684 private:
1685  string_data<traits_t> m_Data;
1686 };
1687 
1688 using cstring = basic_string<char>;
1689 using wstring = basic_string<wchar_t>;
1690 using string = basic_string<char_type>;
1691 
1692 } // namespace qx
1693 
1694 #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:1283
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:1245
size_type find_last_of(value_type chSymbol, size_type nEnd=0) const noexcept
Find last position of character.
Definition: string.inl:1530
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:1803
size_type rfind(value_type chSymbol, size_type nBegin=npos, size_type nEnd=0) const noexcept
Find substring (reverse direction)
Definition: string.inl:1363
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:1225
bool ends_with(value_type chSymbol) const noexcept
Check if current string ends with char.
Definition: string.inl:1939
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 replace(const find_string_t &sFind, const replace_string_t &sReplace, size_type nBegin=0, size_type nEnd=npos) noexcept
Replace first occurrence of sFind with sReplace.
Definition: string.inl:1149
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:1710
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:1891
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 find_first_of(value_type chSymbol, size_type nBegin=0) const noexcept
Find first position of character.
Definition: string.inl:1443
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:1617
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.