20 #include <string_view>
26 template<
class char_t,
class traits_t =
string_traits::traits<
char_t>>
32 template<
class char_t>
33 using ostream = std::basic_ostream<char_t>;
35 template<
class char_t>
36 using istream = std::basic_istream<char_t>;
42 template<
class char_t,
class traits_t>
62 template<
class char_t,
class traits_t>
65 template<
class _
char_t,
class _traits_t>
66 friend qx::details::istream<_char_t>& ::operator>>(
67 qx::details::istream<_char_t>& is,
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...>;
85 static constexpr size_type npos = std::numeric_limits<size_type>::max();
97 basic_string(size_type nSymbols, value_type chSymbol) noexcept;
104 basic_string(const_pointer pszSource, size_type nSymbols) noexcept;
130 template<
class fwd_it_t>
131 basic_string(fwd_it_t itFirst, fwd_it_t itLast) noexcept;
138 template<range_of_t_c<
char_t>
string_t>
148 void assign(size_type nSymbols, value_type chSymbol) noexcept;
155 void assign(const_pointer pszSource, size_type nSymbols) noexcept;
161 void assign(const_pointer pszSource) noexcept;
181 template<
class fwd_it_t>
182 void assign(fwd_it_t itFirst, fwd_it_t itLast) noexcept;
189 template<range_of_t_c<
char_t>
string_t>
190 void assign(
const string_t& str) noexcept;
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);
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,
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);
235 template<
class... args_t>
236 requires format_acceptable_args<char_t, args_t...>
237 void vformat(string_view svFormat, args_t&&... args);
247 template<
class... args_t>
248 requires format_acceptable_args<char_t, args_t...>
258 template<
class... args_t>
259 requires format_acceptable_args<char_t, args_t...>
273 size_type
reserve(size_type nCapacity) noexcept;
283 void free() noexcept;
291 string_view
substr(size_type nPos, size_type nSymbols = npos) const noexcept;
307 value_type
front() const noexcept;
313 value_type
back() const noexcept;
320 size_type
length() const noexcept;
326 const_pointer
c_str() const noexcept;
332 size_type
capacity() const noexcept;
338 static constexpr size_type
max_size() noexcept;
352 std::optional<to_t>
to(const_pointer pszFormat =
nullptr) const noexcept;
361 size_type
copy(pointer pDest, size_type nCount, size_type nPos = 0) const noexcept;
368 template<class from_t>
369 void from(const from_t& data);
377 template<class from_t>
384 void append(value_type chSymbol) noexcept;
391 void append(const_pointer pszStr, size_type nStrSize = npos) noexcept;
405 template<class fwd_it_t>
406 void append(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
413 template<range_of_t_c<char_t> string_t>
414 void append(const string_t& sStr) noexcept;
422 size_type
insert(size_type nPos, value_type chSymbol) noexcept;
431 size_type
insert(size_type nPos, const_pointer pszWhat, size_type nSymbols = npos) noexcept;
449 template<class fwd_it_t>
450 size_type
insert(size_type nPos, fwd_it_t itWhatBegin, fwd_it_t itWhatEnd) noexcept;
459 template<range_of_t_c<char_t> string_t>
460 size_type
insert(size_type nPos, string_t sWhat) noexcept;
477 size_type
insert(
const_iterator itPos, const_pointer pszWhat, size_type nSymbols = npos) noexcept;
495 template<class fwd_it_t>
505 template<range_of_t_c<char_t> string_t>
512 void push_back(value_type chSymbol) noexcept;
518 void push_front(value_type chSymbol) noexcept;
537 void erase(size_type nPos) noexcept;
544 void erase(size_type nPos, size_type nSymbols) noexcept;
569 size_type
trim_left(value_type chSymbol) noexcept;
576 size_type
trim_left(const_pointer pszStr) noexcept;
584 size_type
trim_left(const_pointer pszStr, size_type nStrSize) noexcept;
600 template<class fwd_it_t>
601 size_type
trim_left(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
609 template<range_of_t_c<char_t> string_t>
610 size_type
trim_left(const string_t& sStr) noexcept;
623 size_type
trim_right(value_type chSymbol) noexcept;
630 size_type
trim_right(const_pointer pszStr) noexcept;
638 size_type
trim_right(const_pointer pszStr, size_type nStrSize) noexcept;
654 template<class fwd_it_t>
655 size_type
trim_right(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
663 template<range_of_t_c<char_t> string_t>
664 size_type
trim_right(const string_t& sStr) noexcept;
670 size_type
trim() noexcept;
677 size_type
trim(value_type chSymbol) noexcept;
684 size_type
trim(const_pointer pszStr) noexcept;
692 size_type
trim(const_pointer pszStr, size_type nStrSize) noexcept;
708 template<class fwd_it_t>
709 size_type
trim(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
717 template<range_of_t_c<char_t> string_t>
718 size_type
trim(const string_t& sStr) noexcept;
727 size_type
remove(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) noexcept;
738 const_pointer pszStr,
739 size_type nBegin = 0,
740 size_type nEnd = npos,
741 size_type nStrSize = npos) noexcept;
750 size_type
remove(const
basic_string& sStr, size_type nBegin = 0, size_type nEnd = npos) noexcept;
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;
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;
788 bool remove_prefix(const_pointer pszStr, size_type nStrSize = npos) noexcept;
804 template<class fwd_it_t>
805 bool remove_prefix(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
813 template<range_of_t_c<char_t> string_t>
829 bool remove_suffix(const_pointer pszStr, size_type nStrSize = npos) noexcept;
845 template<class fwd_it_t>
846 bool remove_suffix(fwd_it_t itBegin, fwd_it_t itEnd) noexcept;
854 template<range_of_t_c<char_t> string_t>
864 size_type
remove_all(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) noexcept;
875 const_pointer pszStr,
876 size_type nBegin = 0,
877 size_type nEnd = npos,
878 size_type nStrSize = npos) noexcept;
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;
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;
922 template<class find_string_t, class replace_string_t>
924 const find_string_t& sFind,
925 const replace_string_t& sReplace,
926 size_type nBegin = 0,
927 size_type nEnd = npos) noexcept;
939 template<class find_string_t, class replace_string_t>
941 const find_string_t& sFind,
942 const replace_string_t& sReplace,
943 size_type nBegin = 0,
944 size_type nEnd = npos) noexcept;
955 int compare(value_type chSymbol) const noexcept;
966 int compare(const_pointer pszStr) const noexcept;
978 int compare(const_pointer pStr, size_type nStrSize) const noexcept;
1002 template<class fwd_it_t>
1003 int compare(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1015 template<range_of_t_c<char_t> string_t>
1016 int compare(const string_t& sStr) const noexcept;
1025 size_type
find(value_type chSymbol, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
1035 size_type
find(const_pointer pszWhat, size_type nBegin = 0, size_type nWhatSize = npos, size_type nEnd = npos)
1045 size_type
find(const
basic_string& sWhat, size_type nBegin = 0, size_type nEnd = npos) const noexcept;
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)
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;
1079 size_type
rfind(value_type chSymbol, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
1090 size_type
rfind(const_pointer pszWhat, size_type nBegin = npos, size_type nWhatSize = npos, size_type nEnd = 0)
1101 size_type
rfind(const
basic_string& sWhat, size_type nBegin = npos, size_type nEnd = 0) const noexcept;
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)
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;
1135 size_type
find_first_of(value_type chSymbol, size_type nBegin = 0) const noexcept;
1144 size_type
find_first_of(const_pointer pszWhat, size_type nBegin, size_type nWhatSize) const noexcept;
1152 size_type
find_first_of(const_pointer pszWhat, size_type nBegin = 0) const noexcept;
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;
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;
1189 size_type
find_last_of(value_type chSymbol, size_type nEnd = 0) const noexcept;
1198 size_type
find_last_of(const_pointer pszWhat, size_type nEnd, size_type nWhatSize) const noexcept;
1206 size_type
find_last_of(const_pointer pszWhat, size_type nEnd = 0) const noexcept;
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;
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;
1243 size_type
find_first_not_of(value_type chSymbol, size_type nBegin = 0) const noexcept;
1252 size_type
find_first_not_of(const_pointer pszWhat, size_type nBegin, size_type nWhatSize) const noexcept;
1260 size_type
find_first_not_of(const_pointer pszWhat, size_type nBegin = 0) const noexcept;
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;
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;
1297 size_type
find_last_not_of(value_type chSymbol, size_type nEnd = 0) const noexcept;
1306 size_type
find_last_not_of(const_pointer pszWhat, size_type nEnd, size_type nWhatSize) const noexcept;
1314 size_type
find_last_not_of(const_pointer pszWhat, size_type nEnd = 0) const noexcept;
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;
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;
1350 views
split(const value_type chSeparator) const noexcept;
1358 views
split(const_pointer pszSeparator, size_type nSepLen = npos) const noexcept;
1374 template<class fwd_it_t>
1375 views
split(fwd_it_t itSepFirst, fwd_it_t itSepLast) const noexcept;
1383 template<range_of_t_c<char_t> string_t>
1384 views
split(const string_t& sSeparator) const noexcept;
1391 bool starts_with(value_type chSymbol) const noexcept;
1399 bool starts_with(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1415 template<class fwd_it_t>
1416 bool starts_with(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1424 template<range_of_t_c<char_t> string_t>
1425 bool starts_with(const string_t& sStr) const noexcept;
1432 bool ends_with(value_type chSymbol) const noexcept;
1440 bool ends_with(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1456 template<class fwd_it_t>
1457 bool ends_with(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1465 template<range_of_t_c<char_t> string_t>
1466 bool ends_with(const string_t& sStr) const noexcept;
1474 bool contains(value_type chSymbol) const noexcept;
1483 bool contains(const_pointer pszStr, size_type nStrSize = npos) const noexcept;
1501 template<class fwd_it_t>
1502 bool contains(fwd_it_t itBegin, fwd_it_t itEnd) const noexcept;
1511 template<range_of_t_c<char_t> string_t>
1512 bool contains(const string_t& sStr) const noexcept;
1514 basic_string& operator=(const_pointer pszSource) noexcept;
1517 template<range_of_t_c<char_t> string_t>
1518 basic_string& operator=(const string_t& sStr) noexcept;
1520 basic_string& operator+=(value_type chSymbol) noexcept;
1521 basic_string& operator+=(const_pointer pszSource) noexcept;
1523 template<range_of_t_c<char_t> string_t>
1524 basic_string& operator+=(const string_t& sStr) noexcept;
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;
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;
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;
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;
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;
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;
1562 reference operator[](size_type nSymbol) noexcept;
1563 const_reference operator[](size_type nSymbol) const noexcept;
1565 operator string_view() const noexcept;
1567 explicit operator
bool() const noexcept;
1577 bool _resize(size_type nSymbols, string_resize_type eType = string_resize_type::common) noexcept;
1585 template<class searcher_t>
1586 size_type _trim_left(const searcher_t& searcher) noexcept;
1594 template<class searcher_t>
1595 size_type _trim_right(const searcher_t& searcher) noexcept;
1603 template<class searcher_t>
1604 size_type _trim(const searcher_t& searcher) noexcept;
1614 template<class comparator_t>
1615 size_type _find(size_type nBegin, size_type nEnd, const comparator_t& comparator) const noexcept;
1625 template<class comparator_t>
1626 size_type _rfind(size_type nBegin, size_type nEnd, const comparator_t& comparator) const noexcept;
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)
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)
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)
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)
1694 #include <qx/containers/string/string.inl>
void push_back(value_type chSymbol) noexcept
Insert char in the end of the string.
void erase(iterator itFirst, iterator itLast) noexcept
Erase substring.
size_type find(value_type chSymbol, size_type nBegin=0, size_type nEnd=npos) const noexcept
Find substring.
bool remove_prefix(value_type chSymbol) noexcept
Remove string prefix if matches.
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.
std::optional< to_t > to(const_pointer pszFormat=nullptr) const noexcept
Convert string to specified type.
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.
size_type find_last_of(value_type chSymbol, size_type nEnd=0) const noexcept
Find last position of character.
void push_front(value_type chSymbol) noexcept
Insert char in the beginning of the string.
size_type capacity() const noexcept
Get allocated memory size (including null terminator)
value_type pop_back() noexcept
Erase last char and return it.
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.
views split(const value_type chSeparator) const noexcept
Split string by separator.
size_type rfind(value_type chSymbol, size_type nBegin=npos, size_type nEnd=0) const noexcept
Find substring (reverse direction)
size_type length() const noexcept
Get string length.
void free() noexcept
Clear string and free allocated memory.
void from(const from_t &data)
Construct string from custom type.
size_type trim_right() noexcept
Trim the string to the right (whitespace characters)
void assign(size_type nSymbols, value_type chSymbol) noexcept
Assign by filling.
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.
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.
bool ends_with(value_type chSymbol) const noexcept
Check if current string ends with char.
void swap(basic_string &sOther) noexcept
Swap this str and other.
value_type pop_front() noexcept
Erase first char and return it.
void append(value_type chSymbol) noexcept
Append char.
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)
void to_upper() noexcept
Convert string to uppercase.
void shrink_to_fit() noexcept
Fit allocated size to string's actual size.
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.
size_type find_last_not_of(value_type chSymbol, size_type nEnd=0) const noexcept
Finds the last character not equal to chSymbol.
size_type trim_left() noexcept
Trim the string to the left (whitespace characters)
size_type reserve(size_type nCapacity) noexcept
Reserve memory for the string.
string_view substr(size_type nPos, size_type nSymbols=npos) const noexcept
Get substring.
void to_lower() noexcept
Convert string to lowercase.
size_type insert(size_type nPos, value_type chSymbol) noexcept
Insert substring.
bool remove_suffix(value_type chSymbol) noexcept
Remove string suffix if matches.
const_pointer c_str() const noexcept
Get pointer to string zero terminated.
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.
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.
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.
static constexpr size_type max_size() noexcept
Get the theoretical maximum of string size.
bool starts_with(value_type chSymbol) const noexcept
Check if current string starts with char.
value_type front() const noexcept
Get first char of the string.
value_type back() const noexcept
Get last char of the string.
size_type find_first_of(value_type chSymbol, size_type nBegin=0) const noexcept
Find first position of character.
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.
size_type find_first_not_of(value_type chSymbol, size_type nBegin=0) const noexcept
Finds the first character not equal to chSymbol.
Const random access iterator type.
Non-const random access iterator type.
Check that tuple type contains T.