21#if defined __has_builtin
22# if __has_builtin(__builtin_mul_overflow) && __has_builtin(__builtin_add_overflow)
23# define HAS_BUILTIN_OVERFLOW
28#define _no_unique_address msvc::no_unique_address
29#define decl_empty_bases __declspec(empty_bases)
31#define _no_unique_address no_unique_address
32#define decl_empty_bases
44#define SS_CONSTEVAL constexpr
46#define SS_CONSTEVAL consteval
57inline constexpr bool wchar_is_u16 =
sizeof(wchar_t) ==
sizeof(
char16_t);
59using wchar_type = std::conditional<wchar_is_u16, char16_t, char32_t>::type;
61inline wchar_type* to_w(
wchar_t* p) {
62 return (
reinterpret_cast<wchar_type*
>(p));
65inline const wchar_type* to_w(
const wchar_t* p) {
66 return (
reinterpret_cast<const wchar_type*
>(p));
69inline wchar_t* from_w(wchar_type* p) {
70 return (
reinterpret_cast<wchar_t*
>(p));
73inline const wchar_t* from_w(
const wchar_type* p) {
74 return (
reinterpret_cast<const wchar_t*
>(p));
83using uu8s = std::make_unsigned<u8s>::type;
85template<
typename T,
typename K = void,
typename... Types>
86struct is_one_of_type {
87 static constexpr bool value = std::is_same_v<T, K> || is_one_of_type<T, Types...>::value;
90struct is_one_of_type<T, void> : std::false_type {};
93concept is_one_of_char_v = is_one_of_type<K, u8s, ubs, wchar_t, u16s, u32s>::value;
96concept is_one_of_std_char_v = is_one_of_type<K, u8s, ubs, wchar_t, wchar_type>::value;
98template<is_one_of_std_
char_v From>
99auto to_one_of_std_char(From* from) {
100 if constexpr (std::is_same_v<From, u8s> || std::is_same_v<From, wchar_t>) {
102 }
else if constexpr (std::is_same_v<From, ubs>) {
103 return reinterpret_cast<u8s*
>(from);
109template<is_one_of_std_
char_v From>
110auto to_one_of_std_char(
const From* from) {
111 if constexpr (std::is_same_v<From, u8s> || std::is_same_v<From, wchar_t>) {
113 }
else if constexpr (std::is_same_v<From, ubs>) {
114 return reinterpret_cast<const u8s*
>(from);
121struct to_std_char_type : std::type_identity<K>{};
124struct to_std_char_type<char8_t>{
129struct to_std_char_type<char16_t>{
130 using type = std::conditional_t<
sizeof(char16_t) ==
sizeof(
wchar_t), wchar_t,
void>;
134struct to_std_char_type<char32_t>{
135 using type = std::conditional_t<
sizeof(char32_t) ==
sizeof(
wchar_t), wchar_t,
void>;
139using to_std_char_t =
typename to_std_char_type<K>::type;
142struct to_base_char_type : std::type_identity<K>{};
145struct to_base_char_type<char8_t>{
150struct to_base_char_type<wchar_t>{
151 using type = std::conditional_t<
sizeof(char16_t) ==
sizeof(
wchar_t), char16_t,
char32_t>;
155using to_base_char_t =
typename to_base_char_type<K>::type;
172template<
typename K1,
typename K2>
221template<
typename T>
struct const_lit;
224template<is_one_of_
char_v T,
size_t N>
225struct const_lit<const T(&)[N]> {
227 constexpr static size_t Count = N;
231concept is_const_lit_v =
requires {
232 typename const_lit<T>::symb_type;
237template<
typename K,
typename T>
struct const_lit_for;
239template<
typename K, is_equal_str_type_v<K> P,
size_t N>
240struct const_lit_for<K, const P(&)[N]> {
241 constexpr static size_t Count = N;
244template<
typename K,
size_t N>
245class const_lit_to_array {
248 constexpr size_t find(K s)
const {
249 if constexpr (Idx < N) {
250 return s == symbols_[Idx] ? Idx : find<Idx + 1>(s);
256 constexpr bool exist(K s)
const {
257 if constexpr (Idx < N) {
258 return s == symbols_[Idx] || exist<Idx + 1>(s);
263 const K (&symbols_)[N + 1];
265 template<typename T, size_t M = const_lit_for<K, T>::Count>
requires (M == N + 1)
266 constexpr const_lit_to_array(T&& s)
267 : symbols_((
const K(&)[M])s) {}
269 constexpr bool contain(K s)
const {
272 constexpr size_t index_of(K s)
const {
278concept StrTypeCommon =
requires(
const A& a) {
279 typename std::remove_cvref_t<A>::symb_type;
280 { a.is_empty() } -> std::same_as<bool>;
281 { a.length() } -> std::convertible_to<size_t>;
286concept HasSymbType =
requires {
287 typename std::remove_cvref_t<A>::symb_type;
311template<
typename A,
typename K>
312concept StrType = StrTypeCommon<A> &&
requires(
const A& a) {
313 { a.symbols() } -> std::same_as<const K*>;
314} && std::is_same_v<typename std::remove_cvref_t<A>::symb_type, K>;
316template<
typename T>
struct is_std_string_source : std::false_type{};
318template<
typename K,
typename A>
319struct is_std_string_source<
std::basic_string<K, std::char_traits<K>, A>> : std::true_type{};
322struct is_std_string_source<std::basic_string_view<K, std::char_traits<K>>> : std::true_type{};
325concept is_std_string_source_v = is_std_string_source<T>::value;
328concept StdStrSource = is_std_string_source_v<std::remove_cvref_t<T>>;
330template<
typename T,
typename K>
334concept StrSource = StdStrSource<T> || is_const_lit_v<T> || StrTypeCommon<T>;
337concept StrSourceNoLiteral = StdStrSource<T> || StrTypeCommon<T>;
339template<
typename T>
struct is_std_string : std::false_type{};
341template<
typename K,
typename A>
342struct is_std_string<std::basic_string<K, std::char_traits<K>, A>> : std::true_type{};
345concept is_std_string_v = is_std_string<T>::value;
346template<
typename T,
typename K>
350struct symb_type_from_src {
354template<
typename K,
size_t N>
355struct symb_type_from_src<const K(&)[N]> {
359template<StdStrSource T>
360struct symb_type_from_src<T> {
361 using type =
typename std::remove_cvref_t<T>::value_type;
364template<HasSymbType T>
365struct symb_type_from_src<T> {
366 using type =
typename std::remove_cvref_t<T>::symb_type;
370using symb_type_from_src_t = symb_type_from_src<T>::type;
508 typename std::remove_cvref_t<A>::symb_type;
509 { a.length() } -> std::convertible_to<size_t>;
510 { a.place(std::declval<
typename std::remove_cvref_t<A>::symb_type*>()) } -> std::same_as<typename std::remove_cvref_t<A>::symb_type*>;
524template<
typename A,
typename K>
527template<
typename K,
typename T>
528struct convert_to_strexpr;
530template<
typename A,
typename K>
531concept strexpr_from =
requires(
const A& a) {
532 {convert_to_strexpr<K, std::remove_cvref_t<A>>::convert(a)} ->
StrExprForType<K>;
535template<
typename A,
typename K>
536concept strexpr_std =
requires(
const A& a) {
537 {convert_to_strexpr<K, std::remove_cvref_t<A>>::convert(a)} -> StdStringForType<K>;
540template<
typename A,
typename K>
543template<
typename A,
typename K>
546template<
typename A,
typename K>
547concept to_strexpr_meth =
requires(
const A& a) {
551template<
typename A,
typename K>
552concept to_strexpr_std =
requires(
const A& a) {
553 {a.template to_strexpr<K>()} -> StdStringForType<K>;
556template<
typename A,
typename K>
557concept convertible_to_strexpr = strexpr_for<A, K> || strexpr_from<A, K> || strexpr_std<A, K> || to_strexpr_type<A, K> || to_strexpr_meth<A, K> || to_strexpr_std<A, K>;
559template<
typename K, strexpr_from<K> T>
560constexpr auto to_strexpr(T&& t) {
561 return convert_to_strexpr<K, std::remove_cvref_t<T>>::convert(std::forward<T>(t));
564template<
typename K, strexpr_for<K> T>
565constexpr typename convert_to_strexpr<K, std::remove_cvref_t<T>>::type to_strexpr(T&& t) {
566 return {std::forward<T>(t)};
569template<
typename K, to_strexpr_type<K> T>
570constexpr typename std::remove_cvref_t<T>::strexpr to_strexpr(T&& t) {
571 return {std::forward<T>(t)};
574template<
typename K, to_strexpr_meth<K> T>
575constexpr auto to_strexpr(T&& t) {
576 return t.template to_strexpr<K>();
580struct expr_stdstr_c {
584 expr_stdstr_c(T t) : t_(std::move(t)){}
586 constexpr size_t length() const noexcept {
589 constexpr symb_type* place(symb_type* p)
const noexcept {
590 size_t s = t_.size();
591 std::char_traits<K>::copy(p, (
const K*)t_.data(), s);
596template<
typename K, strexpr_std<K> T>
597constexpr auto to_strexpr(T&& t) {
598 using type =
decltype(convert_to_strexpr<K, std::remove_cvref_t<T>>::convert(std::forward<T>(t)));
599 return expr_stdstr_c<K, type>{convert_to_strexpr<K, std::remove_cvref_t<T>>::convert(std::forward<T>(t))};
602template<
typename K, to_strexpr_std<K> T>
603constexpr auto to_strexpr(T&& t) {
604 using type =
decltype(t.template to_strexpr<K>());
605 return expr_stdstr_c<K, type>{t.template to_strexpr<K>()};
608template<
typename K,
typename T>
609using convert_to_strexpr_t =
decltype(to_strexpr<K>(std::declval<T>()));
627template<
typename K,
typename Allocator, StrExprForType<K> A>
628constexpr std::basic_string<K, std::char_traits<K>, Allocator> to_std_string(
const A& expr) {
629 std::basic_string<K, std::char_traits<K>, Allocator> res;
630 if (
size_t l = expr.length()) {
631 auto fill = [&](K* ptr,
size_t size) ->
size_t {
632 expr.place((
typename A::symb_type*)ptr);
635 if constexpr (
requires { res.resize_and_overwrite(l, fill); }) {
636 res.resize_and_overwrite(l, fill);
637 }
else if constexpr (
requires{ res._Resize_and_overwrite(l, fill); }) {
639 res._Resize_and_overwrite(l, fill);
642 expr.place((
typename A::symb_type*)res.data());
658template<
typename Impl>
660 template<is_equal_str_type_v<
typename Impl::symb_type> P,
typename Allocator>
661 constexpr operator std::basic_string<P, std::char_traits<P>, Allocator>()
const {
662 return to_std_string<P, Allocator>(*
static_cast<const Impl*
>(
this));
681template<StrExpr A, StrExprForType<
typename A::symb_type> B>
683 using symb_type =
typename A::symb_type;
686 constexpr strexprjoin(
const A& a_,
const B& b_) : a(a_), b(b_){}
687 constexpr size_t length()
const noexcept {
688 return a.length() + b.length();
690 constexpr symb_type* place(symb_type* p)
const noexcept {
691 return (symb_type*)b.place((
typename B::symb_type*)a.place(p));
718template<StrExpr A, StrExprForType<
typename A::symb_type> B>
743template<StrExpr A, StrExprForType<
typename A::symb_type> B,
bool last = true>
745 using symb_type =
typename A::symb_type;
748 template<
typename... Args>
requires (std::is_constructible_v<B, Args...>)
749 constexpr strexprjoin_c(
const A& a_, Args&&... args_) : a(a_), b(std::forward<Args>(args_)...) {}
750 constexpr size_t length()
const noexcept {
751 return a.length() + b.length();
753 constexpr symb_type* place(symb_type* p)
const noexcept {
754 if constexpr (last) {
755 return (symb_type*)b.place((
typename B::symb_type*)a.place(p));
757 return a.place((symb_type*)b.place((
typename B::symb_type*)p));
776template<StrExpr A, convertible_to_strexpr<
typename A::symb_type> B>
778 return {a, to_strexpr<typename A::symb_type>(std::forward<B>(b))};
795template<StrExpr A, convertible_to_strexpr<
typename A::symb_type> B>
797 return {a, to_strexpr<typename A::symb_type>(std::forward<B>(b))};
837 constexpr size_t length()
const noexcept {
840 constexpr symb_type* place(symb_type* p)
const noexcept {
877struct expr_char : expr_to_std_string<expr_char<K>>{
880 constexpr expr_char(K v) : value(v){}
881 constexpr size_t length() const noexcept {
884 constexpr symb_type* place(symb_type* p)
const noexcept {
902template<
typename K, StrExprForType<K> A>
922template<
typename K,
size_t N>
923struct expr_literal : expr_to_std_string<expr_literal<K, N>> {
925 const K (&str)[N + 1];
926 constexpr expr_literal(
const K (&str_)[N + 1]) : str(str_){}
928 constexpr size_t length() const noexcept {
931 constexpr symb_type* place(symb_type* p)
const noexcept {
932 if constexpr (N != 0)
933 std::char_traits<K>::copy(p, str, N);
990template<typename T, size_t N = const_lit<T>::Count>
991constexpr expr_literal<typename const_lit<T>::symb_type,
static_cast<size_t>(N - 1)>
e_t(T&& s) {
995template<
bool first,
typename K,
size_t N,
typename A>
996struct expr_literal_join : expr_to_std_string<expr_literal_join<first, K, N, A>> {
998 using atype =
typename A::symb_type;
999 const K (&str)[N + 1];
1001 constexpr expr_literal_join(
const K (&str_)[N + 1],
const A& a_) : str(str_), a(a_){}
1003 constexpr size_t length() const noexcept {
1004 return N + a.length();
1006 constexpr symb_type* place(symb_type* p)
const noexcept {
1007 if constexpr (N != 0) {
1008 if constexpr (first) {
1009 std::char_traits<K>::copy(p, str, N);
1010 return (symb_type*)a.place((atype*)(p + N));
1012 p = (symb_type*)a.place((atype*)p);
1013 std::char_traits<K>::copy(p, str, N);
1017 return (symb_type*)a.place((atype*)p);
1030constexpr expr_literal_join<
false, P, (N - 1), A>
operator+(
const A& a, T&& s) {
1041template<StrExpr A, typename T, typename P = typename const_lit<T>::symb_type,
size_t N = const_lit<T>::Count>
requires is_equal_str_type_v<typename A::symb_type, P>
1042constexpr expr_literal_join<
true, P, (N - 1), A>
operator+(T&& s,
const A& a) {
1059template<
typename K,
size_t N,
size_t S = ' '>
1061 using symb_type = K;
1062 constexpr size_t length()
const noexcept {
1065 constexpr symb_type* place(symb_type* p)
const noexcept {
1066 if constexpr (N != 0)
1067 std::char_traits<K>::assign(p, N,
static_cast<K
>(S));
1121 using symb_type = K;
1124 constexpr expr_pad(
size_t len_, K s_) : len(len_), s(s_){}
1125 constexpr size_t length()
const noexcept {
1128 constexpr symb_type* place(symb_type* p)
const noexcept {
1130 std::char_traits<K>::assign(p, len, s);
1153template<
typename K,
size_t N>
1154struct expr_repeat_lit : expr_to_std_string<expr_repeat_lit<K, N>> {
1155 using symb_type = K;
1157 const K (&s)[N + 1];
1158 constexpr expr_repeat_lit(
size_t repeat,
const K (&s_)[N + 1]) : repeat_(repeat), s(s_){}
1159 constexpr size_t length() const noexcept {
1162 constexpr symb_type* place(symb_type* p)
const noexcept {
1164 for (
size_t i = 0; i < repeat_; i++) {
1165 std::char_traits<K>::copy(p, s, N);
1175 using symb_type =
typename A::symb_type;
1178 mutable size_t len_;
1179 constexpr expr_repeat_expr(
size_t repeat,
const A& expr) : repeat_(repeat), expr_(expr){}
1180 constexpr size_t length() const noexcept {
1182 len_ = expr_.length();
1183 return repeat_ * len_;
1187 constexpr symb_type* place(symb_type* p)
const noexcept {
1188 if (repeat_ && len_) {
1189 symb_type* start = p;
1191 for (
size_t i = repeat_; --i; ) {
1192 std::char_traits<symb_type>::copy(p, start, len_);
1213template<typename T, typename K = const_lit<T>::symb_type,
size_t M = const_lit<T>::Count>
requires (M > 0)
1214constexpr expr_repeat_lit<K, M - 1>
e_repeat(T&& s,
size_t l) {
1232constexpr expr_repeat_expr<A>
e_repeat(
const A& s,
size_t l) {
1249template<StrExpr A, StrExprForType<
typename A::symb_type> B>
1251 using symb_type =
typename A::symb_type;
1252 using my_type = expr_choice<A, B>;
1257 constexpr expr_choice(
const A& _a,
const B& _b,
bool _choice) : a(_a), b(_b), choice(_choice){}
1259 constexpr size_t length()
const noexcept {
1260 return choice ? a.length() : b.length();
1262 constexpr symb_type* place(symb_type* ptr)
const noexcept {
1263 return choice ? a.place(ptr) : (symb_type*)b.place((
typename B::symb_type*)ptr);
1280 using symb_type =
typename A::symb_type;
1281 using my_type = expr_if<A>;
1284 constexpr expr_if(
const A& _a,
bool _choice) : a(_a), choice(_choice){}
1286 constexpr size_t length()
const noexcept {
1287 return choice ? a.length() : 0;
1289 constexpr symb_type* place(symb_type* ptr)
const noexcept {
1290 return choice ? a.place(ptr) : ptr;
1340template<
typename L, StrExprForType<L> A,
size_t N,
bool Compare>
1342 using symb_type = L;
1343 const symb_type (&str)[N + 1];
1346 constexpr expr_choice_one_lit(
const symb_type (&_str)[N + 1],
const A& _a,
bool _choice) : str(_str), a(_a), choice(_choice){}
1348 constexpr size_t length()
const noexcept {
1349 return choice == Compare ? a.length() : N;
1351 constexpr symb_type* place(symb_type* ptr)
const noexcept {
1352 if (choice == Compare) {
1353 return (L*)a.place((
typename A::symb_type*)ptr);
1355 if constexpr (N != 0) {
1356 std::char_traits<symb_type>::copy(ptr, str, N);
1406template<
typename K,
size_t N,
typename P,
size_t M>
1408 using symb_type = K;
1409 const K (&str_a)[N + 1];
1410 const P (&str_b)[M + 1];
1412 constexpr expr_choice_two_lit(
const K(&_str_a)[N + 1],
const P(&_str_b)[M + 1],
bool _choice)
1413 : str_a(_str_a), str_b(_str_b), choice(_choice){}
1415 constexpr size_t length()
const noexcept {
1416 return choice ? N : M;
1418 constexpr symb_type* place(symb_type* ptr)
const noexcept {
1420 if constexpr (N != 0) {
1421 std::char_traits<symb_type>::copy(ptr, str_a, N);
1425 if constexpr (M != 0) {
1426 std::char_traits<symb_type>::copy(ptr, (
const K(&)[M + 1])str_b, M);
1461template<StrExpr A, StrExprForType<
typename A::symb_type> B>
1471template<StrExpr A, typename T, size_t N = const_lit_for<typename A::symb_type, T>::Count>
1481template<StrExpr A, typename T, size_t N = const_lit_for<typename A::symb_type, T>::Count>
1490template<typename T, typename L, typename K = typename const_lit<T>::symb_type,
typename P =
typename const_lit<L>::symb_type,
1491 size_t N = const_lit<T>::Count,
size_t M = const_lit_for<typename const_lit<T>::symb_type, L>::Count>
1492 requires is_equal_str_type_v<K, P>
1494 return {str_a, str_b, c};
1548template<typename T, size_t N = const_lit<T>::Count>
1550 using K =
typename const_lit<T>::symb_type;
1551 const K empty[1] = {0};
1564template<
typename K, StdStrSourceForType<K> T>
1566 using symb_type = K;
1569 expr_stdstr(
const T& t) : t_(t){}
1571 constexpr size_t length()
const noexcept {
1574 constexpr symb_type* place(symb_type* p)
const noexcept {
1575 size_t s = t_.size();
1576 std::char_traits<K>::copy(p, (
const K*)t_.data(), s);
1591template<
typename K, StdStrSource T>
1592struct convert_to_strexpr<K, T> {
1597constexpr const size_t npos =
static_cast<size_t>(-1);
1601std::char_traits<K> char_traits_selector(...);
1604using ch_traits =
decltype(char_traits_selector<K>(
int(0)));
1607concept FromIntNumber =
1608 is_one_of_type<std::remove_cv_t<T>,
unsigned char, int, short, long,
long long, unsigned,
unsigned short,
unsigned long,
unsigned long long>::value;
1611concept ToIntNumber = FromIntNumber<T> || is_one_of_type<T, int8_t>::value;
1613template<
typename K,
bool I,
typename T>
1616 std::make_unsigned_t<T> val;
1617 constexpr need_sign(T t) : negate(t < 0), val(t < 0 ?
std::make_unsigned_t<T>{} - t : t) {}
1618 constexpr void after(K*& ptr) {
1624template<
typename K,
typename T>
1625struct need_sign<K, false, T> {
1627 constexpr need_sign(T t) : val(t){}
1628 constexpr void after(K*&) {}
1631template<
typename K,
typename T>
1632constexpr size_t fromInt(K* bufEnd, T val) {
1633 const char* twoDigit =
1634 "0001020304050607080910111213141516171819"
1635 "2021222324252627282930313233343536373839"
1636 "4041424344454647484950515253545556575859"
1637 "6061626364656667686970717273747576777879"
1638 "8081828384858687888990919293949596979899";
1640 need_sign<K, std::is_signed_v<T>, T> store(val);
1642 while (store.val >= 100) {
1643 const char* ptr = twoDigit + (store.val % 100) * 2;
1644 *--itr =
static_cast<K
>(ptr[1]);
1645 *--itr =
static_cast<K
>(ptr[0]);
1648 if (store.val < 10) {
1649 *--itr =
static_cast<K
>(
'0' + store.val);
1651 const char* ptr = twoDigit + store.val * 2;
1652 *--itr =
static_cast<K
>(ptr[1]);
1653 *--itr =
static_cast<K
>(ptr[0]);
1656 return size_t(bufEnd - itr);
1662template<
typename K,
typename T>
1664 using symb_type = K;
1665 using my_type = expr_num<K, T>;
1667 enum { bufSize = 24 };
1668 mutable K buf[bufSize];
1671 constexpr expr_num(T t) : value(t) {}
1672 constexpr expr_num(expr_num&& t) noexcept : value(t.value) {}
1674 constexpr size_t length() const noexcept {
1675 value =
static_cast<T
>(fromInt(buf + bufSize, value));
1676 return static_cast<size_t>(value);
1678 constexpr K* place(K* ptr)
const noexcept {
1679 size_t len =
static_cast<size_t>(value);
1680 ch_traits<K>::copy(ptr, buf + bufSize - len, len);
1695template<
typename K, FromIntNumber T>
1696struct convert_to_strexpr<K, T> {
1697 using type = expr_num<K, T>;
1715template<
typename K, FromIntNumber T>
1722enum class int_align { none, left, right, center };
1723enum class int_plus_sign {none, plus, space};
1724enum class int_prefix {none, lcase, ucase};
1726enum fmt_kinds :
unsigned {
1737template<
typename A,
typename B,
unsigned Kind>
1741 inline static constexpr unsigned kind = Kind;
1745 inline static constexpr unsigned kind = fmt_none;
1748template<
int_align A>
1750 inline static constexpr unsigned kind = fmt_align;
1753template<
size_t W
idth = 0>
1755 inline static constexpr unsigned kind = fmt_width;
1758template<
unsigned Fill = ' '>
1760 inline static constexpr unsigned kind = fmt_fill;
1763template<
int_plus_sign S>
1765 inline static constexpr unsigned kind = fmt_sign;
1769 inline static constexpr unsigned kind = fmt_upper;
1774 inline static constexpr unsigned kind = fmt_prefix;
1778 inline static constexpr unsigned kind = fmt_zero;
1782concept FmtParam =
requires {
1783 {std::remove_cvref_t<T>::kind} -> std::same_as<const unsigned&>;
1786template<FmtParam A, FmtParam B>
1787requires((A::kind & B::kind) == 0)
1788constexpr auto operator | (
const A&,
const B&) {
1789 return fmt_info<A, B, A::kind | B::kind>{};
1792inline constexpr align_info<int_align::left> l;
1793inline constexpr align_info<int_align::right> r;
1794inline constexpr align_info<int_align::center> c;
1797inline constexpr width_info<W> w;
1800inline constexpr fill_info<F> f;
1802inline constexpr sign_info<int_plus_sign::plus> sp;
1803inline constexpr sign_info<int_plus_sign::space> ss;
1804inline constexpr upper_info u;
1805inline constexpr prefix_info<int_prefix::lcase> p;
1806inline constexpr prefix_info<int_prefix::ucase> P;
1807inline constexpr zero_info z;
1809inline constexpr width_info<unsigned(-1)> wp;
1810inline constexpr fmt_default df;
1813struct extract_align : std::false_type {
1814 inline static constexpr int_align align = int_align::none;
1817template<
int_align A>
1818struct extract_align<align_info<A>> : std::true_type {
1819 inline static constexpr int_align align = A;
1822template<
typename A,
typename B,
unsigned U>
1823struct extract_align<fmt_info<A, B, U>> {
1824 inline static constexpr bool in_a = extract_align<A>::value, in_b = extract_align<B>::value, value = in_a | in_b;
1825 inline static constexpr int_align align = extract_align<std::conditional_t<in_a, A, std::conditional_t<in_b, B, align_info<int_align::none>>>>::align;
1829struct extract_width : std::false_type {
1830 inline static constexpr size_t width = 0;
1834struct extract_width<width_info<W>> : std::true_type {
1835 inline static constexpr size_t width = W;
1838template<
typename A,
typename B,
unsigned U>
1839struct extract_width<fmt_info<A, B, U>> {
1840 inline static constexpr bool in_a = extract_width<A>::value, in_b = extract_width<B>::value, value = in_a | in_b;
1841 inline static constexpr size_t width = extract_width<std::conditional_t<in_a, A, std::conditional_t<in_b, B, width_info<0>>>>::width;
1845struct extract_fill : std::false_type {
1846 inline static constexpr unsigned fill =
' ';
1850struct extract_fill<fill_info<F>> : std::true_type {
1851 inline static constexpr unsigned fill = F;
1854template<
typename A,
typename B,
unsigned U>
1855struct extract_fill<fmt_info<A, B, U>> {
1856 inline static constexpr bool in_a = extract_fill<A>::value, in_b = extract_fill<B>::value, value = in_a | in_b;
1857 inline static constexpr unsigned fill = extract_fill<std::conditional_t<in_a, A, std::conditional_t<in_b, B, fill_info<
' '>>>>::fill;
1861struct extract_sign : std::false_type {
1862 inline static constexpr int_plus_sign sign = int_plus_sign::none;
1865template<
int_plus_sign S>
1866struct extract_sign<sign_info<S>> : std::true_type {
1867 inline static constexpr int_plus_sign sign = S;
1870template<
typename A,
typename B,
unsigned U>
1871struct extract_sign<fmt_info<A, B, U>> {
1872 inline static constexpr bool in_a = extract_sign<A>::value, in_b = extract_sign<B>::value, value = in_a | in_b;
1873 inline static constexpr int_plus_sign sign = extract_sign<std::conditional_t<in_a, A, std::conditional_t<in_b, B, sign_info<int_plus_sign::none>>>>::sign;
1877struct extract_upper : std::false_type {};
1880struct extract_upper<upper_info> : std::true_type {};
1882template<
typename A,
typename B,
unsigned U>
1883struct extract_upper<fmt_info<A, B, U>> {
1884 inline static constexpr bool in_a = extract_upper<A>::value, in_b = extract_upper<B>::value,
1885 value = extract_upper<std::conditional_t<in_a, A, std::conditional_t<in_b, B, std::false_type>>>::value;
1889struct extract_prefix : std::false_type{
1890 inline static constexpr int_prefix prefix = int_prefix::none;
1893template<
int_prefix P>
1894struct extract_prefix<prefix_info<P>> : std::true_type {
1895 inline static constexpr int_prefix prefix = P;
1898template<
typename A,
typename B,
unsigned U>
1899struct extract_prefix<fmt_info<A, B, U>> {
1900 inline static constexpr bool in_a = extract_prefix<A>::value, in_b = extract_prefix<B>::value, value = in_a | in_b;
1901 inline static constexpr int_prefix prefix = extract_prefix<std::conditional_t<in_a, A, std::conditional_t<in_b, B, prefix_info<int_prefix::none>>>>::prefix;
1905struct extract_zero : std::false_type{};
1908struct extract_zero<zero_info> : std::true_type {};
1910template<
typename A,
typename B,
unsigned U>
1911struct extract_zero<fmt_info<A, B, U>> {
1912 inline static constexpr bool in_a = extract_zero<A>::value, in_b = extract_zero<B>::value,
1913 value = extract_zero<std::conditional_t<in_a, A, std::conditional_t<in_b, B, std::false_type>>>::value;
1916template<
int_align Align,
unsigned W
idth,
unsigned Fill,
int_plus_sign Sign,
bool Upper,
int_prefix Prefix,
bool Zero>
1918 inline static constexpr int_align align = Align;
1919 inline static constexpr unsigned width = Width;
1920 inline static constexpr unsigned fill = Fill;
1921 inline static constexpr int_plus_sign sign = Sign;
1922 inline static constexpr bool upper = Upper;
1923 inline static constexpr int_prefix prefix = Prefix;
1924 inline static constexpr bool zero = Zero;
1928using p_to_fmt_t = fmt_params<
1929 extract_align<T>::align,
1930 extract_width<T>::width,
1931 extract_fill<T>::fill,
1932 extract_sign<T>::sign,
1933 extract_upper<T>::value,
1934 extract_prefix<T>::prefix,
1935 extract_zero<T>::value>;
1938using to_fmt_t = p_to_fmt_t<std::remove_cvref_t<T>>;
1941struct is_fmt_params : std::false_type{};
1943template<
int_align Align,
unsigned W
idth,
unsigned Fill,
int_plus_sign Sign,
bool Upper,
int_prefix Prefix,
bool Zero>
1944struct is_fmt_params<fmt_params<Align, Width, Fill, Sign, Upper, Prefix, Zero>> : std::true_type{};
1947concept FmtParamSet = is_fmt_params<T>::value;
1951template<f::FmtParam F>
1952constexpr auto operator|(
const F& f, fmt_end) {
1956template<
char C = 0,
char...Chars>
1957constexpr auto parse_fmt_symbol();
1959template<
unsigned N,
char C =
'Z',
char...Chars>
1960constexpr auto parse_width() {
1961 if constexpr (C >=
'0' && C <=
'9') {
1962 return parse_width<N * 10 + C -
'0', Chars...>();
1964 return w<N> | parse_fmt_symbol<C, Chars...>();
1968template<
unsigned N,
char C =
'Z',
char...Chars>
1969constexpr auto parse_fill() {
1970 if constexpr (C >=
'0' && C <=
'9') {
1971 return parse_fill<N * 16 + C -
'0', Chars...>();
1972 }
else if constexpr (C >=
'a' && C <=
'f') {
1973 return parse_fill<N * 16 + C -
'a' + 10, Chars...>();
1974 }
else if constexpr (C >=
'A' && C <=
'F') {
1975 return parse_fill<N * 16 + C -
'A' + 10, Chars...>();
1977 return f<N> | parse_fmt_symbol<C, Chars...>();
1981template<
char C,
char...Chars>
1982constexpr auto parse_fmt_symbol() {
1983 if constexpr (C ==
'0') {
1984 return z | parse_fmt_symbol<Chars...>();
1985 }
else if constexpr (C ==
'a') {
1986 return p | parse_fmt_symbol<Chars...>();
1987 }
else if constexpr (C ==
'A') {
1988 return P | parse_fmt_symbol<Chars...>();
1989 }
else if constexpr (C ==
'b') {
1990 return l | parse_fmt_symbol<Chars...>();
1991 }
else if constexpr (C ==
'c') {
1992 return c | parse_fmt_symbol<Chars...>();
1993 }
else if constexpr (C ==
'd') {
1994 return r | parse_fmt_symbol<Chars...>();
1995 }
else if constexpr (C ==
'e') {
1996 return sp | parse_fmt_symbol<Chars...>();
1997 }
else if constexpr (C ==
'f') {
1998 return ss | parse_fmt_symbol<Chars...>();
1999 }
else if constexpr (C ==
'E') {
2000 return u | parse_fmt_symbol<Chars...>();
2001 }
else if constexpr (C ==
'\'') {
2002 return parse_fmt_symbol<Chars...>();
2003 }
else if constexpr (C ==
'F') {
2004 return parse_fill<0, Chars...>();
2005 }
else if constexpr (C >=
'1' && C <=
'9') {
2006 return parse_width<C -
'0', Chars...>();
2012template<
unsigned R,
typename T>
2013struct fmt_radix_info {};
2015template<
unsigned N,
char C = 0,
char...Chars>
2016constexpr auto parse_radix() {
2017 if constexpr (C >=
'0' && C <=
'9') {
2018 return parse_radix<N * 10 + C -
'0', Chars...>();
2019 }
else if constexpr (C == 0) {
2020 return fmt_radix_info<N, to_fmt_t<fmt_default>>{};
2022 return fmt_radix_info<N,
decltype(parse_fmt_symbol<C, Chars...>())>{};
2026template<
char C1,
char C2,
char C3,
char...Chars>
2027constexpr auto skip_0x() {
2028 static_assert(C1 ==
'0' && C2 ==
'x' &&
"Fmt symbols must begin with 0x");
2029 static_assert(C3 >=
'1' && C3 <=
'9' &&
"Radix must begin with 1-9");
2030 return parse_radix<C3 -
'0', Chars...>();
2035template<
typename K,
bool Ucase>
2036inline constexpr K digits_symbols[36] = {K(
'0'), K(
'1'), K(
'2'), K(
'3'), K(
'4'), K(
'5'), K(
'6'), K(
'7'), K(
'8'), K(
'9'),
2037 K(Ucase ?
'A' :
'a'), K(Ucase ?
'B' :
'b'), K(Ucase ?
'C' :
'c'), K(Ucase ?
'D' :
'd'), K(Ucase ?
'E' :
'e'),
2038 K(Ucase ?
'F' :
'f'), K(Ucase ?
'G' :
'g'), K(Ucase ?
'H' :
'h'), K(Ucase ?
'I' :
'i'), K(Ucase ?
'J' :
'j'),
2039 K(Ucase ?
'K' :
'k'), K(Ucase ?
'L' :
'l'), K(Ucase ?
'M' :
'm'), K(Ucase ?
'N' :
'n'), K(Ucase ?
'O' :
'o'),
2040 K(Ucase ?
'P' :
'p'), K(Ucase ?
'Q' :
'q'), K(Ucase ?
'R' :
'r'), K(Ucase ?
'S' :
's'), K(Ucase ?
'T' :
't'),
2041 K(Ucase ?
'U' :
'u'), K(Ucase ?
'V' :
'v'), K(Ucase ?
'W' :
'w'), K(Ucase ?
'X' :
'x'), K(Ucase ?
'Y' :
'y'),
2042 K(Ucase ?
'Z' :
'z'),
2045template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2046struct expr_integer_src {
2049 constexpr expr_integer_src(T v) : value_(v){}
2050 constexpr expr_integer_src(T v,
unsigned w) : value_(v), width_(w){}
2052 template<is_std_
string_v S>
2055 template<
typename S>
requires std::is_constructible_v<S, empty_expr<typename S::symb_type>>
2059template<is_one_of_
char_v K, FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
2060requires (Radix > 1 && Radix <= 36)
2062 using symb_type = K;
2064 enum { bufSize = 64 };
2065 mutable K buf[bufSize];
2069 mutable bool negate_{};
2071 constexpr expr_integer(T t) : value_(t){}
2072 constexpr expr_integer(T t,
unsigned w) : value_(t), width_(w){}
2073 constexpr expr_integer(
const expr_integer_src<T, Radix, FP>& v) : value_(v.value_), width_(v.width_){}
2075 constexpr expr_integer(expr_integer&& t) noexcept : value_(t.value_), width_(t.width_){}
2077 constexpr size_t length() const noexcept {
2078 K* bufEnd = std::end(buf), *itr = bufEnd;
2081 need_sign<K, std::is_signed_v<T>, T> store(value_);
2083 *--itr = digits_symbols<K, FP::upper>[store.val % Radix];
2086 if constexpr (std::is_signed_v<T>) {
2087 negate_ = store.negate;
2090 *--itr = digits_symbols<K, FP::upper>[0];
2092 size_t len = bufEnd - itr;
2094 if constexpr (std::is_signed_v<T>) {
2095 if constexpr (FP::sign != f::int_plus_sign::none) {
2103 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2105 if constexpr (Radix != 8) {
2109 if constexpr (FP::width == unsigned(-1)) {
2110 return std::max<size_t>(width_, len);
2112 return std::max<size_t>(FP::width, len);
2115 constexpr K* place(K* ptr)
const noexcept {
2116 size_t len =
static_cast<size_t>(value_), all_len = len;
2117 if constexpr (std::is_signed_v<T>) {
2118 if constexpr (FP::sign != f::int_plus_sign::none) {
2126 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2128 if constexpr (Radix != 8) {
2132 if constexpr (FP::zero) {
2133 if constexpr (std::is_signed_v<T>) {
2137 if constexpr (FP::sign == f::int_plus_sign::plus) {
2139 }
else if constexpr (FP::sign == f::int_plus_sign::space) {
2144 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2146 if constexpr (Radix == 2) {
2147 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'b') : K(
'B');
2148 }
else if constexpr (Radix == 16) {
2149 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'x') : K(
'X');
2153 if constexpr (FP::width == unsigned(-1)) {
2154 if (width_ > all_len) {
2155 before = width_ - all_len;
2158 if (FP::width > all_len) {
2159 before = FP::width - all_len;
2163 ch_traits<K>::assign(ptr, before, K(
'0'));
2166 ch_traits<K>::copy(ptr, std::end(buf) - len, len);
2169 size_t before = 0, after = 0;
2170 if constexpr (FP::width == unsigned(-1)) {
2171 if (width_ > all_len) {
2172 if constexpr (FP::align == f::int_align::left) {
2173 after = width_ - all_len;
2174 }
else if constexpr (FP::align == f::int_align::center) {
2175 before = (width_ - all_len) / 2;
2176 after = width_ - all_len - before;
2178 before = width_ - all_len;
2182 if (FP::width > all_len) {
2183 if constexpr (FP::align == f::int_align::left) {
2184 after = FP::width - all_len;
2185 }
else if constexpr (FP::align == f::int_align::center) {
2186 before = (FP::width - all_len) / 2;
2187 after = FP::width - all_len - before;
2189 before = FP::width - all_len;
2194 ch_traits<K>::assign(ptr, before, K(FP::fill));
2197 if constexpr (std::is_signed_v<T>) {
2201 if constexpr (FP::sign == f::int_plus_sign::plus) {
2203 }
else if constexpr (FP::sign == f::int_plus_sign::space) {
2208 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2210 if constexpr (Radix == 2) {
2211 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'b') : K(
'B');
2212 }
else if constexpr (Radix == 16) {
2213 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'x') : K(
'X');
2216 ch_traits<K>::copy(ptr, std::end(buf) - len, len);
2220 ch_traits<K>::assign(ptr, after, K(FP::fill));
2228template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2229template<is_std_string_v S>
2230expr_integer_src<T, Radix, FP>::operator S()
const {
2231 using st =
typename S::value_type;
2232 using Al =
typename S::allocator_type;
2233 return to_std_string<st, Al>(expr_integer<st, T, Radix, FP>{value_, width_});
2236template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2238expr_integer_src<T, Radix, FP>::operator S()
const {
2239 using st =
typename S::symb_type;
2240 return S{expr_integer<st, T, Radix, FP>{value_, width_}};
2243template<
typename K, FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
2244struct convert_to_strexpr<K, expr_integer_src<T, Radix, FP>> {
2245 using type = expr_integer<K, T, Radix, FP>;
2248template<
unsigned R,
typename T,
typename F>
2249struct flags_checker {
2251 using flags_t = f::to_fmt_t<F>;
2252 inline static constexpr unsigned Radix = R;
2255template<
typename T,
bool ArgW
idth>
2256concept good_int_flags =
2257 T::Radix > 1 && T::Radix <= 36
2260 && (T::flags_t::align == f::int_align::none || !T::flags_t::zero)
2263 && (std::is_signed_v<typename T::val_t> || T::flags_t::sign == f::int_plus_sign::none)
2266 && (T::flags_t::width == unsigned(-1)) == ArgWidth
2269 && (T::flags_t::prefix == f::int_prefix::none || T::Radix == 2 || T::Radix == 8 || T::Radix == 16);
2378template<
unsigned R, auto fp = f::df, FromIntNumber T>
requires good_int_flags<flags_checker<R, T,
decltype(fp)>,
false>
2380 using fmt_param = f::to_fmt_t<
decltype(fp)>;
2381 return expr_integer_src<T, R, fmt_param>{v};
2387template<
unsigned R, auto fp = f::df, FromIntNumber T>
requires good_int_flags<flags_checker<R, T,
decltype(fp)>,
true>
2389 using fmt_param = f::to_fmt_t<
decltype(fp)>;
2390 return expr_integer_src<T, R, fmt_param>{v, w};
2393template<
typename T,
unsigned R,
typename F>
requires good_int_flags<flags_checker<R, T, F>,
false>
2394auto operator / (T v,
const f::fmt_radix_info<R, F>&) {
2395 return expr_integer_src<T, R, f::to_fmt_t<F>>{v};
2400 using symb_type = K;
2401 mutable u8s buf[40];
2404 constexpr expr_real(
double d) : v(d) {}
2405 constexpr expr_real(
float d) : v(d) {}
2407 size_t length() const noexcept {
2408 auto [ptr, ec] = std::to_chars(buf, buf + std::size(buf), v);
2409 l = ec != std::errc{} ? 0 : ptr - buf;
2412 K* place(K* ptr)
const noexcept {
2413 if constexpr (
sizeof(K) ==
sizeof(buf[0])) {
2414 ch_traits<K>::copy(ptr, (K*)buf, l);
2416 for (
size_t i = 0; i < l; i++) {
2434template<
typename K, std::
floating_po
int T>
2435struct convert_to_strexpr<K, T> {
2436 using type = expr_real<K>;
2450template<
typename K>
requires is_one_of_char_v<K>
2451inline constexpr expr_real<K>
e_num(
double t) {
2455template<FromIntNumber Val,
bool All,
bool Ucase,
bool Ox>
2456struct expr_hex_src {
2457 explicit constexpr expr_hex_src(Val v) : v_(v){}
2461template<
typename K, FromIntNumber Val,
bool All,
bool Ucase,
bool Ox>
2463 using symb_type = K;
2464 mutable need_sign<K, std::is_signed_v<Val>, Val> v_;
2465 mutable K buf_[
sizeof(Val) * 2]{};
2467 explicit constexpr expr_hex(Val v) : v_(v){}
2468 constexpr expr_hex(
const expr_hex_src<Val, All, Ucase, Ox>& v) : v_(v.v_){}
2470 constexpr size_t length() const noexcept {
2471 K *ptr = buf_ + std::size(buf_);
2474 *--ptr = digits_symbols<K, Ucase>[v_.val & 0xF];
2478 *--ptr = digits_symbols<K, Ucase>[v_.val & 0xF];
2483 if constexpr (All) {
2484 if (
size_t need =
sizeof(Val) * 2 - l) {
2485 ch_traits<K>::assign(buf_, need, K(
'0'));
2487 l =
sizeof(Val) * 2;
2493 if constexpr (std::is_signed_v<Val>) {
2494 return l + (Ox ? 2 : 0) + (v_.negate ? 1 : 0);
2496 return l + (Ox ? 2 : 0);
2498 constexpr K* place(K* ptr)
const noexcept {
2499 if constexpr (std::is_signed_v<Val>) {
2508 if constexpr (All) {
2509 ch_traits<K>::copy(ptr, buf_,
sizeof(Val) * 2);
2510 return ptr +
sizeof(Val) * 2;
2512 ch_traits<K>::copy(ptr, buf_ + std::size(buf_) - v_.val, v_.val);
2513 return ptr + v_.val;
2579template<
unsigned Flags = 0, FromIntNumber T>
2581 return expr_hex_src<T, (Flags &
HexFlags::Short) == 0, (Flags & HexFlags::Lcase) == 0, (Flags & HexFlags::No0x) == 0>{v};
2584template<
char c = 0,
char...Chars>
2585constexpr unsigned parse_f16_flags() {
2586 if constexpr (c ==
'1') {
2588 }
else if constexpr (c ==
'2') {
2589 return HexFlags::Lcase | parse_f16_flags<Chars...>();
2590 }
else if constexpr (c ==
'3') {
2591 return HexFlags::No0x | parse_f16_flags<Chars...>();
2600template<FromIntNumber T,
unsigned Flags>
2601constexpr auto operator/(T v,
const f16flags<Flags>&) {
2602 return expr_hex_src<T, (Flags &
HexFlags::Short) == 0, (Flags & HexFlags::Lcase) == 0, (Flags & HexFlags::No0x) == 0>{v};
2605inline namespace literals {
2606template<
char...Chars>
2607constexpr auto operator""_f16() {
2608 return f16flags<parse_f16_flags<Chars...>()>{};
2620template<
typename K,
typename Val,
bool All,
bool Ucase,
bool Ox>
2621struct convert_to_strexpr<K, expr_hex_src<Val, All, Ucase, Ox>> {
2622 using type = expr_hex<K, Val, All, Ucase, Ox>;
2626struct expr_pointer : expr_hex<K, uintptr_t, true, true, true> {
2627 constexpr expr_pointer(
const void* ptr) : expr_hex<K, uintptr_t, true, true, true>((uintptr_t)ptr){}
2638template<
typename K,
typename T>
2639struct convert_to_strexpr<K, const T*> {
2640 using type = expr_pointer<K>;
2643template<
typename K, StrExprForType<K> A,
bool Left>
2645 using symb_type = K;
2649 mutable size_t alen_{};
2650 constexpr expr_fill(K symbol,
size_t width,
const A& a) : symbol_(symbol), width_(width), a_(a){}
2652 constexpr size_t length() const noexcept {
2653 alen_ = a_.length();
2654 return std::max(alen_, width_);
2656 constexpr K* place(K* ptr)
const noexcept {
2657 if (alen_ >= width_) {
2658 return (K*)a_.place((
typename A::symb_type*)ptr);
2660 size_t w = width_ - alen_;
2661 if constexpr (Left) {
2662 ch_traits<K>::assign(ptr, w, symbol_);
2664 return (K*)a_.place((
typename A::symb_type*)ptr);
2666 ptr = (K*)a_.place((
typename A::symb_type*)ptr);
2667 ch_traits<K>::assign(ptr, w, symbol_);
2694template<StrExpr A,
typename K =
typename A::symb_type>
2695expr_fill<K, A, true>
e_fill_left(
const A& a,
size_t width, K symbol = K(
' ')) {
2696 return {symbol, width, a};
2720template<StrExpr A,
typename K =
typename A::symb_type>
2721expr_fill<K, A, false>
e_fill_right(
const A& a,
size_t width, K symbol = K(
' ')) {
2722 return {symbol, width, a};
2741template<
typename K,
typename T,
size_t I,
bool tail,
bool skip_empty>
2742struct expr_join : expr_to_std_string<expr_join<K, T, I, tail, skip_empty>> {
2743 using symb_type = K;
2744 using my_type = expr_join<K, T, I, tail, skip_empty>;
2748 constexpr expr_join(
const T& _s,
const K* _delim) : s(_s), delim(_delim){}
2750 constexpr size_t length() const noexcept {
2752 for (
const auto& t: s) {
2753 size_t len = t.length();
2754 if (len > 0 || !skip_empty) {
2755 if (I > 0 && l > 0) {
2761 return l + (tail && I > 0 && (l > 0 || (!skip_empty && std::size(s) > 0))? I : 0);
2763 constexpr K* place(K* ptr)
const noexcept {
2768 for (
const auto& t: s) {
2769 size_t copyLen = t.length();
2770 if ((copyLen > 0 || !skip_empty) && I > 0 && write != ptr) {
2771 ch_traits<K>::copy(write, delim, I);
2774 ch_traits<K>::copy(write, t.data(), copyLen);
2777 if (tail && I > 0 && (write != ptr || (!skip_empty && std::size(s) > 0))) {
2778 ch_traits<K>::copy(write, delim, I);
2798template<bool tail = false, bool skip_empty = false, typename L, typename K = typename const_lit<L>::symb_type,
size_t I = const_lit<L>::Count,
typename T>
2799inline constexpr auto e_join(
const T& s, L&& d) {
2800 return expr_join<K, T, I - 1, tail, skip_empty>{s, d};
2804concept is_const_pattern = N > 1 && N <= 17;
2806template<
typename K,
size_t I>
2808 constexpr static const size_t value = size_t(K(~0x7F)) << ((I - 1) *
sizeof(K) * 8) | _ascii_mask<K, I - 1>::value;
2812struct _ascii_mask<K, 0> {
2813 constexpr static const size_t value = 0;
2818 using uns = std::make_unsigned_t<K>;
2819 constexpr static const size_t WIDTH =
sizeof(size_t) /
sizeof(uns);
2820 constexpr static const size_t VALUE = _ascii_mask<uns, WIDTH>::value;
2824constexpr inline bool isAsciiUpper(K k) {
2825 return k >=
'A' && k <=
'Z';
2829constexpr inline bool isAsciiLower(K k) {
2830 return k >=
'a' && k <=
'z';
2834constexpr inline K makeAsciiLower(K k) {
2835 return isAsciiUpper(k) ? k | 0x20 : k;
2839constexpr inline K makeAsciiUpper(K k) {
2840 return isAsciiLower(k) ? k & ~0x20 : k;
2843enum TrimSides { TrimLeft = 1, TrimRight = 2, TrimAll = 3 };
2844template<TrimS
ides S,
typename K,
size_t N,
bool withSpaces = false>
2845struct trim_operator;
2848struct digits_selector {
2849 using wider_type = uint16_t;
2853struct digits_selector<2> {
2854 using wider_type = uint32_t;
2858struct digits_selector<4> {
2859 using wider_type = uint64_t;
2873template<
bool CanNegate,
bool CheckOverflow,
typename T>
2874struct result_type_selector {
2879struct result_type_selector<true, false, T> {
2880 using type = std::make_unsigned_t<T>;
2883template<
unsigned Base>
2884constexpr unsigned digit_width() {
2903template<
typename T,
unsigned Base>
2904constexpr unsigned max_overflow_digits = (
sizeof(T) * CHAR_BIT) / digit_width<Base>();
2907struct convert_result {
2914 inline static constexpr uint8_t NUMBERS[] = {
2915 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2916 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 1, 2, 3,
2917 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
2918 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 16,
2919 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 255, 255, 255, 255, 255, 255, 255,
2920 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2921 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2922 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2923 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2924 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255};
2926 template<
typename K,
unsigned Base>
2927 static constexpr std::make_unsigned_t<K> toDigit(K s) {
2928 auto us =
static_cast<std::make_unsigned_t<K>
>(s);
2929 if constexpr (Base <= 10) {
2932 if constexpr (
sizeof(K) == 1) {
2935 return us < 256 ? NUMBERS[us] : us;
2940 template<
typename K, ToIntNumber T,
unsigned Base,
bool CheckOverflow>
2942 static constexpr convert_result<T> parse(
const K* start,
const K* current,
const K* end,
bool negate) {
2943 using u_type = std::make_unsigned_t<T>;
2944 #ifndef HAS_BUILTIN_OVERFLOW
2945 u_type maxMult = 0, maxAdd = 0;
2946 if constexpr (CheckOverflow) {
2947 maxMult = std::numeric_limits<u_type>::max() / Base;
2948 maxAdd = std::numeric_limits<u_type>::max() % Base;
2952 unsigned maxDigits = max_overflow_digits<u_type, Base>;
2954 const K* from = current;
2956 bool no_need_check_o_f = !CheckOverflow || end - current <= maxDigits;
2958 if (no_need_check_o_f) {
2960 const u_type digit = toDigit<K, Base>(*current);
2961 if (digit >= Base) {
2964 number = number * Base + digit;
2965 if (++current == end) {
2971 for (;maxDigits; maxDigits--) {
2972 const u_type digit = toDigit<K, Base>(*current);
2973 if (digit >= Base) {
2976 number = number * Base + digit;
2983 const u_type digit = toDigit<K, Base>(*current);
2984 if (digit >= Base) {
2987 #ifdef HAS_BUILTIN_OVERFLOW
2988 if (__builtin_mul_overflow(number, Base, &number) ||
2989 __builtin_add_overflow(number, digit, &number)) {
2991 if (number < maxMult || (number == maxMult && number < maxAdd)) {
2992 number = number * Base + digit;
2996 while(++current < end) {
2997 if (toDigit<K, Base>(*current) >= Base) {
3003 if (++current == end) {
3011 if constexpr (std::is_signed_v<T>) {
3012 result = negate ? 0 - number : number;
3013 if constexpr (CheckOverflow) {
3015 if (number > (u_type)std::numeric_limits<T>::max() + (negate ? 1 : 0)) {
3026 return {result, error, size_t(current - start)};
3033 template<
typename K, ToIntNumber T,
unsigned Base = 0,
bool CheckOverflow = true,
bool SkipWs = true,
bool AllowSign = true>
3034 requires(Base == unsigned(-1) || (Base < 37 && Base != 1))
3035 static constexpr convert_result<T> to_integer(const K* start,
size_t len) noexcept {
3036 const K *ptr = start, *end = ptr + len;
3037 bool negate =
false;
3038 if constexpr (SkipWs) {
3039 while (ptr < end && std::make_unsigned_t<K>(*ptr) <=
' ')
3043 if constexpr (std::is_signed_v<T>) {
3044 if constexpr (AllowSign) {
3049 }
else if (*ptr ==
'-') {
3061 }
else if constexpr (AllowSign) {
3070 if constexpr (Base == 0 || Base == unsigned(-1)) {
3074 if (*ptr ==
'x' || *ptr ==
'X') {
3075 return parse<K, T, 16, CheckOverflow>(start, ++ptr, end, negate);
3077 if constexpr (Base == unsigned(-1)) {
3078 if (*ptr ==
'b' || *ptr ==
'B') {
3079 return parse<K, T, 2, CheckOverflow>(start, ++ptr, end, negate);
3081 if (*ptr ==
'o' || *ptr ==
'O') {
3082 return parse<K, T, 8, CheckOverflow>(start, ++ptr, end, negate);
3085 return parse<K, T, 8, CheckOverflow>(start, --ptr, end, negate);
3089 return parse<K, T, 10, CheckOverflow>(start, ptr, end, negate);
3091 return parse<K, T, Base, CheckOverflow>(start, ptr, end, negate);
3097template<
typename K,
typename Impl>
3098class null_terminated {
3106 constexpr const K* c_str()
const {
return static_cast<const Impl*
>(
this)->symbols(); }
3109template<
typename K,
typename Impl,
bool Mutable>
class buffer_pointers;
3119template<
typename K,
typename Impl>
3120class buffer_pointers<K, Impl, false> {
3121 constexpr const Impl& d()
const {
return *
static_cast<const Impl*
>(
this); }
3129 constexpr const K* data()
const {
return d().symbols(); }
3136 constexpr const K* begin()
const {
return d().symbols(); }
3143 constexpr const K* end()
const {
return d().symbols() + d().length(); }
3150 constexpr const K* cbegin()
const {
return d().symbols(); }
3157 constexpr const K* cend()
const {
return d().symbols() + d().length(); }
3160template<
typename K,
typename Impl>
3161class buffer_pointers<K, Impl, true> :
public buffer_pointers<K, Impl, false> {
3162 constexpr Impl& d() {
return *
static_cast<Impl*
>(
this); }
3163 using base = buffer_pointers<K, Impl, false>;
3171 constexpr const K* data()
const {
return base::data(); }
3178 constexpr const K* begin()
const {
return base::begin(); }
3185 constexpr const K* end()
const {
return base::end(); }
3192 constexpr const K* cbegin()
const {
return base::cbegin(); }
3199 constexpr const K* cend()
const {
return base::cend(); }
3206 constexpr K* data() {
return d().str(); }
3213 constexpr K* begin() {
return d().str(); }
3220 constexpr K* end() {
return d().str() + d().length(); }
3229template<
typename K,
typename StrSrc>
3231 using str_t = StrSrc;
3236 constexpr SplitterBase(str_t text, str_t delim) : text_(text), delim_(delim) {}
3242 return text_.length() == str::npos;
3251 if (!text_.length()) {
3256 }
else if (text_.length() == str::npos) {
3257 return {
nullptr, 0};
3259 size_t pos = text_.find(delim_),
next = 0;
3260 if (pos == str::npos) {
3261 pos = text_.length();
3264 next = pos + delim_.length();
3266 str_t result{text_.str, pos};
3279inline constexpr from_end to_end{0};
3281template<
typename T,
typename K>
3282concept is_slice_find =
requires (
const T& t) {
3283 requires is_equal_str_type_v<K, symb_type_from_src_t<
decltype(t.pattern_)>>;
3284 { T::to_end_of_pattern }->std::same_as<
const bool&>;
3285 { T::offset_from_found }->std::same_as<
const bool&>;
3286 { T::find_reverse }->std::same_as<
const bool&>;
3287 { T::all_at_fail }->std::same_as<
const bool&>;
3288 { t.offset_ } -> std::convertible_to<size_t>;
3289 { t.skip_ } -> std::convertible_to<size_t>;
3290 { t.find(t.pattern_,
size_t(0)) } -> std::convertible_to<size_t>;
3294using slice_find_func = size_t(*)(T, T, size_t);
3296template<
typename Pattern,
bool ToEndOfPattern,
bool OffsetFromFound,
bool AllAtFail,
bool FindReverse, slice_find_func<Pattern> F>
3298 inline static constexpr const bool to_end_of_pattern = ToEndOfPattern;
3299 inline static constexpr const bool offset_from_found = OffsetFromFound;
3300 inline static constexpr const bool find_reverse = FindReverse;
3301 inline static constexpr const bool all_at_fail = AllAtFail;
3303 template<StrSource S>
3304 constexpr slice_find(S&& pattern,
size_t offset = 0,
size_t skip = 0) {
3305 pattern_ = std::forward<S>(pattern);
3310 constexpr size_t find(Pattern where,
size_t offset)
const {
3311 return F(where, pattern_, offset);
3318template<
typename T,
typename K>
3319concept first_index_in_str = std::is_same_v<T, from_end> || std::is_convertible_v<T, size_t> || is_slice_find<T, K>;
3321template<
typename T,
typename K>
3322concept last_index_in_str = first_index_in_str<T, K> || std::is_same_v<T, from_begin>;
3348template<
typename K,
typename StrRef,
typename Impl,
bool Mutable>
3349class str_src_algs :
public buffer_pointers<K, Impl, Mutable> {
3350 constexpr const Impl& d()
const noexcept {
3351 return *
static_cast<const Impl*
>(
this);
3353 constexpr size_t _len()
const noexcept {
3354 return d().length();
3356 constexpr const K* _str()
const noexcept {
3357 return d().symbols();
3359 constexpr bool _is_empty()
const noexcept {
3360 return d().is_empty();
3364 using symb_type = K;
3365 using str_piece = StrRef;
3366 using traits = ch_traits<K>;
3367 using uns_type = std::make_unsigned_t<K>;
3368 using my_type = Impl;
3369 using base = str_src_algs<K, StrRef, Impl, Mutable>;
3370 str_src_algs() =
default;
3384 constexpr K*
place(K* ptr)
const noexcept {
3385 size_t myLen = _len();
3386 traits::copy(ptr, _str(), myLen);
3400 size_t tlen = std::min(_len(), bufSize - 1);
3401 traits::copy(buffer, _str(), tlen);
3421 constexpr std::basic_string_view<D>
to_sv() const noexcept {
3422 return {(
const D*)_str(), _len()};
3431 constexpr operator std::basic_string_view<D, Traits>()
const {
3432 return {(
const D*)_str(), _len()};
3440 template<
typename D = K,
typename Traits = std::
char_traits<D>,
typename Allocator = std::allocator<D>>
requires is_equal_str_type_v<K, D>
3441 constexpr std::basic_string<D, Traits, Allocator>
to_string()
const {
3442 return {(
const D*)_str(), _len()};
3451 constexpr operator std::basic_string<D, Traits, Allocator>()
const {
3452 return {(
const D*)_str(), _len()};
3460 constexpr operator str_piece() const noexcept {
3461 return str_piece{_str(), _len()};
3469 constexpr str_piece
to_str() const noexcept {
3470 return {_str(), _len()};
3495 [[deprecated(
"Use 'slice' or [start, end] in C++23")]]
3496 constexpr str_piece
operator()(ptrdiff_t from, ptrdiff_t len = 0) const noexcept {
3497 size_t myLen = _len(), idxStart = from >= 0 ? from : (ptrdiff_t)myLen > -from ? myLen + from : 0,
3498 idxEnd = len > 0 ? idxStart + len : (ptrdiff_t)myLen > -len ? myLen + len : 0;
3501 if (idxStart > idxEnd)
3503 return str_piece{_str() + idxStart, idxEnd - idxStart};
3573 template<first_index_in_str<K> S, last_index_in_str<K> E>
3574 constexpr str_piece
slice(S start, E end)
const noexcept {
3575 size_t idxStart, idxEnd, len = _len();
3576 if constexpr (is_slice_find<S, K>) {
3577 size_t offset = std::min(S::find_reverse ? len - start.offset_ : start.offset_, len), skip = start.skip_;
3579 size_t find = start.find(d(), offset);
3580 if (find == str::npos) {
3581 if constexpr (S::all_at_fail) {
3589 if constexpr (S::to_end_of_pattern) {
3590 idxStart = find + start.pattern_.length();
3597 if constexpr (!S::find_reverse) {
3598 offset += start.pattern_.length();
3601 }
else if constexpr (std::is_same_v<S, from_end>) {
3602 idxStart = start.idx_ >= len ? 0 : len - start.idx_;
3604 idxStart = std::min(
size_t(start), len);
3607 if constexpr (is_slice_find<E, K>) {
3608 size_t offset = std::min(E::offset_from_found ? idxStart + end.offset_ : E::find_reverse ? len - end.offset_ : end.offset_, len), skip = end.skip_;
3610 size_t find = end.find(d(), offset);
3611 if (find == str::npos) {
3612 if constexpr (E::all_at_fail) {
3620 if constexpr (E::to_end_of_pattern) {
3621 idxEnd = find + end.pattern_.length();
3628 if constexpr (!E::find_reverse) {
3629 offset += end.pattern_.length();
3632 }
else if constexpr (std::is_same_v<E, from_begin>) {
3633 idxEnd = std::max(idxStart, std::min(end.idx_, len));
3634 }
else if constexpr (std::is_same_v<E, from_end>) {
3635 idxEnd = std::max(idxStart, end.idx_ >= len ? 0 : len - end.idx_);
3638 idxEnd = len - idxStart <= e ? len : idxStart + e;
3641 return str_piece{_str() + idxStart, idxEnd - idxStart};
3644#if defined(__cpp_multidimensional_subscript) && __cpp_multidimensional_subscript >= 202211L
3649 template<first_index_in_str<K> S, last_index_in_str<K> E>
3650 constexpr str_piece operator[](S start, E end)
const noexcept {
3651 return slice(start, end);
3658 template<
typename E>
requires std::is_convertible_v<E, size_t> || is_slice_find<E, K>
3659 constexpr str_piece
prefix(E count)
const noexcept {
3660 return slice(0, count);
3666 template<
typename E>
requires std::is_convertible_v<E, size_t> || is_slice_find<E, K>
3667 constexpr str_piece
tail(E count)
const noexcept {
3668 return slice(count, to_end);
3674 template<
typename E>
requires std::is_convertible_v<E, size_t> || is_slice_find<E, K>
3675 constexpr str_piece
suffix(E count)
const noexcept {
3676 if constexpr (std::is_convertible_v<E, size_t>) {
3677 return slice(from_end(
static_cast<size_t>(count)), to_end);
3679 return slice(count, to_end);
3708 template<
typename R = str_piece,
typename E>
3709 requires is_slice_find<E, K>
3711 size_t idxEnd = 0, len = _len(), found = str::npos;
3712 size_t offset = std::min(E::find_reverse ? len - delimeter.offset_ : delimeter.offset_, len), skip = delimeter.skip_;
3714 size_t find = delimeter.find(d(), offset);
3715 if (find == str::npos) {
3716 if constexpr (E::all_at_fail) {
3724 idxEnd = found = find;
3725 if constexpr (E::to_end_of_pattern) {
3726 idxEnd += delimeter.pattern_.length();
3731 if constexpr (!E::find_reverse) {
3732 offset += delimeter.pattern_.length();
3736 auto before = str_piece(_str(), idxEnd);
3738 if constexpr (!E::to_end_of_pattern) {
3739 if (found != str::npos) {
3740 idxEnd += delimeter.pattern_.length();
3743 return { before, str_piece{_str() + idxEnd, len - idxEnd}, found };
3755 [[deprecated(
"Use 'slice' or [start, len] in C++23")]]
3756 constexpr str_piece
mid(
size_t from,
size_t len = -1) const noexcept {
3757 size_t myLen = _len(), idxStart = from, idxEnd = from > std::numeric_limits<size_t>::max() - len ? myLen : from + len;
3760 if (idxStart > idxEnd)
3762 return str_piece{_str() + idxStart, idxEnd - idxStart};
3778 constexpr str_piece
from_to(
size_t from,
size_t to)
const noexcept {
3779 return str_piece{_str() + from, to - from};
3791 [[deprecated(
"Use 'slice(0, begin_or_all(pattern, offset))' or '[0, begin_or_all(pattern, offset)]' in C++23, or 'slice(0, \"pattern\"_boa))'")]]
3792 constexpr str_piece
until(str_piece pattern,
size_t offset = 0) const noexcept {
3812 constexpr K
at(ptrdiff_t idx)
const {
3813 return _str()[idx >= 0 ? idx : _len() + idx];
3817 constexpr int compare(
const K* text,
size_t len)
const {
3818 size_t myLen = _len();
3819 int cmp = traits::compare(_str(), text, std::min(myLen, len));
3820 return cmp == 0 ? (myLen > len ? 1 : myLen == len ? 0 : -1) : cmp;
3831 return compare(o.symbols(), o.length());
3842 size_t myLen = _len(), idx = 0;
3843 const K* ptr = _str();
3844 for (; idx < myLen; idx++) {
3845 uns_type s1 = (uns_type)text[idx];
3849 uns_type s2 = (uns_type)ptr[idx];
3852 }
else if (s1 > s2) {
3856 return text[idx] == 0 ? 0 : -1;
3859 constexpr bool equal(
const K* text,
size_t len)
const noexcept {
3860 return len == _len() && traits::compare(_str(), text, len) == 0;
3870 constexpr bool equal(str_piece other)
const noexcept {
3871 return equal(other.symbols(), other.length());
3882 return equal(other._str(), other._len());
3891 return compare(other._str(), other._len()) <=> 0;
3899 template<typename T, size_t N = const_lit_for<K, T>::Count>
3901 return N - 1 == _len() && traits::compare(_str(), (
const K*)other, N - 1) == 0;
3909 template<typename T, size_t N = const_lit_for<K, T>::Count>
3911 size_t myLen = _len();
3912 int cmp = traits::compare(_str(), (
const K*)other, std::min(myLen, N - 1));
3913 int res = cmp == 0 ? (myLen > N - 1 ? 1 : myLen == N - 1 ? 0 : -1) : cmp;
3919 constexpr int compare_ia(
const K* text,
size_t len)
const noexcept {
3921 return _is_empty() ? 0 : 1;
3922 size_t myLen = _len(), checkLen = std::min(myLen, len);
3923 const uns_type *ptr1 =
reinterpret_cast<const uns_type*
>(_str()), *ptr2 =
reinterpret_cast<const uns_type*
>(text);
3924 while (checkLen--) {
3925 uns_type s1 = *ptr1++, s2 = *ptr2++;
3928 s1 = makeAsciiLower(s1);
3929 s2 = makeAsciiLower(s2);
3935 return myLen == len ? 0 : myLen > len ? 1 : -1;
3946 return compare_ia(text.symbols(), text.length());
3957 constexpr bool equal_ia(str_piece text)
const noexcept {
3958 size_t len = _len();
3959 if (len != text.length())
3961 const uns_type *ptr1 =
reinterpret_cast<const uns_type*
>(_str()), *ptr2 =
reinterpret_cast<const uns_type*
>(text.symbols());
3963 uns_type s1 = *ptr1++, s2 = *ptr2++;
3966 if (isAsciiUpper(s1)) {
3967 if (s1 == (s2 & ~0x20)) {
3970 }
else if (isAsciiLower(s1) && s1 == (s2 | 0x20)) {
3985 constexpr bool less_ia(str_piece text)
const noexcept {
3986 return compare_ia(text.symbols(), text.length()) < 0;
3989 constexpr size_t find(
const K* pattern,
size_t lenPattern,
size_t offset)
const noexcept {
3990 size_t lenText = _len();
3993 if (!lenPattern || offset >= lenText || offset + lenPattern > lenText)
3996 const K *text = _str(), *last = text + lenText - lenPattern, first = pattern[0];
3998 for (
const K* fnd = text + offset;; ++fnd) {
3999 fnd = traits::find(fnd, last - fnd, first);
4002 if (traits::compare(fnd + 1, pattern, lenPattern) == 0)
4003 return static_cast<size_t>(fnd - text);
4016 constexpr size_t find(str_piece pattern,
size_t offset = 0) const noexcept {
4017 return find(pattern.symbols(), pattern.length(), offset);
4035 template<
typename Exc,
typename ... Args>
requires std::is_constructible_v<Exc, Args...>
4036 constexpr size_t find_or_throw(str_piece pattern,
size_t offset = 0, Args&& ... args)
const {
4037 if (
auto fnd = find(pattern.symbols(), pattern.length(), offset); fnd != str::npos) {
4040 throw Exc(std::forward<Args>(args)...);
4052 constexpr size_t find_end(str_piece pattern,
size_t offset = 0) const noexcept {
4053 size_t fnd = find(pattern.symbols(), pattern.length(), offset);
4054 return fnd == str::npos ? fnd : fnd + pattern.length();
4066 constexpr size_t find_or_all(str_piece pattern,
size_t offset = 0) const noexcept {
4067 auto fnd = find(pattern.symbols(), pattern.length(), offset);
4068 return fnd == str::npos ? _len() : fnd;
4081 auto fnd = find(pattern.symbols(), pattern.length(), offset);
4082 return fnd == str::npos ? _len() : fnd + pattern.length();
4085 constexpr size_t find_last(
const K* pattern,
size_t lenPattern,
size_t offset)
const noexcept {
4086 if (lenPattern == 1)
4087 return find_last(pattern[0], offset);
4088 size_t lenText = std::min(_len(), offset);
4091 if (!lenPattern || lenPattern > lenText)
4095 const K *text = _str() + lenPattern, last = pattern[lenPattern];
4096 lenText -= lenPattern;
4098 if (text[--lenText] == last) {
4099 if (traits::compare(text + lenText - lenPattern, pattern, lenPattern) == 0) {
4116 constexpr size_t find_last(str_piece pattern,
size_t offset = -1) const noexcept {
4117 return find_last(pattern.symbols(), pattern.length(), offset);
4130 size_t fnd = find_last(pattern.symbols(), pattern.length(), offset);
4131 return fnd == str::npos ? fnd : fnd + pattern.length();
4144 auto fnd = find_last(pattern.symbols(), pattern.length(), offset);
4145 return fnd == str::npos ? _len() : fnd;
4158 size_t fnd = find_last(pattern.symbols(), pattern.length(), offset);
4159 return fnd == str::npos ? _len() : fnd + pattern.length();
4171 constexpr bool contains(str_piece pattern,
size_t offset = 0) const noexcept {
4172 return find(pattern, offset) != str::npos;
4184 constexpr size_t find(K s,
size_t offset = 0) const noexcept {
4185 size_t len = _len();
4187 const K *
str = _str(), *fnd = traits::find(
str + offset, len - offset, s);
4189 return static_cast<size_t>(fnd -
str);
4204 size_t len = _len();
4206 const K *
str = _str(), *fnd = traits::find(
str + offset, len - offset, s);
4208 return static_cast<size_t>(fnd -
str);
4213 static const K* find_first_by_case(
const K* from,
const K* last, K symbol, K symbolInOtherCase) {
4214 while (from < last) {
4216 if (f == symbol || f == symbolInOtherCase) {
4234 constexpr size_t find_ia(str_piece pattern,
size_t offset = 0) const noexcept {
4235 size_t lenPattern = pattern.length();
4236 size_t lenText = _len();
4239 if (!lenPattern || offset >= lenText || offset + lenPattern > lenText)
4241 const K* patternStr = pattern.symbols();
4243 const K *text = _str(), *last = text + lenText - lenPattern, first = patternStr[0];
4246 bool firstHasCase = isAsciiLower(first);
4248 firstInOtherCase = first & ~0x20;
4249 }
else if (isAsciiUpper(first)) {
4250 firstHasCase =
true;
4251 firstInOtherCase = first | 0x20;
4254 auto equal = [&](
const K* from) {
4255 for (
size_t idx = 0; idx < lenPattern; idx++) {
4256 K s1 = from[idx], s2 = patternStr[idx];
4259 if (isAsciiUpper(s1)) {
4260 if (s1 == (s2 & ~0x20)) {
4263 }
else if (isAsciiLower(s1) && s1 == (s2 | 0x20)) {
4271 for (
const K* fnd = text + offset;;) {
4273 ? find_first_by_case(fnd, last, first, firstInOtherCase)
4274 : traits::find(fnd, last - fnd, first);
4278 return fnd - text - 1;
4295 constexpr size_t find_ia_lower(str_piece pattern_lower,
size_t offset = 0) const noexcept {
4296 size_t lenPattern = pattern_lower.length();
4297 size_t lenText = _len();
4300 if (!lenPattern || offset >= lenText || offset + lenPattern > lenText)
4302 const K* patternStr = pattern_lower.symbols();
4304 const K *text = _str(), *last = text + lenText - lenPattern, first = patternStr[0];
4307 bool firstHasCase = isAsciiLower(first);
4309 firstInOtherCase = first & ~0x20;
4312 auto equal = [&](
const K* from) {
4313 for (
size_t idx = 0; idx < lenPattern; idx++) {
4314 K s1 = from[idx], s2 = patternStr[idx];
4315 if (!(s1 == s2 || (isAsciiUpper(s1) && (s1 | 0x20) == s2))) {
4322 for (
const K* fnd = text + offset;;) {
4324 ? find_first_by_case(fnd, last, first, firstInOtherCase)
4325 : traits::find(fnd, last - fnd, first);
4329 return fnd - text - 1;
4334 template<
typename Op>
4335 constexpr void for_all_founded(
const Op& op,
const K* pattern,
size_t patternLen,
size_t offset,
size_t maxCount)
const {
4338 while (maxCount-- > 0) {
4339 size_t fnd = find(pattern, patternLen, offset);
4340 if (fnd == str::npos)
4343 offset = fnd + patternLen;
4358 template<
typename Op>
4359 constexpr void for_all_founded(
const Op& op, str_piece pattern,
size_t offset = 0,
size_t maxCount = 0)
const {
4360 for_all_founded(op, pattern.symbols(), pattern.length(), offset, maxCount);
4363 template<
typename To = std::vector<
size_t>>
4364 constexpr To find_all(
const K* pattern,
size_t patternLen,
size_t offset,
size_t maxCount)
const {
4366 for_all_founded([&](
auto f) { result.emplace_back(f); }, pattern, patternLen, offset, maxCount);
4381 template<
typename To = std::vector<
size_t>>
4382 constexpr To
find_all(str_piece pattern,
size_t offset = 0,
size_t maxCount = 0)
const {
4383 return find_all(pattern.symbols(), pattern.length(), offset, maxCount);
4385 template<
typename To = std::vector<
size_t>>
4386 constexpr void find_all_to(To& to,
const K* pattern,
size_t len,
size_t offset = 0,
size_t maxCount = 0)
const {
4387 return for_all_founded([&](
size_t pos) {
4388 to.emplace_back(pos);
4389 }, pattern, len, offset, maxCount);
4401 constexpr size_t find_last(K s,
size_t offset = -1) const noexcept {
4402 size_t len = std::min(_len(), offset);
4403 const K *text = _str();
4405 if (text[--len] == s)
4420 constexpr size_t find_first_of(str_piece pattern,
size_t offset = 0) const noexcept {
4421 return std::basic_string_view<K>{_str(), _len()}.find_first_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4433 constexpr std::pair<size_t, size_t>
find_first_of_idx(str_piece pattern,
size_t offset = 0) const noexcept {
4434 const K* text = _str();
4435 size_t fnd = std::basic_string_view<K>{text, _len()}.find_first_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4436 return {fnd, fnd == std::basic_string<K>::npos ? fnd : pattern.find(text[fnd]) };
4449 return std::basic_string_view<K>{_str(), _len()}.find_first_not_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4461 constexpr size_t find_last_of(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4462 return std::basic_string_view<K>{_str(), _len()}.find_last_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4474 constexpr std::pair<size_t, size_t>
find_last_of_idx(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4475 const K* text = _str();
4476 size_t fnd = std::basic_string_view<K>{text, _len()}.find_last_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4477 return {fnd, fnd == std::basic_string<K>::npos ? fnd : pattern.find(text[fnd]) };
4489 constexpr size_t find_last_not_of(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4490 return std::basic_string_view<K>{_str(), _len()}.find_last_not_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4502 [[deprecated(
"Use substring(start, end)")]]
4503 constexpr my_type
substr(ptrdiff_t from, ptrdiff_t len = 0)
const {
4504 return my_type{d()(from, len)};
4514 template<
typename T, first_index_in_str<K> S, last_index_in_str<K> E>
requires std::is_constructible_v<T, str_piece>
4516 str_piece res =
slice(start, end);
4517 if constexpr (std::is_constructible_v<T, const my_type&> && !std::is_same_v<T, str_piece>) {
4518 if (res.is_same(*
this)) {
4528 template<first_index_in_str<K> S, last_index_in_str<K> E>
4529 constexpr my_type
substring(S start, E end)
const noexcept {
4542 [[deprecated(
"Use slice_to(start, end)")]]
4543 constexpr my_type
str_mid(
size_t from,
size_t len = -1)
const {
4544 return my_type{d().mid(from, len)};
4574 template<ToIntNumber T,
bool CheckOverflow = true,
unsigned Base = 0,
bool SkipWs = true,
bool AllowSign = true>
4576 auto [res, err, _] = int_convert::to_integer<K, T, Base, CheckOverflow, SkipWs, AllowSign>(_str(), _len());
4607 template<ToIntNumber T,
bool CheckOverflow = true,
unsigned Base = 0,
bool SkipWs = true,
bool AllowSign = true>
4608 constexpr convert_result<T>
to_int() const noexcept {
4609 return int_convert::to_integer<K, T, Base, CheckOverflow, SkipWs, AllowSign>(_str(), _len());
4617 template<
bool SkipWS = true,
bool AllowPlus = true>
4618 requires(
sizeof(K) == 1 &&
4619 requires { std::from_chars(std::declval<K*>(), std::declval<K*>(), std::declval<double&>()); })
4621 size_t len = _len();
4622 const K* ptr = _str();
4623 if constexpr (SkipWS) {
4624 while (len && uns_type(*ptr) <=
' ') {
4629 if constexpr (AllowPlus) {
4630 if (len && *ptr == K(
'+')) {
4638 if constexpr (
requires { std::from_chars(std::declval<K*>(), std::declval<K*>(), std::declval<double&>()); }) {
4640 if (std::from_chars((
const K*)ptr, (
const K*)ptr + len, d).ec == std::errc{}) {
4652 template<
bool SkipWS = true>
4653 requires(
sizeof(K) == 1 &&
4654 requires { std::from_chars(std::declval<K*>(), std::declval<K*>(), std::declval<double&>()); })
4656 size_t len = _len();
4657 const K* ptr = _str();
4658 if constexpr (SkipWS) {
4659 while (len && uns_type(*ptr) <=
' ') {
4665 if constexpr (
requires { std::from_chars(std::declval<K*>(), std::declval<K*>(), std::declval<double&>()); }) {
4667 if (std::from_chars((
const K*)ptr, (
const K*)ptr + len, d, std::chars_format::hex).ec == std::errc{}) {
4682 template<ToIntNumber T>
4687 template<
typename T,
typename Op>
4688 constexpr T splitf(
const K* delimiter,
size_t lendelimiter,
const Op& beforeFunc,
size_t offset)
const {
4689 size_t mylen = _len();
4690 std::conditional_t<std::is_same_v<T, void>, char, T> results;
4691 str_piece me{_str(), mylen};
4692 for (
size_t i = 0;; i++) {
4693 size_t beginOfDelim = find(delimiter, lendelimiter, offset);
4694 if (beginOfDelim == str::npos) {
4695 str_piece last{me.symbols() + offset, me.length() - offset};
4696 if constexpr (std::is_invocable_v<Op, str_piece&>) {
4699 if constexpr (
requires { results.emplace_back(last); }) {
4700 if (last.is_same(me)) {
4703 results.emplace_back(d());
4705 results.emplace_back(last);
4707 }
else if constexpr (
requires { results.push_back(last); }) {
4708 if (last.is_same(me)) {
4711 results.push_back(d());
4713 results.push_back(last);
4715 }
else if constexpr (
requires {results[i] = last;} &&
requires{std::size(results);}) {
4716 if (i < std::size(results)) {
4717 if (last.is_same(me)) {
4727 str_piece piece{me.symbols() + offset, beginOfDelim - offset};
4728 if constexpr (std::is_invocable_v<Op, str_piece&>) {
4731 if constexpr (
requires { results.emplace_back(piece); }) {
4732 results.emplace_back(piece);
4733 }
else if constexpr (
requires { results.push_back(piece); }) {
4734 results.push_back(piece);
4735 }
else if constexpr (
requires { results[i] = piece; } &&
requires{std::size(results);}) {
4736 if (i < std::size(results)) {
4738 if (i == results.size() - 1) {
4743 offset = beginOfDelim + lendelimiter;
4745 if constexpr (!std::is_same_v<T, void>) {
4779 template<
typename T,
typename Op>
4780 constexpr T
splitf(str_piece delimiter,
const Op& beforeFunc,
size_t offset = 0)
const {
4781 return splitf<T>(delimiter.symbols(), delimiter.length(), beforeFunc, offset);
4795 template<
typename T>
4796 constexpr T
split(str_piece delimiter,
size_t offset = 0)
const {
4797 return splitf<T>(delimiter.symbols(), delimiter.length(), 0, offset);
4802 constexpr bool starts_with(
const K* prefix,
size_t l)
const noexcept {
4803 return _len() >= l && 0 == traits::compare(_str(), prefix, l);
4821 return _len() >
prefix.length() &&
4823 trim_operator<TrimSides::TrimLeft, K, size_t(-1),
true>{}.isTrim(_str()[
prefix.length()]);
4834 return _len() >
prefix.length() &&
4836 trim_operator<TrimSides::TrimLeft, K, 0, false>{next_symbol}.isTrim(_str()[
prefix.length()]);
4838 template<typename T, size_t N = const_lit_for<K, T>::Count,
StrType<K> From>
requires is_const_pattern<N>
4839 constexpr bool starts_with_and_oneof(str_piece prefix, T&& next_symbol)
const noexcept {
4840 return _len() >= N &&
4841 starts_with(prefix) &&
4842 trim_operator<TrimSides::TrimLeft, K, N - 1,
false>{next_symbol}.isTrim(_str()[prefix.length()]);
4845 constexpr bool starts_with_ia(
const K* prefix,
size_t len)
const noexcept {
4846 size_t myLen = _len();
4850 const K* ptr1 = _str();
4852 K s1 = *ptr1++, s2 = *prefix++;
4855 if (makeAsciiLower(s1) != makeAsciiLower(s2))
4867 return starts_with_ia(
prefix.symbols(),
prefix.length());
4876 return _len() >
prefix.length() &&
4877 starts_with_ia(
prefix) &&
4878 trim_operator<TrimSides::TrimLeft, K, size_t(-1),
true>{}.isTrim(_str()[
prefix.length()]);
4889 return _len() >
prefix.length() &&
4890 starts_with_ia(
prefix) &&
4891 trim_operator<TrimSides::TrimLeft, K, 0, false>{next_symbol}.isTrim(_str()[
prefix.length()]);
4893 template<typename T, size_t N = const_lit_for<K, T>::Count,
StrType<K> From>
requires is_const_pattern<N>
4894 constexpr bool starts_with_ia_and_oneof(str_piece prefix, T&& next_symbol)
const noexcept {
4895 return _len() >= N &&
4896 starts_with_ia(prefix) &&
4897 trim_operator<TrimSides::TrimLeft, K, N - 1,
false>{next_symbol}.isTrim(_str()[prefix.length()]);
4902 constexpr bool prefix_in(
const K* text,
size_t len)
const noexcept {
4903 size_t myLen = _len();
4906 return !myLen || 0 == traits::compare(text, _str(), myLen);
4915 return prefix_in(text.symbols(), text.length());
4919 constexpr bool ends_with(
const K* suffix,
size_t len)
const noexcept {
4920 size_t myLen = _len();
4921 return len <= myLen && traits::compare(_str() + myLen - len, suffix, len) == 0;
4934 constexpr bool ends_with_ia(
const K* suffix,
size_t len)
const noexcept {
4935 size_t myLen = _len();
4939 const K* ptr1 = _str() + myLen - len;
4941 K s1 = *ptr1++, s2 = *suffix++;
4944 if (makeAsciiLower(s1) != makeAsciiLower(s2))
4956 return ends_with_ia(
suffix.symbols(),
suffix.length());
4965 if (std::is_constant_evaluated()) {
4966 for (
size_t idx = 0; idx < _len(); idx++) {
4967 if (uns_type(_str()[idx]) > 127) {
4973 const int sl = ascii_mask<K>::WIDTH;
4974 const size_t mask = ascii_mask<K>::VALUE;
4975 size_t len = _len();
4976 const uns_type* ptr =
reinterpret_cast<const uns_type*
>(_str());
4977 if constexpr (sl > 1) {
4978 const size_t roundMask =
sizeof(size_t) - 1;
4979 while (len >= sl && (
reinterpret_cast<size_t>(ptr) & roundMask) != 0) {
4985 if (*
reinterpret_cast<const size_t*
>(ptr) & mask)
5005 template<
typename R = my_type>
5007 return R::upperred_only_ascii_from(d());
5017 template<
typename R = my_type>
5019 return R::lowered_only_ascii_from(d());
5037 template<
typename R = my_type>
5038 R
replaced(str_piece pattern, str_piece repl,
size_t offset = 0,
size_t maxCount = 0)
const {
5039 return R::replaced_from(d(), pattern, repl, offset, maxCount);
5053 template<
typename R = str_piece>
5055 if (starts_with(
prefix)) {
5072 template<
typename R = str_piece>
5074 if (starts_with_ia(
prefix)) {
5091 template<
typename R = str_piece>
5110 template<
typename R = str_piece>
5112 if (ends_with_ia(
suffix)) {
5118 template<StrType<K> From>
5119 constexpr static my_type make_trim_op(
const From& from,
const auto& opTrim) {
5120 str_piece sfrom = from, newPos = opTrim(sfrom);
5121 if (newPos.is_same(sfrom)) {
5125 return my_type{newPos};
5127 template<TrimS
ides S, StrType<K> From>
5128 constexpr static my_type trim_static(
const From& from) {
5129 return make_trim_op(from, trim_operator<S, K,
static_cast<size_t>(-1),
true>{});
5132 template<TrimSides S, bool withSpaces, typename T, size_t N = const_lit_for<K, T>::Count, StrType<K> From>
5133 requires is_const_pattern<N>
5134 constexpr static my_type trim_static(
const From& from, T&& pattern) {
5135 return make_trim_op(from, trim_operator<S, K, N - 1, withSpaces>{pattern});
5138 template<TrimS
ides S,
bool withSpaces, StrType<K> From>
5139 constexpr static my_type trim_static(
const From& from, str_piece pattern) {
5140 return make_trim_op(from, trim_operator<S, K, 0, withSpaces>{{pattern}});
5150 template<
typename R = str_piece>
5152 return R::template trim_static<TrimSides::TrimAll>(d());
5162 template<
typename R = str_piece>
5164 return R::template trim_static<TrimSides::TrimLeft>(d());
5174 template<
typename R = str_piece>
5176 return R::template trim_static<TrimSides::TrimRight>(d());
5188 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
5189 requires is_const_pattern<N>
5191 return R::template trim_static<TrimSides::TrimAll, false>(d(), pattern);
5203 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
5204 requires is_const_pattern<N>
5206 return R::template trim_static<TrimSides::TrimLeft, false>(d(), pattern);
5218 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
5219 requires is_const_pattern<N>
5221 return R::template trim_static<TrimSides::TrimRight, false>(d(), pattern);
5240 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
5241 requires is_const_pattern<N>
5243 return R::template trim_static<TrimSides::TrimAll, true>(d(), pattern);
5259 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
5260 requires is_const_pattern<N>
5262 return R::template trim_static<TrimSides::TrimLeft, true>(d(), pattern);
5278 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
5279 requires is_const_pattern<N>
5281 return R::template trim_static<TrimSides::TrimRight, true>(d(), pattern);
5296 template<
typename R = str_piece>
5298 return R::template trim_static<TrimSides::TrimAll, false>(d(), pattern);
5310 template<
typename R = str_piece>
5312 return R::template trim_static<TrimSides::TrimLeft, false>(d(), pattern);
5324 template<
typename R = str_piece>
5326 return R::template trim_static<TrimSides::TrimRight, false>(d(), pattern);
5342 template<
typename R = str_piece>
5344 return R::template trim_static<TrimSides::TrimAll, true>(d(), pattern);
5360 template<
typename R = str_piece>
5362 return R::template trim_static<TrimSides::TrimLeft, true>(d(), pattern);
5378 template<
typename R = str_piece>
5380 return R::template trim_static<TrimSides::TrimRight, true>(d(), pattern);
5394 template<
typename R = str_piece>
5396 str_piece res = *
this;
5397 while(res.starts_with(
prefix)) {
5398 res.remove_prefix(
prefix.length());
5399 if (--max_count == 0) {
5417 template<
typename R = str_piece>
5419 str_piece res = *
this;
5420 while(res.starts_with_ia(
prefix)) {
5421 res.remove_prefix(
prefix.length());
5422 if (--max_count == 0) {
5440 template<
typename R = str_piece>
5442 str_piece res = *
this;
5443 while(res.ends_with(
suffix)) {
5444 res.remove_suffix(
suffix.length());
5460 template<
typename R = str_piece>
5462 str_piece res = *
this;
5463 while(res.ends_with_ia(
suffix)) {
5464 res.remove_suffix(
suffix.length());
5483template<
size_t N>
requires (N > 1)
5484struct find_all_container {
5485 static constexpr size_t max_capacity = N;
5486 size_t positions_[N];
5489 constexpr void emplace_back(
size_t pos) {
5490 positions_[added_++] = pos;
5513struct str_src : str_src_algs<K, str_src<K>, str_src<K>, false> {
5514 using symb_type = K;
5515 using my_type = str_src<K>;
5517 const symb_type* str;
5520 str_src() =
default;
5525 template<typename T, size_t N = const_lit_for<K, T>::Count>
5526 constexpr str_src(T&& v) noexcept : str((
const K*)v), len(N - 1) {}
5532 constexpr str_src(
const K* p,
size_t l) noexcept : str(p), len(l) {}
5534 template<StrType<K> T>
5535 constexpr str_src(T&& t) :
str(t.symbols()), len(t.length()){}
5541 template<
typename A>
5542 constexpr str_src(
const std::basic_string<K, std::char_traits<K>, A>& s) noexcept : str(s.data()), len(s.length()) {}
5547 constexpr str_src(
const std::basic_string_view<K, std::char_traits<K>>& s) noexcept : str(s.data()), len(s.length()) {}
5560 constexpr const symb_type*
symbols() const noexcept {
5576 constexpr bool is_same(str_src<K> other)
const noexcept {
5577 return str == other.str && len == other.len;
5586 return str >= other.str && str + len <= other.str + other.len;
5649struct str_src_nt : str_src<K>, null_terminated<K, str_src_nt<K>> {
5650 using symb_type = K;
5651 using my_type = str_src_nt<K>;
5652 using base = str_src<K>;
5654 constexpr static const K empty_string[1] = {0};
5656 str_src_nt() =
default;
5673 template<
typename T>
requires std::is_same_v<std::remove_const_t<std::remove_pointer_t<std::remove_cvref_t<T>>>, K>
5676 base::str = base::len ? p : empty_string;
5682 template<typename T, size_t N = const_lit_for<K, T>::Count>
5683 constexpr str_src_nt(T&& v) noexcept : base(std::forward<T>(v)) {}
5689 constexpr str_src_nt(
const K* p,
size_t l) noexcept : base(p, l) {}
5691 template<StrType<K> T>
5694 base::len = t.length();
5700 template<
typename A>
5701 constexpr str_src_nt(
const std::basic_string<K, std::char_traits<K>, A>& s) noexcept : base(s) {}
5703 static const my_type empty_str;
5713 if (from > base::len) {
5716 return {base::str + from, base::len - from};
5721inline const str_src_nt<K> str_src_nt<K>::empty_str{str_src_nt<K>::empty_string, 0};
5722template<
typename K>
struct simple_str_selector;
5724inline namespace literals {
5784template<
char...Chars>
5785SS_CONSTEVAL
auto operator""_fmt() {
5786 return f::skip_0x<Chars...>();
5791#ifndef IN_FULL_SIMSTR
5794using simple_str = str_src<K>;
5797struct simple_str_selector {
5798 using type = simple_str<K>;
5802using simple_str_nt = str_src_nt<K>;
5805using Splitter = SplitterBase<K, str_src<K>>;
5807using ssa = str_src<u8s>;
5808using ssb = str_src<ubs>;
5809using ssw = str_src<wchar_t>;
5810using ssu = str_src<u16s>;
5811using ssuu = str_src<u32s>;
5812using stra = str_src_nt<u8s>;
5813using strb = str_src_nt<ubs>;
5814using strw = str_src_nt<wchar_t>;
5815using stru = str_src_nt<u16s>;
5816using struu = str_src_nt<u32s>;
5819consteval simple_str_nt<K> select_str(simple_str_nt<u8s> s8, simple_str_nt<ubs> sb, simple_str_nt<uws> sw, simple_str_nt<u16s> s16, simple_str_nt<u32s> s32) {
5820 if constexpr (std::is_same_v<K, u8s>)
5822 if constexpr (std::is_same_v<K, ubs>)
5824 if constexpr (std::is_same_v<K, uws>)
5826 if constexpr (std::is_same_v<K, u16s>)
5828 if constexpr (std::is_same_v<K, u32s>)
5832#define uni_string(K, p) select_str<K>(p, u8##p, L##p, u##p, U##p)
5834inline namespace literals {
5908constexpr size_t slice_simple_find_func(str_src<K> str, str_src<K> pattern,
size_t offset){
return str.find(pattern, offset);}
5910constexpr size_t slice_simple_find_rev_func(str_src<K> str, str_src<K> pattern,
size_t offset){
return str.find_last(pattern, offset);}
5912template<
typename K,
bool ToEndOfPattern,
bool OffsetFromFound,
bool AllAtFail, auto F = slice_simple_find_func<K>>
5913struct slice_simple_find : slice_find<str_src<K>, ToEndOfPattern, OffsetFromFound, AllAtFail, false, F> {
5914 using slice_find<str_src<K>, ToEndOfPattern, OffsetFromFound, AllAtFail,
false, F>::slice_find;
5918struct begin_or_all : slice_simple_find<K, false, true, true> {
5919 using base = slice_simple_find<K, false, true, true>;
5923struct end_or_all : slice_simple_find<K, true, true, true> {
5924 using base = slice_simple_find<K, true, true, true>;
5929struct begin_or_empty : slice_simple_find<K, false, true, false> {
5930 using base = slice_simple_find<K, false, true, false>;
5934struct end_or_empty : slice_simple_find<K, true, true, false> {
5935 using base = slice_simple_find<K, true, true, false>;
5939template<
typename K,
bool ToEndOfPattern,
bool OffsetFromFound,
bool AllAtFail, auto F = slice_simple_find_rev_func<K>>
5940struct slice_simple_find_rev : slice_find<str_src<K>, ToEndOfPattern, OffsetFromFound, AllAtFail, true, F> {
5941 using slice_find<str_src<K>, ToEndOfPattern, OffsetFromFound, AllAtFail,
true, F>::slice_find;
5945struct begin_last_or_all : slice_simple_find_rev<K, false, false, true> {
5946 using base = slice_simple_find_rev<K, false, false, true>;
5951struct end_last_or_all : slice_simple_find_rev<K, true, false, true> {
5952 using base = slice_simple_find_rev<K, true, false, true>;
5957struct begin_last_or_empty : slice_simple_find_rev<K, false, false, false> {
5958 using base = slice_simple_find_rev<K, false, false, false>;
5963struct end_last_or_empty : slice_simple_find_rev<K, true, false, false> {
5964 using base = slice_simple_find_rev<K, true, false, false>;
5968#define CTAD_SLICE_FIND(name) template<StrSource S> name(S&&) -> name<symb_type_from_src_t<S>>;\
5969 template<StrSource S> name(S&&, size_t) -> name<symb_type_from_src_t<S>>;\
5970 template<StrSource S> name(S&&, size_t, size_t) -> name<symb_type_from_src_t<S>>
5972CTAD_SLICE_FIND(begin_or_all);
5973CTAD_SLICE_FIND(end_or_all);
5974CTAD_SLICE_FIND(begin_or_empty);
5975CTAD_SLICE_FIND(end_or_empty);
5976CTAD_SLICE_FIND(begin_last_or_all);
5977CTAD_SLICE_FIND(end_last_or_all);
5978CTAD_SLICE_FIND(begin_last_or_empty);
5979CTAD_SLICE_FIND(end_last_or_empty);
5981inline namespace literals {
5983#define FIND_LITERAL(name, type, suffix) SS_CONSTEVAL name<type> operator ""_##suffix(const type* ptr, size_t l) {return str_src<type>{ptr, l};}
5984#define FIND_LITERALS(name, suffix) \
5985 FIND_LITERAL(name, u8s, suffix) \
5986 FIND_LITERAL(name, ubs, suffix) \
5987 FIND_LITERAL(name, u16s, suffix) \
5988 FIND_LITERAL(name, u32s, suffix) \
5989 FIND_LITERAL(name, wchar_t, suffix)
5991FIND_LITERALS(begin_or_all, boa)
5992FIND_LITERALS(end_or_all, eoa)
5993FIND_LITERALS(begin_or_empty, boe)
5994FIND_LITERALS(end_or_empty, eoe)
5995FIND_LITERALS(begin_last_or_all, bloa)
5996FIND_LITERALS(end_last_or_all, eloa)
5997FIND_LITERALS(begin_last_or_empty, bloe)
5998FIND_LITERALS(end_last_or_empty, eloe)
6002template<
typename K,
bool withSpaces>
6003struct CheckSpaceTrim {
6004 constexpr bool is_trim_spaces(K s)
const {
6005 return s ==
' ' || (s >= 9 && s <= 13);
6009struct CheckSpaceTrim<K, false> {
6010 constexpr bool is_trim_spaces(K)
const {
6016struct CheckSymbolsTrim {
6018 constexpr bool is_trim_symbols(K s)
const {
6019 return symbols.len != 0 && str_src<K>::traits::find(symbols.str, symbols.len, s) !=
nullptr;
6023template<
typename K,
size_t N>
6024struct CheckConstSymbolsTrim {
6025 const const_lit_to_array<K, N> symbols;
6027 template<typename T, size_t M = const_lit_for<K, T>::Count>
requires (M == N + 1)
6028 constexpr CheckConstSymbolsTrim(T&& s) : symbols(std::forward<T>(s)) {}
6030 constexpr bool is_trim_symbols(K s)
const noexcept {
6031 return symbols.contain(s);
6036struct CheckConstSymbolsTrim<K, 0> {
6037 constexpr bool is_trim_symbols(K)
const {
6042template<
typename K,
size_t N>
6043struct SymbSelector {
6044 using type = CheckConstSymbolsTrim<K, N>;
6048struct SymbSelector<K, 0> {
6049 using type = CheckSymbolsTrim<K>;
6053struct SymbSelector<K, static_cast<size_t>(-1)> {
6054 using type = CheckConstSymbolsTrim<K, 0>;
6057template<TrimS
ides S,
typename K,
size_t N,
bool withSpaces>
6058struct trim_operator : SymbSelector<K, N>::type, CheckSpaceTrim<K, withSpaces> {
6059 constexpr bool isTrim(K s)
const {
6060 return CheckSpaceTrim<K, withSpaces>::is_trim_spaces(s) || SymbSelector<K, N>::type::is_trim_symbols(s);
6062 constexpr str_src<K> operator()(str_src<K> from)
const {
6063 if constexpr ((S & TrimSides::TrimLeft) != 0) {
6065 if (isTrim(*from.str)) {
6072 if constexpr ((S & TrimSides::TrimRight) != 0) {
6073 const K* back = from.str + from.len - 1;
6075 if (isTrim(*back)) {
6086template<TrimS
ides S,
typename K>
6087using SimpleTrim = trim_operator<S, K, size_t(-1),
true>;
6089template<TrimSides S = TrimSides::TrimAll, bool withSpaces = false, typename K, typename T, size_t N = const_lit_for<K, T>::Count>
6090 requires is_const_pattern<N>
6091constexpr inline auto trimOp(T&& pattern) {
6092 return trim_operator<S, K, N - 1, withSpaces>{pattern};
6095template<TrimS
ides S = TrimS
ides::TrimAll,
bool withSpaces = false,
typename K>
6096constexpr inline auto trimOp(str_src<K> pattern) {
6097 return trim_operator<S, K, 0, withSpaces>{pattern};
6100static constexpr size_t FIND_CACHE_SIZE = 16;
6102template<
typename K,
size_t N,
size_t L>
6103struct expr_replaces : expr_to_std_string<expr_replaces<K, N, L>> {
6104 using symb_type = K;
6105 using my_type = expr_replaces<K, N, L>;
6107 const K(&pattern)[N + 1];
6108 const K(&repl)[L + 1];
6109 mutable find_all_container<FIND_CACHE_SIZE> matches_;
6110 mutable size_t last_;
6112 constexpr expr_replaces(str_src<K> w,
const K(&p)[N + 1],
const K(&r)[L + 1]) : what(w), pattern(p), repl(r) {}
6114 constexpr size_t length()
const {
6115 size_t l = what.length();
6116 if constexpr (N == L) {
6119 what.find_all_to(matches_, pattern, N, 0, FIND_CACHE_SIZE);
6120 if (matches_.added_) {
6121 last_ = matches_.positions_[matches_.added_ - 1] + N;
6122 l += int(L - N) * matches_.added_;
6124 if (matches_.added_ == FIND_CACHE_SIZE) {
6126 size_t next = what.find(pattern, N, last_);
6127 if (next == str::npos) {
6136 matches_.added_ = -1;
6140 constexpr K* place(K* ptr)
const noexcept {
6141 if constexpr (N == L) {
6142 const K* from = what.symbols();
6143 for (
size_t start = 0; start < what.length();) {
6144 size_t next = what.find(pattern, N, start);
6145 if (next == str::npos) {
6146 next = what.length();
6148 size_t delta = next - start;
6149 ch_traits<K>::copy(ptr, from + start, delta);
6151 ch_traits<K>::copy(ptr, repl, L);
6157 if (matches_.added_ == 0) {
6158 return what.place(ptr);
6159 }
else if (matches_.added_ ==
size_t(-1)) {
6163 const K* from = what.symbols();
6164 for (
size_t start = 0, offset = matches_.positions_[0], idx = 1; ;) {
6165 ch_traits<K>::copy(ptr, from + start, offset - start);
6166 ptr += offset - start;
6167 ch_traits<K>::copy(ptr, repl, L);
6170 if (start >= last_) {
6171 size_t tail = what.length() - last_;
6172 ch_traits<K>::copy(ptr, from + last_, tail);
6176 offset = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern, N, start);
6196template<StrSource A,
typename K = symb_type_from_src_t<A>,
typename T,
size_t N = const_lit_for<K, T>::Count,
typename X,
size_t L = const_lit_for<K, X>::Count>
6199 return expr_replaces<K, N - 1, L - 1>{std::forward<A>(w), p, r};
6211 using symb_type = K;
6216 mutable find_all_container<FIND_CACHE_SIZE> matches_;
6217 mutable size_t last_;
6230 constexpr size_t length()
const {
6232 if (!plen || plen == rlen) {
6235 what.find_all_to(matches_, pattern.
symbols(), plen, 0, FIND_CACHE_SIZE);
6236 if (matches_.added_) {
6237 last_ = matches_.positions_[matches_.added_ - 1] + plen;
6238 l += int(rlen - plen) * matches_.added_;
6240 if (matches_.added_ == FIND_CACHE_SIZE) {
6242 size_t next = what.find(pattern.
symbols(), plen, last_);
6243 if (next == str::npos) {
6246 last_ = next + plen;
6252 matches_.added_ = -1;
6256 constexpr K* place(K* ptr)
const noexcept {
6259 const K* from = what.
symbols();
6260 for (
size_t start = 0; start < what.
length();) {
6261 size_t next = what.find(pattern, start);
6262 if (next == str::npos) {
6265 size_t delta = next - start;
6266 ch_traits<K>::copy(ptr, from + start, delta);
6268 ch_traits<K>::copy(ptr, repl.
symbols(), rlen);
6270 start = next + plen;
6274 if (matches_.added_ == 0) {
6275 return what.
place(ptr);
6276 }
else if (matches_.added_ == -1) {
6280 const K* from = what.
symbols();
6281 for (
size_t start = 0, offset = matches_.positions_[0], idx = 1; ;) {
6282 ch_traits<K>::copy(ptr, from + start, offset - start);
6283 ptr += offset - start;
6284 ch_traits<K>::copy(ptr, repl.
symbols(), rlen);
6286 start = offset + plen;
6287 if (start >= last_) {
6288 size_t tail = what.
length() - start;
6289 ch_traits<K>::copy(ptr, from + start, tail);
6293 offset = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern.
symbols(), plen, start);
6315template<
typename K, StrExprForType<K> E>
6317 using symb_type = K;
6321 mutable size_t replLen;
6322 mutable find_all_container<FIND_CACHE_SIZE> matches_;
6323 mutable size_t last_;
6337 constexpr size_t length()
const {
6342 matches_.positions_[0] = what.find(pattern);
6343 if (matches_.positions_[0] == -1) {
6347 matches_.added_ = 1;
6349 replLen = expr.length();
6350 if (replLen == plen) {
6354 what.find_all_to(matches_, pattern.
symbols(), plen, matches_.positions_[0] + plen, FIND_CACHE_SIZE - 1);
6356 last_ = matches_.positions_[matches_.added_ - 1] + plen;
6357 l += int(replLen - plen) * matches_.added_;
6359 if (matches_.added_ == FIND_CACHE_SIZE) {
6361 size_t next = what.find(pattern.
symbols(), plen, last_);
6362 if (next == str::npos) {
6365 last_ = next + plen;
6366 l += replLen - plen;
6370 matches_.added_ = -1;
6374 constexpr K* place(K* ptr)
const noexcept {
6375 if (matches_.added_ == 0) {
6377 return what.
place(ptr);
6378 }
else if (matches_.added_ == -1) {
6382 size_t plen = pattern.
length();
6383 const K* from = what.
symbols();
6384 ch_traits<K>::copy(ptr, from, matches_.positions_[0]);
6385 ptr += matches_.positions_[0];
6386 const K* repl = ptr;
6387 expr.
place((
typename E::symb_type*)ptr);
6389 size_t start = matches_.positions_[0] + plen;
6391 if (plen == replLen) {
6393 size_t next = what.find(pattern, start);
6394 if (next == str::npos) {
6397 size_t delta = next - start;
6398 ch_traits<K>::copy(ptr, from + start, delta);
6400 ch_traits<K>::copy(ptr, repl, replLen);
6402 start = next + plen;
6405 for (
size_t idx = 1;;) {
6406 if (start >= last_) {
6409 size_t next = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern, start);
6410 size_t delta = next - start;
6411 ch_traits<K>::copy(ptr, from + start, delta);
6413 ch_traits<K>::copy(ptr, repl, replLen);
6415 start = next + plen;
6418 size_t tail = what.
length() - start;
6419 ch_traits<K>::copy(ptr, from + start, tail);
6437template<StrSource A,
typename K = symb_type_from_src_t<A>,
typename T,
typename X>
6438 requires (std::is_constructible_v<str_src<K>, T> && std::is_constructible_v<str_src<K>, X> && (!is_const_lit_v<T> || !is_const_lit_v<X>))
6458template<StrSource A,
typename K = symb_type_from_src_t<A>,
typename T, StrExprForType<K> E>
6459 requires std::is_constructible_v<str_src<K>, T>
6460constexpr auto e_repl(A&& w, T&& p,
const E& expr) {
6465template<
bool UseVectorForReplace>
6466struct replace_search_result_store {
6468 std::pair<size_t, size_t> replaces_[16];
6472struct replace_search_result_store<true> : std::vector<std::pair<size_t, size_t>> {};
6476template<
typename K,
size_t N,
bool UseVectorForReplace>
6477struct expr_replace_const_symbols : expr_to_std_string<expr_replace_const_symbols<K, N, UseVectorForReplace>> {
6478 using symb_type = K;
6479 inline static const int BIT_SEARCH_TRESHHOLD = 4;
6480 const K pattern_[N];
6481 const str_src<K> source_;
6482 const str_src<K> replaces_[N];
6484 mutable replace_search_result_store<UseVectorForReplace> search_results_;
6486 [[_no_unique_address]]
6487 std::array<uu8s, N >= BIT_SEARCH_TRESHHOLD ? (
sizeof(K) == 1 ? 32 : 64) : 0> bit_mask_{};
6489 template<
typename ... Repl>
requires (
sizeof...(Repl) == N * 2)
6490 constexpr expr_replace_const_symbols(str_src<K> source, Repl&& ... repl) : expr_replace_const_symbols(0, source, std::forward<Repl>(repl)...) {}
6492 size_t length()
const {
6493 size_t l = source_.length();
6494 auto [fnd, num] = find_first_of(source_.str, source_.len);
6495 if (fnd == str::npos) {
6498 l += replaces_[num].len - 1;
6499 if constexpr (UseVectorForReplace) {
6500 search_results_.reserve((l >> 4) + 8);
6501 search_results_.emplace_back(fnd, num);
6502 for (
size_t start = fnd + 1;;) {
6503 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6504 if (fnd == str::npos) {
6507 search_results_.emplace_back(fnd, idx);
6509 l += replaces_[idx].len - 1;
6512 const size_t max_store = std::size(search_results_.replaces_);
6513 search_results_.replaces_[0] = {fnd, num};
6514 search_results_.count_++;
6515 for (
size_t start = fnd + 1;;) {
6516 auto [found, idx] = find_first_of(source_.str, source_.len, start);
6517 if (found == str::npos) {
6520 if (search_results_.count_ < max_store) {
6521 search_results_.replaces_[search_results_.count_] = {found, idx};
6523 l += replaces_[idx].len - 1;
6524 search_results_.count_++;
6530 K* place(K* ptr)
const noexcept {
6532 const K* text = source_.str;
6533 if constexpr (UseVectorForReplace) {
6534 for (
const auto& [pos, num] : search_results_) {
6535 size_t delta = pos - start;
6536 ch_traits<K>::copy(ptr, text + start, delta);
6538 ptr = replaces_[num].place(ptr);
6542 const size_t max_store = std::size(search_results_.replaces_);
6543 size_t founded = search_results_.count_;
6544 for (
size_t idx = 0, stop = std::min(founded, max_store); idx < stop; idx++) {
6545 const auto [pos, num] = search_results_.replaces_[idx];
6546 size_t delta = pos - start;
6547 ch_traits<K>::copy(ptr, text + start, delta);
6549 ptr = replaces_[num].place(ptr);
6552 if (founded > max_store) {
6553 founded -= max_store;
6555 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6556 size_t delta = fnd - start;
6557 ch_traits<K>::copy(ptr, text + start, delta);
6559 ptr = replaces_[idx].place(ptr);
6564 size_t tail = source_.len - start;
6565 ch_traits<K>::copy(ptr, text + start, tail);
6570 template<
typename ... Repl>
6571 constexpr expr_replace_const_symbols(
int, str_src<K> source, K s, str_src<K> r, Repl&&... repl) :
6572 expr_replace_const_symbols(0, source, std::forward<Repl>(repl)..., std::make_pair(s, r)){}
6574 template<
typename ... Repl>
requires (
sizeof...(Repl) == N)
6575 constexpr expr_replace_const_symbols(
int, str_src<K> source, Repl&&... repl) :
6576 source_(source), pattern_ {repl.first...}, replaces_{repl.second...}
6578 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
6579 for (
size_t idx = 0; idx < N; idx++) {
6580 uu8s s =
static_cast<uu8s
>(pattern_[idx]);
6581 if constexpr (
sizeof(K) == 1) {
6582 bit_mask_[s >> 3] |= 1 << (s & 7);
6584 if (std::make_unsigned_t<const K>(pattern_[idx]) > 255) {
6585 bit_mask_[32 + (s >> 3)] |= 1 << (s & 7);
6587 bit_mask_[s >> 3] |= 1 << (s & 7);
6594 template<
size_t Idx>
6595 size_t index_of(K s)
const {
6596 if constexpr (Idx < N) {
6597 return pattern_[Idx] == s ? Idx : index_of<Idx + 1>(s);
6601 bool is_in_mask(uu8s s)
const {
6602 return (bit_mask_[s >> 3] & (1 <<(s & 7))) != 0;
6604 bool is_in_mask2(uu8s s)
const {
6605 return (bit_mask_[32 + (s >> 3)] & (1 <<(s & 7))) != 0;
6607 bool is_in_pattern(K s,
size_t& idx)
const {
6608 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
6609 if constexpr (
sizeof(K) == 1) {
6610 if (is_in_mask(s)) {
6611 idx = index_of<0>(s);
6615 if (std::make_unsigned_t<const K>(s) > 255) {
6616 if (is_in_mask2(s)) {
6617 return (idx = index_of<0>(s)) != -1;
6620 if (is_in_mask(s)) {
6621 idx = index_of<0>(s);
6629 std::pair<size_t, size_t> find_first_of(
const K* text,
size_t len,
size_t offset = 0)
const {
6630 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
6632 while (offset < len) {
6633 if (is_in_pattern(text[offset], idx)) {
6634 return {offset, idx};
6639 while (offset < len) {
6640 if (
size_t idx = index_of<0>(text[offset]); idx != -1) {
6641 return {offset, idx};
6689template<
bool UseVector = false, StrSource A,
typename K = symb_type_from_src_t<A>,
typename ... Repl>
6690 requires (
sizeof...(Repl) % 2 == 0)
6692 return expr_replace_const_symbols<K,
sizeof...(Repl) / 2, UseVector>(std::forward<A>(src), std::forward<Repl>(other)...);
6734template<
typename K,
bool UseVectorForReplace = false>
6736 using symb_type = K;
6737 using str_t =
typename simple_str_selector<K>::type;
6738 inline static const int BIT_SEARCH_TRESHHOLD = 4;
6741 const std::vector<std::pair<K, str_t>>& replaces_;
6743 std::basic_string<K, ch_traits<K>, std::allocator<K>> pattern_;
6745 mutable replace_search_result_store<UseVectorForReplace> search_results_;
6747 uu8s bit_mask_[
sizeof(K) == 1 ? 32 : 64]{};
6776 : source_(source), replaces_(repl)
6778 size_t pattern_len = replaces_.size();
6779 pattern_.resize(pattern_len);
6780 K* pattern = pattern_.data();
6782 for (
size_t idx = 0; idx < replaces_.size(); idx++) {
6783 *pattern++ = replaces_[idx].first;
6786 if (pattern_len >= BIT_SEARCH_TRESHHOLD) {
6787 for (
size_t idx = 0; idx < pattern_len; idx++) {
6788 uu8s s =
static_cast<uu8s
>(pattern_[idx]);
6789 if constexpr (
sizeof(K) == 1) {
6790 bit_mask_[s >> 3] |= (1 << (s & 7));
6792 if (std::make_unsigned_t<K>(pattern_[idx]) > 255) {
6793 bit_mask_[32 + (s >> 3)] |= (1 << (s & 7));
6795 bit_mask_[s >> 3] |= (1 << (s & 7));
6802 size_t length()
const {
6803 size_t l = source_.
length();
6804 auto [fnd, num] = find_first_of(source_.str, source_.len);
6805 if (fnd == str::npos) {
6808 l += replaces_[num].second.len - 1;
6809 if constexpr (UseVectorForReplace) {
6810 search_results_.reserve((l >> 4) + 8);
6811 search_results_.emplace_back(fnd, num);
6812 for (
size_t start = fnd + 1;;) {
6813 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6814 if (fnd == str::npos) {
6817 search_results_.emplace_back(fnd, idx);
6819 l += replaces_[idx].second.len - 1;
6822 const size_t max_store = std::size(search_results_.replaces_);
6823 search_results_.replaces_[0] = {fnd, num};
6824 search_results_.count_++;
6825 for (
size_t start = fnd + 1;;) {
6826 auto [found, idx] = find_first_of(source_.str, source_.len, start);
6827 if (found == str::npos) {
6830 if (search_results_.count_ < max_store) {
6831 search_results_.replaces_[search_results_.count_] = {found, idx};
6833 l += replaces_[idx].second.len - 1;
6834 search_results_.count_++;
6840 K* place(K* ptr)
const noexcept {
6842 const K* text = source_.str;
6843 if constexpr (UseVectorForReplace) {
6844 for (
const auto& [pos, num] : search_results_) {
6845 size_t delta = pos - start;
6846 ch_traits<K>::copy(ptr, text + start, delta);
6848 ptr = replaces_[num].second.place(ptr);
6852 const size_t max_store = std::size(search_results_.replaces_);
6853 size_t founded = search_results_.count_;
6854 for (
size_t idx = 0, stop = std::min(founded, max_store); idx < stop; idx++) {
6855 const auto [pos, num] = search_results_.replaces_[idx];
6856 size_t delta = pos - start;
6857 ch_traits<K>::copy(ptr, text + start, delta);
6859 ptr = replaces_[num].second.place(ptr);
6862 if (founded > max_store) {
6863 founded -= max_store;
6865 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6866 size_t delta = fnd - start;
6867 ch_traits<K>::copy(ptr, text + start, delta);
6869 ptr = replaces_[idx].second.place(ptr);
6874 size_t tail = source_.len - start;
6875 ch_traits<K>::copy(ptr, text + start, tail);
6880 size_t index_of(K s)
const {
6881 return pattern_.find(s);
6884 bool is_in_mask(uu8s s)
const {
6885 return (bit_mask_[s >> 3] & (1 << (s & 7))) != 0;
6887 bool is_in_mask2(uu8s s)
const {
6888 return (bit_mask_[32 + (s >> 3)] & (1 << (s & 7))) != 0;
6891 bool is_in_pattern(K s,
size_t& idx)
const {
6892 if constexpr (
sizeof(K) == 1) {
6893 if (is_in_mask(s)) {
6898 if (std::make_unsigned_t<const K>(s) > 255) {
6899 if (is_in_mask2(s)) {
6900 return (idx = index_of(s)) != -1;
6903 if (is_in_mask(s)) {
6912 std::pair<size_t, size_t> find_first_of(
const K* text,
size_t len,
size_t offset = 0)
const {
6913 size_t pl = pattern_.length();
6914 if (pl >= BIT_SEARCH_TRESHHOLD) {
6916 while (offset < len) {
6917 if (is_in_pattern(text[offset], idx)) {
6918 return {offset, idx};
6923 while (offset < len) {
6924 if (
size_t idx = index_of(text[offset]); idx != -1) {
6925 return {offset, idx};
6934template<
typename K, StrExprForType<K> T>
6937 force_copy(
const T& t) : t_(t){}
6940template<
typename K,
typename T>
6941struct symb_type_from_src<force_copy<K, T>> {
6947force_copy(T&&) -> force_copy<typename T::symb_type, T>;
6949template<
typename K,
typename T>
6950constexpr auto to_subst(T&& t) {
6951 return to_strexpr<K>(std::forward<T>(t));
6954template<
typename K,
typename T,
size_t N>
6955constexpr auto to_subst(
const T(&t)[N]) {
6956 return expr_literal<T, N - 1>{t};
6959template<
typename K, StrExprForType<K> T>
6960constexpr decltype(
auto) to_subst(T&& t) {
6961 return std::forward<T>(t);
6964template<
typename K,
typename T>
6965constexpr T to_subst(
const force_copy<K, T>& t) {
6969template<
typename K,
typename T>
6970constexpr T to_subst(force_copy<K, T>&& t) {
6974template<
typename K,
typename T>
6975constexpr T to_subst(force_copy<K, T>& t) {
6979template<
typename K,
typename T>
6980using to_str_exp_t =
decltype(to_subst<K>(std::declval<T>()));
6989template<
typename K,
typename G,
typename Arg,
typename...Args>
6991 using symb_type = K;
6992 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
6993 using arg_t = to_str_exp_t<K, Arg>;
6994 to_str_exp_t<K, G> glue_;
6997 mutable size_t glue_len_;
7031 : glue_(to_subst<K>(
std::forward<G>(glue)))
7032 , arg_(to_subst<K>(
std::forward<Arg>(arg)))
7033 , args_(to_subst<K>(
std::forward<Args>(args))...) {}
7035 constexpr size_t length() const noexcept {
7036 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
7037 glue_len_ = glue_.length();
7038 size_t l = arg_.length() + glue_len_ *
sizeof...(Args);
7039 ((l += std::get<Indexes>(args_).length()),...);
7041 }(std::make_index_sequence<
sizeof...(Args)>());
7043 constexpr K* place(K* ptr)
const noexcept {
7044 return [
this]<
size_t...Indexes>(K* ptr, std::index_sequence<Indexes...>) {
7045 ptr = (K*)arg_.place((
typename std::remove_cvref_t<arg_t>::symb_type*)ptr);
7046 const K* glueStart = ptr;
7047 ptr = glue_.place(ptr);
7050 ptr = (K*)std::get<Indexes>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Indexes, store_t>>::symb_type*)ptr),
7051 glue_len_ > 0 && Indexes <
sizeof...(Args) - 1 ? (ch_traits<K>::copy(ptr, glueStart, glue_len_), ptr += glue_len_) :
nullptr
7055 }(ptr, std::make_index_sequence<
sizeof...(Args)>());
7059template<
typename T,
typename ... Args>
requires (
sizeof...(Args) > 1)
7060e_concat(T&&, Args&&...) -> e_concat<symb_type_from_src_t<T>, T, Args...>;
7062struct parse_subst_string_error {
7063 parse_subst_string_error(
const char*){}
7068template<
typename K,
size_t NParams>
7069constexpr size_t parse_pattern_string(str_src<K> pattern,
auto&& add_part,
auto&& add_param) {
7070 char used_args[NParams] = {0};
7071 const K* first = pattern.begin(), *last = pattern.end(), *start = first;
7074 auto find = [](
const K* from,
const K* last, K s) {
7075 while (from != last) {
7083 size_t idx_in_params = 0;
7085 while (first != last) {
7086 const K* open_pos = first;
7087 if (*first !=
'{') {
7088 open_pos = find(first, last,
'{');
7091 const K* close_pos = find(first, open_pos,
'}');
7092 if (close_pos == open_pos) {
7093 unsigned len = open_pos - first;
7094 add_part(first - start, len);
7099 if (close_pos == open_pos || *close_pos !=
'}') {
7100 throw parse_subst_string_error{
"unescaped }"};
7102 unsigned len = close_pos - first;
7103 add_part(first - start, len);
7105 first = ++close_pos;
7107 if (open_pos == last) {
7111 if (++open_pos == last) {
7112 throw parse_subst_string_error{
"unescaped {"};
7114 if (*open_pos ==
'}') {
7115 if (idx_in_params == -1) {
7116 throw parse_subst_string_error{
"already used param ids"};
7118 if (idx_in_params == NParams) {
7119 throw parse_subst_string_error{
"too many params"};
7121 used_args[idx_in_params] = 1;
7122 add_param(idx_in_params++);
7123 first = open_pos + 1;
7124 }
else if (*open_pos ==
'{') {
7125 add_part(open_pos - start, 1);
7127 first = open_pos + 1;
7129 if (idx_in_params != 0 && idx_in_params != -1) {
7130 throw parse_subst_string_error{
"already used non id params"};
7133 const K* end = find(open_pos, last,
'}');
7135 throw parse_subst_string_error{
"not found }"};
7137 auto [p, err, _] = str_src<K>(open_pos, end - open_pos).template to_int<unsigned, true, 10, false, false>();
7138 if (err != IntConvertResult::Success || p < 1 || p > NParams) {
7139 throw parse_subst_string_error{
"bad param id"};
7146 for (
auto c : used_args) {
7148 throw parse_subst_string_error{
"unused param"};
7157 unsigned is_param: 1;
7159 portion() =
default;
7161 constexpr void set_param(
unsigned param) {
7162 if (param >= (1 << 16)) {
7163 throw parse_subst_string_error{
"the parameter id is too large"};
7168 constexpr void set_part(
unsigned from,
unsigned l) {
7169 if (from >= (1 << 16) || l >= (1 << 15)) {
7170 throw parse_subst_string_error{
"the string part is too large"};
7178template<
typename K,
size_t PtLen,
size_t NParams>
7179struct subst_params {
7180 const K(&source_)[PtLen];
7181 unsigned all_len_{};
7185 portion portions_[1 + ((PtLen - 2) * 2 / 3)]{};
7187 consteval subst_params(
const K(&pattern)[PtLen]) : source_(pattern) {
7188 all_len_ = parse_pattern_string<K, NParams>(pattern,
7189 [
this](
unsigned from,
unsigned len) {
7190 portions_[actual_++].set_part(from, len);
7191 }, [
this](
unsigned param) {
7192 portions_[actual_++].set_param(param);
7204template<
typename K,
size_t PtLen,
typename ... Args>
7206 inline static constexpr size_t NParams =
sizeof...(Args);
7207 using symb_type = K;
7208 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
7210 const details::subst_params<K, PtLen, NParams>& subst_;
7252 constexpr e_subst(
const details::subst_params<K, PtLen, NParams>& subst, Args&&...args)
7254 , args_(to_subst<K>(
std::forward<Args>(args))...){}
7256 constexpr size_t length() const noexcept {
7257 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
7259 size_t expr_length_[NParams] = {};
7260 ((expr_length_[idx++] = std::get<Indexes>(args_).length()),...);
7261 size_t l = subst_.all_len_;
7262 for (idx = 0; idx < subst_.actual_; idx++) {
7263 if (subst_.portions_[idx].is_param) {
7264 l += expr_length_[subst_.portions_[idx].start];
7268 }(std::make_index_sequence<
sizeof...(Args)>());
7270 template<
size_t Idx>
7271 constexpr K* place_idx(K* ptr,
size_t idx)
const noexcept {
7273 return (K*)std::get<Idx>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Idx, store_t>>::symb_type*)ptr);
7275 if constexpr (Idx < NParams - 1) {
7276 return place_idx<Idx + 1>(ptr, idx);
7280 constexpr K* place(K* ptr)
const noexcept {
7281 for (
size_t idx = 0; idx < subst_.actual_; idx++) {
7282 if (subst_.portions_[idx].is_param) {
7283 ptr = place_idx<0>(ptr, subst_.portions_[idx].start);
7285 ch_traits<K>::copy(ptr, subst_.source_ + subst_.portions_[idx].start, subst_.portions_[idx].len);
7286 ptr += subst_.portions_[idx].len;
7294template<
typename K,
size_t N,
typename...Args>
requires (
sizeof...(Args) > 0)
7295e_subst(
const K(&)[N], Args&&...) -> e_subst<K, N, Args...>;
7302template<
typename K,
typename ... Args>
7304 inline static constexpr size_t Nparams =
sizeof...(Args);
7305 using symb_type = K;
7306 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
7308 details::portion portions_[Nparams * 3];
7309 std::vector<details::portion> more_portions_;
7353 , args_(to_subst<K>(
std::forward<Args>(args))...) {
7355 all_len_ = details::parse_pattern_string<K, Nparams>(pattern_, [
this](
unsigned from,
unsigned len) {
7356 if (actual_ < std::size(portions_)) {
7357 portions_[actual_++].set_part(from, len);
7359 if (actual_ == std::size(portions_)) {
7360 more_portions_.reserve((pattern_.len - 1) * 2 / 3 - std::size(portions_));
7362 more_portions_.emplace_back().set_part(from, len);
7364 }, [
this](
unsigned param) {
7365 if (actual_ < std::size(portions_)) {
7366 portions_[actual_++].set_param(param);
7368 if (actual_ == std::size(portions_)) {
7369 more_portions_.reserve((pattern_.len - 1) * 2 / 3 - std::size(portions_));
7371 more_portions_.emplace_back().set_param(param);
7376 constexpr size_t length() const noexcept {
7377 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
7379 size_t expr_length_[Nparams] = {};
7380 ((expr_length_[idx++] = std::get<Indexes>(args_).length()),...);
7381 size_t l = all_len_;
7382 for (idx = 0; idx < actual_; idx++) {
7383 if (portions_[idx].is_param) {
7384 l += expr_length_[portions_[idx].start];
7387 for (
const auto& p : more_portions_) {
7389 l += expr_length_[p.start];
7393 }(std::make_index_sequence<
sizeof...(Args)>());
7395 template<
size_t Idx>
7396 constexpr K* place_idx(K* ptr,
size_t idx)
const noexcept {
7398 return (K*)std::get<Idx>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Idx, store_t>>::symb_type*)ptr);
7400 if constexpr (Idx < Nparams - 1) {
7401 return place_idx<Idx + 1>(ptr, idx);
7405 constexpr K* place(K* ptr)
const noexcept {
7406 for (
size_t idx = 0; idx < actual_; idx++) {
7407 if (portions_[idx].is_param) {
7408 ptr = place_idx<0>(ptr, portions_[idx].start);
7410 ch_traits<K>::copy(ptr, pattern_.
symbols() + portions_[idx].start, portions_[idx].len);
7411 ptr += portions_[idx].len;
7414 for (
const auto& p : more_portions_) {
7416 ptr = place_idx<0>(ptr, p.start);
7418 const K* from = pattern_.
symbols() + p.start;
7419 for (
size_t idx = p.len; idx--;) {
7430template<StrSourceNoLiteral T,
typename...Args>
requires (
sizeof...(Args) > 0)
7431e_vsubst(T&&, Args&&...) -> e_vsubst<symb_type_from_src_t<T>, Args...>;
7433template<is_one_of_
char_v K,
bool upper>
7434struct expr_change_case_ascii : expr_to_std_string<expr_change_case_ascii<K, upper>>{
7435 using symb_type = K;
7439 template<StrSource S>
7440 expr_change_case_ascii(S&& s) : src_(std::forward<S>(s)){}
7442 constexpr size_t length() const noexcept {
7443 return src_.length();
7445 constexpr K* place(K* ptr)
const noexcept {
7446 const K* read = src_.str;
7447 for (
size_t l = src_.len; l--;) {
7448 if constexpr (upper) {
7449 *ptr++ = makeAsciiUpper(*read++);
7451 *ptr++ = makeAsciiLower(*read++);
7472template<is_one_of_
char_v K>
7474 using base = expr_change_case_ascii<K, true>;
7478template<StrSource S>
7495template<is_one_of_
char_v K>
7497 using base = expr_change_case_ascii<K, false>;
7501template<StrSource S>
7542template<
typename K,
typename A, StrExprForType<K> E>
7543std::basic_string<K, std::char_traits<K>, A>&
change(std::basic_string<K, std::char_traits<K>, A>&
str,
size_t from,
size_t count,
const E& expr) {
7544 size_t expr_length = expr.length();
7546 str.erase(from, count);
7549 size_t str_length =
str.length();
7550 if (from > str_length) {
7553 if (count > str_length || from + count > str_length) {
7554 count = str_length - from;
7556 size_t new_length = str_length - count + expr_length;
7557 size_t tail_length = str_length - count - from;
7559 if (new_length <= str_length) {
7560 K* data =
str.data();
7561 expr.place((
typename E::symb_type*)data + from);
7562 if (expr_length < count) {
7564 std::char_traits<K>::move(data + from + expr_length, data + from + count, tail_length);
7566 str.resize(new_length);
7569 auto fill = [&](K* data, size_t) ->
size_t {
7571 std::char_traits<K>::move(data + from + expr_length, data + from + count, tail_length);
7573 expr.place((
typename E::symb_type*)data + from);
7576 if constexpr (
requires{
str.resize_and_overwrite(new_length, fill);}) {
7577 str.resize_and_overwrite(new_length, fill);
7578 }
else if constexpr (
requires{
str._Resize_and_overwrite(new_length, fill);}) {
7579 str._Resize_and_overwrite(new_length, fill);
7581 str.resize(new_length);
7582 fill(
str.data(), 0);
7615template<
typename K,
typename A, StrExprForType<K> E>
7616std::basic_string<K, std::char_traits<K>, A>&
append(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
7648template<
typename K,
typename A, StrExprForType<K> E>
7649std::basic_string<K, std::char_traits<K>, A>&
prepend(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
7683template<
typename K,
typename A, StrExprForType<K> E>
7684std::basic_string<K, std::char_traits<K>, A>&
insert(std::basic_string<K, std::char_traits<K>, A>&
str,
size_t from,
const E& expr) {
7712template<
typename K,
typename A, StrExprForType<K> E>
7713std::basic_string<K, std::char_traits<K>, A>&
overwrite(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
7714 if (
size_t expr_length = expr.length()) {
7715 if (expr_length <=
str.length()) {
7716 K* data =
str.data();
7717 expr.place((
typename E::symb_type*)data);
7718 str.resize(expr_length);
7720 auto fill = [&](K* data, size_t) ->
size_t {
7721 expr.place((
typename E::symb_type*)data);
7724 if constexpr (
requires{
str.resize_and_overwrite(expr_length, fill);}) {
7725 str.resize_and_overwrite(expr_length, fill);
7726 }
else if constexpr (
requires{
str._Resize_and_overwrite(expr_length, fill);}) {
7727 str._Resize_and_overwrite(expr_length, fill);
7729 str.resize(expr_length);
7730 expr.place((
typename E::symb_type*)
str.data());
7741template<
typename K,
typename A,
typename E>
7742struct replace_grow_helper {
7743 using my_type = std::basic_string<K, std::char_traits<K>, A>;
7745 replace_grow_helper(my_type& src,
str_src<K> p,
const K* r,
size_t rl,
size_t mc,
size_t d,
const E& e)
7746 :
str(src), source(src), pattern(p), repl(const_cast<K*>(r)), replLen(rl), maxCount(mc), delta(d), expr(e) {}
7749 const str_src<K> source;
7750 const str_src<K> pattern;
7752 const size_t replLen;
7759 K* reserve_for_copy{};
7760 size_t end_of_piece{};
7761 size_t total_length{};
7763 std::optional<my_type> dst;
7766 size_t found[16] = {offset};
7769 offset += pattern.len;
7772 for (; idx < std::size(found) && maxCount > 0; idx++, maxCount--) {
7773 found[idx] = source.find(pattern, offset);
7774 if (found[idx] == npos) {
7777 offset = found[idx] + pattern.len;
7780 if (idx == std::size(found) && maxCount > 0 && (offset = source.find(pattern, offset)) != str::npos) {
7785 if (!reserve_for_copy) {
7788 end_of_piece = source.length();
7789 total_length = end_of_piece + all_delta;
7791 if (total_length <= str.capacity()) {
7796 dst_str = &dst.emplace();
7798 auto fill = [
this](K* p, size_t) ->
size_t {
7799 reserve_for_copy = p;
7800 return total_length;
7802 if constexpr (
requires{dst_str->_Resize_and_overwrite(total_length, fill);}) {
7803 dst_str->_Resize_and_overwrite(total_length, fill);
7804 }
else if constexpr (
requires{dst_str->resize_and_overwrite(total_length, fill);}) {
7805 dst_str->resize_and_overwrite(total_length, fill);
7807 dst_str->resize(total_length);
7808 reserve_for_copy = dst_str->data();
7811 const K* src_start = str.c_str();
7813 size_t pos = found[idx] + pattern.len;
7814 size_t lenOfPiece = end_of_piece - pos;
7815 ch_traits<K>::move(reserve_for_copy + pos + all_delta, src_start + pos, lenOfPiece);
7816 if constexpr (std::is_same_v<E, int>) {
7817 ch_traits<K>::copy(reserve_for_copy + pos + all_delta - replLen, repl, replLen);
7820 repl = reserve_for_copy + pos + all_delta - replLen;
7823 ch_traits<K>::copy(reserve_for_copy + pos + all_delta - replLen, repl, replLen);
7827 end_of_piece = found[idx];
7829 if (!all_delta && reserve_for_copy != src_start) {
7830 ch_traits<K>::copy(reserve_for_copy, src_start, found[0]);
7831 str = std::move(*dst);
7872template<
typename K,
typename A, StrExprForType<K> E,
typename T>
7873requires (std::is_constructible_v<str_src<K>, T>)
7874std::basic_string<K, std::char_traits<K>, A>&
replace(std::basic_string<K, std::char_traits<K>, A>&
str, T&& pattern,
const E& repl,
size_t offset = 0,
size_t max_count = -1) {
7879 str_src<K> spattern{std::forward<T>(pattern)};
7880 offset = src.find(pattern, offset);
7881 if (offset == npos) {
7884 size_t replLen = repl.length();
7886 if (spattern.len == replLen) {
7889 K* ptr =
str.data();
7890 replStart = ptr + offset;
7891 repl.place(replStart);
7893 while (--max_count) {
7894 offset = src.find(spattern, offset + replLen);
7897 ch_traits<K>::copy(ptr + offset, replStart, replLen);
7899 }
else if (spattern.len > replLen) {
7902 K* ptr =
str.data();
7903 replStart = ptr + offset;
7904 repl.place(replStart);
7905 size_t posWrite = offset + replLen;
7906 offset += spattern.len;
7908 while (--max_count) {
7909 size_t idx = src.find(spattern, offset);
7912 size_t lenOfPiece = idx - offset;
7913 ch_traits<K>::move(ptr + posWrite, ptr + offset, lenOfPiece);
7914 posWrite += lenOfPiece;
7915 ch_traits<K>::copy(ptr + posWrite, replStart, replLen);
7916 posWrite += replLen;
7917 offset = idx + spattern.len;
7919 size_t tailLen = src.len - offset;
7920 ch_traits<K>::move(ptr + posWrite, ptr + offset, tailLen);
7921 str.resize(posWrite + tailLen);
7923 details::replace_grow_helper<K, A, E>(
str, spattern,
nullptr, replLen, max_count, replLen - spattern.len, repl).replace(offset);
7948template<
typename K,
typename A>
7949std::basic_string<K, std::char_traits<K>, A>&
replace(std::basic_string<K, std::char_traits<K>, A>&
str,
str_src<K> pattern,
str_src<K> repl,
size_t offset = 0,
size_t max_count = -1) {
7954 offset = src.find(pattern, offset);
7955 if (offset == npos) {
7958 if (pattern.len == repl.len) {
7961 K* ptr =
str.data();
7962 while (max_count--) {
7963 ch_traits<K>::copy(ptr + offset, repl.str, repl.len);
7964 offset = src.find(pattern, offset + repl.len);
7968 }
else if (pattern.len > repl.len) {
7971 K* ptr =
str.data();
7972 ch_traits<K>::copy(ptr + offset, repl.str, repl.len);
7973 size_t posWrite = offset + repl.len;
7974 offset += pattern.len;
7976 while (--max_count) {
7977 size_t idx = src.find(pattern, offset);
7980 size_t lenOfPiece = idx - offset;
7981 ch_traits<K>::move(ptr + posWrite, ptr + offset, lenOfPiece);
7982 posWrite += lenOfPiece;
7983 ch_traits<K>::copy(ptr + posWrite, repl.str, repl.len);
7984 posWrite += repl.len;
7985 offset = idx + pattern.len;
7987 size_t tailLen = src.len - offset;
7988 ch_traits<K>::move(ptr + posWrite, ptr + offset, tailLen);
7989 str.resize(posWrite + tailLen);
7991 details::replace_grow_helper<K, A, int>(
str, pattern, repl.str, repl.len, max_count, repl.len - pattern.len, 0).replace(offset);
7996template<
typename K,
typename A,
typename T,
typename M>
7997requires (std::is_constructible_v<str_src<K>, T> && std::is_constructible_v<str_src<K>, M>)
7998std::basic_string<K, std::char_traits<K>, A>& replace(std::basic_string<K, std::char_traits<K>, A>&
str, T&& pattern, M&& repl,
size_t offset = 0,
size_t max_count = -1) {
7999 return replace(
str,
str_src<K>{std::forward<T>(pattern)}, str_src<K>{std::forward<M>(repl)}, offset, max_count);
8014template<
typename K,
typename A>
8015std::basic_string<K, std::char_traits<K>, A>&
make_ascii_upper(std::basic_string<K, std::char_traits<K>, A>&
str,
size_t from = 0,
size_t to = -1) {
8016 for (K *ptr =
str.data() + std::min(from,
str.length()), *end =
str.data() + std::min(to,
str.length()); ptr < end; ptr++) {
8018 if (isAsciiLower(s)) {
8037template<
typename K,
typename A>
8038std::basic_string<K, std::char_traits<K>, A>&
make_ascii_lower(std::basic_string<K, std::char_traits<K>, A>&
str,
size_t from = 0,
size_t to = -1) {
8039 for (K *ptr =
str.data() + std::min(from,
str.length()), *end =
str.data() + std::min(to,
str.length()); ptr < end; ptr++) {
8041 if (isAsciiUpper(s)) {
8076template<simstr::StdStrSource T>
8108template<
typename K,
typename A, simstr::StrExprForType<K> E>
8109std::basic_string<K, std::char_traits<K>, A>& operator |=(std::basic_string<K, std::char_traits<K>, A>& str,
const E& expr) {
8140template<
typename K,
typename A, simstr::StrExprForType<K> E>
8141std::basic_string<K, std::char_traits<K>, A>& operator ^=(std::basic_string<K, std::char_traits<K>, A>& str,
const E& expr) {
Класс для последовательного получения подстрок по заданному разделителю.
Определения strexpr.h:3230
constexpr bool is_done() const
Узнать, не закончились ли подстроки.
Определения strexpr.h:3241
constexpr str_t next()
Получить следующую подстроку.
Определения strexpr.h:3250
constexpr R trimmed_right_with_spaces(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, а также пробельных символов,...
Определения strexpr.h:5379
constexpr size_t find_last(K s, size_t offset=-1) const noexcept
Найти последнее вхождения символа в этой строке.
Определения strexpr.h:4401
constexpr int compare_ia(str_piece text) const noexcept
Сравнение строк посимвольно без учёта регистра ASCII символов.
Определения strexpr.h:3945
constexpr int compare(str_piece o) const
Сравнение строк посимвольно.
Определения strexpr.h:3830
constexpr size_t find(K s, size_t offset=0) const noexcept
Найти символ в этой строке.
Определения strexpr.h:4184
constexpr std::optional< R > strip_suffix(str_piece suffix) const
Получить строку без суффикса, если она заканчивается им.
Определения strexpr.h:5092
constexpr bool ends_with(str_piece suffix) const noexcept
Заканчивается ли строка указанной подстрокой.
Определения strexpr.h:4929
constexpr bool operator==(const base &other) const noexcept
Оператор сравнение строк на равенство.
Определения strexpr.h:3881
constexpr std::basic_string_view< D > to_sv() const noexcept
Конвертировать в std::basic_string_view.
Определения strexpr.h:3421
constexpr T slice_to(S start, E end) const noexcept
Получить результат slice и поместить его в объект заданного типа.
Определения strexpr.h:4515
constexpr bool starts_with_ia_and_ws(str_piece prefix) const noexcept
Проверить, начинается ли строка с указанной подстроки без учета регистра ASCII, за которой следует не...
Определения strexpr.h:4875
constexpr R trimmed_right() const
Получить строку с удалением пробельных символов справа.
Определения strexpr.h:5175
constexpr R trimmed_prefix_ia(str_piece prefix, size_t max_count=0) const
Возвращает строку, в которой удалено начало строки, если она начинается с указанного префикса без учё...
Определения strexpr.h:5418
constexpr size_t find_end_or_all(str_piece pattern, size_t offset=0) const noexcept
Найти конец первого вхождения подстроки в этой строке или конец строки.
Определения strexpr.h:4080
constexpr bool starts_with(str_piece prefix) const noexcept
Начинается ли строка с заданной подстроки.
Определения strexpr.h:4811
constexpr bool equal(str_piece other) const noexcept
Сравнение строк на равенство.
Определения strexpr.h:3870
void copy_to(K *buffer, size_t bufSize)
Копировать строку в указанный буфер.
Определения strexpr.h:3399
constexpr str_piece until(str_piece pattern, size_t offset=0) const noexcept
Получить подстроку str_src от начала и до первого найденного вхождения указанной подстроки.
Определения strexpr.h:3792
constexpr R trimmed(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, слева и справа.
Определения strexpr.h:5297
constexpr T as_int() const noexcept
Преобразовать строку в число заданного типа.
Определения strexpr.h:4575
constexpr my_type substring(S start, E end) const noexcept
Обёртка вокруг slice_to<my_type>
Определения strexpr.h:4529
constexpr bool less_ia(str_piece text) const noexcept
Меньше ли строка другой строки посимвольно без учёта регистра ASCII символов.
Определения strexpr.h:3985
constexpr T split(str_piece delimiter, size_t offset=0) const
Разделить строку на подстроки по заданному разделителю.
Определения strexpr.h:4796
constexpr R trimmed_right_with_spaces(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, а также пробельных символов,...
Определения strexpr.h:5280
constexpr str_piece mid(size_t from, size_t len=-1) const noexcept
Получить часть строки как "кусок строки".
Определения strexpr.h:3756
constexpr my_type substr(ptrdiff_t from, ptrdiff_t len=0) const
Получить подстроку. Работает аналогично operator(), только результат выдает того же типа,...
Определения strexpr.h:4503
R upperred_only_ascii() const
Получить копию строки в верхнем регистре ASCII символов.
Определения strexpr.h:5006
constexpr str_piece to_str() const noexcept
Преобразовать себя в "кусок строки", включающий всю строку.
Определения strexpr.h:3469
constexpr bool starts_with_and_ws(str_piece prefix) const noexcept
Проверить, начинается ли строка с указанной подстроки, за которой следует ней пробельный ASCII символ...
Определения strexpr.h:4820
constexpr str_piece from_to(size_t from, size_t to) const noexcept
Получить подстроку str_src с позиции от from до позиции to (не включая её).
Определения strexpr.h:3778
constexpr R trimmed_left_with_spaces(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, а также пробельных символов,...
Определения strexpr.h:5361
R replaced(str_piece pattern, str_piece repl, size_t offset=0, size_t maxCount=0) const
Получить копию строки с заменёнными вхождениями подстрок.
Определения strexpr.h:5038
constexpr int strcmp(const K *text) const
Сравнение с C-строкой посимвольно.
Определения strexpr.h:3841
constexpr size_t find_ia(str_piece pattern, size_t offset=0) const noexcept
Найти начало первого вхождения подстроки в этой строке без учёта регистра ASCII.
Определения strexpr.h:4234
constexpr R trimmed_left() const
Получить строку с удалением пробельных символов слева.
Определения strexpr.h:5163
constexpr bool ends_with_ia(str_piece suffix) const noexcept
Заканчивается ли строка указанной подстрокой без учёта регистра ASCII символов.
Определения strexpr.h:4955
constexpr size_t find_first_not_of(str_piece pattern, size_t offset=0) const noexcept
Найти первое вхождение символа не из заданного набора символов.
Определения strexpr.h:4448
constexpr size_t find_first_of(str_piece pattern, size_t offset=0) const noexcept
Найти первое вхождение символа из заданного набора символов.
Определения strexpr.h:4420
constexpr R trimmed_right(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, справа.
Определения strexpr.h:5325
constexpr R trimmed_with_spaces(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, а также пробельных символов,...
Определения strexpr.h:5242
constexpr size_t find_last_or_all(str_piece pattern, size_t offset=-1) const noexcept
Найти начало последнего вхождения подстроки в этой строке или конец строки.
Определения strexpr.h:4143
constexpr R trimmed_prefix(str_piece prefix, size_t max_count=0) const
Возвращает строку, в которой удалено начало строки, если она начинается с указанного префикса.
Определения strexpr.h:5395
constexpr bool starts_with_ia(str_piece prefix) const noexcept
Начинается ли строка с заданной подстроки без учёта регистра ASCII символов.
Определения strexpr.h:4866
constexpr str_piece slice(S start, E end) const noexcept
Получить часть строки как "str_src".
Определения strexpr.h:3574
constexpr R trimmed_left_with_spaces(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, а также пробельных символов,...
Определения strexpr.h:5261
constexpr size_t find_last(str_piece pattern, size_t offset=-1) const noexcept
Найти начало последнего вхождения подстроки в этой строке.
Определения strexpr.h:4116
constexpr size_t find_last_of(str_piece pattern, size_t offset=str::npos) const noexcept
Найти последнее вхождение символа из заданного набора символов.
Определения strexpr.h:4461
constexpr size_t find_or_all(K s, size_t offset=0) const noexcept
Найти символ в этой строке или конец строки.
Определения strexpr.h:4203
constexpr size_t find_last_not_of(str_piece pattern, size_t offset=str::npos) const noexcept
Найти последнее вхождение символа не из заданного набора символов.
Определения strexpr.h:4489
std::optional< double > to_double() const noexcept
Преобразовать строку в double.
Определения strexpr.h:4620
constexpr size_t find_ia_lower(str_piece pattern_lower, size_t offset=0) const noexcept
Найти начало первого вхождения подстроки в этой строке без учёта регистра ASCII, если шаблон поиска з...
Определения strexpr.h:4295
constexpr size_t find_end(str_piece pattern, size_t offset=0) const noexcept
Найти конец вхождения подстроки в этой строке.
Определения strexpr.h:4052
std::optional< double > to_double_hex() const noexcept
Преобразовать строку в 16ричной записи в double. Пока работает только для char.
Определения strexpr.h:4655
constexpr std::optional< R > strip_prefix(str_piece prefix) const
Получить строку без префикса, если она начинается с него.
Определения strexpr.h:5054
constexpr bool operator!() const noexcept
Проверка на пустоту.
Определения strexpr.h:3799
constexpr R trimmed() const
Получить строку с удалением пробельных символов слева и справа.
Определения strexpr.h:5151
constexpr size_t size() const
Размер строки в символах.
Определения strexpr.h:3410
constexpr To find_all(str_piece pattern, size_t offset=0, size_t maxCount=0) const
Найти все вхождения подстроки в этой строке.
Определения strexpr.h:4382
constexpr str_piece prefix(E count) const noexcept
Обертка вокруг slice(0, count). Также позволяет задавать границу поисковым способом.
Определения strexpr.h:3659
constexpr my_type str_mid(size_t from, size_t len=-1) const
Получить часть строки объектом того же типа, к которому применён метод, аналогично mid.
Определения strexpr.h:4543
constexpr str_piece tail(E count) const noexcept
Обертка вокруг slice(count, to_end). Также позволяет задавать границу поисковым способом.
Определения strexpr.h:3667
constexpr size_t find_end_of_last(str_piece pattern, size_t offset=-1) const noexcept
Найти конец последнего вхождения подстроки в этой строке.
Определения strexpr.h:4129
constexpr std::pair< size_t, size_t > find_first_of_idx(str_piece pattern, size_t offset=0) const noexcept
Найти первое вхождение символа из заданного набора символов.
Определения strexpr.h:4433
constexpr str_piece suffix(E count) const noexcept
Обертка вокруг slice(from_end(count), to_end). Также позволяет задавать границу поисковым способом.
Определения strexpr.h:3675
constexpr bool is_ascii() const noexcept
Содержит ли строка только ASCII символы.
Определения strexpr.h:4962
constexpr size_t find(str_piece pattern, size_t offset=0) const noexcept
Найти начало первого вхождения подстроки в этой строке.
Определения strexpr.h:4016
constexpr SplitterBase< K, str_piece > splitter(str_piece delimiter) const
Получить объект Splitter по заданному разделителю, который позволяет последовательно получать подстро...
Определения strexpr.h:5478
constexpr std::pair< size_t, size_t > find_last_of_idx(str_piece pattern, size_t offset=str::npos) const noexcept
Найти последнее вхождение символа из заданного набора символов.
Определения strexpr.h:4474
constexpr R trimmed_left(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, слева.
Определения strexpr.h:5205
constexpr size_t find_or_all(str_piece pattern, size_t offset=0) const noexcept
Найти начало первого вхождения подстроки в этой строке или конец строки.
Определения strexpr.h:4066
constexpr R trimmed_left(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, слева.
Определения strexpr.h:5311
constexpr bool operator==(T &&other) const noexcept
Оператор сравнения строки и строкового литерала на равенство.
Определения strexpr.h:3900
constexpr auto operator<=>(const base &other) const noexcept
Оператор сравнения строк.
Определения strexpr.h:3890
constexpr bool contains(str_piece pattern, size_t offset=0) const noexcept
Содержит ли строка указанную подстроку.
Определения strexpr.h:4171
constexpr R trimmed_suffix_ia(str_piece suffix) const
Возвращает строку, в которой удалён конец строки, если она заканчивается указанным суффиксом без учёт...
Определения strexpr.h:5461
constexpr str_piece operator()(ptrdiff_t from, ptrdiff_t len=0) const noexcept
Получить часть строки как "str_src".
Определения strexpr.h:3496
constexpr std::tuple< R, R, size_t > before_and_after(E delimeter) const noexcept
Разделяет строку на две части по заданному разделителю.
Определения strexpr.h:3710
constexpr K at(ptrdiff_t idx) const
Получить символ на заданной позиции .
Определения strexpr.h:3812
R lowered_only_ascii() const
Получить копию строки в нижнем регистре ASCII символов.
Определения strexpr.h:5018
constexpr R trimmed_with_spaces(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, а также пробельных символов,...
Определения strexpr.h:5343
constexpr auto operator<=>(T &&other) const noexcept
Оператор сравнения строки и строкового литерала.
Определения strexpr.h:3910
constexpr std::basic_string< D, Traits, Allocator > to_string() const
Конвертировать в std::basic_string.
Определения strexpr.h:3441
constexpr R trimmed_right(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, справа.
Определения strexpr.h:5220
constexpr void for_all_founded(const Op &op, str_piece pattern, size_t offset=0, size_t maxCount=0) const
Вызвать функтор для всех найденных вхождений подстроки в этой строке.
Определения strexpr.h:4359
constexpr T splitf(str_piece delimiter, const Op &beforeFunc, size_t offset=0) const
Разделить строку на части по заданному разделителю, с возможным применением функтора к каждой подстро...
Определения strexpr.h:4780
constexpr R trimmed(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, слева и справа.
Определения strexpr.h:5190
constexpr bool prefix_in(str_piece text) const noexcept
Является ли эта строка началом другой строки.
Определения strexpr.h:4914
constexpr std::optional< R > strip_prefix_ia(str_piece prefix) const
Получить строку без префикса, если она начинается с него без учёта регистра ASCII символов.
Определения strexpr.h:5073
constexpr bool starts_with_ia_and_oneof(str_piece prefix, str_piece next_symbol) const noexcept
Проверить, начинается ли строка с указанной подстроки без учета регистра ASCII, за которой следует од...
Определения strexpr.h:4888
constexpr size_t find_or_throw(str_piece pattern, size_t offset=0, Args &&... args) const
Найти начало первого вхождения подстроки в этой строке или выкинуть исключение.
Определения strexpr.h:4036
constexpr std::optional< R > strip_suffix_ia(str_piece suffix) const
Получить строку без суффикса, если она заканчивается им без учёта регистра ASCII символов.
Определения strexpr.h:5111
constexpr R trimmed_suffix(str_piece suffix) const
Возвращает строку, в которой удалён конец строки, если она заканчивается указанным суффиксом.
Определения strexpr.h:5441
constexpr K * place(K *ptr) const noexcept
Копировать строку в указанный буфер.
Определения strexpr.h:3384
constexpr convert_result< T > to_int() const noexcept
Преобразовать строку в число заданного типа.
Определения strexpr.h:4608
constexpr bool equal_ia(str_piece text) const noexcept
Равна ли строка другой строке посимвольно без учёта регистра ASCII символов.
Определения strexpr.h:3957
constexpr void as_number(T &t) const
Преобразовать строку в целое число.
Определения strexpr.h:4683
constexpr size_t find_end_last_or_all(str_piece pattern, size_t offset=-1) const noexcept
Найти конец последнего вхождения подстроки в этой строке или конец строки.
Определения strexpr.h:4157
constexpr bool starts_with_and_oneof(str_piece prefix, str_piece next_symbol) const noexcept
Проверить, начинается ли строка с указанной подстроки, за которой следует один из указанных символов.
Определения strexpr.h:4833
Концепт строкового выражения, совместимого с заданным типом символов.
Определения strexpr.h:525
Концепт "Строковых выражений".
Определения strexpr.h:507
Базовая концепция строкового объекта.
Определения strexpr.h:312
Проверка, являются ли два типа совместимыми строковыми типами.
Определения strexpr.h:173
constexpr expr_if< A > e_if(bool c, const A &a)
Создание условного строкового выражения expr_if.
Определения strexpr.h:1540
simstr::expr_stdstr< typename T::value_type, T > operator+(const T &str)
Унарный оператор+ для преобразования стандартных строк в строковые выражения.
Определения strexpr.h:8077
constexpr expr_spaces< uws, N > e_spcw()
Генерирует строку из N wchar_t пробелов.
Определения strexpr.h:1104
expr_fill< K, A, true > e_fill_left(const A &a, size_t width, K symbol=K(' '))
Создает выражение, которое дополняет указанное строковое выражение до заданной длины заданным символо...
Определения strexpr.h:2695
constexpr empty_expr< uws > eew
Пустое строковое выражение типа wchar_t.
Определения strexpr.h:862
constexpr expr_spaces< u8s, N > e_spca()
Генерирует строку из N char пробелов.
Определения strexpr.h:1086
constexpr empty_expr< u32s > eeuu
Пустое строковое выражение типа char32_t.
Определения strexpr.h:874
constexpr expr_num< K, T > e_num(T t)
Преобразование целого числа в строковое выражение.
Определения strexpr.h:1716
constexpr empty_expr< ubs > eeb
Пустое строковое выражение типа char8_t.
Определения strexpr.h:856
HexFlags
Флаги для функции e_hex.
Определения strexpr.h:2523
constexpr auto e_hex(T v)
Создает объект, который может преобразовываться в строковое выражение, генерирующее 16ричное представ...
Определения strexpr.h:2580
constexpr strexprjoin< A, B > operator+(const A &a, const B &b)
Оператор сложения двух произвольных строковых выражения для одинакового типа символов.
Определения strexpr.h:719
constexpr expr_repeat_lit< K, M - 1 > e_repeat(T &&s, size_t l)
Генерирует строку из l строковых констант s типа K.
Определения strexpr.h:1214
constexpr expr_literal< typename const_lit< T >::symb_type, static_cast< size_t >(N - 1)> e_t(T &&s)
Преобразует строковый литерал в строковое выражение.
Определения strexpr.h:991
expr_fill< K, A, false > e_fill_right(const A &a, size_t width, K symbol=K(' '))
Создает выражение, которое дополняет указанное строковое выражение до заданной длины заданным символо...
Определения strexpr.h:2721
constexpr expr_choice< A, B > e_choice(bool c, const A &a, const B &b)
Создание условного строкового выражения expr_choice.
Определения strexpr.h:1462
constexpr expr_char< K > e_char(K s)
Генерирует строку из 1 заданного символа.
Определения strexpr.h:918
constexpr empty_expr< u8s > eea
Пустое строковое выражение типа char.
Определения strexpr.h:850
constexpr expr_pad< K > e_c(size_t l, K s)
Генерирует строку из l символов s типа K.
Определения strexpr.h:1149
constexpr empty_expr< u16s > eeu
Пустое строковое выражение типа char16_t.
Определения strexpr.h:868
auto e_repl_const_symbols(A &&src, Repl &&... other)
Возвращает строковое выражение, генерирующее строку, в которой заданные символы заменены на заданные ...
Определения strexpr.h:6691
constexpr auto e_int(T v)
Создает объект, который преобразовывается в строковое выражение, генерирующее строковое представление...
Определения strexpr.h:2379
constexpr auto e_repl(A &&w, T &&p, X &&r)
Получить строковое выражение, генерирующее строку с заменой всех вхождений заданной подстроки.
Определения strexpr.h:6198
constexpr auto e_join(const T &s, L &&d)
Получить строковое выражение, конкатенирующее строки в контейнере в одну строку с заданным разделител...
Определения strexpr.h:2799
@ Short
without leading zeroes
Определения strexpr.h:2524
Небольшое пространство для методов работы со стандартными строками.
Определения strexpr.h:1596
std::basic_string< K, std::char_traits< K >, A > & append(std::basic_string< K, std::char_traits< K >, A > &str, const E &expr)
Добавить к стандартной строке строковое выражение.
Определения strexpr.h:7616
std::basic_string< K, std::char_traits< K >, A > & prepend(std::basic_string< K, std::char_traits< K >, A > &str, const E &expr)
Вставить строковое выражение в начало стандартной строки.
Определения strexpr.h:7649
std::basic_string< K, std::char_traits< K >, A > & make_ascii_upper(std::basic_string< K, std::char_traits< K >, A > &str, size_t from=0, size_t to=-1)
Изменить строчные ASCII символы строки (a-z) на прописные.
Определения strexpr.h:8015
std::basic_string< K, std::char_traits< K >, A > & change(std::basic_string< K, std::char_traits< K >, A > &str, size_t from, size_t count, const E &expr)
Изменить часть стандартной строки на заданное строковое выражение.
Определения strexpr.h:7543
std::basic_string< K, std::char_traits< K >, A > & replace(std::basic_string< K, std::char_traits< K >, A > &str, T &&pattern, const E &repl, size_t offset=0, size_t max_count=-1)
Функция поиска подстрок в стандартной строке и замены найденных вхождений на значение строкового выра...
Определения strexpr.h:7874
std::basic_string< K, std::char_traits< K >, A > & make_ascii_lower(std::basic_string< K, std::char_traits< K >, A > &str, size_t from=0, size_t to=-1)
Изменить прописные ASCII символы строки (A-Z) на строчные.
Определения strexpr.h:8038
std::basic_string< K, std::char_traits< K >, A > & overwrite(std::basic_string< K, std::char_traits< K >, A > &str, const E &expr)
Переписать всю строку заданным строковым выражением, при необходимости изменив размер строки.
Определения strexpr.h:7713
std::basic_string< K, std::char_traits< K >, A > & insert(std::basic_string< K, std::char_traits< K >, A > &str, size_t from, const E &expr)
Вставить строковое выражение в указанную позицию стандартной строки.
Определения strexpr.h:7684
Пространство имён для объектов библиотеки
Определения sstring.cpp:12
IntConvertResult
Перечисление с возможными результатами преобразования строки в целое число
Определения strexpr.h:2866
@ Overflow
Переполнение, число не помещается в заданный тип
Определения strexpr.h:2869
@ Success
Успешно
Определения strexpr.h:2867
@ NotNumber
Вообще не число
Определения strexpr.h:2870
@ BadSymbolAtTail
Число закончилось не числовым символом
Определения strexpr.h:2868
Некоторые методы для работы с стандартными строками.
Определения strexpr.h:8056
Генерирует строку на основе исходной, заменяя все ASCII прописные буквы (A-Z) на строчные.
Определения strexpr.h:7496
Генерирует строку на основе исходной, заменяя все ASCII строчные буквы (a-z) на прописные.
Определения strexpr.h:7473
constexpr e_concat(G &&glue, Arg &&arg, Args &&...args)
Создание строкового выражения, объединяющего указанные строковые выражения, с использованием заданног...
Определения strexpr.h:7030
constexpr e_subst(const details::subst_params< K, PtLen, NParams > &subst, Args &&...args)
Создает строковое выражение, которое подставляет в заданные места в строковом литерале - образце знач...
Определения strexpr.h:7252
constexpr e_vsubst(str_src< K > pattern, Args &&...args)
Создает строковое выражение, которое подставляет в заданные места в строке-образце,...
Определения strexpr.h:7351
"Пустое" строковое выражение.
Определения strexpr.h:835
Строковое выражение условного выбора.
Определения strexpr.h:1341
Строковое выражение условного выбора.
Определения strexpr.h:1407
Строковое выражение условного выбора.
Определения strexpr.h:1250
Строковое выражение условного выбора.
Определения strexpr.h:1279
Тип строкового выражения, возвращающего N заданных символов.
Определения strexpr.h:1120
constexpr expr_replace_symbols(str_t source, const std::vector< std::pair< K, str_t > > &repl)
Конструктор выражения.
Определения strexpr.h:6775
Строковое выражение, генерирующее строку с заменой всех вхождений заданной подстроки на строковое выр...
Определения strexpr.h:6316
constexpr expr_replaced_e(str_src< K > w, str_src< K > p, const E &e)
Конструктор.
Определения strexpr.h:6335
Строковое выражение, генерирующее строку с заменой всех вхождений заданной подстроки на другую строку...
Определения strexpr.h:6210
constexpr expr_replaced(str_src< K > w, str_src< K > p, str_src< K > r)
Конструктор.
Определения strexpr.h:6228
Тип строкового выражения, возвращающего N заданных символов.
Определения strexpr.h:1060
Тип для использования std::basic_string и std::basic_string_view как источников в строковых выражения...
Определения strexpr.h:1565
Базовый класс для преобразования строковых выражений в стандартные строки
Определения strexpr.h:659
Класс, заявляющий, что ссылается на нуль-терминированную строку.
Определения strexpr.h:5649
constexpr my_type to_nts(size_t from)
Получить нуль-терминированную строку, сдвинув начало на заданное количество символов.
Определения strexpr.h:5712
constexpr str_src_nt(T &&v) noexcept
Конструктор из строкового литерала.
Определения strexpr.h:5683
constexpr str_src_nt(T &&p) noexcept
Явный конструктор из С-строки.
Определения strexpr.h:5674
constexpr str_src_nt(const std::basic_string< K, std::char_traits< K >, A > &s) noexcept
Конструктор из std::basic_string.
Определения strexpr.h:5701
constexpr str_src_nt(const K *p, size_t l) noexcept
Конструктор из указателя и длины.
Определения strexpr.h:5689
Простейший класс иммутабельной не владеющей строки.
Определения strexpr.h:5513
constexpr str_src(const std::basic_string< K, std::char_traits< K >, A > &s) noexcept
Конструктор из std::basic_string.
Определения strexpr.h:5542
constexpr bool is_empty() const noexcept
Проверить, не пуста ли строка.
Определения strexpr.h:5567
constexpr size_t length() const noexcept
Получить длину строки.
Определения strexpr.h:5553
constexpr K operator[](size_t idx) const
Получить символ из указанной позиции. Проверка границ не выполняется.
Определения strexpr.h:5596
constexpr my_type & remove_prefix(size_t delta)
Сдвигает начало строки на заданное количество символов.
Определения strexpr.h:5607
constexpr str_src(const K *p, size_t l) noexcept
Конструктор из указателя и длины.
Определения strexpr.h:5532
constexpr bool is_same(str_src< K > other) const noexcept
Проверить, не указывают ли два объекта на одну строку.
Определения strexpr.h:5576
constexpr str_src(const std::basic_string_view< K, std::char_traits< K > > &s) noexcept
Конструктор из std::basic_string_view.
Определения strexpr.h:5547
constexpr const symb_type * symbols() const noexcept
Получить указатель на константный буфер с символами строки.
Определения strexpr.h:5560
constexpr my_type & remove_suffix(size_t delta)
Укорачивает строку на заданное количество символов.
Определения strexpr.h:5620
constexpr bool is_part_of(str_src< K > other) const noexcept
Проверить, не является ли строка частью другой строки.
Определения strexpr.h:5585
constexpr str_src(T &&v) noexcept
Конструктор из строкового литерала.
Определения strexpr.h:5526
Конкатенация ссылки на строковое выражение и значения строкового выражения.
Определения strexpr.h:744
Шаблонный класс для конкатенации двух строковых выражений в одно с помощью operator +
Определения strexpr.h:682