20#if defined __has_builtin
21# if __has_builtin(__builtin_mul_overflow) && __has_builtin(__builtin_add_overflow)
22# define HAS_BUILTIN_OVERFLOW
27#define _no_unique_address msvc::no_unique_address
28#define decl_empty_bases __declspec(empty_bases)
30#define _no_unique_address no_unique_address
31#define decl_empty_bases
43#define SS_CONSTEVAL constexpr
45#define SS_CONSTEVAL consteval
56inline constexpr bool wchar_is_u16 =
sizeof(wchar_t) ==
sizeof(
char16_t);
58using wchar_type = std::conditional<wchar_is_u16, char16_t, char32_t>::type;
60inline wchar_type* to_w(
wchar_t* p) {
61 return (
reinterpret_cast<wchar_type*
>(p));
64inline const wchar_type* to_w(
const wchar_t* p) {
65 return (
reinterpret_cast<const wchar_type*
>(p));
68inline wchar_t* from_w(wchar_type* p) {
69 return (
reinterpret_cast<wchar_t*
>(p));
72inline const wchar_t* from_w(
const wchar_type* p) {
73 return (
reinterpret_cast<const wchar_t*
>(p));
82using uu8s = std::make_unsigned<u8s>::type;
84template<
typename T,
typename K = void,
typename... Types>
85struct is_one_of_type {
86 static constexpr bool value = std::is_same_v<T, K> || is_one_of_type<T, Types...>::value;
89struct is_one_of_type<T, void> : std::false_type {};
92concept is_one_of_char_v = is_one_of_type<K, u8s, ubs, wchar_t, u16s, u32s>::value;
95concept is_one_of_std_char_v = is_one_of_type<K, u8s, ubs, wchar_t, wchar_type>::value;
97template<is_one_of_std_
char_v From>
98auto to_one_of_std_char(From* from) {
99 if constexpr (std::is_same_v<From, u8s> || std::is_same_v<From, wchar_t>) {
101 }
else if constexpr (std::is_same_v<From, ubs>) {
102 return reinterpret_cast<u8s*
>(from);
108template<is_one_of_std_
char_v From>
109auto to_one_of_std_char(
const From* from) {
110 if constexpr (std::is_same_v<From, u8s> || std::is_same_v<From, wchar_t>) {
112 }
else if constexpr (std::is_same_v<From, ubs>) {
113 return reinterpret_cast<const u8s*
>(from);
120struct to_std_char_type : std::type_identity<K>{};
123struct to_std_char_type<char8_t>{
128struct to_std_char_type<char16_t>{
129 using type = std::conditional_t<
sizeof(char16_t) ==
sizeof(
wchar_t), wchar_t,
void>;
133struct to_std_char_type<char32_t>{
134 using type = std::conditional_t<
sizeof(char32_t) ==
sizeof(
wchar_t), wchar_t,
void>;
138using to_std_char_t =
typename to_std_char_type<K>::type;
141struct to_base_char_type : std::type_identity<K>{};
144struct to_base_char_type<char8_t>{
149struct to_base_char_type<wchar_t>{
150 using type = std::conditional_t<
sizeof(char16_t) ==
sizeof(
wchar_t), char16_t,
char32_t>;
154using to_base_char_t =
typename to_base_char_type<K>::type;
171template<
typename K1,
typename K2>
220template<
typename T>
struct const_lit;
223template<is_one_of_
char_v T,
size_t N>
224struct const_lit<const T(&)[N]> {
226 constexpr static size_t Count = N;
230concept is_const_lit_v =
requires {
231 typename const_lit<T>::symb_type;
236template<
typename K,
typename T>
struct const_lit_for;
238template<
typename K, is_equal_str_type_v<K> P,
size_t N>
239struct const_lit_for<K, const P(&)[N]> {
240 constexpr static size_t Count = N;
243template<
typename K,
size_t N>
244class const_lit_to_array {
247 constexpr size_t find(K s)
const {
248 if constexpr (Idx < N) {
249 return s == symbols_[Idx] ? Idx : find<Idx + 1>(s);
255 constexpr bool exist(K s)
const {
256 if constexpr (Idx < N) {
257 return s == symbols_[Idx] || exist<Idx + 1>(s);
262 const K (&symbols_)[N + 1];
264 template<typename T, size_t M = const_lit_for<K, T>::Count>
requires (M == N + 1)
265 constexpr const_lit_to_array(T&& s)
266 : symbols_((
const K(&)[M])s) {}
268 constexpr bool contain(K s)
const {
271 constexpr size_t index_of(K s)
const {
277concept StrTypeCommon =
requires(
const A& a) {
278 typename std::remove_cvref_t<A>::symb_type;
279 { a.is_empty() } -> std::same_as<bool>;
280 { a.length() } -> std::convertible_to<size_t>;
285concept HasSymbType =
requires {
286 typename std::remove_cvref_t<A>::symb_type;
310template<
typename A,
typename K>
311concept StrType = StrTypeCommon<A> &&
requires(
const A& a) {
312 { a.symbols() } -> std::same_as<const K*>;
313} && std::is_same_v<typename std::remove_cvref_t<A>::symb_type, K>;
315template<
typename T>
struct is_std_string_source : std::false_type{};
317template<
typename K,
typename A>
318struct is_std_string_source<std::basic_string<K, std::char_traits<K>, A>> : std::true_type{};
321struct is_std_string_source<std::basic_string_view<K, std::char_traits<K>>> : std::true_type{};
324concept is_std_string_source_v = is_std_string_source<T>::value;
327concept StdStrSource = is_std_string_source_v<std::remove_cvref_t<T>>;
329template<
typename T,
typename K>
333concept StrSource = StdStrSource<T> || is_const_lit_v<T> || StrTypeCommon<T>;
336concept StrSourceNoLiteral = StdStrSource<T> || StrTypeCommon<T>;
338template<
typename T>
struct is_std_string : std::false_type{};
340template<
typename K,
typename A>
341struct is_std_string<std::basic_string<K, std::char_traits<K>, A>> : std::true_type{};
344concept is_std_string_v = is_std_string<T>::value;
345template<
typename T,
typename K>
349struct 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, StrExpr 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>
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);
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 constexpr expr_repeat_expr(
size_t repeat,
const A& expr) : repeat_(repeat), expr_(expr){}
1179 constexpr size_t length() const noexcept {
1181 return repeat_ * expr_.length();
1185 constexpr symb_type* place(symb_type* p)
const noexcept {
1188 return expr_.place(p);
1190 symb_type* start = p;
1192 size_t len = size_t(p - start);
1194 for (
size_t i = 1; i < repeat_; i++) {
1195 std::char_traits<symb_type>::copy(p, start, len);
1217template<typename T, typename K = const_lit<T>::symb_type,
size_t M = const_lit<T>::Count>
requires (M > 0)
1218constexpr expr_repeat_lit<K, M - 1>
e_repeat(T&& s,
size_t l) {
1236constexpr expr_repeat_expr<A>
e_repeat(
const A& s,
size_t l) {
1253template<StrExpr A, StrExprForType<
typename A::symb_type> B>
1255 using symb_type =
typename A::symb_type;
1256 using my_type = expr_choice<A, B>;
1261 constexpr expr_choice(
const A& _a,
const B& _b,
bool _choice) : a(_a), b(_b), choice(_choice){}
1263 constexpr size_t length()
const noexcept {
1264 return choice ? a.length() : b.length();
1266 constexpr symb_type* place(symb_type* ptr)
const noexcept {
1267 return choice ? a.place(ptr) : (symb_type*)b.place((
typename B::symb_type*)ptr);
1284 using symb_type =
typename A::symb_type;
1285 using my_type = expr_if<A>;
1288 constexpr expr_if(
const A& _a,
bool _choice) : a(_a), choice(_choice){}
1290 constexpr size_t length()
const noexcept {
1291 return choice ? a.length() : 0;
1293 constexpr symb_type* place(symb_type* ptr)
const noexcept {
1294 return choice ? a.place(ptr) : ptr;
1344template<
typename L, StrExprForType<L> A,
size_t N,
bool Compare>
1346 using symb_type = L;
1347 const symb_type (&str)[N + 1];
1350 constexpr expr_choice_one_lit(
const symb_type (&_str)[N + 1],
const A& _a,
bool _choice) : str(_str), a(_a), choice(_choice){}
1352 constexpr size_t length()
const noexcept {
1353 return choice == Compare ? a.length() : N;
1355 constexpr symb_type* place(symb_type* ptr)
const noexcept {
1356 if (choice == Compare) {
1357 return (L*)a.place((
typename A::symb_type*)ptr);
1359 if constexpr (N != 0) {
1360 std::char_traits<symb_type>::copy(ptr, str, N);
1410template<
typename K,
size_t N,
typename P,
size_t M>
1412 using symb_type = K;
1413 const K (&str_a)[N + 1];
1414 const P (&str_b)[M + 1];
1416 constexpr expr_choice_two_lit(
const K(&_str_a)[N + 1],
const P(&_str_b)[M + 1],
bool _choice)
1417 : str_a(_str_a), str_b(_str_b), choice(_choice){}
1419 constexpr size_t length()
const noexcept {
1420 return choice ? N : M;
1422 constexpr symb_type* place(symb_type* ptr)
const noexcept {
1424 if constexpr (N != 0) {
1425 std::char_traits<symb_type>::copy(ptr, str_a, N);
1429 if constexpr (M != 0) {
1430 std::char_traits<symb_type>::copy(ptr, (
const K(&)[M + 1])str_b, M);
1465template<StrExpr A, StrExprForType<
typename A::symb_type> B>
1475template<StrExpr A, typename T, size_t N = const_lit_for<typename A::symb_type, T>::Count>
1485template<StrExpr A, typename T, size_t N = const_lit_for<typename A::symb_type, T>::Count>
1494template<typename T, typename L, typename K = typename const_lit<T>::symb_type,
typename P =
typename const_lit<L>::symb_type,
1495 size_t N = const_lit<T>::Count,
size_t M = const_lit_for<typename const_lit<T>::symb_type, L>::Count>
1496 requires is_equal_str_type_v<K, P>
1498 return {str_a, str_b, c};
1552template<typename T, size_t N = const_lit<T>::Count>
1554 using K =
typename const_lit<T>::symb_type;
1555 const K empty[1] = {0};
1568template<
typename K, StdStrSourceForType<K> T>
1570 using symb_type = K;
1573 expr_stdstr(
const T& t) : t_(t){}
1575 constexpr size_t length()
const noexcept {
1578 constexpr symb_type* place(symb_type* p)
const noexcept {
1579 size_t s = t_.size();
1580 std::char_traits<K>::copy(p, (
const K*)t_.data(), s);
1595template<
typename K, StdStrSource T>
1596struct convert_to_strexpr<K, T> {
1601constexpr const size_t npos =
static_cast<size_t>(-1);
1605struct ch_traits : std::char_traits<K>{};
1608concept FromIntNumber =
1609 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;
1612concept ToIntNumber = FromIntNumber<T> || is_one_of_type<T, int8_t>::value;
1614template<
typename K,
bool I,
typename T>
1617 std::make_unsigned_t<T> val;
1618 constexpr need_sign(T t) : negate(t < 0), val(t < 0 ? std::make_unsigned_t<T>{} - t : t) {}
1619 constexpr void after(K*& ptr) {
1625template<
typename K,
typename T>
1626struct need_sign<K, false, T> {
1628 constexpr need_sign(T t) : val(t){}
1629 constexpr void after(K*&) {}
1632template<
typename K,
typename T>
1633constexpr size_t fromInt(K* bufEnd, T val) {
1634 const char* twoDigit =
1635 "0001020304050607080910111213141516171819"
1636 "2021222324252627282930313233343536373839"
1637 "4041424344454647484950515253545556575859"
1638 "6061626364656667686970717273747576777879"
1639 "8081828384858687888990919293949596979899";
1641 need_sign<K, std::is_signed_v<T>, T> store(val);
1643 while (store.val >= 100) {
1644 const char* ptr = twoDigit + (store.val % 100) * 2;
1645 *--itr =
static_cast<K
>(ptr[1]);
1646 *--itr =
static_cast<K
>(ptr[0]);
1649 if (store.val < 10) {
1650 *--itr =
static_cast<K
>(
'0' + store.val);
1652 const char* ptr = twoDigit + store.val * 2;
1653 *--itr =
static_cast<K
>(ptr[1]);
1654 *--itr =
static_cast<K
>(ptr[0]);
1657 return size_t(bufEnd - itr);
1663template<
typename K,
typename T>
1665 using symb_type = K;
1666 using my_type = expr_num<K, T>;
1668 enum { bufSize = 24 };
1669 mutable K buf[bufSize];
1672 constexpr expr_num(T t) : value(t) {}
1673 constexpr expr_num(expr_num&& t) noexcept : value(t.value) {}
1675 constexpr size_t length() const noexcept {
1676 value = (T)fromInt(buf + bufSize, value);
1677 return (
size_t)value;
1679 constexpr K* place(K* ptr)
const noexcept {
1680 size_t len = (size_t)value;
1681 ch_traits<K>::copy(ptr, buf + bufSize - len, len);
1696template<
typename K, FromIntNumber T>
1697struct convert_to_strexpr<K, T> {
1698 using type = expr_num<K, T>;
1716template<
typename K, FromIntNumber T>
1723enum class int_align { none, left, right, center };
1724enum class int_plus_sign {none, plus, space};
1725enum class int_prefix {none, lcase, ucase};
1727enum fmt_kinds :
unsigned {
1738template<
typename A,
typename B,
unsigned Kind>
1742 inline static constexpr unsigned kind = Kind;
1746 inline static constexpr unsigned kind = fmt_none;
1749template<
int_align A>
1751 inline static constexpr unsigned kind = fmt_align;
1754template<
size_t W
idth = 0>
1756 inline static constexpr unsigned kind = fmt_width;
1759template<
unsigned Fill = ' '>
1761 inline static constexpr unsigned kind = fmt_fill;
1764template<
int_plus_sign S>
1766 inline static constexpr unsigned kind = fmt_sign;
1770 inline static constexpr unsigned kind = fmt_upper;
1775 inline static constexpr unsigned kind = fmt_prefix;
1779 inline static constexpr unsigned kind = fmt_zero;
1783concept FmtParam =
requires {
1784 {std::remove_cvref_t<T>::kind} -> std::same_as<const unsigned&>;
1787template<FmtParam A, FmtParam B>
1788requires((A::kind & B::kind) == 0)
1789constexpr auto operator | (
const A&,
const B&) {
1790 return fmt_info<A, B, A::kind | B::kind>{};
1793inline constexpr align_info<int_align::left> l;
1794inline constexpr align_info<int_align::right> r;
1795inline constexpr align_info<int_align::center> c;
1798inline constexpr width_info<W> w;
1801inline constexpr fill_info<F> f;
1803inline constexpr sign_info<int_plus_sign::plus> sp;
1804inline constexpr sign_info<int_plus_sign::space> ss;
1805inline constexpr upper_info u;
1806inline constexpr prefix_info<int_prefix::lcase> p;
1807inline constexpr prefix_info<int_prefix::ucase> P;
1808inline constexpr zero_info z;
1810inline constexpr width_info<unsigned(-1)> wp;
1811inline constexpr fmt_default df;
1814struct extract_align : std::false_type {
1815 inline static constexpr int_align align = int_align::none;
1818template<
int_align A>
1819struct extract_align<align_info<A>> : std::true_type {
1820 inline static constexpr int_align align = A;
1823template<
typename A,
typename B,
unsigned U>
1824struct extract_align<fmt_info<A, B, U>> {
1825 inline static constexpr bool in_a = extract_align<A>::value, in_b = extract_align<B>::value, value = in_a | in_b;
1826 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;
1830struct extract_width : std::false_type {
1831 inline static constexpr size_t width = 0;
1835struct extract_width<width_info<W>> : std::true_type {
1836 inline static constexpr size_t width = W;
1839template<
typename A,
typename B,
unsigned U>
1840struct extract_width<fmt_info<A, B, U>> {
1841 inline static constexpr bool in_a = extract_width<A>::value, in_b = extract_width<B>::value, value = in_a | in_b;
1842 inline static constexpr size_t width = extract_width<std::conditional_t<in_a, A, std::conditional_t<in_b, B, width_info<0>>>>::width;
1846struct extract_fill : std::false_type {
1847 inline static constexpr unsigned fill =
' ';
1851struct extract_fill<fill_info<F>> : std::true_type {
1852 inline static constexpr unsigned fill = F;
1855template<
typename A,
typename B,
unsigned U>
1856struct extract_fill<fmt_info<A, B, U>> {
1857 inline static constexpr bool in_a = extract_fill<A>::value, in_b = extract_fill<B>::value, value = in_a | in_b;
1858 inline static constexpr unsigned fill = extract_fill<std::conditional_t<in_a, A, std::conditional_t<in_b, B, fill_info<
' '>>>>::fill;
1862struct extract_sign : std::false_type {
1863 inline static constexpr int_plus_sign sign = int_plus_sign::none;
1866template<
int_plus_sign S>
1867struct extract_sign<sign_info<S>> : std::true_type {
1868 inline static constexpr int_plus_sign sign = S;
1871template<
typename A,
typename B,
unsigned U>
1872struct extract_sign<fmt_info<A, B, U>> {
1873 inline static constexpr bool in_a = extract_sign<A>::value, in_b = extract_sign<B>::value, value = in_a | in_b;
1874 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;
1878struct extract_upper : std::false_type {};
1881struct extract_upper<upper_info> : std::true_type {};
1883template<
typename A,
typename B,
unsigned U>
1884struct extract_upper<fmt_info<A, B, U>> {
1885 inline static constexpr bool in_a = extract_upper<A>::value, in_b = extract_upper<B>::value,
1886 value = extract_upper<std::conditional_t<in_a, A, std::conditional_t<in_b, B, std::false_type>>>::value;
1890struct extract_prefix : std::false_type{
1891 inline static constexpr int_prefix prefix = int_prefix::none;
1894template<
int_prefix P>
1895struct extract_prefix<prefix_info<P>> : std::true_type {
1896 inline static constexpr int_prefix prefix = P;
1899template<
typename A,
typename B,
unsigned U>
1900struct extract_prefix<fmt_info<A, B, U>> {
1901 inline static constexpr bool in_a = extract_prefix<A>::value, in_b = extract_prefix<B>::value, value = in_a | in_b;
1902 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;
1906struct extract_zero : std::false_type{};
1909struct extract_zero<zero_info> : std::true_type {};
1911template<
typename A,
typename B,
unsigned U>
1912struct extract_zero<fmt_info<A, B, U>> {
1913 inline static constexpr bool in_a = extract_zero<A>::value, in_b = extract_zero<B>::value,
1914 value = extract_zero<std::conditional_t<in_a, A, std::conditional_t<in_b, B, std::false_type>>>::value;
1917template<
int_align Align,
unsigned W
idth,
unsigned Fill,
int_plus_sign Sign,
bool Upper,
int_prefix Prefix,
bool Zero>
1919 inline static constexpr int_align align = Align;
1920 inline static constexpr unsigned width = Width;
1921 inline static constexpr unsigned fill = Fill;
1922 inline static constexpr int_plus_sign sign = Sign;
1923 inline static constexpr bool upper = Upper;
1924 inline static constexpr int_prefix prefix = Prefix;
1925 inline static constexpr bool zero = Zero;
1929using p_to_fmt_t = fmt_params<
1930 extract_align<T>::align,
1931 extract_width<T>::width,
1932 extract_fill<T>::fill,
1933 extract_sign<T>::sign,
1934 extract_upper<T>::value,
1935 extract_prefix<T>::prefix,
1936 extract_zero<T>::value>;
1939using to_fmt_t = p_to_fmt_t<std::remove_cvref_t<T>>;
1942struct is_fmt_params : std::false_type{};
1944template<
int_align Align,
unsigned W
idth,
unsigned Fill,
int_plus_sign Sign,
bool Upper,
int_prefix Prefix,
bool Zero>
1945struct is_fmt_params<fmt_params<Align, Width, Fill, Sign, Upper, Prefix, Zero>> : std::true_type{};
1948concept FmtParamSet = is_fmt_params<T>::value;
1952template<f::FmtParam F>
1953constexpr auto operator|(
const F& f, fmt_end) {
1957template<
char C = 0,
char...Chars>
1958constexpr auto parse_fmt_symbol();
1960template<
unsigned N,
char C =
'Z',
char...Chars>
1961constexpr auto parse_width() {
1962 if constexpr (C >=
'0' && C <=
'9') {
1963 return parse_width<N * 10 + C -
'0', Chars...>();
1965 return w<N> | parse_fmt_symbol<C, Chars...>();
1969template<
unsigned N,
char C =
'Z',
char...Chars>
1970constexpr auto parse_fill() {
1971 if constexpr (C >=
'0' && C <=
'9') {
1972 return parse_fill<N * 16 + C -
'0', Chars...>();
1973 }
else if constexpr (C >=
'a' && C <=
'f') {
1974 return parse_fill<N * 16 + C -
'a' + 10, Chars...>();
1975 }
else if constexpr (C >=
'A' && C <=
'F') {
1976 return parse_fill<N * 16 + C -
'A' + 10, Chars...>();
1978 return f<N> | parse_fmt_symbol<C, Chars...>();
1982template<
char C,
char...Chars>
1983constexpr auto parse_fmt_symbol() {
1984 if constexpr (C ==
'0') {
1985 return z | parse_fmt_symbol<Chars...>();
1986 }
else if constexpr (C ==
'a') {
1987 return p | parse_fmt_symbol<Chars...>();
1988 }
else if constexpr (C ==
'A') {
1989 return P | parse_fmt_symbol<Chars...>();
1990 }
else if constexpr (C ==
'b') {
1991 return l | parse_fmt_symbol<Chars...>();
1992 }
else if constexpr (C ==
'c') {
1993 return c | parse_fmt_symbol<Chars...>();
1994 }
else if constexpr (C ==
'd') {
1995 return r | parse_fmt_symbol<Chars...>();
1996 }
else if constexpr (C ==
'e') {
1997 return sp | parse_fmt_symbol<Chars...>();
1998 }
else if constexpr (C ==
'f') {
1999 return ss | parse_fmt_symbol<Chars...>();
2000 }
else if constexpr (C ==
'E') {
2001 return u | parse_fmt_symbol<Chars...>();
2002 }
else if constexpr (C ==
'\'') {
2003 return parse_fmt_symbol<Chars...>();
2004 }
else if constexpr (C ==
'F') {
2005 return parse_fill<0, Chars...>();
2006 }
else if constexpr (C >=
'1' && C <=
'9') {
2007 return parse_width<C -
'0', Chars...>();
2013template<
unsigned R,
typename T>
2014struct fmt_radix_info {};
2016template<
unsigned N,
char C = 0,
char...Chars>
2017constexpr auto parse_radix() {
2018 if constexpr (C >=
'0' && C <=
'9') {
2019 return parse_radix<N * 10 + C -
'0', Chars...>();
2020 }
else if constexpr (C == 0) {
2021 return fmt_radix_info<N, to_fmt_t<fmt_default>>{};
2023 return fmt_radix_info<N,
decltype(parse_fmt_symbol<C, Chars...>())>{};
2027template<
char C1,
char C2,
char C3,
char...Chars>
2028constexpr auto skip_0x() {
2029 static_assert(C1 ==
'0' && C2 ==
'x' &&
"Fmt symbols must begin with 0x");
2030 static_assert(C3 >=
'1' && C3 <=
'9' &&
"Radix must begin with 1-9");
2031 return parse_radix<C3 -
'0', Chars...>();
2036template<
typename K,
bool Ucase>
2037inline 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'),
2038 K(Ucase ?
'A' :
'a'), K(Ucase ?
'B' :
'b'), K(Ucase ?
'C' :
'c'), K(Ucase ?
'D' :
'd'), K(Ucase ?
'E' :
'e'),
2039 K(Ucase ?
'F' :
'f'), K(Ucase ?
'G' :
'g'), K(Ucase ?
'H' :
'h'), K(Ucase ?
'I' :
'i'), K(Ucase ?
'J' :
'j'),
2040 K(Ucase ?
'K' :
'k'), K(Ucase ?
'L' :
'l'), K(Ucase ?
'M' :
'm'), K(Ucase ?
'N' :
'n'), K(Ucase ?
'O' :
'o'),
2041 K(Ucase ?
'P' :
'p'), K(Ucase ?
'Q' :
'q'), K(Ucase ?
'R' :
'r'), K(Ucase ?
'S' :
's'), K(Ucase ?
'T' :
't'),
2042 K(Ucase ?
'U' :
'u'), K(Ucase ?
'V' :
'v'), K(Ucase ?
'W' :
'w'), K(Ucase ?
'X' :
'x'), K(Ucase ?
'Y' :
'y'),
2043 K(Ucase ?
'Z' :
'z'),
2046template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2047struct expr_integer_src {
2050 constexpr expr_integer_src(T v) : value_(v){}
2051 constexpr expr_integer_src(T v,
unsigned w) : value_(v), width_(w){}
2053 template<is_std_
string_v S>
2056 template<
typename S>
requires std::is_constructible_v<S, empty_expr<typename S::symb_type>>
2060template<is_one_of_
char_v K, FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
2061requires (Radix > 1 && Radix <= 36)
2063 using symb_type = K;
2064 using my_type = expr_num<K, T>;
2066 enum { bufSize = 64 };
2067 mutable K buf[bufSize];
2071 mutable bool negate_{};
2073 constexpr expr_integer(T t) : value_(t){}
2074 constexpr expr_integer(T t,
unsigned w) : value_(t), width_(w){}
2075 constexpr expr_integer(
const expr_integer_src<T, Radix, FP>& v) : value_(v.value_), width_(v.width_){}
2077 constexpr expr_integer(expr_integer&& t) noexcept : value_(t.value_), width_(t.width_){}
2079 constexpr size_t length() const noexcept {
2080 K* bufEnd = std::end(buf), *itr = bufEnd;
2083 need_sign<K, std::is_signed_v<T>, T> store(value_);
2085 *--itr = digits_symbols<K, FP::upper>[store.val % Radix];
2088 if constexpr (std::is_signed_v<T>) {
2089 negate_ = store.negate;
2092 *--itr = digits_symbols<K, FP::upper>[0];
2094 size_t len = bufEnd - itr;
2096 if constexpr (std::is_signed_v<T>) {
2097 if constexpr (FP::sign != f::int_plus_sign::none) {
2105 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2107 if constexpr (Radix != 8) {
2111 if constexpr (FP::width == unsigned(-1)) {
2112 return std::max<size_t>(width_, len);
2114 return std::max<size_t>(FP::width, len);
2117 constexpr K* place(K* ptr)
const noexcept {
2118 size_t len = (size_t)value_, all_len = len;
2119 if constexpr (std::is_signed_v<T>) {
2120 if constexpr (FP::sign != f::int_plus_sign::none) {
2128 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2130 if constexpr (Radix != 8) {
2134 if constexpr (FP::zero) {
2135 if constexpr (std::is_signed_v<T>) {
2139 if constexpr (FP::sign == f::int_plus_sign::plus) {
2141 }
else if constexpr (FP::sign == f::int_plus_sign::space) {
2146 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2148 if constexpr (Radix == 2) {
2149 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'b') : K(
'B');
2150 }
else if constexpr (Radix == 16) {
2151 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'x') : K(
'X');
2155 if constexpr (FP::width == unsigned(-1)) {
2156 if (width_ > all_len) {
2157 before = width_ - all_len;
2160 if (FP::width > all_len) {
2161 before = FP::width - all_len;
2165 ch_traits<K>::assign(ptr, before, K(
'0'));
2168 ch_traits<K>::copy(ptr, std::end(buf) - len, len);
2171 size_t before = 0, after = 0;
2172 if constexpr (FP::width == unsigned(-1)) {
2173 if (width_ > all_len) {
2174 if constexpr (FP::align == f::int_align::left) {
2175 after = width_ - all_len;
2176 }
else if constexpr (FP::align == f::int_align::center) {
2177 before = (width_ - all_len) / 2;
2178 after = width_ - all_len - before;
2180 before = width_ - all_len;
2184 if (FP::width > all_len) {
2185 if constexpr (FP::align == f::int_align::left) {
2186 after = FP::width - all_len;
2187 }
else if constexpr (FP::align == f::int_align::center) {
2188 before = (FP::width - all_len) / 2;
2189 after = FP::width - all_len - before;
2191 before = FP::width - all_len;
2196 ch_traits<K>::assign(ptr, before, K(FP::fill));
2199 if constexpr (std::is_signed_v<T>) {
2203 if constexpr (FP::sign == f::int_plus_sign::plus) {
2205 }
else if constexpr (FP::sign == f::int_plus_sign::space) {
2210 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2212 if constexpr (Radix == 2) {
2213 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'b') : K(
'B');
2214 }
else if constexpr (Radix == 16) {
2215 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'x') : K(
'X');
2218 ch_traits<K>::copy(ptr, std::end(buf) - len, len);
2222 ch_traits<K>::assign(ptr, after, K(FP::fill));
2230template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2231template<is_std_string_v S>
2232expr_integer_src<T, Radix, FP>::operator S()
const {
2233 using st =
typename S::value_type;
2234 using Al =
typename S::allocator_type;
2235 return to_std_string<st, Al>(expr_integer<st, T, Radix, FP>{value_, width_});
2238template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2240expr_integer_src<T, Radix, FP>::operator S()
const {
2241 using st =
typename S::symb_type;
2242 return S{expr_integer<st, T, Radix, FP>{value_, width_}};
2245template<
typename K, FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
2246struct convert_to_strexpr<K, expr_integer_src<T, Radix, FP>> {
2247 using type = expr_integer<K, T, Radix, FP>;
2250template<
unsigned R,
typename T,
typename F>
2251struct flags_checker {
2253 using flags_t = f::to_fmt_t<F>;
2254 inline static constexpr unsigned Radix = R;
2257template<
typename T,
bool ArgW
idth>
2258concept good_int_flags =
2259 T::Radix > 1 && T::Radix <= 36
2262 && (T::flags_t::align == f::int_align::none || !T::flags_t::zero)
2265 && (std::is_signed_v<typename T::val_t> || T::flags_t::sign == f::int_plus_sign::none)
2268 && (T::flags_t::width == unsigned(-1)) == ArgWidth
2271 && (T::flags_t::prefix == f::int_prefix::none || T::Radix == 2 || T::Radix == 8 || T::Radix == 16);
2380template<
unsigned R, auto fp = f::df, FromIntNumber T>
requires good_int_flags<flags_checker<R, T,
decltype(fp)>,
false>
2382 using fmt_param = f::to_fmt_t<
decltype(fp)>;
2383 return expr_integer_src<T, R, fmt_param>{v};
2389template<
unsigned R, auto fp = f::df, FromIntNumber T>
requires good_int_flags<flags_checker<R, T,
decltype(fp)>,
true>
2391 using fmt_param = f::to_fmt_t<
decltype(fp)>;
2392 return expr_integer_src<T, R, fmt_param>{v, w};
2395template<
typename T,
unsigned R,
typename F>
requires good_int_flags<flags_checker<R, T, F>,
false>
2396auto operator / (T v,
const f::fmt_radix_info<R, F>&) {
2397 return expr_integer_src<T, R, f::to_fmt_t<F>>{v};
2402 using symb_type = K;
2403 mutable u8s buf[40];
2406 constexpr expr_real(
double d) : v(d) {}
2407 constexpr expr_real(
float d) : v(d) {}
2409 size_t length() const noexcept {
2410 auto [ptr, ec] = std::to_chars(buf, buf + std::size(buf), v);
2411 l = ec != std::errc{} ? 0 : ptr - buf;
2414 K* place(K* ptr)
const noexcept {
2415 if constexpr (
sizeof(K) ==
sizeof(buf[0])) {
2416 ch_traits<K>::copy(ptr, (K*)buf, l);
2418 for (
size_t i = 0; i < l; i++) {
2436template<
typename K, std::
floating_po
int T>
2437struct convert_to_strexpr<K, T> {
2438 using type = expr_real<K>;
2452template<
typename K>
requires is_one_of_char_v<K>
2453inline constexpr expr_real<K>
e_num(
double t) {
2457template<FromIntNumber Val,
bool All,
bool Ucase,
bool Ox>
2458struct expr_hex_src {
2459 explicit constexpr expr_hex_src(Val v) : v_(v){}
2463template<
typename K, FromIntNumber Val,
bool All,
bool Ucase,
bool Ox>
2465 using symb_type = K;
2466 mutable need_sign<K, std::is_signed_v<Val>, Val> v_;
2467 mutable K buf_[
sizeof(Val) * 2]{};
2469 explicit constexpr expr_hex(Val v) : v_(v){}
2470 constexpr expr_hex(
const expr_hex_src<Val, All, Ucase, Ox>& v) : v_(v.v_){}
2472 constexpr size_t length() const noexcept {
2473 K *ptr = buf_ + std::size(buf_);
2476 *--ptr = digits_symbols<K, Ucase>[v_.val & 0xF];
2480 *--ptr = digits_symbols<K, Ucase>[v_.val & 0xF];
2485 if constexpr (All) {
2486 if (
size_t need =
sizeof(Val) * 2 - l) {
2487 ch_traits<K>::assign(buf_, need, K(
'0'));
2489 l =
sizeof(Val) * 2;
2495 if constexpr (std::is_signed_v<Val>) {
2496 return l + (Ox ? 2 : 0) + (v_.negate ? 1 : 0);
2498 return l + (Ox ? 2 : 0);
2500 constexpr K* place(K* ptr)
const noexcept {
2501 if constexpr (std::is_signed_v<Val>) {
2510 if constexpr (All) {
2511 ch_traits<K>::copy(ptr, buf_,
sizeof(Val) * 2);
2512 return ptr +
sizeof(Val) * 2;
2514 ch_traits<K>::copy(ptr, buf_ + std::size(buf_) - v_.val, v_.val);
2515 return ptr + v_.val;
2581template<
unsigned Flags = 0, FromIntNumber T>
2583 return expr_hex_src<T, (Flags &
HexFlags::Short) == 0, (Flags & HexFlags::Lcase) == 0, (Flags & HexFlags::No0x) == 0>{v};
2586template<
char c = 0,
char...Chars>
2587constexpr unsigned parse_f16_flags() {
2588 if constexpr (c ==
'1') {
2590 }
else if constexpr (c ==
'2') {
2591 return HexFlags::Lcase | parse_f16_flags<Chars...>();
2592 }
else if constexpr (c ==
'3') {
2593 return HexFlags::No0x | parse_f16_flags<Chars...>();
2602template<FromIntNumber T,
unsigned Flags>
2603constexpr auto operator/(T v,
const f16flags<Flags>&) {
2604 return expr_hex_src<T, (Flags &
HexFlags::Short) == 0, (Flags & HexFlags::Lcase) == 0, (Flags & HexFlags::No0x) == 0>{v};
2607inline namespace literals {
2608template<
char...Chars>
2609constexpr auto operator""_f16() {
2610 return f16flags<parse_f16_flags<Chars...>()>{};
2622template<
typename K,
typename Val,
bool All,
bool Ucase,
bool Ox>
2623struct convert_to_strexpr<K, expr_hex_src<Val, All, Ucase, Ox>> {
2624 using type = expr_hex<K, Val, All, Ucase, Ox>;
2628struct expr_pointer : expr_hex<K, uintptr_t, true, true, true> {
2629 constexpr expr_pointer(
const void* ptr) : expr_hex<K, uintptr_t, true, true, true>((uintptr_t)ptr){}
2640template<
typename K,
typename T>
2641struct convert_to_strexpr<K, const T*> {
2642 using type = expr_pointer<K>;
2645template<
typename K, StrExprForType<K> A,
bool Left>
2647 using symb_type = K;
2651 mutable size_t alen_{};
2652 constexpr expr_fill(K symbol,
size_t width,
const A& a) : symbol_(symbol), width_(width), a_(a){}
2654 constexpr size_t length() const noexcept {
2655 alen_ = a_.length();
2656 return std::max(alen_, width_);
2658 constexpr K* place(K* ptr)
const noexcept {
2659 if (alen_ >= width_) {
2660 return (K*)a_.place((
typename A::symb_type*)ptr);
2662 size_t w = width_ - alen_;
2663 if constexpr (Left) {
2664 ch_traits<K>::assign(ptr, w, symbol_);
2666 return (K*)a_.place((
typename A::symb_type*)ptr);
2668 ptr = (K*)a_.place((
typename A::symb_type*)ptr);
2669 ch_traits<K>::assign(ptr, w, symbol_);
2696template<StrExpr A,
typename K =
typename A::symb_type>
2697expr_fill<K, A, true>
e_fill_left(
const A& a,
size_t width, K symbol = K(
' ')) {
2698 return {symbol, width, a};
2722template<StrExpr A,
typename K =
typename A::symb_type>
2723expr_fill<K, A, false>
e_fill_right(
const A& a,
size_t width, K symbol = K(
' ')) {
2724 return {symbol, width, a};
2743template<
typename K,
typename T,
size_t I,
bool tail,
bool skip_empty>
2744struct expr_join : expr_to_std_string<expr_join<K, T, I, tail, skip_empty>> {
2745 using symb_type = K;
2746 using my_type = expr_join<K, T, I, tail, skip_empty>;
2750 constexpr expr_join(
const T& _s,
const K* _delim) : s(_s), delim(_delim){}
2752 constexpr size_t length() const noexcept {
2754 for (
const auto& t: s) {
2755 size_t len = t.length();
2756 if (len > 0 || !skip_empty) {
2757 if (I > 0 && l > 0) {
2763 return l + (tail && I > 0 && (l > 0 || (!skip_empty && s.size() > 0))? I : 0);
2765 constexpr K* place(K* ptr)
const noexcept {
2770 for (
const auto& t: s) {
2771 size_t copyLen = t.length();
2772 if (I > 0 && write != ptr && (copyLen || !skip_empty)) {
2773 ch_traits<K>::copy(write, delim, I);
2776 ch_traits<K>::copy(write, t.data(), copyLen);
2779 if (I > 0 && tail && (write != ptr || (!skip_empty && s.size() > 0))) {
2780 ch_traits<K>::copy(write, delim, I);
2800template<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>
2801inline constexpr auto e_join(
const T& s, L&& d) {
2802 return expr_join<K, T, I - 1, tail, skip_empty>{s, d};
2806concept is_const_pattern = N > 1 && N <= 17;
2808template<
typename K,
size_t I>
2810 constexpr static const size_t value = size_t(K(~0x7F)) << ((I - 1) *
sizeof(K) * 8) | _ascii_mask<K, I - 1>::value;
2814struct _ascii_mask<K, 0> {
2815 constexpr static const size_t value = 0;
2820 using uns = std::make_unsigned_t<K>;
2821 constexpr static const size_t WIDTH =
sizeof(size_t) /
sizeof(uns);
2822 constexpr static const size_t VALUE = _ascii_mask<uns, WIDTH>::value;
2826constexpr inline bool isAsciiUpper(K k) {
2827 return k >=
'A' && k <=
'Z';
2831constexpr inline bool isAsciiLower(K k) {
2832 return k >=
'a' && k <=
'z';
2836constexpr inline K makeAsciiLower(K k) {
2837 return isAsciiUpper(k) ? k | 0x20 : k;
2841constexpr inline K makeAsciiUpper(K k) {
2842 return isAsciiLower(k) ? k & ~0x20 : k;
2845enum TrimSides { TrimLeft = 1, TrimRight = 2, TrimAll = 3 };
2846template<TrimS
ides S,
typename K,
size_t N,
bool withSpaces = false>
2847struct trim_operator;
2850struct digits_selector {
2851 using wider_type = uint16_t;
2855struct digits_selector<2> {
2856 using wider_type = uint32_t;
2860struct digits_selector<4> {
2861 using wider_type = uint64_t;
2875template<
bool CanNegate,
bool CheckOverflow,
typename T>
2876struct result_type_selector {
2881struct result_type_selector<true, false, T> {
2882 using type = std::make_unsigned_t<T>;
2885template<
unsigned Base>
2886constexpr unsigned digit_width() {
2905template<
typename T,
unsigned Base>
2906constexpr unsigned max_overflow_digits = (
sizeof(T) * CHAR_BIT) / digit_width<Base>();
2909struct convert_result {
2916 inline static constexpr uint8_t NUMBERS[] = {
2917 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,
2918 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,
2919 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,
2920 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,
2921 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,
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, 255, 255, 255, 255,
2925 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,
2926 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255};
2928 template<
typename K,
unsigned Base>
2929 static constexpr std::make_unsigned_t<K> toDigit(K s) {
2930 auto us =
static_cast<std::make_unsigned_t<K>
>(s);
2931 if constexpr (Base <= 10) {
2934 if constexpr (
sizeof(K) == 1) {
2937 return us < 256 ? NUMBERS[us] : us;
2942 template<
typename K, ToIntNumber T,
unsigned Base,
bool CheckOverflow>
2944 static constexpr convert_result<T> parse(
const K* start,
const K* current,
const K* end,
bool negate) {
2945 using u_type = std::make_unsigned_t<T>;
2946 #ifndef HAS_BUILTIN_OVERFLOW
2947 u_type maxMult = 0, maxAdd = 0;
2948 if constexpr (CheckOverflow) {
2949 maxMult = std::numeric_limits<u_type>::max() / Base;
2950 maxAdd = std::numeric_limits<u_type>::max() % Base;
2954 unsigned maxDigits = max_overflow_digits<u_type, Base>;
2956 const K* from = current;
2958 bool no_need_check_o_f = !CheckOverflow || end - current <= maxDigits;
2960 if (no_need_check_o_f) {
2962 const u_type digit = toDigit<K, Base>(*current);
2963 if (digit >= Base) {
2966 number = number * Base + digit;
2967 if (++current == end) {
2973 for (;maxDigits; maxDigits--) {
2974 const u_type digit = toDigit<K, Base>(*current);
2975 if (digit >= Base) {
2978 number = number * Base + digit;
2985 const u_type digit = toDigit<K, Base>(*current);
2986 if (digit >= Base) {
2989 #ifdef HAS_BUILTIN_OVERFLOW
2990 if (__builtin_mul_overflow(number, Base, &number) ||
2991 __builtin_add_overflow(number, digit, &number)) {
2993 if (number < maxMult || (number == maxMult && number < maxAdd)) {
2994 number = number * Base + digit;
2998 while(++current < end) {
2999 if (toDigit<K, Base>(*current) >= Base) {
3005 if (++current == end) {
3013 if constexpr (std::is_signed_v<T>) {
3014 result = negate ? 0 - number : number;
3015 if constexpr (CheckOverflow) {
3017 if (number > std::numeric_limits<T>::max() + (negate ? 1 : 0)) {
3028 return {result, error, size_t(current - start)};
3035 template<
typename K, ToIntNumber T,
unsigned Base = 0,
bool CheckOverflow = true,
bool SkipWs = true,
bool AllowSign = true>
3036 requires(Base == -1 || (Base < 37 && Base != 1))
3037 static constexpr convert_result<T> to_integer(
const K* start,
size_t len)
noexcept {
3038 const K *ptr = start, *end = ptr + len;
3039 bool negate =
false;
3040 if constexpr (SkipWs) {
3041 while (ptr < end && std::make_unsigned_t<K>(*ptr) <=
' ')
3045 if constexpr (std::is_signed_v<T>) {
3046 if constexpr (AllowSign) {
3051 }
else if (*ptr ==
'-') {
3063 }
else if constexpr (AllowSign) {
3072 if constexpr (Base == 0 || Base == -1) {
3076 if (*ptr ==
'x' || *ptr ==
'X') {
3077 return parse<K, T, 16, CheckOverflow>(start, ++ptr, end, negate);
3079 if constexpr (Base == -1) {
3080 if (*ptr ==
'b' || *ptr ==
'B') {
3081 return parse<K, T, 2, CheckOverflow>(start, ++ptr, end, negate);
3083 if (*ptr ==
'o' || *ptr ==
'O') {
3084 return parse<K, T, 8, CheckOverflow>(start, ++ptr, end, negate);
3087 return parse<K, T, 8, CheckOverflow>(start, --ptr, end, negate);
3091 return parse<K, T, 10, CheckOverflow>(start, ptr, end, negate);
3093 return parse<K, T, Base, CheckOverflow>(start, ptr, end, negate);
3099template<
typename K,
typename Impl>
3100class null_terminated {
3108 constexpr const K* c_str()
const {
return static_cast<const Impl*
>(
this)->symbols(); }
3111template<
typename K,
typename Impl,
bool Mutable>
class buffer_pointers;
3121template<
typename K,
typename Impl>
3122class buffer_pointers<K, Impl, false> {
3123 constexpr const Impl& d()
const {
return *
static_cast<const Impl*
>(
this); }
3131 constexpr const K* data()
const {
return d().symbols(); }
3138 constexpr const K* begin()
const {
return d().symbols(); }
3145 constexpr const K* end()
const {
return d().symbols() + d().length(); }
3152 constexpr const K* cbegin()
const {
return d().symbols(); }
3159 constexpr const K* cend()
const {
return d().symbols() + d().length(); }
3162template<
typename K,
typename Impl>
3163class buffer_pointers<K, Impl, true> :
public buffer_pointers<K, Impl, false> {
3164 constexpr Impl& d() {
return *
static_cast<Impl*
>(
this); }
3165 using base = buffer_pointers<K, Impl, false>;
3173 constexpr const K* data()
const {
return base::data(); }
3180 constexpr const K* begin()
const {
return base::begin(); }
3187 constexpr const K* end()
const {
return base::end(); }
3194 constexpr const K* cbegin()
const {
return base::cbegin(); }
3201 constexpr const K* cend()
const {
return base::cend(); }
3208 constexpr K* data() {
return d().str(); }
3215 constexpr K* begin() {
return d().str(); }
3222 constexpr K* end() {
return d().str() + d().length(); }
3231template<
typename K,
typename StrSrc>
3233 using str_t = StrSrc;
3238 constexpr SplitterBase(str_t text, str_t delim) : text_(text), delim_(delim) {}
3244 return text_.length() == str::npos;
3253 if (!text_.length()) {
3258 }
else if (text_.length() == str::npos) {
3259 return {
nullptr, 0};
3261 size_t pos = text_.find(delim_),
next = 0;
3262 if (pos == str::npos) {
3263 pos = text_.length();
3266 next = pos + delim_.length();
3268 str_t result{text_.str, pos};
3299template<
typename K,
typename StrRef,
typename Impl,
bool Mutable>
3300class str_src_algs :
public buffer_pointers<K, Impl, Mutable> {
3301 constexpr const Impl& d()
const noexcept {
3302 return *
static_cast<const Impl*
>(
this);
3304 constexpr size_t _len()
const noexcept {
3305 return d().length();
3307 constexpr const K* _str()
const noexcept {
3308 return d().symbols();
3310 constexpr bool _is_empty()
const noexcept {
3311 return d().is_empty();
3315 using symb_type = K;
3316 using str_piece = StrRef;
3317 using traits = ch_traits<K>;
3318 using uns_type = std::make_unsigned_t<K>;
3319 using my_type = Impl;
3320 using base = str_src_algs<K, StrRef, Impl, Mutable>;
3321 str_src_algs() =
default;
3335 constexpr K*
place(K* ptr)
const noexcept {
3336 size_t myLen = _len();
3337 traits::copy(ptr, _str(), myLen);
3351 size_t tlen = std::min(_len(), bufSize - 1);
3352 traits::copy(buffer, _str(), tlen);
3372 constexpr std::basic_string_view<D>
to_sv() const noexcept {
3373 return {(
const D*)_str(), _len()};
3382 constexpr operator std::basic_string_view<D, Traits>()
const {
3383 return {(
const D*)_str(), _len()};
3391 template<
typename D = K,
typename Traits = std::
char_traits<D>,
typename Allocator = std::allocator<D>>
requires is_equal_str_type_v<K, D>
3392 constexpr std::basic_string<D, Traits, Allocator>
to_string()
const {
3393 return {(
const D*)_str(), _len()};
3402 constexpr operator std::basic_string<D, Traits, Allocator>()
const {
3403 return {(
const D*)_str(), _len()};
3411 constexpr operator str_piece() const noexcept {
3412 return str_piece{_str(), _len()};
3420 constexpr str_piece
to_str() const noexcept {
3421 return {_str(), _len()};
3446 constexpr str_piece
operator()(ptrdiff_t from, ptrdiff_t len = 0) const noexcept {
3447 size_t myLen = _len(), idxStart = from >= 0 ? from : myLen > -from ? myLen + from : 0,
3448 idxEnd = len > 0 ? idxStart + len : myLen > -len ? myLen + len : 0;
3451 if (idxStart > idxEnd)
3453 return str_piece{_str() + idxStart, idxEnd - idxStart};
3465 constexpr str_piece
mid(
size_t from,
size_t len = -1) const noexcept {
3466 size_t myLen = _len(), idxStart = from, idxEnd = from > std::numeric_limits<size_t>::max() - len ? myLen : from + len;
3469 if (idxStart > idxEnd)
3471 return str_piece{_str() + idxStart, idxEnd - idxStart};
3487 constexpr str_piece
from_to(
size_t from,
size_t to)
const noexcept {
3488 return str_piece{_str() + from, to - from};
3500 constexpr str_piece
until(str_piece pattern,
size_t offset = 0) const noexcept {
3520 constexpr K
at(ptrdiff_t idx)
const {
3521 return _str()[idx >= 0 ? idx : _len() + idx];
3525 constexpr int compare(
const K* text,
size_t len)
const {
3526 size_t myLen = _len();
3527 int cmp = traits::compare(_str(), text, std::min(myLen, len));
3528 return cmp == 0 ? (myLen > len ? 1 : myLen == len ? 0 : -1) : cmp;
3539 return compare(o.symbols(), o.length());
3550 size_t myLen = _len(), idx = 0;
3551 const K* ptr = _str();
3552 for (; idx < myLen; idx++) {
3553 uns_type s1 = (uns_type)text[idx];
3557 uns_type s2 = (uns_type)ptr[idx];
3560 }
else if (s1 > s2) {
3564 return text[idx] == 0 ? 0 : -1;
3567 constexpr bool equal(
const K* text,
size_t len)
const noexcept {
3568 return len == _len() && traits::compare(_str(), text, len) == 0;
3578 constexpr bool equal(str_piece other)
const noexcept {
3579 return equal(other.symbols(), other.length());
3590 return equal(other._str(), other._len());
3599 return compare(other._str(), other._len()) <=> 0;
3607 template<typename T, size_t N = const_lit_for<K, T>::Count>
3609 return N - 1 == _len() && traits::compare(_str(), (
const K*)other, N - 1) == 0;
3617 template<typename T, size_t N = const_lit_for<K, T>::Count>
3619 size_t myLen = _len();
3620 int cmp = traits::compare(_str(), (
const K*)other, std::min(myLen, N - 1));
3621 int res = cmp == 0 ? (myLen > N - 1 ? 1 : myLen == N - 1 ? 0 : -1) : cmp;
3627 constexpr int compare_ia(
const K* text,
size_t len)
const noexcept {
3629 return _is_empty() ? 0 : 1;
3630 size_t myLen = _len(), checkLen = std::min(myLen, len);
3631 const uns_type *ptr1 =
reinterpret_cast<const uns_type*
>(_str()), *ptr2 =
reinterpret_cast<const uns_type*
>(text);
3632 while (checkLen--) {
3633 uns_type s1 = *ptr1++, s2 = *ptr2++;
3636 s1 = makeAsciiLower(s1);
3637 s2 = makeAsciiLower(s2);
3643 return myLen == len ? 0 : myLen > len ? 1 : -1;
3654 return compare_ia(text.symbols(), text.length());
3665 constexpr bool equal_ia(str_piece text)
const noexcept {
3666 return text.length() == _len() && compare_ia(text.symbols(), text.length()) == 0;
3676 constexpr bool less_ia(str_piece text)
const noexcept {
3677 return compare_ia(text.symbols(), text.length()) < 0;
3680 constexpr size_t find(
const K* pattern,
size_t lenPattern,
size_t offset)
const noexcept {
3681 size_t lenText = _len();
3684 if (!lenPattern || offset >= lenText || offset + lenPattern > lenText)
3687 const K *text = _str(), *last = text + lenText - lenPattern, first = pattern[0];
3689 for (
const K* fnd = text + offset;; ++fnd) {
3690 fnd = traits::find(fnd, last - fnd, first);
3693 if (traits::compare(fnd + 1, pattern, lenPattern) == 0)
3694 return static_cast<size_t>(fnd - text);
3707 constexpr size_t find(str_piece pattern,
size_t offset = 0) const noexcept {
3708 return find(pattern.symbols(), pattern.length(), offset);
3726 template<
typename Exc,
typename ... Args>
requires std::is_constructible_v<Exc, Args...>
3727 constexpr size_t find_or_throw(str_piece pattern,
size_t offset = 0, Args&& ... args)
const noexcept {
3728 if (
auto fnd = find(pattern.symbols(), pattern.length(), offset); fnd != str::npos) {
3731 throw Exc(std::forward<Args>(args)...);
3743 constexpr size_t find_end(str_piece pattern,
size_t offset = 0) const noexcept {
3744 size_t fnd = find(pattern.symbols(), pattern.length(), offset);
3745 return fnd == str::npos ? fnd : fnd + pattern.length();
3757 constexpr size_t find_or_all(str_piece pattern,
size_t offset = 0) const noexcept {
3758 auto fnd = find(pattern.symbols(), pattern.length(), offset);
3759 return fnd == str::npos ? _len() : fnd;
3772 auto fnd = find(pattern.symbols(), pattern.length(), offset);
3773 return fnd == str::npos ? _len() : fnd + pattern.length();
3776 constexpr size_t find_last(
const K* pattern,
size_t lenPattern,
size_t offset)
const noexcept {
3777 if (lenPattern == 1)
3778 return find_last(pattern[0], offset);
3779 size_t lenText = std::min(_len(), offset);
3782 if (!lenPattern || lenPattern > lenText)
3786 const K *text = _str() + lenPattern, last = pattern[lenPattern];
3787 lenText -= lenPattern;
3789 if (text[--lenText] == last) {
3790 if (traits::compare(text + lenText - lenPattern, pattern, lenPattern) == 0) {
3807 constexpr size_t find_last(str_piece pattern,
size_t offset = -1) const noexcept {
3808 return find_last(pattern.symbols(), pattern.length(), offset);
3821 size_t fnd = find_last(pattern.symbols(), pattern.length(), offset);
3822 return fnd == str::npos ? fnd : fnd + pattern.length();
3835 auto fnd = find_last(pattern.symbols(), pattern.length(), offset);
3836 return fnd == str::npos ? _len() : fnd;
3849 size_t fnd = find_last(pattern.symbols(), pattern.length(), offset);
3850 return fnd == str::npos ? _len() : fnd + pattern.length();
3862 constexpr bool contains(str_piece pattern,
size_t offset = 0) const noexcept {
3863 return find(pattern, offset) != str::npos;
3875 constexpr size_t find(K s,
size_t offset = 0) const noexcept {
3876 size_t len = _len();
3878 const K *
str = _str(), *fnd = traits::find(
str + offset, len - offset, s);
3880 return static_cast<size_t>(fnd -
str);
3895 size_t len = _len();
3897 const K *
str = _str(), *fnd = traits::find(
str + offset, len - offset, s);
3899 return static_cast<size_t>(fnd -
str);
3904 template<
typename Op>
3905 constexpr void for_all_finded(
const Op& op,
const K* pattern,
size_t patternLen,
size_t offset,
size_t maxCount)
const {
3908 while (maxCount-- > 0) {
3909 size_t fnd = find(pattern, patternLen, offset);
3910 if (fnd == str::npos)
3913 offset = fnd + patternLen;
3928 template<
typename Op>
3929 constexpr void for_all_finded(
const Op& op, str_piece pattern,
size_t offset = 0,
size_t maxCount = 0)
const {
3930 for_all_finded(op, pattern.symbols(), pattern.length(), offset, maxCount);
3933 template<
typename To = std::vector<
size_t>>
3934 constexpr To find_all(
const K* pattern,
size_t patternLen,
size_t offset,
size_t maxCount)
const {
3936 for_all_finded([&](
auto f) { result.emplace_back(f); }, pattern, patternLen, offset, maxCount);
3951 template<
typename To = std::vector<
size_t>>
3952 constexpr To
find_all(str_piece pattern,
size_t offset = 0,
size_t maxCount = 0)
const {
3953 return find_all(pattern.symbols(), pattern.length(), offset, maxCount);
3955 template<
typename To = std::vector<
size_t>>
3956 constexpr void find_all_to(To& to,
const K* pattern,
size_t len,
size_t offset = 0,
size_t maxCount = 0)
const {
3957 return for_all_finded([&](
size_t pos) {
3958 to.emplace_back(pos);
3959 }, pattern, len, offset, maxCount);
3971 constexpr size_t find_last(K s,
size_t offset = -1) const noexcept {
3972 size_t len = std::min(_len(), offset);
3973 const K *text = _str();
3975 if (text[--len] == s)
3990 constexpr size_t find_first_of(str_piece pattern,
size_t offset = 0) const noexcept {
3991 return std::basic_string_view<K>{_str(), _len()}.find_first_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4003 constexpr std::pair<size_t, size_t>
find_first_of_idx(str_piece pattern,
size_t offset = 0) const noexcept {
4004 const K* text = _str();
4005 size_t fnd = std::basic_string_view<K>{text, _len()}.find_first_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4006 return {fnd, fnd == std::basic_string<K>::npos ? fnd : pattern.find(text[fnd]) };
4019 return std::basic_string_view<K>{_str(), _len()}.find_first_not_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4031 constexpr size_t find_last_of(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4032 return std::basic_string_view<K>{_str(), _len()}.find_last_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4044 constexpr std::pair<size_t, size_t>
find_last_of_idx(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4045 const K* text = _str();
4046 size_t fnd = std::basic_string_view<K>{text, _len()}.find_last_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4047 return {fnd, fnd == std::basic_string<K>::npos ? fnd : pattern.find(text[fnd]) };
4059 constexpr size_t find_last_not_of(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4060 return std::basic_string_view<K>{_str(), _len()}.find_last_not_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4072 constexpr my_type
substr(ptrdiff_t from, ptrdiff_t len = 0)
const {
4073 return my_type{d()(from, len)};
4085 constexpr my_type
str_mid(
size_t from,
size_t len = -1)
const {
4086 return my_type{d().mid(from, len)};
4116 template<ToIntNumber T,
bool CheckOverflow = true,
unsigned Base = 0,
bool SkipWs = true,
bool AllowSign = true>
4118 auto [res, err, _] = int_convert::to_integer<K, T, Base, CheckOverflow, SkipWs, AllowSign>(_str(), _len());
4149 template<ToIntNumber T,
bool CheckOverflow = true,
unsigned Base = 0,
bool SkipWs = true,
bool AllowSign = true>
4150 constexpr convert_result<T>
to_int() const noexcept {
4151 return int_convert::to_integer<K, T, Base, CheckOverflow, SkipWs, AllowSign>(_str(), _len());
4159 template<
bool SkipWS = true,
bool AllowPlus = true>
requires (
sizeof(K) == 1)
4161 size_t len = _len();
4162 const K* ptr = _str();
4163 if constexpr (SkipWS) {
4164 while (len && uns_type(*ptr) <=
' ') {
4169 if constexpr (AllowPlus) {
4170 if (len && *ptr == K(
'+')) {
4179 if (std::from_chars((
const u8s*)ptr, (
const u8s*)ptr + len, d).ec == std::errc{}) {
4190 template<
bool SkipWS = true>
requires (
sizeof(K) == 1)
4192 size_t len = _len();
4193 const K* ptr = _str();
4194 if constexpr (SkipWS) {
4195 while (len && uns_type(*ptr) <=
' ') {
4202 if (std::from_chars(ptr, ptr + len, d, std::chars_format::hex).ec == std::errc{}) {
4216 template<ToIntNumber T>
4221 template<
typename T,
typename Op>
4222 constexpr T splitf(
const K* delimiter,
size_t lendelimiter,
const Op& beforeFunc,
size_t offset)
const {
4223 size_t mylen = _len();
4224 std::conditional_t<std::is_same_v<T, void>, char, T> results;
4225 str_piece me{_str(), mylen};
4226 for (
int i = 0;; i++) {
4227 size_t beginOfDelim = find(delimiter, lendelimiter, offset);
4228 if (beginOfDelim == str::npos) {
4229 str_piece last{me.symbols() + offset, me.length() - offset};
4230 if constexpr (std::is_invocable_v<Op, str_piece&>) {
4233 if constexpr (
requires { results.emplace_back(last); }) {
4234 if (last.is_same(me)) {
4237 results.emplace_back(d());
4239 results.emplace_back(last);
4241 }
else if constexpr (
requires { results.push_back(last); }) {
4242 if (last.is_same(me)) {
4245 results.push_back(d());
4247 results.push_back(last);
4249 }
else if constexpr (
requires {results[i] = last;} &&
requires{std::size(results);}) {
4250 if (i < std::size(results)) {
4251 if (last.is_same(me)) {
4261 str_piece piece{me.symbols() + offset, beginOfDelim - offset};
4262 if constexpr (std::is_invocable_v<Op, str_piece&>) {
4265 if constexpr (
requires { results.emplace_back(piece); }) {
4266 results.emplace_back(piece);
4267 }
else if constexpr (
requires { results.push_back(piece); }) {
4268 results.push_back(piece);
4269 }
else if constexpr (
requires { results[i] = piece; } &&
requires{std::size(results);}) {
4270 if (i < std::size(results)) {
4272 if (i == results.size() - 1) {
4277 offset = beginOfDelim + lendelimiter;
4279 if constexpr (!std::is_same_v<T, void>) {
4313 template<
typename T,
typename Op>
4314 constexpr T
splitf(str_piece delimiter,
const Op& beforeFunc,
size_t offset = 0)
const {
4315 return splitf<T>(delimiter.symbols(), delimiter.length(), beforeFunc, offset);
4329 template<
typename T>
4330 constexpr T
split(str_piece delimiter,
size_t offset = 0)
const {
4331 return splitf<T>(delimiter.symbols(), delimiter.length(), 0, offset);
4336 constexpr bool starts_with(
const K* prefix,
size_t l)
const noexcept {
4337 return _len() >= l && 0 == traits::compare(_str(), prefix, l);
4346 return starts_with(prefix.symbols(), prefix.length());
4349 constexpr bool starts_with_ia(
const K* prefix,
size_t len)
const noexcept {
4350 size_t myLen = _len();
4354 const K* ptr1 = _str();
4356 K s1 = *ptr1++, s2 = *prefix++;
4359 if (makeAsciiLower(s1) != makeAsciiLower(s2))
4371 return starts_with_ia(prefix.symbols(), prefix.length());
4376 constexpr bool prefix_in(
const K* text,
size_t len)
const noexcept {
4377 size_t myLen = _len();
4380 return !myLen || 0 == traits::compare(text, _str(), myLen);
4389 return prefix_in(text.symbols(), text.length());
4393 constexpr bool ends_with(
const K* suffix,
size_t len)
const noexcept {
4394 size_t myLen = _len();
4395 return len <= myLen && traits::compare(_str() + myLen - len, suffix, len) == 0;
4404 return ends_with(suffix.symbols(), suffix.length());
4408 constexpr bool ends_with_ia(
const K* suffix,
size_t len)
const noexcept {
4409 size_t myLen = _len();
4413 const K* ptr1 = _str() + myLen - len;
4415 K s1 = *ptr1++, s2 = *suffix++;
4418 if (makeAsciiLower(s1) != makeAsciiLower(s2))
4430 return ends_with_ia(suffix.symbols(), suffix.length());
4439 if (std::is_constant_evaluated()) {
4440 for (
size_t idx = 0; idx < _len(); idx++) {
4441 if (uns_type(_str()[idx]) > 127) {
4447 const int sl = ascii_mask<K>::WIDTH;
4448 const size_t mask = ascii_mask<K>::VALUE;
4449 size_t len = _len();
4450 const uns_type* ptr =
reinterpret_cast<const uns_type*
>(_str());
4451 if constexpr (sl > 1) {
4452 const size_t roundMask =
sizeof(size_t) - 1;
4453 while (len >= sl && (
reinterpret_cast<size_t>(ptr) & roundMask) != 0) {
4459 if (*
reinterpret_cast<const size_t*
>(ptr) & mask)
4479 template<
typename R = my_type>
4481 return R::upperred_only_ascii_from(d());
4491 template<
typename R = my_type>
4493 return R::lowered_only_ascii_from(d());
4511 template<
typename R = my_type>
4512 R
replaced(str_piece pattern, str_piece repl,
size_t offset = 0,
size_t maxCount = 0)
const {
4513 return R::replaced_from(d(), pattern, repl, offset, maxCount);
4516 template<StrType<K> From>
4517 constexpr static my_type make_trim_op(
const From& from,
const auto& opTrim) {
4518 str_piece sfrom = from, newPos = opTrim(sfrom);
4519 if (newPos.is_same(sfrom)) {
4523 return my_type{newPos};
4525 template<TrimS
ides S, StrType<K> From>
4526 constexpr static my_type trim_static(
const From& from) {
4527 return make_trim_op(from, trim_operator<S, K,
static_cast<size_t>(-1),
true>{});
4530 template<TrimSides S, bool withSpaces, typename T, size_t N = const_lit_for<K, T>::Count, StrType<K> From>
4531 requires is_const_pattern<N>
4532 constexpr static my_type trim_static(
const From& from, T&& pattern) {
4533 return make_trim_op(from, trim_operator<S, K, N - 1, withSpaces>{pattern});
4536 template<TrimS
ides S,
bool withSpaces, StrType<K> From>
4537 constexpr static my_type trim_static(
const From& from, str_piece pattern) {
4538 return make_trim_op(from, trim_operator<S, K, 0, withSpaces>{{pattern}});
4548 template<
typename R = str_piece>
4550 return R::template trim_static<TrimSides::TrimAll>(d());
4560 template<
typename R = str_piece>
4562 return R::template trim_static<TrimSides::TrimLeft>(d());
4572 template<
typename R = str_piece>
4574 return R::template trim_static<TrimSides::TrimRight>(d());
4586 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4587 requires is_const_pattern<N>
4589 return R::template trim_static<TrimSides::TrimAll, false>(d(), pattern);
4601 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4602 requires is_const_pattern<N>
4604 return R::template trim_static<TrimSides::TrimLeft, false>(d(), pattern);
4616 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4617 requires is_const_pattern<N>
4619 return R::template trim_static<TrimSides::TrimRight, false>(d(), pattern);
4638 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4639 requires is_const_pattern<N>
4641 return R::template trim_static<TrimSides::TrimAll, true>(d(), pattern);
4657 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4658 requires is_const_pattern<N>
4660 return R::template trim_static<TrimSides::TrimLeft, true>(d(), pattern);
4676 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4677 requires is_const_pattern<N>
4679 return R::template trim_static<TrimSides::TrimRight, true>(d(), pattern);
4694 template<
typename R = str_piece>
4696 return R::template trim_static<TrimSides::TrimAll, false>(d(), pattern);
4708 template<
typename R = str_piece>
4710 return R::template trim_static<TrimSides::TrimLeft, false>(d(), pattern);
4722 template<
typename R = str_piece>
4724 return R::template trim_static<TrimSides::TrimRight, false>(d(), pattern);
4740 template<
typename R = str_piece>
4742 return R::template trim_static<TrimSides::TrimAll, true>(d(), pattern);
4758 template<
typename R = str_piece>
4760 return R::template trim_static<TrimSides::TrimLeft, true>(d(), pattern);
4776 template<
typename R = str_piece>
4778 return R::template trim_static<TrimSides::TrimRight, true>(d(), pattern);
4796template<
size_t N>
requires (N > 1)
4797struct find_all_container {
4798 static constexpr size_t max_capacity = N;
4799 size_t positions_[N];
4802 constexpr void emplace_back(
size_t pos) {
4803 positions_[added_++] = pos;
4826struct str_src : str_src_algs<K, str_src<K>, str_src<K>, false> {
4827 using symb_type = K;
4828 using my_type = str_src<K>;
4830 const symb_type* str;
4833 str_src() =
default;
4838 template<typename T, size_t N = const_lit_for<K, T>::Count>
4839 constexpr str_src(T&& v) noexcept : str((
const K*)v), len(N - 1) {}
4845 constexpr str_src(
const K* p,
size_t l) noexcept : str(p), len(l) {}
4847 template<StrType<K> T>
4848 constexpr str_src(T&& t) :
str(t.symbols()), len(t.length()){}
4854 template<
typename A>
4855 constexpr str_src(
const std::basic_string<K, std::char_traits<K>, A>& s) noexcept : str(s.data()), len(s.length()) {}
4860 constexpr str_src(
const std::basic_string_view<K, std::char_traits<K>>& s) noexcept : str(s.data()), len(s.length()) {}
4873 constexpr const symb_type*
symbols() const noexcept {
4889 constexpr bool is_same(str_src<K> other)
const noexcept {
4890 return str == other.str && len == other.len;
4899 return str >= other.str && str + len <= other.str + other.len;
4962struct str_src_nt : str_src<K>, null_terminated<K, str_src_nt<K>> {
4963 using symb_type = K;
4964 using my_type = str_src_nt<K>;
4965 using base = str_src<K>;
4967 constexpr static const K empty_string[1] = {0};
4969 str_src_nt() =
default;
4986 template<
typename T>
requires std::is_same_v<std::remove_const_t<std::remove_pointer_t<std::remove_cvref_t<T>>>, K>
4989 base::str = base::len ? p : empty_string;
4995 template<typename T, size_t N = const_lit_for<K, T>::Count>
4996 constexpr str_src_nt(T&& v) noexcept : base(std::forward<T>(v)) {}
5002 constexpr str_src_nt(
const K* p,
size_t l) noexcept : base(p, l) {}
5004 template<StrType<K> T>
5007 base::len = t.length();
5013 template<
typename A>
5014 constexpr str_src_nt(
const std::basic_string<K, std::char_traits<K>, A>& s) noexcept : base(s) {}
5016 static const my_type empty_str;
5026 if (from > base::len) {
5029 return {base::str + from, base::len - from};
5034inline const str_src_nt<K> str_src_nt<K>::empty_str{str_src_nt<K>::empty_string, 0};
5035template<
typename K>
struct simple_str_selector;
5037inline namespace literals {
5097template<
char...Chars>
5098SS_CONSTEVAL
auto operator""_fmt() {
5099 return f::skip_0x<Chars...>();
5104#ifndef IN_FULL_SIMSTR
5107using simple_str = str_src<K>;
5110struct simple_str_selector {
5111 using type = simple_str<K>;
5115using simple_str_nt = str_src_nt<K>;
5118using Splitter = SplitterBase<K, str_src<K>>;
5120using ssa = str_src<u8s>;
5121using ssb = str_src<ubs>;
5122using ssw = str_src<wchar_t>;
5123using ssu = str_src<u16s>;
5124using ssuu = str_src<u32s>;
5125using stra = str_src_nt<u8s>;
5126using strb = str_src_nt<ubs>;
5127using strw = str_src_nt<wchar_t>;
5128using stru = str_src_nt<u16s>;
5129using struu = str_src_nt<u32s>;
5132consteval 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) {
5133 if constexpr (std::is_same_v<K, u8s>)
5135 if constexpr (std::is_same_v<K, ubs>)
5137 if constexpr (std::is_same_v<K, uws>)
5139 if constexpr (std::is_same_v<K, u16s>)
5141 if constexpr (std::is_same_v<K, u32s>)
5145#define uni_string(K, p) select_str<K>(p, u8##p, L##p, u##p, U##p)
5147inline namespace literals {
5220template<
typename K,
bool withSpaces>
5221struct CheckSpaceTrim {
5222 constexpr bool is_trim_spaces(K s)
const {
5223 return s ==
' ' || (s >= 9 && s <= 13);
5227struct CheckSpaceTrim<K, false> {
5228 constexpr bool is_trim_spaces(K)
const {
5234struct CheckSymbolsTrim {
5236 constexpr bool is_trim_symbols(K s)
const {
5237 return symbols.len != 0 && str_src<K>::traits::find(symbols.str, symbols.len, s) !=
nullptr;
5241template<
typename K,
size_t N>
5242struct CheckConstSymbolsTrim {
5243 const const_lit_to_array<K, N> symbols;
5245 template<typename T, size_t M = const_lit_for<K, T>::Count>
requires (M == N + 1)
5246 constexpr CheckConstSymbolsTrim(T&& s) : symbols(std::forward<T>(s)) {}
5248 constexpr bool is_trim_symbols(K s)
const noexcept {
5249 return symbols.contain(s);
5254struct CheckConstSymbolsTrim<K, 0> {
5255 constexpr bool is_trim_symbols(K)
const {
5260template<
typename K,
size_t N>
5261struct SymbSelector {
5262 using type = CheckConstSymbolsTrim<K, N>;
5266struct SymbSelector<K, 0> {
5267 using type = CheckSymbolsTrim<K>;
5271struct SymbSelector<K, static_cast<size_t>(-1)> {
5272 using type = CheckConstSymbolsTrim<K, 0>;
5275template<TrimS
ides S,
typename K,
size_t N,
bool withSpaces>
5276struct trim_operator : SymbSelector<K, N>::type, CheckSpaceTrim<K, withSpaces> {
5277 constexpr bool isTrim(K s)
const {
5278 return CheckSpaceTrim<K, withSpaces>::is_trim_spaces(s) || SymbSelector<K, N>::type::is_trim_symbols(s);
5280 constexpr str_src<K> operator()(str_src<K> from)
const {
5281 if constexpr ((S & TrimSides::TrimLeft) != 0) {
5283 if (isTrim(*from.str)) {
5290 if constexpr ((S & TrimSides::TrimRight) != 0) {
5291 const K* back = from.str + from.len - 1;
5293 if (isTrim(*back)) {
5304template<TrimS
ides S,
typename K>
5305using SimpleTrim = trim_operator<S, K, size_t(-1),
true>;
5307template<TrimSides S = TrimSides::TrimAll, bool withSpaces = false, typename K, typename T, size_t N = const_lit_for<K, T>::Count>
5308 requires is_const_pattern<N>
5309constexpr inline auto trimOp(T&& pattern) {
5310 return trim_operator<S, K, N - 1, withSpaces>{pattern};
5313template<TrimS
ides S = TrimS
ides::TrimAll,
bool withSpaces = false,
typename K>
5314constexpr inline auto trimOp(str_src<K> pattern) {
5315 return trim_operator<S, K, 0, withSpaces>{pattern};
5318static constexpr size_t FIND_CACHE_SIZE = 16;
5320template<
typename K,
size_t N,
size_t L>
5321struct expr_replaces : expr_to_std_string<expr_replaces<K, N, L>> {
5322 using symb_type = K;
5323 using my_type = expr_replaces<K, N, L>;
5325 const K(&pattern)[N + 1];
5326 const K(&repl)[L + 1];
5327 mutable find_all_container<FIND_CACHE_SIZE> matches_;
5328 mutable size_t last_;
5330 constexpr expr_replaces(str_src<K> w,
const K(&p)[N + 1],
const K(&r)[L + 1]) : what(w), pattern(p), repl(r) {}
5332 constexpr size_t length()
const {
5333 size_t l = what.length();
5334 if constexpr (N == L) {
5337 what.find_all_to(matches_, pattern, N, 0, FIND_CACHE_SIZE);
5338 if (matches_.added_) {
5339 last_ = matches_.positions_[matches_.added_ - 1] + N;
5340 l += int(L - N) * matches_.added_;
5342 if (matches_.added_ == FIND_CACHE_SIZE) {
5344 size_t next = what.find(pattern, N, last_);
5345 if (next == str::npos) {
5354 matches_.added_ = -1;
5358 constexpr K* place(K* ptr)
const noexcept {
5359 if constexpr (N == L) {
5360 const K* from = what.symbols();
5361 for (
size_t start = 0; start < what.length();) {
5362 size_t next = what.find(pattern, N, start);
5363 if (next == str::npos) {
5364 next = what.length();
5366 size_t delta = next - start;
5367 ch_traits<K>::copy(ptr, from + start, delta);
5369 ch_traits<K>::copy(ptr, repl, L);
5375 if (matches_.added_ == 0) {
5376 return what.place(ptr);
5377 }
else if (matches_.added_ == -1) {
5381 const K* from = what.symbols();
5382 for (
size_t start = 0, offset = matches_.positions_[0], idx = 1; ;) {
5383 ch_traits<K>::copy(ptr, from + start, offset - start);
5384 ptr += offset - start;
5385 ch_traits<K>::copy(ptr, repl, L);
5388 if (start >= last_) {
5389 size_t tail = what.length() - last_;
5390 ch_traits<K>::copy(ptr, from + last_, tail);
5394 offset = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern, N, start);
5414template<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>
5417 return expr_replaces<K, N - 1, L - 1>{std::forward<A>(w), p, r};
5429 using symb_type = K;
5434 mutable find_all_container<FIND_CACHE_SIZE> matches_;
5435 mutable size_t last_;
5448 constexpr size_t length()
const {
5450 if (!plen || plen == rlen) {
5453 what.find_all_to(matches_, pattern.
symbols(), plen, 0, FIND_CACHE_SIZE);
5454 if (matches_.added_) {
5455 last_ = matches_.positions_[matches_.added_ - 1] + plen;
5456 l += int(rlen - plen) * matches_.added_;
5458 if (matches_.added_ == FIND_CACHE_SIZE) {
5460 size_t next = what.find(pattern.
symbols(), plen, last_);
5461 if (next == str::npos) {
5464 last_ = next + plen;
5470 matches_.added_ = -1;
5474 constexpr K* place(K* ptr)
const noexcept {
5477 const K* from = what.
symbols();
5478 for (
size_t start = 0; start < what.
length();) {
5479 size_t next = what.find(pattern, start);
5480 if (next == str::npos) {
5483 size_t delta = next - start;
5484 ch_traits<K>::copy(ptr, from + start, delta);
5486 ch_traits<K>::copy(ptr, repl.
symbols(), rlen);
5488 start = next + plen;
5492 if (matches_.added_ == 0) {
5493 return what.
place(ptr);
5494 }
else if (matches_.added_ == -1) {
5498 const K* from = what.
symbols();
5499 for (
size_t start = 0, offset = matches_.positions_[0], idx = 1; ;) {
5500 ch_traits<K>::copy(ptr, from + start, offset - start);
5501 ptr += offset - start;
5502 ch_traits<K>::copy(ptr, repl.
symbols(), rlen);
5504 start = offset + plen;
5505 if (start >= last_) {
5506 size_t tail = what.
length() - start;
5507 ch_traits<K>::copy(ptr, from + start, tail);
5511 offset = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern.
symbols(), plen, start);
5533template<
typename K, StrExprForType<K> E>
5535 using symb_type = K;
5539 mutable size_t replLen;
5540 mutable find_all_container<FIND_CACHE_SIZE> matches_;
5541 mutable size_t last_;
5555 constexpr size_t length()
const {
5560 matches_.positions_[0] = what.find(pattern);
5561 if (matches_.positions_[0] == -1) {
5565 matches_.added_ = 1;
5567 replLen = expr.length();
5568 if (replLen == plen) {
5572 what.find_all_to(matches_, pattern.
symbols(), plen, matches_.positions_[0] + plen, FIND_CACHE_SIZE - 1);
5574 last_ = matches_.positions_[matches_.added_ - 1] + plen;
5575 l += int(replLen - plen) * matches_.added_;
5577 if (matches_.added_ == FIND_CACHE_SIZE) {
5579 size_t next = what.find(pattern.
symbols(), plen, last_);
5580 if (next == str::npos) {
5583 last_ = next + plen;
5584 l += replLen - plen;
5588 matches_.added_ = -1;
5592 constexpr K* place(K* ptr)
const noexcept {
5593 if (matches_.added_ == 0) {
5595 return what.
place(ptr);
5596 }
else if (matches_.added_ == -1) {
5600 size_t plen = pattern.
length();
5601 const K* from = what.
symbols();
5602 ch_traits<K>::copy(ptr, from, matches_.positions_[0]);
5603 ptr += matches_.positions_[0];
5604 const K* repl = ptr;
5605 expr.
place((
typename E::symb_type*)ptr);
5607 size_t start = matches_.positions_[0] + plen;
5609 if (plen == replLen) {
5611 size_t next = what.find(pattern, start);
5612 if (next == str::npos) {
5615 size_t delta = next - start;
5616 ch_traits<K>::copy(ptr, from + start, delta);
5618 ch_traits<K>::copy(ptr, repl, replLen);
5620 start = next + plen;
5623 for (
size_t idx = 1;;) {
5624 if (start >= last_) {
5627 size_t next = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern, start);
5628 size_t delta = next - start;
5629 ch_traits<K>::copy(ptr, from + start, delta);
5631 ch_traits<K>::copy(ptr, repl, replLen);
5633 start = next + plen;
5636 size_t tail = what.
length() - start;
5637 ch_traits<K>::copy(ptr, from + start, tail);
5655template<StrSource A,
typename K = symb_type_from_src_t<A>,
typename T,
typename X>
5656 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>))
5676template<StrSource A,
typename K = symb_type_from_src_t<A>,
typename T, StrExprForType<K> E>
5677 requires std::is_constructible_v<str_src<K>, T>
5678constexpr auto e_repl(A&& w, T&& p,
const E& expr) {
5683template<
bool UseVectorForReplace>
5684struct replace_search_result_store {
5686 std::pair<size_t, size_t> replaces_[16];
5690struct replace_search_result_store<true> : std::vector<std::pair<size_t, size_t>> {};
5694template<
typename K,
size_t N,
bool UseVectorForReplace>
5695struct expr_replace_const_symbols : expr_to_std_string<expr_replace_const_symbols<K, N, UseVectorForReplace>> {
5696 using symb_type = K;
5697 inline static const int BIT_SEARCH_TRESHHOLD = 4;
5698 const K pattern_[N];
5699 const str_src<K> source_;
5700 const str_src<K> replaces_[N];
5702 mutable replace_search_result_store<UseVectorForReplace> search_results_;
5704 [[_no_unique_address]]
5705 uu8s bit_mask_[N >= BIT_SEARCH_TRESHHOLD ? (
sizeof(K) == 1 ? 32 : 64) : 0]{};
5707 template<
typename ... Repl>
requires (
sizeof...(Repl) == N * 2)
5708 constexpr expr_replace_const_symbols(str_src<K> source, Repl&& ... repl) : expr_replace_const_symbols(0, source, std::forward<Repl>(repl)...) {}
5710 size_t length()
const {
5711 size_t l = source_.length();
5712 auto [fnd, num] = find_first_of(source_.str, source_.len);
5713 if (fnd == str::npos) {
5716 l += replaces_[num].len - 1;
5717 if constexpr (UseVectorForReplace) {
5718 search_results_.reserve((l >> 4) + 8);
5719 search_results_.emplace_back(fnd, num);
5720 for (
size_t start = fnd + 1;;) {
5721 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
5722 if (fnd == str::npos) {
5725 search_results_.emplace_back(fnd, idx);
5727 l += replaces_[idx].len - 1;
5730 const size_t max_store = std::size(search_results_.replaces_);
5731 search_results_.replaces_[0] = {fnd, num};
5732 search_results_.count_++;
5733 for (
size_t start = fnd + 1;;) {
5734 auto [found, idx] = find_first_of(source_.str, source_.len, start);
5735 if (found == str::npos) {
5738 if (search_results_.count_ < max_store) {
5739 search_results_.replaces_[search_results_.count_] = {found, idx};
5741 l += replaces_[idx].len - 1;
5742 search_results_.count_++;
5748 K* place(K* ptr)
const noexcept {
5750 const K* text = source_.str;
5751 if constexpr (UseVectorForReplace) {
5752 for (
const auto& [pos, num] : search_results_) {
5753 size_t delta = pos - start;
5754 ch_traits<K>::copy(ptr, text + start, delta);
5756 ptr = replaces_[num].place(ptr);
5760 const size_t max_store = std::size(search_results_.replaces_);
5761 size_t founded = search_results_.count_;
5762 for (
size_t idx = 0, stop = std::min(founded, max_store); idx < stop; idx++) {
5763 const auto [pos, num] = search_results_.replaces_[idx];
5764 size_t delta = pos - start;
5765 ch_traits<K>::copy(ptr, text + start, delta);
5767 ptr = replaces_[num].place(ptr);
5770 if (founded > max_store) {
5771 founded -= max_store;
5773 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
5774 size_t delta = fnd - start;
5775 ch_traits<K>::copy(ptr, text + start, delta);
5777 ptr = replaces_[idx].place(ptr);
5782 size_t tail = source_.len - start;
5783 ch_traits<K>::copy(ptr, text + start, tail);
5788 template<
typename ... Repl>
5789 constexpr expr_replace_const_symbols(
int, str_src<K> source, K s, str_src<K> r, Repl&&... repl) :
5790 expr_replace_const_symbols(0, source, std::forward<Repl>(repl)..., std::make_pair(s, r)){}
5792 template<
typename ... Repl>
requires (
sizeof...(Repl) == N)
5793 constexpr expr_replace_const_symbols(
int, str_src<K> source, Repl&&... repl) :
5794 source_(source), pattern_ {repl.first...}, replaces_{repl.second...}
5796 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
5797 for (
size_t idx = 0; idx < N; idx++) {
5798 uu8s s =
static_cast<uu8s
>(pattern_[idx]);
5799 if constexpr (
sizeof(K) == 1) {
5800 bit_mask_[s >> 3] |= 1 << (s & 7);
5802 if (std::make_unsigned_t<const K>(pattern_[idx]) > 255) {
5803 bit_mask_[32 + (s >> 3)] |= 1 << (s & 7);
5805 bit_mask_[s >> 3] |= 1 << (s & 7);
5812 template<
size_t Idx>
5813 size_t index_of(K s)
const {
5814 if constexpr (Idx < N) {
5815 return pattern_[Idx] == s ? Idx : index_of<Idx + 1>(s);
5819 bool is_in_mask(uu8s s)
const {
5820 return (bit_mask_[s >> 3] & (1 <<(s & 7))) != 0;
5822 bool is_in_mask2(uu8s s)
const {
5823 return (bit_mask_[32 + (s >> 3)] & (1 <<(s & 7))) != 0;
5825 bool is_in_pattern(K s,
size_t& idx)
const {
5826 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
5827 if constexpr (
sizeof(K) == 1) {
5828 if (is_in_mask(s)) {
5829 idx = index_of<0>(s);
5833 if (std::make_unsigned_t<const K>(s) > 255) {
5834 if (is_in_mask2(s)) {
5835 return (idx = index_of<0>(s)) != -1;
5838 if (is_in_mask(s)) {
5839 idx = index_of<0>(s);
5847 std::pair<size_t, size_t> find_first_of(
const K* text,
size_t len,
size_t offset = 0)
const {
5848 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
5850 while (offset < len) {
5851 if (is_in_pattern(text[offset], idx)) {
5852 return {offset, idx};
5857 while (offset < len) {
5858 if (
size_t idx = index_of<0>(text[offset]); idx != -1) {
5859 return {offset, idx};
5907template<
bool UseVector = false, StrSource A,
typename K = symb_type_from_src_t<A>,
typename ... Repl>
5908 requires (
sizeof...(Repl) % 2 == 0)
5910 return expr_replace_const_symbols<K,
sizeof...(Repl) / 2, UseVector>(std::forward<A>(src), std::forward<Repl>(other)...);
5952template<
typename K,
bool UseVectorForReplace = false>
5954 using symb_type = K;
5955 using str_t =
typename simple_str_selector<K>::type;
5956 inline static const int BIT_SEARCH_TRESHHOLD = 4;
5959 const std::vector<std::pair<K, str_t>>& replaces_;
5961 std::basic_string<K, ch_traits<K>, std::allocator<K>> pattern_;
5963 mutable replace_search_result_store<UseVectorForReplace> search_results_;
5965 uu8s bit_mask_[
sizeof(K) == 1 ? 32 : 64]{};
5994 : source_(source), replaces_(repl)
5996 size_t pattern_len = replaces_.size();
5997 pattern_.resize(pattern_len);
5998 K* pattern = pattern_.data();
6000 for (
size_t idx = 0; idx < replaces_.size(); idx++) {
6001 *pattern++ = replaces_[idx].first;
6004 if (pattern_len >= BIT_SEARCH_TRESHHOLD) {
6005 for (
size_t idx = 0; idx < pattern_len; idx++) {
6006 uu8s s =
static_cast<uu8s
>(pattern_[idx]);
6007 if constexpr (
sizeof(K) == 1) {
6008 bit_mask_[s >> 3] |= (1 << (s & 7));
6010 if (std::make_unsigned_t<K>(pattern_[idx]) > 255) {
6011 bit_mask_[32 + (s >> 3)] |= (1 << (s & 7));
6013 bit_mask_[s >> 3] |= (1 << (s & 7));
6020 size_t length()
const {
6021 size_t l = source_.
length();
6022 auto [fnd, num] = find_first_of(source_.str, source_.len);
6023 if (fnd == str::npos) {
6026 l += replaces_[num].second.len - 1;
6027 if constexpr (UseVectorForReplace) {
6028 search_results_.reserve((l >> 4) + 8);
6029 search_results_.emplace_back(fnd, num);
6030 for (
size_t start = fnd + 1;;) {
6031 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6032 if (fnd == str::npos) {
6035 search_results_.emplace_back(fnd, idx);
6037 l += replaces_[idx].second.len - 1;
6040 const size_t max_store = std::size(search_results_.replaces_);
6041 search_results_.replaces_[0] = {fnd, num};
6042 search_results_.count_++;
6043 for (
size_t start = fnd + 1;;) {
6044 auto [found, idx] = find_first_of(source_.str, source_.len, start);
6045 if (found == str::npos) {
6048 if (search_results_.count_ < max_store) {
6049 search_results_.replaces_[search_results_.count_] = {found, idx};
6051 l += replaces_[idx].second.len - 1;
6052 search_results_.count_++;
6058 K* place(K* ptr)
const noexcept {
6060 const K* text = source_.str;
6061 if constexpr (UseVectorForReplace) {
6062 for (
const auto& [pos, num] : search_results_) {
6063 size_t delta = pos - start;
6064 ch_traits<K>::copy(ptr, text + start, delta);
6066 ptr = replaces_[num].second.place(ptr);
6070 const size_t max_store = std::size(search_results_.replaces_);
6071 size_t founded = search_results_.count_;
6072 for (
size_t idx = 0, stop = std::min(founded, max_store); idx < stop; idx++) {
6073 const auto [pos, num] = search_results_.replaces_[idx];
6074 size_t delta = pos - start;
6075 ch_traits<K>::copy(ptr, text + start, delta);
6077 ptr = replaces_[num].second.place(ptr);
6080 if (founded > max_store) {
6081 founded -= max_store;
6083 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6084 size_t delta = fnd - start;
6085 ch_traits<K>::copy(ptr, text + start, delta);
6087 ptr = replaces_[idx].second.place(ptr);
6092 size_t tail = source_.len - start;
6093 ch_traits<K>::copy(ptr, text + start, tail);
6098 size_t index_of(K s)
const {
6099 return pattern_.find(s);
6102 bool is_in_mask(uu8s s)
const {
6103 return (bit_mask_[s >> 3] & (1 << (s & 7))) != 0;
6105 bool is_in_mask2(uu8s s)
const {
6106 return (bit_mask_[32 + (s >> 3)] & (1 << (s & 7))) != 0;
6109 bool is_in_pattern(K s,
size_t& idx)
const {
6110 if constexpr (
sizeof(K) == 1) {
6111 if (is_in_mask(s)) {
6116 if (std::make_unsigned_t<const K>(s) > 255) {
6117 if (is_in_mask2(s)) {
6118 return (idx = index_of(s)) != -1;
6121 if (is_in_mask(s)) {
6130 std::pair<size_t, size_t> find_first_of(
const K* text,
size_t len,
size_t offset = 0)
const {
6131 size_t pl = pattern_.length();
6132 if (pl >= BIT_SEARCH_TRESHHOLD) {
6134 while (offset < len) {
6135 if (is_in_pattern(text[offset], idx)) {
6136 return {offset, idx};
6141 while (offset < len) {
6142 if (
size_t idx = index_of(text[offset]); idx != -1) {
6143 return {offset, idx};
6152template<
typename K, StrExprForType<K> T>
6155 force_copy(
const T& t) : t_(t){}
6158template<
typename K,
typename T>
6159struct symb_type_from_src<force_copy<K, T>> {
6165force_copy(T&&) -> force_copy<typename T::symb_type, T>;
6167template<
typename K,
typename T>
6168constexpr auto to_subst(T&& t) {
6169 return to_strexpr<K>(std::forward<T>(t));
6172template<
typename K,
typename T,
size_t N>
6173constexpr auto to_subst(
const T(&t)[N]) {
6174 return expr_literal<T, N - 1>{t};
6177template<
typename K, StrExprForType<K> T>
6178constexpr decltype(
auto) to_subst(T&& t) {
6179 return std::forward<T>(t);
6182template<
typename K,
typename T>
6183constexpr T to_subst(
const force_copy<K, T>& t) {
6187template<
typename K,
typename T>
6188constexpr T to_subst(force_copy<K, T>&& t) {
6192template<
typename K,
typename T>
6193constexpr T to_subst(force_copy<K, T>& t) {
6197template<
typename K,
typename T>
6198using to_str_exp_t =
decltype(to_subst<K>(std::declval<T>()));
6207template<
typename K,
typename G,
typename Arg,
typename...Args>
6209 using symb_type = K;
6210 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
6211 using arg_t = to_str_exp_t<K, Arg>;
6212 to_str_exp_t<K, G> glue_;
6215 mutable size_t glue_len_;
6249 : glue_(to_subst<K>(std::forward<G>(glue)))
6250 , arg_(to_subst<K>(std::forward<Arg>(arg)))
6251 , args_(to_subst<K>(std::forward<Args>(args))...) {}
6253 constexpr size_t length() const noexcept {
6254 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
6255 glue_len_ = glue_.length();
6256 size_t l = arg_.length() + glue_len_ *
sizeof...(Args);
6257 ((l += std::get<Indexes>(args_).length()),...);
6259 }(std::make_index_sequence<
sizeof...(Args)>());
6261 constexpr K* place(K* ptr)
const noexcept {
6262 return [
this]<
size_t...Indexes>(K* ptr, std::index_sequence<Indexes...>) {
6263 ptr = (K*)arg_.place((
typename std::remove_cvref_t<arg_t>::symb_type*)ptr);
6264 const K* glueStart = ptr;
6265 ptr = glue_.place(ptr);
6268 ptr = (K*)std::get<Indexes>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Indexes, store_t>>::symb_type*)ptr),
6269 glue_len_ > 0 && Indexes <
sizeof...(Args) - 1 ? (ch_traits<K>::copy(ptr, glueStart, glue_len_), ptr += glue_len_) :
nullptr
6273 }(ptr, std::make_index_sequence<
sizeof...(Args)>());
6277template<
typename T,
typename ... Args>
requires (
sizeof...(Args) > 1)
6278e_concat(T&&, Args&&...) -> e_concat<symb_type_from_src_t<T>, T, Args...>;
6280struct parse_subst_string_error {
6281 parse_subst_string_error(
const char*){}
6286template<
typename K,
size_t NParams>
6287constexpr size_t parse_pattern_string(str_src<K> pattern,
auto&& add_part,
auto&& add_param) {
6288 char used_args[NParams] = {0};
6289 const K* first = pattern.begin(), *last = pattern.end(), *start = first;
6292 auto find = [](
const K* from,
const K* last, K s) {
6293 while (from != last) {
6301 size_t idx_in_params = 0;
6303 while (first != last) {
6304 const K* open_pos = first;
6305 if (*first !=
'{') {
6306 open_pos = find(first, last,
'{');
6309 const K* close_pos = find(first, open_pos,
'}');
6310 if (close_pos == open_pos) {
6311 unsigned len = open_pos - first;
6312 add_part(first - start, len);
6317 if (close_pos == open_pos || *close_pos !=
'}') {
6318 throw parse_subst_string_error{
"unescaped }"};
6320 unsigned len = close_pos - first;
6321 add_part(first - start, len);
6323 first = ++close_pos;
6325 if (open_pos == last) {
6329 if (++open_pos == last) {
6330 throw parse_subst_string_error{
"unescaped {"};
6332 if (*open_pos ==
'}') {
6333 if (idx_in_params == -1) {
6334 throw parse_subst_string_error{
"already used param ids"};
6336 if (idx_in_params == NParams) {
6337 throw parse_subst_string_error{
"too many params"};
6339 used_args[idx_in_params] = 1;
6340 add_param(idx_in_params++);
6341 first = open_pos + 1;
6342 }
else if (*open_pos ==
'{') {
6343 add_part(open_pos - start, 1);
6345 first = open_pos + 1;
6347 if (idx_in_params != 0 && idx_in_params != -1) {
6348 throw parse_subst_string_error{
"already used non id params"};
6351 const K* end = find(open_pos, last,
'}');
6353 throw parse_subst_string_error{
"not found }"};
6355 auto [p, err, _] = str_src<K>(open_pos, end - open_pos).template to_int<unsigned, true, 10, false, false>();
6356 if (err != IntConvertResult::Success || p < 1 || p > NParams) {
6357 throw parse_subst_string_error{
"bad param id"};
6364 for (
auto c : used_args) {
6366 throw parse_subst_string_error{
"unused param"};
6375 unsigned is_param: 1;
6377 portion() =
default;
6379 constexpr void set_param(
unsigned param) {
6380 if (param >= (1 << 16)) {
6381 throw parse_subst_string_error{
"the parameter id is too large"};
6386 constexpr void set_part(
unsigned from,
unsigned l) {
6387 if (from >= (1 << 16) || len >= (1 << 15)) {
6388 throw parse_subst_string_error{
"the string part is too large"};
6396template<
typename K,
size_t PtLen,
size_t NParams>
6397struct subst_params {
6398 const K(&source_)[PtLen];
6399 unsigned all_len_{};
6403 portion portions_[1 + ((PtLen - 2) * 2 / 3)]{};
6405 consteval subst_params(
const K(&pattern)[PtLen]) : source_(pattern) {
6406 all_len_ = parse_pattern_string<K, NParams>(pattern,
6407 [
this](
unsigned from,
unsigned len) {
6408 portions_[actual_++].set_part(from, len);
6409 }, [
this](
unsigned param) {
6410 portions_[actual_++].set_param(param);
6422template<
typename K,
size_t PtLen,
typename ... Args>
6424 inline static constexpr size_t NParams =
sizeof...(Args);
6425 using symb_type = K;
6426 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
6428 const details::subst_params<K, PtLen, NParams>& subst_;
6470 constexpr e_subst(
const details::subst_params<K, PtLen, NParams>& subst, Args&&...args)
6472 , args_(to_subst<K>(std::forward<Args>(args))...){}
6474 constexpr size_t length() const noexcept {
6475 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
6477 size_t expr_length_[NParams] = {};
6478 ((expr_length_[idx++] = std::get<Indexes>(args_).length()),...);
6479 size_t l = subst_.all_len_;
6480 for (idx = 0; idx < subst_.actual_; idx++) {
6481 if (subst_.portions_[idx].is_param) {
6482 l += expr_length_[subst_.portions_[idx].start];
6486 }(std::make_index_sequence<
sizeof...(Args)>());
6488 template<
size_t Idx>
6489 constexpr K* place_idx(K* ptr,
size_t idx)
const noexcept {
6491 return (K*)std::get<Idx>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Idx, store_t>>::symb_type*)ptr);
6493 if constexpr (Idx < NParams - 1) {
6494 return place_idx<Idx + 1>(ptr, idx);
6498 constexpr K* place(K* ptr)
const noexcept {
6499 for (
size_t idx = 0; idx < subst_.actual_; idx++) {
6500 if (subst_.portions_[idx].is_param) {
6501 ptr = place_idx<0>(ptr, subst_.portions_[idx].start);
6503 ch_traits<K>::copy(ptr, subst_.source_ + subst_.portions_[idx].start, subst_.portions_[idx].len);
6504 ptr += subst_.portions_[idx].len;
6512template<
typename K,
size_t N,
typename...Args>
requires (
sizeof...(Args) > 0)
6513e_subst(
const K(&)[N], Args&&...) -> e_subst<K, N, Args...>;
6520template<
typename K,
typename ... Args>
6522 inline static constexpr size_t Nparams =
sizeof...(Args);
6523 using symb_type = K;
6524 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
6526 details::portion portions_[Nparams * 3];
6527 std::vector<details::portion> more_portions_;
6571 , args_(to_subst<K>(std::forward<Args>(args))...) {
6573 all_len_ = details::parse_pattern_string<K, Nparams>(pattern_, [
this](
unsigned from,
unsigned len) {
6574 if (actual_ < std::size(portions_)) {
6575 portions_[actual_++].set_part(from, len);
6577 if (actual_ == std::size(portions_)) {
6578 more_portions_.reserve((pattern_.len - 1) * 2 / 3 - std::size(portions_));
6580 more_portions_.emplace_back().set_part(from, len);
6582 }, [
this](
unsigned param) {
6583 if (actual_ < std::size(portions_)) {
6584 portions_[actual_++].set_param(param);
6586 if (actual_ == std::size(portions_)) {
6587 more_portions_.reserve((pattern_.len - 1) * 2 / 3 - std::size(portions_));
6589 more_portions_.emplace_back().set_param(param);
6594 constexpr size_t length() const noexcept {
6595 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
6597 size_t expr_length_[Nparams] = {};
6598 ((expr_length_[idx++] = std::get<Indexes>(args_).length()),...);
6599 size_t l = all_len_;
6600 for (idx = 0; idx < actual_; idx++) {
6601 if (portions_[idx].is_param) {
6602 l += expr_length_[portions_[idx].start];
6605 for (
const auto& p : more_portions_) {
6607 l += expr_length_[p.start];
6611 }(std::make_index_sequence<
sizeof...(Args)>());
6613 template<
size_t Idx>
6614 constexpr K* place_idx(K* ptr,
size_t idx)
const noexcept {
6616 return (K*)std::get<Idx>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Idx, store_t>>::symb_type*)ptr);
6618 if constexpr (Idx < Nparams - 1) {
6619 return place_idx<Idx + 1>(ptr, idx);
6623 constexpr K* place(K* ptr)
const noexcept {
6624 for (
size_t idx = 0; idx < actual_; idx++) {
6625 if (portions_[idx].is_param) {
6626 ptr = place_idx<0>(ptr, portions_[idx].start);
6628 ch_traits<K>::copy(ptr, pattern_.
symbols() + portions_[idx].start, portions_[idx].len);
6629 ptr += portions_[idx].len;
6632 for (
const auto& p : more_portions_) {
6634 ptr = place_idx<0>(ptr, p.start);
6636 const K* from = pattern_.
symbols() + p.start;
6637 for (
size_t idx = p.len; idx--;) {
6648template<StrSourceNoLiteral T,
typename...Args>
requires (
sizeof...(Args) > 0)
6649e_vsubst(T&&, Args&&...) -> e_vsubst<symb_type_from_src_t<T>, Args...>;
6689template<
typename K,
typename A, StrExprForType<K> E>
6690std::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) {
6691 size_t expr_length = expr.length();
6693 str.erase(from, count);
6696 size_t str_length =
str.length();
6697 if (from > str_length) {
6700 if (from + count > str_length) {
6701 count = str_length - from;
6703 size_t new_length = str_length - count + expr_length;
6704 size_t tail_length = str_length - count - from;
6706 if (new_length <= str_length) {
6707 K* data =
str.data();
6708 expr.place((
typename E::symb_type*)data + from);
6709 if (expr_length < count) {
6711 std::char_traits<K>::move(data + from + expr_length, data + from + count, tail_length);
6713 str.resize(new_length);
6716 auto fill = [&](K* data, size_t) ->
size_t {
6718 std::char_traits<K>::move(data + from + expr_length, data + from + count, tail_length);
6720 expr.place((
typename E::symb_type*)data + from);
6723 if constexpr (
requires{
str.resize_and_overwrite(new_length, fill);}) {
6724 str.resize_and_overwrite(new_length, fill);
6725 }
else if constexpr (
requires{
str._Resize_and_overwrite(new_length, fill);}) {
6726 str._Resize_and_overwrite(new_length, fill);
6728 str.resize(new_length);
6729 fill(
str.data(), 0);
6762template<
typename K,
typename A, StrExprForType<K> E>
6763std::basic_string<K, std::char_traits<K>, A>&
append(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
6795template<
typename K,
typename A, StrExprForType<K> E>
6796std::basic_string<K, std::char_traits<K>, A>&
prepend(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
6830template<
typename K,
typename A, StrExprForType<K> E>
6831std::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) {
6859template<
typename K,
typename A, StrExprForType<K> E>
6860std::basic_string<K, std::char_traits<K>, A>&
overwrite(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
6861 if (
size_t expr_length = expr.length()) {
6862 if (expr_length <=
str.length()) {
6863 K* data =
str.data();
6864 expr.place((
typename E::symb_type*)data);
6865 str.resize(expr_length);
6867 auto fill = [&](K* data, size_t) ->
size_t {
6868 expr.place((
typename E::symb_type*)data);
6871 if constexpr (
requires{
str.resize_and_overwrite(expr_length, fill);}) {
6872 str.resize_and_overwrite(expr_length, fill);
6873 }
else if constexpr (
requires{
str._Resize_and_overwrite(expr_length, fill);}) {
6874 str._Resize_and_overwrite(expr_length, fill);
6876 str.resize(expr_length);
6877 expr.place((
typename E::symb_type*)
str.data());
6888template<
typename K,
typename A,
typename E>
6889struct replace_grow_helper {
6890 using my_type = std::basic_string<K, std::char_traits<K>, A>;
6892 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)
6893 :
str(src), source(src), pattern(p), repl(const_cast<K*>(r)), replLen(rl), maxCount(mc), delta(d), expr(e) {}
6896 const str_src<K> source;
6897 const str_src<K> pattern;
6899 const size_t replLen;
6906 K* reserve_for_copy{};
6907 size_t end_of_piece{};
6908 size_t total_length{};
6910 std::optional<my_type> dst;
6913 size_t found[16] = {offset};
6916 offset += pattern.len;
6919 for (; idx < std::size(found) && maxCount > 0; idx++, maxCount--) {
6920 found[idx] = source.find(pattern, offset);
6921 if (found[idx] == npos) {
6924 offset = found[idx] + pattern.len;
6927 if (idx == std::size(found) && maxCount > 0 && (offset = source.find(pattern, offset)) != str::npos) {
6932 if (!reserve_for_copy) {
6935 end_of_piece = source.length();
6936 total_length = end_of_piece + all_delta;
6938 if (total_length <= str.capacity()) {
6943 dst_str = &dst.emplace();
6945 auto fill = [
this](K* p, size_t) ->
size_t {
6946 reserve_for_copy = p;
6947 return total_length;
6949 if constexpr (
requires{dst_str->_Resize_and_overwrite(total_length, fill);}) {
6950 dst_str->_Resize_and_overwrite(total_length, fill);
6951 }
else if constexpr (
requires{dst_str->resize_and_overwrite(total_length, fill);}) {
6952 dst_str->resize_and_overwrite(total_length, fill);
6954 dst_str->resize(total_length);
6955 reserve_for_copy = dst_str->data();
6958 const K* src_start = str.c_str();
6960 size_t pos = found[idx] + pattern.len;
6961 size_t lenOfPiece = end_of_piece - pos;
6962 ch_traits<K>::move(reserve_for_copy + pos + all_delta, src_start + pos, lenOfPiece);
6963 if constexpr (std::is_same_v<E, int>) {
6964 ch_traits<K>::copy(reserve_for_copy + pos + all_delta - replLen, repl, replLen);
6967 repl = reserve_for_copy + pos + all_delta - replLen;
6970 ch_traits<K>::copy(reserve_for_copy + pos + all_delta - replLen, repl, replLen);
6974 end_of_piece = found[idx];
6976 if (!all_delta && reserve_for_copy != src_start) {
6977 ch_traits<K>::copy(reserve_for_copy, src_start, found[0]);
6978 str = std::move(*dst);
7019template<
typename K,
typename A, StrExprForType<K> E,
typename T>
7020requires (std::is_constructible_v<str_src<K>, T>)
7021std::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) {
7026 str_src<K> spattern{std::forward<T>(pattern)};
7027 offset = src.find(pattern, offset);
7028 if (offset == npos) {
7031 size_t replLen = repl.length();
7033 if (spattern.len == replLen) {
7036 K* ptr =
str.data();
7037 replStart = ptr + offset;
7038 repl.place(replStart);
7040 while (--max_count) {
7041 offset = src.find(spattern, offset + replLen);
7044 ch_traits<K>::copy(ptr + offset, replStart, replLen);
7046 }
else if (spattern.len > replLen) {
7049 K* ptr =
str.data();
7050 replStart = ptr + offset;
7051 repl.place(replStart);
7052 size_t posWrite = offset + replLen;
7053 offset += spattern.len;
7055 while (--max_count) {
7056 size_t idx = src.find(spattern, offset);
7059 size_t lenOfPiece = idx - offset;
7060 ch_traits<K>::move(ptr + posWrite, ptr + offset, lenOfPiece);
7061 posWrite += lenOfPiece;
7062 ch_traits<K>::copy(ptr + posWrite, replStart, replLen);
7063 posWrite += replLen;
7064 offset = idx + spattern.len;
7066 size_t tailLen = src.len - offset;
7067 ch_traits<K>::move(ptr + posWrite, ptr + offset, tailLen);
7068 str.resize(posWrite + tailLen);
7070 details::replace_grow_helper<K, A, E>(
str, spattern,
nullptr, replLen, max_count, replLen - spattern.len, repl).replace(offset);
7095template<
typename K,
typename A>
7096std::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) {
7101 offset = src.find(pattern, offset);
7102 if (offset == npos) {
7105 if (pattern.len == repl.len) {
7108 K* ptr =
str.data();
7109 while (max_count--) {
7110 ch_traits<K>::copy(ptr + offset, repl.str, repl.len);
7111 offset = src.find(pattern, offset + repl.len);
7115 }
else if (pattern.len > repl.len) {
7118 K* ptr =
str.data();
7119 ch_traits<K>::copy(ptr + offset, repl.str, repl.len);
7120 size_t posWrite = offset + repl.len;
7121 offset += pattern.len;
7123 while (--max_count) {
7124 size_t idx = src.find(pattern, offset);
7127 size_t lenOfPiece = idx - offset;
7128 ch_traits<K>::move(ptr + posWrite, ptr + offset, lenOfPiece);
7129 posWrite += lenOfPiece;
7130 ch_traits<K>::copy(ptr + posWrite, repl.str, repl.len);
7131 posWrite += repl.len;
7132 offset = idx + pattern.len;
7134 size_t tailLen = src.len - offset;
7135 ch_traits<K>::move(ptr + posWrite, ptr + offset, tailLen);
7136 str.resize(posWrite + tailLen);
7138 details::replace_grow_helper<K, A, int>(
str, pattern, repl.str, repl.len, max_count, repl.len - pattern.len, 0).replace(offset);
7143template<
typename K,
typename A,
typename T,
typename M>
7144requires (std::is_constructible_v<str_src<K>, T> && std::is_constructible_v<str_src<K>, M>)
7145std::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) {
7146 return replace(
str,
str_src<K>{std::forward<T>(pattern)}, str_src<K>{std::forward<M>(repl)}, offset, max_count);
7173template<simstr::StdStrSource T>
7206template<
typename K,
typename A, simstr::StrExprForType<K> E>
7207std::basic_string<K, std::char_traits<K>, A>& operator |=(std::basic_string<K, std::char_traits<K>, A>& str,
const E& expr) {
7239template<
typename K,
typename A, simstr::StrExprForType<K> E>
7240std::basic_string<K, std::char_traits<K>, A>& operator ^=(std::basic_string<K, std::char_traits<K>, A>& str,
const E& expr) {
Класс для последовательного получения подстрок по заданному разделителю.
Определения strexpr.h:3232
constexpr bool is_done() const
Узнать, не закончились ли подстроки.
Определения strexpr.h:3243
constexpr str_t next()
Получить следующую подстроку.
Определения strexpr.h:3252
std::optional< double > to_double_hex() const noexcept
Преобразовать строку в 16ричной записи в double. Пока работает только для char.
Определения strexpr.h:4191
constexpr size_t find_last(K s, size_t offset=-1) const noexcept
Найти последнее вхождения символа в этой строке.
Определения strexpr.h:3971
R trimmed_right() const
Получить строку с удалением пробельных символов справа.
Определения strexpr.h:4573
constexpr int compare_ia(str_piece text) const noexcept
Сравнение строк посимвольно без учёта регистра ASCII символов.
Определения strexpr.h:3653
constexpr int compare(str_piece o) const
Сравнение строк посимвольно.
Определения strexpr.h:3538
constexpr size_t find(K s, size_t offset=0) const noexcept
Найти символ в этой строке.
Определения strexpr.h:3875
constexpr bool ends_with(str_piece suffix) const noexcept
Заканчивается ли строка указанной подстрокой.
Определения strexpr.h:4403
R trimmed(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, слева и справа.
Определения strexpr.h:4695
R trimmed_left(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, слева.
Определения strexpr.h:4709
constexpr bool operator==(const base &other) const noexcept
Оператор сравнение строк на равенство.
Определения strexpr.h:3589
constexpr std::basic_string_view< D > to_sv() const noexcept
Конвертировать в std::basic_string_view.
Определения strexpr.h:3372
R trimmed_left() const
Получить строку с удалением пробельных символов слева.
Определения strexpr.h:4561
constexpr size_t find_end_or_all(str_piece pattern, size_t offset=0) const noexcept
Найти конец первого вхождения подстроки в этой строке или конец строки.
Определения strexpr.h:3771
constexpr bool starts_with(str_piece prefix) const noexcept
Начинается ли строка с заданной подстроки.
Определения strexpr.h:4345
constexpr bool equal(str_piece other) const noexcept
Сравнение строк на равенство.
Определения strexpr.h:3578
void copy_to(K *buffer, size_t bufSize)
Копировать строку в указанный буфер.
Определения strexpr.h:3350
constexpr size_t find_or_throw(str_piece pattern, size_t offset=0, Args &&... args) const noexcept
Найти начало первого вхождения подстроки в этой строке или выкинуть исключение.
Определения strexpr.h:3727
constexpr str_piece until(str_piece pattern, size_t offset=0) const noexcept
Получить подстроку str_src от начала и до первого найденного вхождения указанной подстроки.
Определения strexpr.h:3500
constexpr T as_int() const noexcept
Преобразовать строку в число заданного типа.
Определения strexpr.h:4117
constexpr bool less_ia(str_piece text) const noexcept
Меньше ли строка другой строки посимвольно без учёта регистра ASCII символов.
Определения strexpr.h:3676
constexpr T split(str_piece delimiter, size_t offset=0) const
Разделить строку на подстроки по заданному разделителю.
Определения strexpr.h:4330
constexpr str_piece mid(size_t from, size_t len=-1) const noexcept
Получить часть строки как "кусок строки".
Определения strexpr.h:3465
constexpr my_type substr(ptrdiff_t from, ptrdiff_t len=0) const
Получить подстроку. Работает аналогично operator(), только результат выдает того же типа,...
Определения strexpr.h:4072
R upperred_only_ascii() const
Получить копию строки в верхнем регистре ASCII символов.
Определения strexpr.h:4480
constexpr str_piece to_str() const noexcept
Преобразовать себя в "кусок строки", включающий всю строку.
Определения strexpr.h:3420
constexpr str_piece from_to(size_t from, size_t to) const noexcept
Получить подстроку str_src с позиции от from до позиции to (не включая её).
Определения strexpr.h:3487
R replaced(str_piece pattern, str_piece repl, size_t offset=0, size_t maxCount=0) const
Получить копию строки с заменёнными вхождениями подстрок.
Определения strexpr.h:4512
constexpr int strcmp(const K *text) const
Сравнение с C-строкой посимвольно.
Определения strexpr.h:3549
constexpr bool ends_with_ia(str_piece suffix) const noexcept
Заканчивается ли строка указанной подстрокой без учёта регистра ASCII символов.
Определения strexpr.h:4429
constexpr size_t find_first_not_of(str_piece pattern, size_t offset=0) const noexcept
Найти первое вхождение символа не из заданного набора символов.
Определения strexpr.h:4018
constexpr size_t find_first_of(str_piece pattern, size_t offset=0) const noexcept
Найти первое вхождение символа из заданного набора символов.
Определения strexpr.h:3990
constexpr size_t find_last_or_all(str_piece pattern, size_t offset=-1) const noexcept
Найти начало последнего вхождения подстроки в этой строке или конец строки.
Определения strexpr.h:3834
R trimmed_with_spaces(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, а также пробельных символов,...
Определения strexpr.h:4741
constexpr bool starts_with_ia(str_piece prefix) const noexcept
Начинается ли строка с заданной подстроки без учёта регистра ASCII символов.
Определения strexpr.h:4370
constexpr size_t find_last(str_piece pattern, size_t offset=-1) const noexcept
Найти начало последнего вхождения подстроки в этой строке.
Определения strexpr.h:3807
constexpr size_t find_last_of(str_piece pattern, size_t offset=str::npos) const noexcept
Найти последнее вхождение символа из заданного набора символов.
Определения strexpr.h:4031
constexpr size_t find_or_all(K s, size_t offset=0) const noexcept
Найти символ в этой строке или конец строки.
Определения strexpr.h:3894
constexpr size_t find_last_not_of(str_piece pattern, size_t offset=str::npos) const noexcept
Найти последнее вхождение символа не из заданного набора символов.
Определения strexpr.h:4059
constexpr void for_all_finded(const Op &op, str_piece pattern, size_t offset=0, size_t maxCount=0) const
Вызвать функтор для всех найденных вхождений подстроки в этой строке.
Определения strexpr.h:3929
constexpr size_t find_end(str_piece pattern, size_t offset=0) const noexcept
Найти конец вхождения подстроки в этой строке.
Определения strexpr.h:3743
constexpr bool operator!() const noexcept
Проверка на пустоту.
Определения strexpr.h:3507
R trimmed(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, слева и справа.
Определения strexpr.h:4588
constexpr R trimmed() const
Получить строку с удалением пробельных символов слева и справа.
Определения strexpr.h:4549
constexpr size_t size() const
Размер строки в символах.
Определения strexpr.h:3361
R trimmed_right(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, справа.
Определения strexpr.h:4723
constexpr To find_all(str_piece pattern, size_t offset=0, size_t maxCount=0) const
Найти все вхождения подстроки в этой строке.
Определения strexpr.h:3952
constexpr my_type str_mid(size_t from, size_t len=-1) const
Получить часть строки объектом того же типа, к которому применён метод, аналогично mid.
Определения strexpr.h:4085
constexpr size_t find_end_of_last(str_piece pattern, size_t offset=-1) const noexcept
Найти конец последнего вхождения подстроки в этой строке.
Определения strexpr.h:3820
constexpr std::pair< size_t, size_t > find_first_of_idx(str_piece pattern, size_t offset=0) const noexcept
Найти первое вхождение символа из заданного набора символов.
Определения strexpr.h:4003
constexpr bool is_ascii() const noexcept
Содержит ли строка только ASCII символы.
Определения strexpr.h:4436
constexpr size_t find(str_piece pattern, size_t offset=0) const noexcept
Найти начало первого вхождения подстроки в этой строке.
Определения strexpr.h:3707
constexpr SplitterBase< K, str_piece > splitter(str_piece delimiter) const
Получить объект Splitter по заданному разделителю, который позволяет последовательно получать подстро...
Определения strexpr.h:4791
constexpr std::pair< size_t, size_t > find_last_of_idx(str_piece pattern, size_t offset=str::npos) const noexcept
Найти последнее вхождение символа из заданного набора символов.
Определения strexpr.h:4044
R trimmed_left(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, слева.
Определения strexpr.h:4603
R trimmed_with_spaces(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, а также пробельных символов,...
Определения strexpr.h:4640
std::optional< double > to_double() const noexcept
Преобразовать строку в double.
Определения strexpr.h:4160
constexpr size_t find_or_all(str_piece pattern, size_t offset=0) const noexcept
Найти начало первого вхождения подстроки в этой строке или конец строки.
Определения strexpr.h:3757
constexpr bool operator==(T &&other) const noexcept
Оператор сравнения строки и строкового литерала на равенство.
Определения strexpr.h:3608
R trimmed_right_with_spaces(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, а также пробельных символов,...
Определения strexpr.h:4777
constexpr auto operator<=>(const base &other) const noexcept
Оператор сравнения строк.
Определения strexpr.h:3598
constexpr bool contains(str_piece pattern, size_t offset=0) const noexcept
Содержит ли строка указанную подстроку.
Определения strexpr.h:3862
R trimmed_right(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, справа.
Определения strexpr.h:4618
constexpr str_piece operator()(ptrdiff_t from, ptrdiff_t len=0) const noexcept
Получить часть строки как "str_src".
Определения strexpr.h:3446
constexpr K at(ptrdiff_t idx) const
Получить символ на заданной позиции .
Определения strexpr.h:3520
R lowered_only_ascii() const
Получить копию строки в нижнем регистре ASCII символов.
Определения strexpr.h:4492
R trimmed_right_with_spaces(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, а также пробельных символов,...
Определения strexpr.h:4678
constexpr auto operator<=>(T &&other) const noexcept
Оператор сравнения строки и строкового литерала.
Определения strexpr.h:3618
constexpr std::basic_string< D, Traits, Allocator > to_string() const
Конвертировать в std::basic_string.
Определения strexpr.h:3392
constexpr T splitf(str_piece delimiter, const Op &beforeFunc, size_t offset=0) const
Разделить строку на части по заданному разделителю, с возможным применением функтора к каждой подстро...
Определения strexpr.h:4314
R trimmed_left_with_spaces(T &&pattern) const
Получить строку с удалением символов, заданных строковым литералом, а также пробельных символов,...
Определения strexpr.h:4659
constexpr size_t find_end_of_last_or_all(str_piece pattern, size_t offset=-1) const noexcept
Найти конец последнего вхождения подстроки в этой строке или конец строки.
Определения strexpr.h:3848
constexpr bool prefix_in(str_piece text) const noexcept
Является ли эта строка началом другой строки.
Определения strexpr.h:4388
R trimmed_left_with_spaces(str_piece pattern) const
Получить строку с удалением символов, заданных другой строкой, а также пробельных символов,...
Определения strexpr.h:4759
constexpr K * place(K *ptr) const noexcept
Копировать строку в указанный буфер.
Определения strexpr.h:3335
constexpr convert_result< T > to_int() const noexcept
Преобразовать строку в число заданного типа.
Определения strexpr.h:4150
constexpr bool equal_ia(str_piece text) const noexcept
Равна ли строка другой строке посимвольно без учёта регистра ASCII символов.
Определения strexpr.h:3665
constexpr void as_number(T &t) const
Преобразовать строку в целое число.
Определения strexpr.h:4217
Концепт строкового выражения, совместимого с заданным типом символов.
Определения strexpr.h:525
Концепт "Строковых выражений".
Определения strexpr.h:507
Базовая концепция строкового объекта.
Определения strexpr.h:311
Проверка, являются ли два типа совместимыми строковыми типами.
Определения strexpr.h:172
constexpr expr_if< A > e_if(bool c, const A &a)
Создание условного строкового выражения expr_if.
Определения strexpr.h:1544
simstr::expr_stdstr< typename T::value_type, T > operator+(const T &str)
Унарный оператор+ для преобразования стандартных строк в строковые выражения.
Определения strexpr.h:7174
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:2697
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:1717
HexFlags
Флаги для функции e_hex.
Определения strexpr.h:2525
constexpr auto e_hex(T v)
Создает объект, который может преобразовываться в строковое выражение, генерирующее 16ричное представ...
Определения strexpr.h:2582
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:1218
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:2723
constexpr expr_choice< A, B > e_choice(bool c, const A &a, const B &b)
Создание условного строкового выражения expr_choice.
Определения strexpr.h:1466
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:5909
constexpr auto e_int(T v)
Создает объект, который преобразовывается в строковое выражение, генерирующее строковое представление...
Определения strexpr.h:2381
constexpr empty_expr< u8s > eeb
Пустое строковое выражение типа char8_t.
Определения strexpr.h:856
constexpr auto e_repl(A &&w, T &&p, X &&r)
Получить строковое выражение, генерирующее строку с заменой всех вхождений заданной подстроки.
Определения strexpr.h:5416
constexpr auto e_join(const T &s, L &&d)
Получить строковое выражение, конкатенирующее строки в контейнере в одну строку с заданным разделител...
Определения strexpr.h:2801
@ Short
without leading zeroes
Определения strexpr.h:2526
Небольшое пространство для методов работы со стандартными строками.
Определения strexpr.h:1600
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:6763
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:6796
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:6690
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:7021
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:6860
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:6831
Пространство имён для объектов библиотеки
Определения sstring.cpp:12
IntConvertResult
Перечисление с возможными результатами преобразования строки в целое число
Определения strexpr.h:2868
@ Overflow
Переполнение, число не помещается в заданный тип
Определения strexpr.h:2871
@ Success
Успешно
Определения strexpr.h:2869
@ NotNumber
Вообще не число
Определения strexpr.h:2872
@ BadSymbolAtTail
Число закончилось не числовым символом
Определения strexpr.h:2870
constexpr e_concat(G &&glue, Arg &&arg, Args &&...args)
Создание строкового выражения, объединяющего указанные строковые выражения, с использованием заданног...
Определения strexpr.h:6248
constexpr e_subst(const details::subst_params< K, PtLen, NParams > &subst, Args &&...args)
Создает строковое выражение, которое подставляет в заданные места в строковом литерале - образце знач...
Определения strexpr.h:6470
constexpr e_vsubst(str_src< K > pattern, Args &&...args)
Создает строковое выражение, которое подставляет в заданные места в строке-образце,...
Определения strexpr.h:6569
"Пустое" строковое выражение.
Определения strexpr.h:835
Строковое выражение условного выбора.
Определения strexpr.h:1345
Строковое выражение условного выбора.
Определения strexpr.h:1411
Строковое выражение условного выбора.
Определения strexpr.h:1254
Строковое выражение условного выбора.
Определения strexpr.h:1283
Тип строкового выражения, возвращающего N заданных символов.
Определения strexpr.h:1120
constexpr expr_replace_symbols(str_t source, const std::vector< std::pair< K, str_t > > &repl)
Конструктор выражения.
Определения strexpr.h:5993
Строковое выражение, генерирующее строку с заменой всех вхождений заданной подстроки на строковое выр...
Определения strexpr.h:5534
constexpr expr_replaced_e(str_src< K > w, str_src< K > p, const E &e)
Конструктор.
Определения strexpr.h:5553
Строковое выражение, генерирующее строку с заменой всех вхождений заданной подстроки на другую строку...
Определения strexpr.h:5428
constexpr expr_replaced(str_src< K > w, str_src< K > p, str_src< K > r)
Конструктор.
Определения strexpr.h:5446
Тип строкового выражения, возвращающего N заданных символов.
Определения strexpr.h:1060
Тип для использования std::basic_string и std::basic_string_view как источников в строковых выражения...
Определения strexpr.h:1569
Базовый класс для преобразования строковых выражений в стандартные строки
Определения strexpr.h:659
Класс, заявляющий, что ссылается на нуль-терминированную строку.
Определения strexpr.h:4962
constexpr my_type to_nts(size_t from)
Получить нуль-терминированную строку, сдвинув начало на заданное количество символов.
Определения strexpr.h:5025
constexpr str_src_nt(T &&v) noexcept
Конструктор из строкового литерала.
Определения strexpr.h:4996
constexpr str_src_nt(T &&p) noexcept
Явный конструктор из С-строки.
Определения strexpr.h:4987
constexpr str_src_nt(const std::basic_string< K, std::char_traits< K >, A > &s) noexcept
Конструктор из std::basic_string.
Определения strexpr.h:5014
constexpr str_src_nt(const K *p, size_t l) noexcept
Конструктор из указателя и длины.
Определения strexpr.h:5002
Простейший класс иммутабельной не владеющей строки.
Определения strexpr.h:4826
constexpr str_src(const std::basic_string< K, std::char_traits< K >, A > &s) noexcept
Конструктор из std::basic_string.
Определения strexpr.h:4855
constexpr bool is_empty() const noexcept
Проверить, не пуста ли строка.
Определения strexpr.h:4880
constexpr size_t length() const noexcept
Получить длину строки.
Определения strexpr.h:4866
constexpr K operator[](size_t idx) const
Получить символ из указанной позиции. Проверка границ не выполняется.
Определения strexpr.h:4909
constexpr my_type & remove_prefix(size_t delta)
Сдвигает начало строки на заданное количество символов.
Определения strexpr.h:4920
constexpr str_src(const K *p, size_t l) noexcept
Конструктор из указателя и длины.
Определения strexpr.h:4845
constexpr bool is_same(str_src< K > other) const noexcept
Проверить, не указывают ли два объекта на одну строку.
Определения strexpr.h:4889
constexpr str_src(const std::basic_string_view< K, std::char_traits< K > > &s) noexcept
Конструктор из std::basic_string_view.
Определения strexpr.h:4860
constexpr const symb_type * symbols() const noexcept
Получить указатель на константный буфер с символами строки.
Определения strexpr.h:4873
constexpr my_type & remove_suffix(size_t delta)
Укорачивает строку на заданное количество символов.
Определения strexpr.h:4933
constexpr bool is_part_of(str_src< K > other) const noexcept
Проверить, не является ли строка частью другой строки.
Определения strexpr.h:4898
constexpr str_src(T &&v) noexcept
Конструктор из строкового литерала.
Определения strexpr.h:4839
Конкатенация ссылки на строковое выражение и значения строкового выражения.
Определения strexpr.h:744
Шаблонный класс для конкатенации двух строковых выражений в одно с помощью operator +
Определения strexpr.h:682