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);
1605std::char_traits<K> char_traits_selector(...);
1608using ch_traits =
decltype(char_traits_selector<K>(
int(0)));
1611concept FromIntNumber =
1612 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;
1615concept ToIntNumber = FromIntNumber<T> || is_one_of_type<T, int8_t>::value;
1617template<
typename K,
bool I,
typename T>
1620 std::make_unsigned_t<T> val;
1621 constexpr need_sign(T t) : negate(t < 0), val(t < 0 ?
std::make_unsigned_t<T>{} - t : t) {}
1622 constexpr void after(K*& ptr) {
1628template<
typename K,
typename T>
1629struct need_sign<K, false, T> {
1631 constexpr need_sign(T t) : val(t){}
1632 constexpr void after(K*&) {}
1635template<
typename K,
typename T>
1636constexpr size_t fromInt(K* bufEnd, T val) {
1637 const char* twoDigit =
1638 "0001020304050607080910111213141516171819"
1639 "2021222324252627282930313233343536373839"
1640 "4041424344454647484950515253545556575859"
1641 "6061626364656667686970717273747576777879"
1642 "8081828384858687888990919293949596979899";
1644 need_sign<K, std::is_signed_v<T>, T> store(val);
1646 while (store.val >= 100) {
1647 const char* ptr = twoDigit + (store.val % 100) * 2;
1648 *--itr =
static_cast<K
>(ptr[1]);
1649 *--itr =
static_cast<K
>(ptr[0]);
1652 if (store.val < 10) {
1653 *--itr =
static_cast<K
>(
'0' + store.val);
1655 const char* ptr = twoDigit + store.val * 2;
1656 *--itr =
static_cast<K
>(ptr[1]);
1657 *--itr =
static_cast<K
>(ptr[0]);
1660 return size_t(bufEnd - itr);
1666template<
typename K,
typename T>
1668 using symb_type = K;
1669 using my_type = expr_num<K, T>;
1671 enum { bufSize = 24 };
1672 mutable K buf[bufSize];
1675 constexpr expr_num(T t) : value(t) {}
1676 constexpr expr_num(expr_num&& t) noexcept : value(t.value) {}
1678 constexpr size_t length() const noexcept {
1679 value =
static_cast<T
>(fromInt(buf + bufSize, value));
1680 return static_cast<size_t>(value);
1682 constexpr K* place(K* ptr)
const noexcept {
1683 size_t len =
static_cast<size_t>(value);
1684 ch_traits<K>::copy(ptr, buf + bufSize - len, len);
1699template<
typename K, FromIntNumber T>
1700struct convert_to_strexpr<K, T> {
1701 using type = expr_num<K, T>;
1719template<
typename K, FromIntNumber T>
1726enum class int_align { none, left, right, center };
1727enum class int_plus_sign {none, plus, space};
1728enum class int_prefix {none, lcase, ucase};
1730enum fmt_kinds :
unsigned {
1741template<
typename A,
typename B,
unsigned Kind>
1745 inline static constexpr unsigned kind = Kind;
1749 inline static constexpr unsigned kind = fmt_none;
1752template<
int_align A>
1754 inline static constexpr unsigned kind = fmt_align;
1757template<
size_t W
idth = 0>
1759 inline static constexpr unsigned kind = fmt_width;
1762template<
unsigned Fill = ' '>
1764 inline static constexpr unsigned kind = fmt_fill;
1767template<
int_plus_sign S>
1769 inline static constexpr unsigned kind = fmt_sign;
1773 inline static constexpr unsigned kind = fmt_upper;
1778 inline static constexpr unsigned kind = fmt_prefix;
1782 inline static constexpr unsigned kind = fmt_zero;
1786concept FmtParam =
requires {
1787 {std::remove_cvref_t<T>::kind} -> std::same_as<const unsigned&>;
1790template<FmtParam A, FmtParam B>
1791requires((A::kind & B::kind) == 0)
1792constexpr auto operator | (
const A&,
const B&) {
1793 return fmt_info<A, B, A::kind | B::kind>{};
1796inline constexpr align_info<int_align::left> l;
1797inline constexpr align_info<int_align::right> r;
1798inline constexpr align_info<int_align::center> c;
1801inline constexpr width_info<W> w;
1804inline constexpr fill_info<F> f;
1806inline constexpr sign_info<int_plus_sign::plus> sp;
1807inline constexpr sign_info<int_plus_sign::space> ss;
1808inline constexpr upper_info u;
1809inline constexpr prefix_info<int_prefix::lcase> p;
1810inline constexpr prefix_info<int_prefix::ucase> P;
1811inline constexpr zero_info z;
1813inline constexpr width_info<unsigned(-1)> wp;
1814inline constexpr fmt_default df;
1817struct extract_align : std::false_type {
1818 inline static constexpr int_align align = int_align::none;
1821template<
int_align A>
1822struct extract_align<align_info<A>> : std::true_type {
1823 inline static constexpr int_align align = A;
1826template<
typename A,
typename B,
unsigned U>
1827struct extract_align<fmt_info<A, B, U>> {
1828 inline static constexpr bool in_a = extract_align<A>::value, in_b = extract_align<B>::value, value = in_a | in_b;
1829 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;
1833struct extract_width : std::false_type {
1834 inline static constexpr size_t width = 0;
1838struct extract_width<width_info<W>> : std::true_type {
1839 inline static constexpr size_t width = W;
1842template<
typename A,
typename B,
unsigned U>
1843struct extract_width<fmt_info<A, B, U>> {
1844 inline static constexpr bool in_a = extract_width<A>::value, in_b = extract_width<B>::value, value = in_a | in_b;
1845 inline static constexpr size_t width = extract_width<std::conditional_t<in_a, A, std::conditional_t<in_b, B, width_info<0>>>>::width;
1849struct extract_fill : std::false_type {
1850 inline static constexpr unsigned fill =
' ';
1854struct extract_fill<fill_info<F>> : std::true_type {
1855 inline static constexpr unsigned fill = F;
1858template<
typename A,
typename B,
unsigned U>
1859struct extract_fill<fmt_info<A, B, U>> {
1860 inline static constexpr bool in_a = extract_fill<A>::value, in_b = extract_fill<B>::value, value = in_a | in_b;
1861 inline static constexpr unsigned fill = extract_fill<std::conditional_t<in_a, A, std::conditional_t<in_b, B, fill_info<
' '>>>>::fill;
1865struct extract_sign : std::false_type {
1866 inline static constexpr int_plus_sign sign = int_plus_sign::none;
1869template<
int_plus_sign S>
1870struct extract_sign<sign_info<S>> : std::true_type {
1871 inline static constexpr int_plus_sign sign = S;
1874template<
typename A,
typename B,
unsigned U>
1875struct extract_sign<fmt_info<A, B, U>> {
1876 inline static constexpr bool in_a = extract_sign<A>::value, in_b = extract_sign<B>::value, value = in_a | in_b;
1877 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;
1881struct extract_upper : std::false_type {};
1884struct extract_upper<upper_info> : std::true_type {};
1886template<
typename A,
typename B,
unsigned U>
1887struct extract_upper<fmt_info<A, B, U>> {
1888 inline static constexpr bool in_a = extract_upper<A>::value, in_b = extract_upper<B>::value,
1889 value = extract_upper<std::conditional_t<in_a, A, std::conditional_t<in_b, B, std::false_type>>>::value;
1893struct extract_prefix : std::false_type{
1894 inline static constexpr int_prefix prefix = int_prefix::none;
1897template<
int_prefix P>
1898struct extract_prefix<prefix_info<P>> : std::true_type {
1899 inline static constexpr int_prefix prefix = P;
1902template<
typename A,
typename B,
unsigned U>
1903struct extract_prefix<fmt_info<A, B, U>> {
1904 inline static constexpr bool in_a = extract_prefix<A>::value, in_b = extract_prefix<B>::value, value = in_a | in_b;
1905 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;
1909struct extract_zero : std::false_type{};
1912struct extract_zero<zero_info> : std::true_type {};
1914template<
typename A,
typename B,
unsigned U>
1915struct extract_zero<fmt_info<A, B, U>> {
1916 inline static constexpr bool in_a = extract_zero<A>::value, in_b = extract_zero<B>::value,
1917 value = extract_zero<std::conditional_t<in_a, A, std::conditional_t<in_b, B, std::false_type>>>::value;
1920template<
int_align Align,
unsigned W
idth,
unsigned Fill,
int_plus_sign Sign,
bool Upper,
int_prefix Prefix,
bool Zero>
1922 inline static constexpr int_align align = Align;
1923 inline static constexpr unsigned width = Width;
1924 inline static constexpr unsigned fill = Fill;
1925 inline static constexpr int_plus_sign sign = Sign;
1926 inline static constexpr bool upper = Upper;
1927 inline static constexpr int_prefix prefix = Prefix;
1928 inline static constexpr bool zero = Zero;
1932using p_to_fmt_t = fmt_params<
1933 extract_align<T>::align,
1934 extract_width<T>::width,
1935 extract_fill<T>::fill,
1936 extract_sign<T>::sign,
1937 extract_upper<T>::value,
1938 extract_prefix<T>::prefix,
1939 extract_zero<T>::value>;
1942using to_fmt_t = p_to_fmt_t<std::remove_cvref_t<T>>;
1945struct is_fmt_params : std::false_type{};
1947template<
int_align Align,
unsigned W
idth,
unsigned Fill,
int_plus_sign Sign,
bool Upper,
int_prefix Prefix,
bool Zero>
1948struct is_fmt_params<fmt_params<Align, Width, Fill, Sign, Upper, Prefix, Zero>> : std::true_type{};
1951concept FmtParamSet = is_fmt_params<T>::value;
1955template<f::FmtParam F>
1956constexpr auto operator|(
const F& f, fmt_end) {
1960template<
char C = 0,
char...Chars>
1961constexpr auto parse_fmt_symbol();
1963template<
unsigned N,
char C =
'Z',
char...Chars>
1964constexpr auto parse_width() {
1965 if constexpr (C >=
'0' && C <=
'9') {
1966 return parse_width<N * 10 + C -
'0', Chars...>();
1968 return w<N> | parse_fmt_symbol<C, Chars...>();
1972template<
unsigned N,
char C =
'Z',
char...Chars>
1973constexpr auto parse_fill() {
1974 if constexpr (C >=
'0' && C <=
'9') {
1975 return parse_fill<N * 16 + C -
'0', Chars...>();
1976 }
else if constexpr (C >=
'a' && C <=
'f') {
1977 return parse_fill<N * 16 + C -
'a' + 10, Chars...>();
1978 }
else if constexpr (C >=
'A' && C <=
'F') {
1979 return parse_fill<N * 16 + C -
'A' + 10, Chars...>();
1981 return f<N> | parse_fmt_symbol<C, Chars...>();
1985template<
char C,
char...Chars>
1986constexpr auto parse_fmt_symbol() {
1987 if constexpr (C ==
'0') {
1988 return z | parse_fmt_symbol<Chars...>();
1989 }
else if constexpr (C ==
'a') {
1990 return p | parse_fmt_symbol<Chars...>();
1991 }
else if constexpr (C ==
'A') {
1992 return P | parse_fmt_symbol<Chars...>();
1993 }
else if constexpr (C ==
'b') {
1994 return l | parse_fmt_symbol<Chars...>();
1995 }
else if constexpr (C ==
'c') {
1996 return c | parse_fmt_symbol<Chars...>();
1997 }
else if constexpr (C ==
'd') {
1998 return r | parse_fmt_symbol<Chars...>();
1999 }
else if constexpr (C ==
'e') {
2000 return sp | parse_fmt_symbol<Chars...>();
2001 }
else if constexpr (C ==
'f') {
2002 return ss | parse_fmt_symbol<Chars...>();
2003 }
else if constexpr (C ==
'E') {
2004 return u | parse_fmt_symbol<Chars...>();
2005 }
else if constexpr (C ==
'\'') {
2006 return parse_fmt_symbol<Chars...>();
2007 }
else if constexpr (C ==
'F') {
2008 return parse_fill<0, Chars...>();
2009 }
else if constexpr (C >=
'1' && C <=
'9') {
2010 return parse_width<C -
'0', Chars...>();
2016template<
unsigned R,
typename T>
2017struct fmt_radix_info {};
2019template<
unsigned N,
char C = 0,
char...Chars>
2020constexpr auto parse_radix() {
2021 if constexpr (C >=
'0' && C <=
'9') {
2022 return parse_radix<N * 10 + C -
'0', Chars...>();
2023 }
else if constexpr (C == 0) {
2024 return fmt_radix_info<N, to_fmt_t<fmt_default>>{};
2026 return fmt_radix_info<N,
decltype(parse_fmt_symbol<C, Chars...>())>{};
2030template<
char C1,
char C2,
char C3,
char...Chars>
2031constexpr auto skip_0x() {
2032 static_assert(C1 ==
'0' && C2 ==
'x' &&
"Fmt symbols must begin with 0x");
2033 static_assert(C3 >=
'1' && C3 <=
'9' &&
"Radix must begin with 1-9");
2034 return parse_radix<C3 -
'0', Chars...>();
2039template<
typename K,
bool Ucase>
2040inline 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'),
2041 K(Ucase ?
'A' :
'a'), K(Ucase ?
'B' :
'b'), K(Ucase ?
'C' :
'c'), K(Ucase ?
'D' :
'd'), K(Ucase ?
'E' :
'e'),
2042 K(Ucase ?
'F' :
'f'), K(Ucase ?
'G' :
'g'), K(Ucase ?
'H' :
'h'), K(Ucase ?
'I' :
'i'), K(Ucase ?
'J' :
'j'),
2043 K(Ucase ?
'K' :
'k'), K(Ucase ?
'L' :
'l'), K(Ucase ?
'M' :
'm'), K(Ucase ?
'N' :
'n'), K(Ucase ?
'O' :
'o'),
2044 K(Ucase ?
'P' :
'p'), K(Ucase ?
'Q' :
'q'), K(Ucase ?
'R' :
'r'), K(Ucase ?
'S' :
's'), K(Ucase ?
'T' :
't'),
2045 K(Ucase ?
'U' :
'u'), K(Ucase ?
'V' :
'v'), K(Ucase ?
'W' :
'w'), K(Ucase ?
'X' :
'x'), K(Ucase ?
'Y' :
'y'),
2046 K(Ucase ?
'Z' :
'z'),
2049template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2050struct expr_integer_src {
2053 constexpr expr_integer_src(T v) : value_(v){}
2054 constexpr expr_integer_src(T v,
unsigned w) : value_(v), width_(w){}
2056 template<is_std_
string_v S>
2059 template<
typename S>
requires std::is_constructible_v<S, empty_expr<typename S::symb_type>>
2063template<is_one_of_
char_v K, FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
2064requires (Radix > 1 && Radix <= 36)
2066 using symb_type = K;
2068 enum { bufSize = 64 };
2069 mutable K buf[bufSize];
2073 mutable bool negate_{};
2075 constexpr expr_integer(T t) : value_(t){}
2076 constexpr expr_integer(T t,
unsigned w) : value_(t), width_(w){}
2077 constexpr expr_integer(
const expr_integer_src<T, Radix, FP>& v) : value_(v.value_), width_(v.width_){}
2079 constexpr expr_integer(expr_integer&& t) noexcept : value_(t.value_), width_(t.width_){}
2081 constexpr size_t length() const noexcept {
2082 K* bufEnd = std::end(buf), *itr = bufEnd;
2085 need_sign<K, std::is_signed_v<T>, T> store(value_);
2087 *--itr = digits_symbols<K, FP::upper>[store.val % Radix];
2090 if constexpr (std::is_signed_v<T>) {
2091 negate_ = store.negate;
2094 *--itr = digits_symbols<K, FP::upper>[0];
2096 size_t len = bufEnd - itr;
2098 if constexpr (std::is_signed_v<T>) {
2099 if constexpr (FP::sign != f::int_plus_sign::none) {
2107 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2109 if constexpr (Radix != 8) {
2113 if constexpr (FP::width == unsigned(-1)) {
2114 return std::max<size_t>(width_, len);
2116 return std::max<size_t>(FP::width, len);
2119 constexpr K* place(K* ptr)
const noexcept {
2120 size_t len =
static_cast<size_t>(value_), all_len = len;
2121 if constexpr (std::is_signed_v<T>) {
2122 if constexpr (FP::sign != f::int_plus_sign::none) {
2130 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2132 if constexpr (Radix != 8) {
2136 if constexpr (FP::zero) {
2137 if constexpr (std::is_signed_v<T>) {
2141 if constexpr (FP::sign == f::int_plus_sign::plus) {
2143 }
else if constexpr (FP::sign == f::int_plus_sign::space) {
2148 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2150 if constexpr (Radix == 2) {
2151 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'b') : K(
'B');
2152 }
else if constexpr (Radix == 16) {
2153 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'x') : K(
'X');
2157 if constexpr (FP::width == unsigned(-1)) {
2158 if (width_ > all_len) {
2159 before = width_ - all_len;
2162 if (FP::width > all_len) {
2163 before = FP::width - all_len;
2167 ch_traits<K>::assign(ptr, before, K(
'0'));
2170 ch_traits<K>::copy(ptr, std::end(buf) - len, len);
2173 size_t before = 0, after = 0;
2174 if constexpr (FP::width == unsigned(-1)) {
2175 if (width_ > all_len) {
2176 if constexpr (FP::align == f::int_align::left) {
2177 after = width_ - all_len;
2178 }
else if constexpr (FP::align == f::int_align::center) {
2179 before = (width_ - all_len) / 2;
2180 after = width_ - all_len - before;
2182 before = width_ - all_len;
2186 if (FP::width > all_len) {
2187 if constexpr (FP::align == f::int_align::left) {
2188 after = FP::width - all_len;
2189 }
else if constexpr (FP::align == f::int_align::center) {
2190 before = (FP::width - all_len) / 2;
2191 after = FP::width - all_len - before;
2193 before = FP::width - all_len;
2198 ch_traits<K>::assign(ptr, before, K(FP::fill));
2201 if constexpr (std::is_signed_v<T>) {
2205 if constexpr (FP::sign == f::int_plus_sign::plus) {
2207 }
else if constexpr (FP::sign == f::int_plus_sign::space) {
2212 if constexpr (FP::prefix != f::int_prefix::none && (Radix == 2 || Radix == 8 || Radix == 16)) {
2214 if constexpr (Radix == 2) {
2215 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'b') : K(
'B');
2216 }
else if constexpr (Radix == 16) {
2217 *ptr++ = FP::prefix == f::int_prefix::lcase ? K(
'x') : K(
'X');
2220 ch_traits<K>::copy(ptr, std::end(buf) - len, len);
2224 ch_traits<K>::assign(ptr, after, K(FP::fill));
2232template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2233template<is_std_string_v S>
2234expr_integer_src<T, Radix, FP>::operator S()
const {
2235 using st =
typename S::value_type;
2236 using Al =
typename S::allocator_type;
2237 return to_std_string<st, Al>(expr_integer<st, T, Radix, FP>{value_, width_});
2240template<FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
requires (Radix > 1 && Radix <= 36)
2242expr_integer_src<T, Radix, FP>::operator S()
const {
2243 using st =
typename S::symb_type;
2244 return S{expr_integer<st, T, Radix, FP>{value_, width_}};
2247template<
typename K, FromIntNumber T,
unsigned Radix, f::FmtParamSet FP>
2248struct convert_to_strexpr<K, expr_integer_src<T, Radix, FP>> {
2249 using type = expr_integer<K, T, Radix, FP>;
2252template<
unsigned R,
typename T,
typename F>
2253struct flags_checker {
2255 using flags_t = f::to_fmt_t<F>;
2256 inline static constexpr unsigned Radix = R;
2259template<
typename T,
bool ArgW
idth>
2260concept good_int_flags =
2261 T::Radix > 1 && T::Radix <= 36
2264 && (T::flags_t::align == f::int_align::none || !T::flags_t::zero)
2267 && (std::is_signed_v<typename T::val_t> || T::flags_t::sign == f::int_plus_sign::none)
2270 && (T::flags_t::width == unsigned(-1)) == ArgWidth
2273 && (T::flags_t::prefix == f::int_prefix::none || T::Radix == 2 || T::Radix == 8 || T::Radix == 16);
2382template<
unsigned R, auto fp = f::df, FromIntNumber T>
requires good_int_flags<flags_checker<R, T,
decltype(fp)>,
false>
2384 using fmt_param = f::to_fmt_t<
decltype(fp)>;
2385 return expr_integer_src<T, R, fmt_param>{v};
2391template<
unsigned R, auto fp = f::df, FromIntNumber T>
requires good_int_flags<flags_checker<R, T,
decltype(fp)>,
true>
2393 using fmt_param = f::to_fmt_t<
decltype(fp)>;
2394 return expr_integer_src<T, R, fmt_param>{v, w};
2397template<
typename T,
unsigned R,
typename F>
requires good_int_flags<flags_checker<R, T, F>,
false>
2398auto operator / (T v,
const f::fmt_radix_info<R, F>&) {
2399 return expr_integer_src<T, R, f::to_fmt_t<F>>{v};
2404 using symb_type = K;
2405 mutable u8s buf[40];
2408 constexpr expr_real(
double d) : v(d) {}
2409 constexpr expr_real(
float d) : v(d) {}
2411 size_t length() const noexcept {
2412 auto [ptr, ec] = std::to_chars(buf, buf + std::size(buf), v);
2413 l = ec != std::errc{} ? 0 : ptr - buf;
2416 K* place(K* ptr)
const noexcept {
2417 if constexpr (
sizeof(K) ==
sizeof(buf[0])) {
2418 ch_traits<K>::copy(ptr, (K*)buf, l);
2420 for (
size_t i = 0; i < l; i++) {
2438template<
typename K, std::
floating_po
int T>
2439struct convert_to_strexpr<K, T> {
2440 using type = expr_real<K>;
2454template<
typename K>
requires is_one_of_char_v<K>
2455inline constexpr expr_real<K>
e_num(
double t) {
2459template<FromIntNumber Val,
bool All,
bool Ucase,
bool Ox>
2460struct expr_hex_src {
2461 explicit constexpr expr_hex_src(Val v) : v_(v){}
2465template<
typename K, FromIntNumber Val,
bool All,
bool Ucase,
bool Ox>
2467 using symb_type = K;
2468 mutable need_sign<K, std::is_signed_v<Val>, Val> v_;
2469 mutable K buf_[
sizeof(Val) * 2]{};
2471 explicit constexpr expr_hex(Val v) : v_(v){}
2472 constexpr expr_hex(
const expr_hex_src<Val, All, Ucase, Ox>& v) : v_(v.v_){}
2474 constexpr size_t length() const noexcept {
2475 K *ptr = buf_ + std::size(buf_);
2478 *--ptr = digits_symbols<K, Ucase>[v_.val & 0xF];
2482 *--ptr = digits_symbols<K, Ucase>[v_.val & 0xF];
2487 if constexpr (All) {
2488 if (
size_t need =
sizeof(Val) * 2 - l) {
2489 ch_traits<K>::assign(buf_, need, K(
'0'));
2491 l =
sizeof(Val) * 2;
2497 if constexpr (std::is_signed_v<Val>) {
2498 return l + (Ox ? 2 : 0) + (v_.negate ? 1 : 0);
2500 return l + (Ox ? 2 : 0);
2502 constexpr K* place(K* ptr)
const noexcept {
2503 if constexpr (std::is_signed_v<Val>) {
2512 if constexpr (All) {
2513 ch_traits<K>::copy(ptr, buf_,
sizeof(Val) * 2);
2514 return ptr +
sizeof(Val) * 2;
2516 ch_traits<K>::copy(ptr, buf_ + std::size(buf_) - v_.val, v_.val);
2517 return ptr + v_.val;
2583template<
unsigned Flags = 0, FromIntNumber T>
2585 return expr_hex_src<T, (Flags &
HexFlags::Short) == 0, (Flags & HexFlags::Lcase) == 0, (Flags & HexFlags::No0x) == 0>{v};
2588template<
char c = 0,
char...Chars>
2589constexpr unsigned parse_f16_flags() {
2590 if constexpr (c ==
'1') {
2592 }
else if constexpr (c ==
'2') {
2593 return HexFlags::Lcase | parse_f16_flags<Chars...>();
2594 }
else if constexpr (c ==
'3') {
2595 return HexFlags::No0x | parse_f16_flags<Chars...>();
2604template<FromIntNumber T,
unsigned Flags>
2605constexpr auto operator/(T v,
const f16flags<Flags>&) {
2606 return expr_hex_src<T, (Flags &
HexFlags::Short) == 0, (Flags & HexFlags::Lcase) == 0, (Flags & HexFlags::No0x) == 0>{v};
2609inline namespace literals {
2610template<
char...Chars>
2611constexpr auto operator""_f16() {
2612 return f16flags<parse_f16_flags<Chars...>()>{};
2624template<
typename K,
typename Val,
bool All,
bool Ucase,
bool Ox>
2625struct convert_to_strexpr<K, expr_hex_src<Val, All, Ucase, Ox>> {
2626 using type = expr_hex<K, Val, All, Ucase, Ox>;
2630struct expr_pointer : expr_hex<K, uintptr_t, true, true, true> {
2631 constexpr expr_pointer(
const void* ptr) : expr_hex<K, uintptr_t, true, true, true>((uintptr_t)ptr){}
2642template<
typename K,
typename T>
2643struct convert_to_strexpr<K, const T*> {
2644 using type = expr_pointer<K>;
2647template<
typename K, StrExprForType<K> A,
bool Left>
2649 using symb_type = K;
2653 mutable size_t alen_{};
2654 constexpr expr_fill(K symbol,
size_t width,
const A& a) : symbol_(symbol), width_(width), a_(a){}
2656 constexpr size_t length() const noexcept {
2657 alen_ = a_.length();
2658 return std::max(alen_, width_);
2660 constexpr K* place(K* ptr)
const noexcept {
2661 if (alen_ >= width_) {
2662 return (K*)a_.place((
typename A::symb_type*)ptr);
2664 size_t w = width_ - alen_;
2665 if constexpr (Left) {
2666 ch_traits<K>::assign(ptr, w, symbol_);
2668 return (K*)a_.place((
typename A::symb_type*)ptr);
2670 ptr = (K*)a_.place((
typename A::symb_type*)ptr);
2671 ch_traits<K>::assign(ptr, w, symbol_);
2698template<StrExpr A,
typename K =
typename A::symb_type>
2699expr_fill<K, A, true>
e_fill_left(
const A& a,
size_t width, K symbol = K(
' ')) {
2700 return {symbol, width, a};
2724template<StrExpr A,
typename K =
typename A::symb_type>
2725expr_fill<K, A, false>
e_fill_right(
const A& a,
size_t width, K symbol = K(
' ')) {
2726 return {symbol, width, a};
2745template<
typename K,
typename T,
size_t I,
bool tail,
bool skip_empty>
2746struct expr_join : expr_to_std_string<expr_join<K, T, I, tail, skip_empty>> {
2747 using symb_type = K;
2748 using my_type = expr_join<K, T, I, tail, skip_empty>;
2752 constexpr expr_join(
const T& _s,
const K* _delim) : s(_s), delim(_delim){}
2754 constexpr size_t length() const noexcept {
2756 for (
const auto& t: s) {
2757 size_t len = t.length();
2758 if (len > 0 || !skip_empty) {
2759 if (I > 0 && l > 0) {
2765 return l + (tail && I > 0 && (l > 0 || (!skip_empty && s.size() > 0))? I : 0);
2767 constexpr K* place(K* ptr)
const noexcept {
2772 for (
const auto& t: s) {
2773 size_t copyLen = t.length();
2774 if (I > 0 && write != ptr && (copyLen || !skip_empty)) {
2775 ch_traits<K>::copy(write, delim, I);
2778 ch_traits<K>::copy(write, t.data(), copyLen);
2781 if (I > 0 && tail && (write != ptr || (!skip_empty && s.size() > 0))) {
2782 ch_traits<K>::copy(write, delim, I);
2802template<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>
2803inline constexpr auto e_join(
const T& s, L&& d) {
2804 return expr_join<K, T, I - 1, tail, skip_empty>{s, d};
2808concept is_const_pattern = N > 1 && N <= 17;
2810template<
typename K,
size_t I>
2812 constexpr static const size_t value = size_t(K(~0x7F)) << ((I - 1) *
sizeof(K) * 8) | _ascii_mask<K, I - 1>::value;
2816struct _ascii_mask<K, 0> {
2817 constexpr static const size_t value = 0;
2822 using uns = std::make_unsigned_t<K>;
2823 constexpr static const size_t WIDTH =
sizeof(size_t) /
sizeof(uns);
2824 constexpr static const size_t VALUE = _ascii_mask<uns, WIDTH>::value;
2828constexpr inline bool isAsciiUpper(K k) {
2829 return k >=
'A' && k <=
'Z';
2833constexpr inline bool isAsciiLower(K k) {
2834 return k >=
'a' && k <=
'z';
2838constexpr inline K makeAsciiLower(K k) {
2839 return isAsciiUpper(k) ? k | 0x20 : k;
2843constexpr inline K makeAsciiUpper(K k) {
2844 return isAsciiLower(k) ? k & ~0x20 : k;
2847enum TrimSides { TrimLeft = 1, TrimRight = 2, TrimAll = 3 };
2848template<TrimS
ides S,
typename K,
size_t N,
bool withSpaces = false>
2849struct trim_operator;
2852struct digits_selector {
2853 using wider_type = uint16_t;
2857struct digits_selector<2> {
2858 using wider_type = uint32_t;
2862struct digits_selector<4> {
2863 using wider_type = uint64_t;
2877template<
bool CanNegate,
bool CheckOverflow,
typename T>
2878struct result_type_selector {
2883struct result_type_selector<true, false, T> {
2884 using type = std::make_unsigned_t<T>;
2887template<
unsigned Base>
2888constexpr unsigned digit_width() {
2907template<
typename T,
unsigned Base>
2908constexpr unsigned max_overflow_digits = (
sizeof(T) * CHAR_BIT) / digit_width<Base>();
2911struct convert_result {
2918 inline static constexpr uint8_t NUMBERS[] = {
2919 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,
2920 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,
2921 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,
2922 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,
2923 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,
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, 255, 255, 255, 255,
2927 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,
2928 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255};
2930 template<
typename K,
unsigned Base>
2931 static constexpr std::make_unsigned_t<K> toDigit(K s) {
2932 auto us =
static_cast<std::make_unsigned_t<K>
>(s);
2933 if constexpr (Base <= 10) {
2936 if constexpr (
sizeof(K) == 1) {
2939 return us < 256 ? NUMBERS[us] : us;
2944 template<
typename K, ToIntNumber T,
unsigned Base,
bool CheckOverflow>
2946 static constexpr convert_result<T> parse(
const K* start,
const K* current,
const K* end,
bool negate) {
2947 using u_type = std::make_unsigned_t<T>;
2948 #ifndef HAS_BUILTIN_OVERFLOW
2949 u_type maxMult = 0, maxAdd = 0;
2950 if constexpr (CheckOverflow) {
2951 maxMult = std::numeric_limits<u_type>::max() / Base;
2952 maxAdd = std::numeric_limits<u_type>::max() % Base;
2956 unsigned maxDigits = max_overflow_digits<u_type, Base>;
2958 const K* from = current;
2960 bool no_need_check_o_f = !CheckOverflow || end - current <= maxDigits;
2962 if (no_need_check_o_f) {
2964 const u_type digit = toDigit<K, Base>(*current);
2965 if (digit >= Base) {
2968 number = number * Base + digit;
2969 if (++current == end) {
2975 for (;maxDigits; maxDigits--) {
2976 const u_type digit = toDigit<K, Base>(*current);
2977 if (digit >= Base) {
2980 number = number * Base + digit;
2987 const u_type digit = toDigit<K, Base>(*current);
2988 if (digit >= Base) {
2991 #ifdef HAS_BUILTIN_OVERFLOW
2992 if (__builtin_mul_overflow(number, Base, &number) ||
2993 __builtin_add_overflow(number, digit, &number)) {
2995 if (number < maxMult || (number == maxMult && number < maxAdd)) {
2996 number = number * Base + digit;
3000 while(++current < end) {
3001 if (toDigit<K, Base>(*current) >= Base) {
3007 if (++current == end) {
3015 if constexpr (std::is_signed_v<T>) {
3016 result = negate ? 0 - number : number;
3017 if constexpr (CheckOverflow) {
3019 if (number > (u_type)std::numeric_limits<T>::max() + (negate ? 1 : 0)) {
3030 return {result, error, size_t(current - start)};
3037 template<
typename K, ToIntNumber T,
unsigned Base = 0,
bool CheckOverflow = true,
bool SkipWs = true,
bool AllowSign = true>
3038 requires(Base == -1 || (Base < 37 && Base != 1))
3039 static constexpr convert_result<T> to_integer(
const K* start,
size_t len)
noexcept {
3040 const K *ptr = start, *end = ptr + len;
3041 bool negate =
false;
3042 if constexpr (SkipWs) {
3043 while (ptr < end && std::make_unsigned_t<K>(*ptr) <=
' ')
3047 if constexpr (std::is_signed_v<T>) {
3048 if constexpr (AllowSign) {
3053 }
else if (*ptr ==
'-') {
3065 }
else if constexpr (AllowSign) {
3074 if constexpr (Base == 0 || Base == -1) {
3078 if (*ptr ==
'x' || *ptr ==
'X') {
3079 return parse<K, T, 16, CheckOverflow>(start, ++ptr, end, negate);
3081 if constexpr (Base == -1) {
3082 if (*ptr ==
'b' || *ptr ==
'B') {
3083 return parse<K, T, 2, CheckOverflow>(start, ++ptr, end, negate);
3085 if (*ptr ==
'o' || *ptr ==
'O') {
3086 return parse<K, T, 8, CheckOverflow>(start, ++ptr, end, negate);
3089 return parse<K, T, 8, CheckOverflow>(start, --ptr, end, negate);
3093 return parse<K, T, 10, CheckOverflow>(start, ptr, end, negate);
3095 return parse<K, T, Base, CheckOverflow>(start, ptr, end, negate);
3101template<
typename K,
typename Impl>
3102class null_terminated {
3110 constexpr const K* c_str()
const {
return static_cast<const Impl*
>(
this)->symbols(); }
3113template<
typename K,
typename Impl,
bool Mutable>
class buffer_pointers;
3123template<
typename K,
typename Impl>
3124class buffer_pointers<K, Impl, false> {
3125 constexpr const Impl& d()
const {
return *
static_cast<const Impl*
>(
this); }
3133 constexpr const K* data()
const {
return d().symbols(); }
3140 constexpr const K* begin()
const {
return d().symbols(); }
3147 constexpr const K* end()
const {
return d().symbols() + d().length(); }
3154 constexpr const K* cbegin()
const {
return d().symbols(); }
3161 constexpr const K* cend()
const {
return d().symbols() + d().length(); }
3164template<
typename K,
typename Impl>
3165class buffer_pointers<K, Impl, true> :
public buffer_pointers<K, Impl, false> {
3166 constexpr Impl& d() {
return *
static_cast<Impl*
>(
this); }
3167 using base = buffer_pointers<K, Impl, false>;
3175 constexpr const K* data()
const {
return base::data(); }
3182 constexpr const K* begin()
const {
return base::begin(); }
3189 constexpr const K* end()
const {
return base::end(); }
3196 constexpr const K* cbegin()
const {
return base::cbegin(); }
3203 constexpr const K* cend()
const {
return base::cend(); }
3210 constexpr K* data() {
return d().str(); }
3217 constexpr K* begin() {
return d().str(); }
3224 constexpr K* end() {
return d().str() + d().length(); }
3233template<
typename K,
typename StrSrc>
3235 using str_t = StrSrc;
3240 constexpr SplitterBase(str_t text, str_t delim) : text_(text), delim_(delim) {}
3246 return text_.length() == str::npos;
3255 if (!text_.length()) {
3260 }
else if (text_.length() == str::npos) {
3261 return {
nullptr, 0};
3263 size_t pos = text_.find(delim_),
next = 0;
3264 if (pos == str::npos) {
3265 pos = text_.length();
3268 next = pos + delim_.length();
3270 str_t result{text_.str, pos};
3301template<
typename K,
typename StrRef,
typename Impl,
bool Mutable>
3302class str_src_algs :
public buffer_pointers<K, Impl, Mutable> {
3303 constexpr const Impl& d()
const noexcept {
3304 return *
static_cast<const Impl*
>(
this);
3306 constexpr size_t _len()
const noexcept {
3307 return d().length();
3309 constexpr const K* _str()
const noexcept {
3310 return d().symbols();
3312 constexpr bool _is_empty()
const noexcept {
3313 return d().is_empty();
3317 using symb_type = K;
3318 using str_piece = StrRef;
3319 using traits = ch_traits<K>;
3320 using uns_type = std::make_unsigned_t<K>;
3321 using my_type = Impl;
3322 using base = str_src_algs<K, StrRef, Impl, Mutable>;
3323 str_src_algs() =
default;
3337 constexpr K*
place(K* ptr)
const noexcept {
3338 size_t myLen = _len();
3339 traits::copy(ptr, _str(), myLen);
3353 size_t tlen = std::min(_len(), bufSize - 1);
3354 traits::copy(buffer, _str(), tlen);
3374 constexpr std::basic_string_view<D>
to_sv() const noexcept {
3375 return {(
const D*)_str(), _len()};
3384 constexpr operator std::basic_string_view<D, Traits>()
const {
3385 return {(
const D*)_str(), _len()};
3393 template<
typename D = K,
typename Traits = std::
char_traits<D>,
typename Allocator = std::allocator<D>>
requires is_equal_str_type_v<K, D>
3394 constexpr std::basic_string<D, Traits, Allocator>
to_string()
const {
3395 return {(
const D*)_str(), _len()};
3404 constexpr operator std::basic_string<D, Traits, Allocator>()
const {
3405 return {(
const D*)_str(), _len()};
3413 constexpr operator str_piece() const noexcept {
3414 return str_piece{_str(), _len()};
3422 constexpr str_piece
to_str() const noexcept {
3423 return {_str(), _len()};
3448 constexpr str_piece
operator()(ptrdiff_t from, ptrdiff_t len = 0) const noexcept {
3449 size_t myLen = _len(), idxStart = from >= 0 ? from : (ptrdiff_t)myLen > -from ? myLen + from : 0,
3450 idxEnd = len > 0 ? idxStart + len : (ptrdiff_t)myLen > -len ? myLen + len : 0;
3453 if (idxStart > idxEnd)
3455 return str_piece{_str() + idxStart, idxEnd - idxStart};
3467 constexpr str_piece
mid(
size_t from,
size_t len = -1) const noexcept {
3468 size_t myLen = _len(), idxStart = from, idxEnd = from > std::numeric_limits<size_t>::max() - len ? myLen : from + len;
3471 if (idxStart > idxEnd)
3473 return str_piece{_str() + idxStart, idxEnd - idxStart};
3489 constexpr str_piece
from_to(
size_t from,
size_t to)
const noexcept {
3490 return str_piece{_str() + from, to - from};
3502 constexpr str_piece
until(str_piece pattern,
size_t offset = 0) const noexcept {
3522 constexpr K
at(ptrdiff_t idx)
const {
3523 return _str()[idx >= 0 ? idx : _len() + idx];
3527 constexpr int compare(
const K* text,
size_t len)
const {
3528 size_t myLen = _len();
3529 int cmp = traits::compare(_str(), text, std::min(myLen, len));
3530 return cmp == 0 ? (myLen > len ? 1 : myLen == len ? 0 : -1) : cmp;
3541 return compare(o.symbols(), o.length());
3552 size_t myLen = _len(), idx = 0;
3553 const K* ptr = _str();
3554 for (; idx < myLen; idx++) {
3555 uns_type s1 = (uns_type)text[idx];
3559 uns_type s2 = (uns_type)ptr[idx];
3562 }
else if (s1 > s2) {
3566 return text[idx] == 0 ? 0 : -1;
3569 constexpr bool equal(
const K* text,
size_t len)
const noexcept {
3570 return len == _len() && traits::compare(_str(), text, len) == 0;
3580 constexpr bool equal(str_piece other)
const noexcept {
3581 return equal(other.symbols(), other.length());
3592 return equal(other._str(), other._len());
3601 return compare(other._str(), other._len()) <=> 0;
3609 template<typename T, size_t N = const_lit_for<K, T>::Count>
3611 return N - 1 == _len() && traits::compare(_str(), (
const K*)other, N - 1) == 0;
3619 template<typename T, size_t N = const_lit_for<K, T>::Count>
3621 size_t myLen = _len();
3622 int cmp = traits::compare(_str(), (
const K*)other, std::min(myLen, N - 1));
3623 int res = cmp == 0 ? (myLen > N - 1 ? 1 : myLen == N - 1 ? 0 : -1) : cmp;
3629 constexpr int compare_ia(
const K* text,
size_t len)
const noexcept {
3631 return _is_empty() ? 0 : 1;
3632 size_t myLen = _len(), checkLen = std::min(myLen, len);
3633 const uns_type *ptr1 =
reinterpret_cast<const uns_type*
>(_str()), *ptr2 =
reinterpret_cast<const uns_type*
>(text);
3634 while (checkLen--) {
3635 uns_type s1 = *ptr1++, s2 = *ptr2++;
3638 s1 = makeAsciiLower(s1);
3639 s2 = makeAsciiLower(s2);
3645 return myLen == len ? 0 : myLen > len ? 1 : -1;
3656 return compare_ia(text.symbols(), text.length());
3667 constexpr bool equal_ia(str_piece text)
const noexcept {
3668 return text.length() == _len() && compare_ia(text.symbols(), text.length()) == 0;
3678 constexpr bool less_ia(str_piece text)
const noexcept {
3679 return compare_ia(text.symbols(), text.length()) < 0;
3682 constexpr size_t find(
const K* pattern,
size_t lenPattern,
size_t offset)
const noexcept {
3683 size_t lenText = _len();
3686 if (!lenPattern || offset >= lenText || offset + lenPattern > lenText)
3689 const K *text = _str(), *last = text + lenText - lenPattern, first = pattern[0];
3691 for (
const K* fnd = text + offset;; ++fnd) {
3692 fnd = traits::find(fnd, last - fnd, first);
3695 if (traits::compare(fnd + 1, pattern, lenPattern) == 0)
3696 return static_cast<size_t>(fnd - text);
3709 constexpr size_t find(str_piece pattern,
size_t offset = 0) const noexcept {
3710 return find(pattern.symbols(), pattern.length(), offset);
3728 template<
typename Exc,
typename ... Args>
requires std::is_constructible_v<Exc, Args...>
3729 constexpr size_t find_or_throw(str_piece pattern,
size_t offset = 0, Args&& ... args)
const noexcept {
3730 if (
auto fnd = find(pattern.symbols(), pattern.length(), offset); fnd != str::npos) {
3733 throw Exc(std::forward<Args>(args)...);
3745 constexpr size_t find_end(str_piece pattern,
size_t offset = 0) const noexcept {
3746 size_t fnd = find(pattern.symbols(), pattern.length(), offset);
3747 return fnd == str::npos ? fnd : fnd + pattern.length();
3759 constexpr size_t find_or_all(str_piece pattern,
size_t offset = 0) const noexcept {
3760 auto fnd = find(pattern.symbols(), pattern.length(), offset);
3761 return fnd == str::npos ? _len() : fnd;
3774 auto fnd = find(pattern.symbols(), pattern.length(), offset);
3775 return fnd == str::npos ? _len() : fnd + pattern.length();
3778 constexpr size_t find_last(
const K* pattern,
size_t lenPattern,
size_t offset)
const noexcept {
3779 if (lenPattern == 1)
3780 return find_last(pattern[0], offset);
3781 size_t lenText = std::min(_len(), offset);
3784 if (!lenPattern || lenPattern > lenText)
3788 const K *text = _str() + lenPattern, last = pattern[lenPattern];
3789 lenText -= lenPattern;
3791 if (text[--lenText] == last) {
3792 if (traits::compare(text + lenText - lenPattern, pattern, lenPattern) == 0) {
3809 constexpr size_t find_last(str_piece pattern,
size_t offset = -1) const noexcept {
3810 return find_last(pattern.symbols(), pattern.length(), offset);
3823 size_t fnd = find_last(pattern.symbols(), pattern.length(), offset);
3824 return fnd == str::npos ? fnd : fnd + pattern.length();
3837 auto fnd = find_last(pattern.symbols(), pattern.length(), offset);
3838 return fnd == str::npos ? _len() : fnd;
3851 size_t fnd = find_last(pattern.symbols(), pattern.length(), offset);
3852 return fnd == str::npos ? _len() : fnd + pattern.length();
3864 constexpr bool contains(str_piece pattern,
size_t offset = 0) const noexcept {
3865 return find(pattern, offset) != str::npos;
3877 constexpr size_t find(K s,
size_t offset = 0) const noexcept {
3878 size_t len = _len();
3880 const K *
str = _str(), *fnd = traits::find(
str + offset, len - offset, s);
3882 return static_cast<size_t>(fnd -
str);
3897 size_t len = _len();
3899 const K *
str = _str(), *fnd = traits::find(
str + offset, len - offset, s);
3901 return static_cast<size_t>(fnd -
str);
3906 template<
typename Op>
3907 constexpr void for_all_finded(
const Op& op,
const K* pattern,
size_t patternLen,
size_t offset,
size_t maxCount)
const {
3910 while (maxCount-- > 0) {
3911 size_t fnd = find(pattern, patternLen, offset);
3912 if (fnd == str::npos)
3915 offset = fnd + patternLen;
3930 template<
typename Op>
3931 constexpr void for_all_finded(
const Op& op, str_piece pattern,
size_t offset = 0,
size_t maxCount = 0)
const {
3932 for_all_finded(op, pattern.symbols(), pattern.length(), offset, maxCount);
3935 template<
typename To = std::vector<
size_t>>
3936 constexpr To find_all(
const K* pattern,
size_t patternLen,
size_t offset,
size_t maxCount)
const {
3938 for_all_finded([&](
auto f) { result.emplace_back(f); }, pattern, patternLen, offset, maxCount);
3953 template<
typename To = std::vector<
size_t>>
3954 constexpr To
find_all(str_piece pattern,
size_t offset = 0,
size_t maxCount = 0)
const {
3955 return find_all(pattern.symbols(), pattern.length(), offset, maxCount);
3957 template<
typename To = std::vector<
size_t>>
3958 constexpr void find_all_to(To& to,
const K* pattern,
size_t len,
size_t offset = 0,
size_t maxCount = 0)
const {
3959 return for_all_finded([&](
size_t pos) {
3960 to.emplace_back(pos);
3961 }, pattern, len, offset, maxCount);
3973 constexpr size_t find_last(K s,
size_t offset = -1) const noexcept {
3974 size_t len = std::min(_len(), offset);
3975 const K *text = _str();
3977 if (text[--len] == s)
3992 constexpr size_t find_first_of(str_piece pattern,
size_t offset = 0) const noexcept {
3993 return std::basic_string_view<K>{_str(), _len()}.find_first_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4005 constexpr std::pair<size_t, size_t>
find_first_of_idx(str_piece pattern,
size_t offset = 0) const noexcept {
4006 const K* text = _str();
4007 size_t fnd = std::basic_string_view<K>{text, _len()}.find_first_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4008 return {fnd, fnd == std::basic_string<K>::npos ? fnd : pattern.find(text[fnd]) };
4021 return std::basic_string_view<K>{_str(), _len()}.find_first_not_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4033 constexpr size_t find_last_of(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4034 return std::basic_string_view<K>{_str(), _len()}.find_last_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4046 constexpr std::pair<size_t, size_t>
find_last_of_idx(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4047 const K* text = _str();
4048 size_t fnd = std::basic_string_view<K>{text, _len()}.find_last_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4049 return {fnd, fnd == std::basic_string<K>::npos ? fnd : pattern.find(text[fnd]) };
4061 constexpr size_t find_last_not_of(str_piece pattern,
size_t offset = str::npos)
const noexcept {
4062 return std::basic_string_view<K>{_str(), _len()}.find_last_not_of(std::basic_string_view<K>{pattern.str, pattern.len}, offset);
4074 constexpr my_type
substr(ptrdiff_t from, ptrdiff_t len = 0)
const {
4075 return my_type{d()(from, len)};
4087 constexpr my_type
str_mid(
size_t from,
size_t len = -1)
const {
4088 return my_type{d().mid(from, len)};
4118 template<ToIntNumber T,
bool CheckOverflow = true,
unsigned Base = 0,
bool SkipWs = true,
bool AllowSign = true>
4120 auto [res, err, _] = int_convert::to_integer<K, T, Base, CheckOverflow, SkipWs, AllowSign>(_str(), _len());
4151 template<ToIntNumber T,
bool CheckOverflow = true,
unsigned Base = 0,
bool SkipWs = true,
bool AllowSign = true>
4152 constexpr convert_result<T>
to_int() const noexcept {
4153 return int_convert::to_integer<K, T, Base, CheckOverflow, SkipWs, AllowSign>(_str(), _len());
4161 template<
bool SkipWS = true,
bool AllowPlus = true>
4162 requires(
sizeof(K) == 1 &&
4163 requires { std::from_chars(std::declval<K*>(), std::declval<K*>(), std::declval<double&>()); })
4165 size_t len = _len();
4166 const K* ptr = _str();
4167 if constexpr (SkipWS) {
4168 while (len && uns_type(*ptr) <=
' ') {
4173 if constexpr (AllowPlus) {
4174 if (len && *ptr == K(
'+')) {
4182 if constexpr (
requires { std::from_chars(std::declval<K*>(), std::declval<K*>(), std::declval<double&>()); }) {
4184 if (std::from_chars((
const K*)ptr, (
const K*)ptr + len, d).ec == std::errc{}) {
4196 template<
bool SkipWS = true>
4197 requires(
sizeof(K) == 1 &&
4198 requires { std::from_chars(std::declval<K*>(), std::declval<K*>(), std::declval<double&>()); })
4200 size_t len = _len();
4201 const K* ptr = _str();
4202 if constexpr (SkipWS) {
4203 while (len && uns_type(*ptr) <=
' ') {
4209 if constexpr (
requires { std::from_chars(std::declval<K*>(), std::declval<K*>(), std::declval<double&>()); }) {
4211 if (std::from_chars((
const K*)ptr, (
const K*)ptr + len, d, std::chars_format::hex).ec == std::errc{}) {
4226 template<ToIntNumber T>
4231 template<
typename T,
typename Op>
4232 constexpr T splitf(
const K* delimiter,
size_t lendelimiter,
const Op& beforeFunc,
size_t offset)
const {
4233 size_t mylen = _len();
4234 std::conditional_t<std::is_same_v<T, void>, char, T> results;
4235 str_piece me{_str(), mylen};
4236 for (
size_t i = 0;; i++) {
4237 size_t beginOfDelim = find(delimiter, lendelimiter, offset);
4238 if (beginOfDelim == str::npos) {
4239 str_piece last{me.symbols() + offset, me.length() - offset};
4240 if constexpr (std::is_invocable_v<Op, str_piece&>) {
4243 if constexpr (
requires { results.emplace_back(last); }) {
4244 if (last.is_same(me)) {
4247 results.emplace_back(d());
4249 results.emplace_back(last);
4251 }
else if constexpr (
requires { results.push_back(last); }) {
4252 if (last.is_same(me)) {
4255 results.push_back(d());
4257 results.push_back(last);
4259 }
else if constexpr (
requires {results[i] = last;} &&
requires{std::size(results);}) {
4260 if (i < std::size(results)) {
4261 if (last.is_same(me)) {
4271 str_piece piece{me.symbols() + offset, beginOfDelim - offset};
4272 if constexpr (std::is_invocable_v<Op, str_piece&>) {
4275 if constexpr (
requires { results.emplace_back(piece); }) {
4276 results.emplace_back(piece);
4277 }
else if constexpr (
requires { results.push_back(piece); }) {
4278 results.push_back(piece);
4279 }
else if constexpr (
requires { results[i] = piece; } &&
requires{std::size(results);}) {
4280 if (i < std::size(results)) {
4282 if (i == results.size() - 1) {
4287 offset = beginOfDelim + lendelimiter;
4289 if constexpr (!std::is_same_v<T, void>) {
4323 template<
typename T,
typename Op>
4324 constexpr T
splitf(str_piece delimiter,
const Op& beforeFunc,
size_t offset = 0)
const {
4325 return splitf<T>(delimiter.symbols(), delimiter.length(), beforeFunc, offset);
4339 template<
typename T>
4340 constexpr T
split(str_piece delimiter,
size_t offset = 0)
const {
4341 return splitf<T>(delimiter.symbols(), delimiter.length(), 0, offset);
4346 constexpr bool starts_with(
const K* prefix,
size_t l)
const noexcept {
4347 return _len() >= l && 0 == traits::compare(_str(), prefix, l);
4356 return starts_with(prefix.symbols(), prefix.length());
4365 return _len() > prefix.length() &&
4366 starts_with(prefix) &&
4367 trim_operator<TrimSides::TrimLeft, K, size_t(-1),
true>{}.isTrim(_str()[prefix.length()]);
4378 return _len() > prefix.length() &&
4379 starts_with(prefix) &&
4380 trim_operator<TrimSides::TrimLeft, K, 0, false>{next_symbol}.isTrim(_str()[prefix.length()]);
4382 template<typename T, size_t N = const_lit_for<K, T>::Count,
StrType<K> From>
requires is_const_pattern<N>
4383 constexpr bool starts_with_and_oneof(str_piece prefix, T&& next_symbol)
const noexcept {
4384 return _len() >= N &&
4385 starts_with(prefix) &&
4386 trim_operator<TrimSides::TrimLeft, K, N - 1,
false>{next_symbol}.isTrim(_str()[prefix.length()]);
4389 constexpr bool starts_with_ia(
const K* prefix,
size_t len)
const noexcept {
4390 size_t myLen = _len();
4394 const K* ptr1 = _str();
4396 K s1 = *ptr1++, s2 = *prefix++;
4399 if (makeAsciiLower(s1) != makeAsciiLower(s2))
4411 return starts_with_ia(prefix.symbols(), prefix.length());
4420 return _len() > prefix.length() &&
4421 starts_with_ia(prefix) &&
4422 trim_operator<TrimSides::TrimLeft, K, size_t(-1),
true>{}.isTrim(_str()[prefix.length()]);
4433 return _len() > prefix.length() &&
4434 starts_with_ia(prefix) &&
4435 trim_operator<TrimSides::TrimLeft, K, 0, false>{next_symbol}.isTrim(_str()[prefix.length()]);
4437 template<typename T, size_t N = const_lit_for<K, T>::Count,
StrType<K> From>
requires is_const_pattern<N>
4438 constexpr bool starts_with_ia_and_oneof(str_piece prefix, T&& next_symbol)
const noexcept {
4439 return _len() >= N &&
4440 starts_with_ia(prefix) &&
4441 trim_operator<TrimSides::TrimLeft, K, N - 1,
false>{next_symbol}.isTrim(_str()[prefix.length()]);
4446 constexpr bool prefix_in(
const K* text,
size_t len)
const noexcept {
4447 size_t myLen = _len();
4450 return !myLen || 0 == traits::compare(text, _str(), myLen);
4459 return prefix_in(text.symbols(), text.length());
4463 constexpr bool ends_with(
const K* suffix,
size_t len)
const noexcept {
4464 size_t myLen = _len();
4465 return len <= myLen && traits::compare(_str() + myLen - len, suffix, len) == 0;
4474 return ends_with(suffix.symbols(), suffix.length());
4478 constexpr bool ends_with_ia(
const K* suffix,
size_t len)
const noexcept {
4479 size_t myLen = _len();
4483 const K* ptr1 = _str() + myLen - len;
4485 K s1 = *ptr1++, s2 = *suffix++;
4488 if (makeAsciiLower(s1) != makeAsciiLower(s2))
4500 return ends_with_ia(suffix.symbols(), suffix.length());
4509 if (std::is_constant_evaluated()) {
4510 for (
size_t idx = 0; idx < _len(); idx++) {
4511 if (uns_type(_str()[idx]) > 127) {
4517 const int sl = ascii_mask<K>::WIDTH;
4518 const size_t mask = ascii_mask<K>::VALUE;
4519 size_t len = _len();
4520 const uns_type* ptr =
reinterpret_cast<const uns_type*
>(_str());
4521 if constexpr (sl > 1) {
4522 const size_t roundMask =
sizeof(size_t) - 1;
4523 while (len >= sl && (
reinterpret_cast<size_t>(ptr) & roundMask) != 0) {
4529 if (*
reinterpret_cast<const size_t*
>(ptr) & mask)
4549 template<
typename R = my_type>
4551 return R::upperred_only_ascii_from(d());
4561 template<
typename R = my_type>
4563 return R::lowered_only_ascii_from(d());
4581 template<
typename R = my_type>
4582 R
replaced(str_piece pattern, str_piece repl,
size_t offset = 0,
size_t maxCount = 0)
const {
4583 return R::replaced_from(d(), pattern, repl, offset, maxCount);
4597 template<
typename R = str_piece>
4599 if (starts_with(prefix)) {
4616 template<
typename R = str_piece>
4618 if (starts_with_ia(prefix)) {
4635 template<
typename R = str_piece>
4637 if (ends_with(suffix)) {
4654 template<
typename R = str_piece>
4656 if (ends_with_ia(suffix)) {
4662 template<StrType<K> From>
4663 constexpr static my_type make_trim_op(
const From& from,
const auto& opTrim) {
4664 str_piece sfrom = from, newPos = opTrim(sfrom);
4665 if (newPos.is_same(sfrom)) {
4669 return my_type{newPos};
4671 template<TrimS
ides S, StrType<K> From>
4672 constexpr static my_type trim_static(
const From& from) {
4673 return make_trim_op(from, trim_operator<S, K,
static_cast<size_t>(-1),
true>{});
4676 template<TrimSides S, bool withSpaces, typename T, size_t N = const_lit_for<K, T>::Count, StrType<K> From>
4677 requires is_const_pattern<N>
4678 constexpr static my_type trim_static(
const From& from, T&& pattern) {
4679 return make_trim_op(from, trim_operator<S, K, N - 1, withSpaces>{pattern});
4682 template<TrimS
ides S,
bool withSpaces, StrType<K> From>
4683 constexpr static my_type trim_static(
const From& from, str_piece pattern) {
4684 return make_trim_op(from, trim_operator<S, K, 0, withSpaces>{{pattern}});
4694 template<
typename R = str_piece>
4696 return R::template trim_static<TrimSides::TrimAll>(d());
4706 template<
typename R = str_piece>
4708 return R::template trim_static<TrimSides::TrimLeft>(d());
4718 template<
typename R = str_piece>
4720 return R::template trim_static<TrimSides::TrimRight>(d());
4732 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4733 requires is_const_pattern<N>
4735 return R::template trim_static<TrimSides::TrimAll, false>(d(), pattern);
4747 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4748 requires is_const_pattern<N>
4750 return R::template trim_static<TrimSides::TrimLeft, false>(d(), pattern);
4762 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4763 requires is_const_pattern<N>
4765 return R::template trim_static<TrimSides::TrimRight, false>(d(), pattern);
4784 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4785 requires is_const_pattern<N>
4787 return R::template trim_static<TrimSides::TrimAll, true>(d(), pattern);
4803 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4804 requires is_const_pattern<N>
4806 return R::template trim_static<TrimSides::TrimLeft, true>(d(), pattern);
4822 template<typename R = str_piece, typename T, size_t N = const_lit_for<K, T>::Count>
4823 requires is_const_pattern<N>
4825 return R::template trim_static<TrimSides::TrimRight, true>(d(), pattern);
4840 template<
typename R = str_piece>
4842 return R::template trim_static<TrimSides::TrimAll, false>(d(), pattern);
4854 template<
typename R = str_piece>
4856 return R::template trim_static<TrimSides::TrimLeft, false>(d(), pattern);
4868 template<
typename R = str_piece>
4870 return R::template trim_static<TrimSides::TrimRight, false>(d(), pattern);
4886 template<
typename R = str_piece>
4888 return R::template trim_static<TrimSides::TrimAll, true>(d(), pattern);
4904 template<
typename R = str_piece>
4906 return R::template trim_static<TrimSides::TrimLeft, true>(d(), pattern);
4922 template<
typename R = str_piece>
4924 return R::template trim_static<TrimSides::TrimRight, true>(d(), pattern);
4938 template<
typename R = str_piece>
4940 str_piece res = *
this;
4941 while(res.starts_with(prefix)) {
4942 res = res(prefix.length());
4943 if (--max_count == 0) {
4961 template<
typename R = str_piece>
4963 str_piece res = *
this;
4964 while(res.starts_with_ia(prefix)) {
4965 res = res(prefix.length());
4966 if (--max_count == 0) {
4984 template<
typename R = str_piece>
4986 str_piece res = *
this;
4987 while(res.ends_with(suffix)) {
4988 res = res(0, -suffix.length());
5004 template<
typename R = str_piece>
5006 str_piece res = *
this;
5007 while(res.ends_with_ia(suffix)) {
5008 res = res(0, -suffix.length());
5027template<
size_t N>
requires (N > 1)
5028struct find_all_container {
5029 static constexpr size_t max_capacity = N;
5030 size_t positions_[N];
5033 constexpr void emplace_back(
size_t pos) {
5034 positions_[added_++] = pos;
5057struct str_src : str_src_algs<K, str_src<K>, str_src<K>, false> {
5058 using symb_type = K;
5059 using my_type = str_src<K>;
5061 const symb_type* str;
5064 str_src() =
default;
5069 template<typename T, size_t N = const_lit_for<K, T>::Count>
5070 constexpr str_src(T&& v) noexcept : str((
const K*)v), len(N - 1) {}
5076 constexpr str_src(
const K* p,
size_t l) noexcept : str(p), len(l) {}
5078 template<StrType<K> T>
5079 constexpr str_src(T&& t) :
str(t.symbols()), len(t.length()){}
5085 template<
typename A>
5086 constexpr str_src(
const std::basic_string<K, std::char_traits<K>, A>& s) noexcept : str(s.data()), len(s.length()) {}
5091 constexpr str_src(
const std::basic_string_view<K, std::char_traits<K>>& s) noexcept : str(s.data()), len(s.length()) {}
5104 constexpr const symb_type*
symbols() const noexcept {
5120 constexpr bool is_same(str_src<K> other)
const noexcept {
5121 return str == other.str && len == other.len;
5130 return str >= other.str && str + len <= other.str + other.len;
5193struct str_src_nt : str_src<K>, null_terminated<K, str_src_nt<K>> {
5194 using symb_type = K;
5195 using my_type = str_src_nt<K>;
5196 using base = str_src<K>;
5198 constexpr static const K empty_string[1] = {0};
5200 str_src_nt() =
default;
5217 template<
typename T>
requires std::is_same_v<std::remove_const_t<std::remove_pointer_t<std::remove_cvref_t<T>>>, K>
5220 base::str = base::len ? p : empty_string;
5226 template<typename T, size_t N = const_lit_for<K, T>::Count>
5227 constexpr str_src_nt(T&& v) noexcept : base(std::forward<T>(v)) {}
5233 constexpr str_src_nt(
const K* p,
size_t l) noexcept : base(p, l) {}
5235 template<StrType<K> T>
5238 base::len = t.length();
5244 template<
typename A>
5245 constexpr str_src_nt(
const std::basic_string<K, std::char_traits<K>, A>& s) noexcept : base(s) {}
5247 static const my_type empty_str;
5257 if (from > base::len) {
5260 return {base::str + from, base::len - from};
5265inline const str_src_nt<K> str_src_nt<K>::empty_str{str_src_nt<K>::empty_string, 0};
5266template<
typename K>
struct simple_str_selector;
5268inline namespace literals {
5328template<
char...Chars>
5329SS_CONSTEVAL
auto operator""_fmt() {
5330 return f::skip_0x<Chars...>();
5335#ifndef IN_FULL_SIMSTR
5338using simple_str = str_src<K>;
5341struct simple_str_selector {
5342 using type = simple_str<K>;
5346using simple_str_nt = str_src_nt<K>;
5349using Splitter = SplitterBase<K, str_src<K>>;
5351using ssa = str_src<u8s>;
5352using ssb = str_src<ubs>;
5353using ssw = str_src<wchar_t>;
5354using ssu = str_src<u16s>;
5355using ssuu = str_src<u32s>;
5356using stra = str_src_nt<u8s>;
5357using strb = str_src_nt<ubs>;
5358using strw = str_src_nt<wchar_t>;
5359using stru = str_src_nt<u16s>;
5360using struu = str_src_nt<u32s>;
5363consteval 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) {
5364 if constexpr (std::is_same_v<K, u8s>)
5366 if constexpr (std::is_same_v<K, ubs>)
5368 if constexpr (std::is_same_v<K, uws>)
5370 if constexpr (std::is_same_v<K, u16s>)
5372 if constexpr (std::is_same_v<K, u32s>)
5376#define uni_string(K, p) select_str<K>(p, u8##p, L##p, u##p, U##p)
5378inline namespace literals {
5451template<
typename K,
bool withSpaces>
5452struct CheckSpaceTrim {
5453 constexpr bool is_trim_spaces(K s)
const {
5454 return s ==
' ' || (s >= 9 && s <= 13);
5458struct CheckSpaceTrim<K, false> {
5459 constexpr bool is_trim_spaces(K)
const {
5465struct CheckSymbolsTrim {
5467 constexpr bool is_trim_symbols(K s)
const {
5468 return symbols.len != 0 && str_src<K>::traits::find(symbols.str, symbols.len, s) !=
nullptr;
5472template<
typename K,
size_t N>
5473struct CheckConstSymbolsTrim {
5474 const const_lit_to_array<K, N> symbols;
5476 template<typename T, size_t M = const_lit_for<K, T>::Count>
requires (M == N + 1)
5477 constexpr CheckConstSymbolsTrim(T&& s) : symbols(std::forward<T>(s)) {}
5479 constexpr bool is_trim_symbols(K s)
const noexcept {
5480 return symbols.contain(s);
5485struct CheckConstSymbolsTrim<K, 0> {
5486 constexpr bool is_trim_symbols(K)
const {
5491template<
typename K,
size_t N>
5492struct SymbSelector {
5493 using type = CheckConstSymbolsTrim<K, N>;
5497struct SymbSelector<K, 0> {
5498 using type = CheckSymbolsTrim<K>;
5502struct SymbSelector<K, static_cast<size_t>(-1)> {
5503 using type = CheckConstSymbolsTrim<K, 0>;
5506template<TrimS
ides S,
typename K,
size_t N,
bool withSpaces>
5507struct trim_operator : SymbSelector<K, N>::type, CheckSpaceTrim<K, withSpaces> {
5508 constexpr bool isTrim(K s)
const {
5509 return CheckSpaceTrim<K, withSpaces>::is_trim_spaces(s) || SymbSelector<K, N>::type::is_trim_symbols(s);
5511 constexpr str_src<K> operator()(str_src<K> from)
const {
5512 if constexpr ((S & TrimSides::TrimLeft) != 0) {
5514 if (isTrim(*from.str)) {
5521 if constexpr ((S & TrimSides::TrimRight) != 0) {
5522 const K* back = from.str + from.len - 1;
5524 if (isTrim(*back)) {
5535template<TrimS
ides S,
typename K>
5536using SimpleTrim = trim_operator<S, K, size_t(-1),
true>;
5538template<TrimSides S = TrimSides::TrimAll, bool withSpaces = false, typename K, typename T, size_t N = const_lit_for<K, T>::Count>
5539 requires is_const_pattern<N>
5540constexpr inline auto trimOp(T&& pattern) {
5541 return trim_operator<S, K, N - 1, withSpaces>{pattern};
5544template<TrimS
ides S = TrimS
ides::TrimAll,
bool withSpaces = false,
typename K>
5545constexpr inline auto trimOp(str_src<K> pattern) {
5546 return trim_operator<S, K, 0, withSpaces>{pattern};
5549static constexpr size_t FIND_CACHE_SIZE = 16;
5551template<
typename K,
size_t N,
size_t L>
5552struct expr_replaces : expr_to_std_string<expr_replaces<K, N, L>> {
5553 using symb_type = K;
5554 using my_type = expr_replaces<K, N, L>;
5556 const K(&pattern)[N + 1];
5557 const K(&repl)[L + 1];
5558 mutable find_all_container<FIND_CACHE_SIZE> matches_;
5559 mutable size_t last_;
5561 constexpr expr_replaces(str_src<K> w,
const K(&p)[N + 1],
const K(&r)[L + 1]) : what(w), pattern(p), repl(r) {}
5563 constexpr size_t length()
const {
5564 size_t l = what.length();
5565 if constexpr (N == L) {
5568 what.find_all_to(matches_, pattern, N, 0, FIND_CACHE_SIZE);
5569 if (matches_.added_) {
5570 last_ = matches_.positions_[matches_.added_ - 1] + N;
5571 l += int(L - N) * matches_.added_;
5573 if (matches_.added_ == FIND_CACHE_SIZE) {
5575 size_t next = what.find(pattern, N, last_);
5576 if (next == str::npos) {
5585 matches_.added_ = -1;
5589 constexpr K* place(K* ptr)
const noexcept {
5590 if constexpr (N == L) {
5591 const K* from = what.symbols();
5592 for (
size_t start = 0; start < what.length();) {
5593 size_t next = what.find(pattern, N, start);
5594 if (next == str::npos) {
5595 next = what.length();
5597 size_t delta = next - start;
5598 ch_traits<K>::copy(ptr, from + start, delta);
5600 ch_traits<K>::copy(ptr, repl, L);
5606 if (matches_.added_ == 0) {
5607 return what.place(ptr);
5608 }
else if (matches_.added_ ==
size_t(-1)) {
5612 const K* from = what.symbols();
5613 for (
size_t start = 0, offset = matches_.positions_[0], idx = 1; ;) {
5614 ch_traits<K>::copy(ptr, from + start, offset - start);
5615 ptr += offset - start;
5616 ch_traits<K>::copy(ptr, repl, L);
5619 if (start >= last_) {
5620 size_t tail = what.length() - last_;
5621 ch_traits<K>::copy(ptr, from + last_, tail);
5625 offset = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern, N, start);
5645template<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>
5648 return expr_replaces<K, N - 1, L - 1>{std::forward<A>(w), p, r};
5660 using symb_type = K;
5665 mutable find_all_container<FIND_CACHE_SIZE> matches_;
5666 mutable size_t last_;
5679 constexpr size_t length()
const {
5681 if (!plen || plen == rlen) {
5684 what.find_all_to(matches_, pattern.
symbols(), plen, 0, FIND_CACHE_SIZE);
5685 if (matches_.added_) {
5686 last_ = matches_.positions_[matches_.added_ - 1] + plen;
5687 l += int(rlen - plen) * matches_.added_;
5689 if (matches_.added_ == FIND_CACHE_SIZE) {
5691 size_t next = what.find(pattern.
symbols(), plen, last_);
5692 if (next == str::npos) {
5695 last_ = next + plen;
5701 matches_.added_ = -1;
5705 constexpr K* place(K* ptr)
const noexcept {
5708 const K* from = what.
symbols();
5709 for (
size_t start = 0; start < what.
length();) {
5710 size_t next = what.find(pattern, start);
5711 if (next == str::npos) {
5714 size_t delta = next - start;
5715 ch_traits<K>::copy(ptr, from + start, delta);
5717 ch_traits<K>::copy(ptr, repl.
symbols(), rlen);
5719 start = next + plen;
5723 if (matches_.added_ == 0) {
5724 return what.
place(ptr);
5725 }
else if (matches_.added_ == -1) {
5729 const K* from = what.
symbols();
5730 for (
size_t start = 0, offset = matches_.positions_[0], idx = 1; ;) {
5731 ch_traits<K>::copy(ptr, from + start, offset - start);
5732 ptr += offset - start;
5733 ch_traits<K>::copy(ptr, repl.
symbols(), rlen);
5735 start = offset + plen;
5736 if (start >= last_) {
5737 size_t tail = what.
length() - start;
5738 ch_traits<K>::copy(ptr, from + start, tail);
5742 offset = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern.
symbols(), plen, start);
5764template<
typename K, StrExprForType<K> E>
5766 using symb_type = K;
5770 mutable size_t replLen;
5771 mutable find_all_container<FIND_CACHE_SIZE> matches_;
5772 mutable size_t last_;
5786 constexpr size_t length()
const {
5791 matches_.positions_[0] = what.find(pattern);
5792 if (matches_.positions_[0] == -1) {
5796 matches_.added_ = 1;
5798 replLen = expr.length();
5799 if (replLen == plen) {
5803 what.find_all_to(matches_, pattern.
symbols(), plen, matches_.positions_[0] + plen, FIND_CACHE_SIZE - 1);
5805 last_ = matches_.positions_[matches_.added_ - 1] + plen;
5806 l += int(replLen - plen) * matches_.added_;
5808 if (matches_.added_ == FIND_CACHE_SIZE) {
5810 size_t next = what.find(pattern.
symbols(), plen, last_);
5811 if (next == str::npos) {
5814 last_ = next + plen;
5815 l += replLen - plen;
5819 matches_.added_ = -1;
5823 constexpr K* place(K* ptr)
const noexcept {
5824 if (matches_.added_ == 0) {
5826 return what.
place(ptr);
5827 }
else if (matches_.added_ == -1) {
5831 size_t plen = pattern.
length();
5832 const K* from = what.
symbols();
5833 ch_traits<K>::copy(ptr, from, matches_.positions_[0]);
5834 ptr += matches_.positions_[0];
5835 const K* repl = ptr;
5836 expr.
place((
typename E::symb_type*)ptr);
5838 size_t start = matches_.positions_[0] + plen;
5840 if (plen == replLen) {
5842 size_t next = what.find(pattern, start);
5843 if (next == str::npos) {
5846 size_t delta = next - start;
5847 ch_traits<K>::copy(ptr, from + start, delta);
5849 ch_traits<K>::copy(ptr, repl, replLen);
5851 start = next + plen;
5854 for (
size_t idx = 1;;) {
5855 if (start >= last_) {
5858 size_t next = idx < FIND_CACHE_SIZE ? matches_.positions_[idx++] : what.find(pattern, start);
5859 size_t delta = next - start;
5860 ch_traits<K>::copy(ptr, from + start, delta);
5862 ch_traits<K>::copy(ptr, repl, replLen);
5864 start = next + plen;
5867 size_t tail = what.
length() - start;
5868 ch_traits<K>::copy(ptr, from + start, tail);
5886template<StrSource A,
typename K = symb_type_from_src_t<A>,
typename T,
typename X>
5887 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>))
5907template<StrSource A,
typename K = symb_type_from_src_t<A>,
typename T, StrExprForType<K> E>
5908 requires std::is_constructible_v<str_src<K>, T>
5909constexpr auto e_repl(A&& w, T&& p,
const E& expr) {
5914template<
bool UseVectorForReplace>
5915struct replace_search_result_store {
5917 std::pair<size_t, size_t> replaces_[16];
5921struct replace_search_result_store<true> : std::vector<std::pair<size_t, size_t>> {};
5925template<
typename K,
size_t N,
bool UseVectorForReplace>
5926struct expr_replace_const_symbols : expr_to_std_string<expr_replace_const_symbols<K, N, UseVectorForReplace>> {
5927 using symb_type = K;
5928 inline static const int BIT_SEARCH_TRESHHOLD = 4;
5929 const K pattern_[N];
5930 const str_src<K> source_;
5931 const str_src<K> replaces_[N];
5933 mutable replace_search_result_store<UseVectorForReplace> search_results_;
5935 [[_no_unique_address]]
5936 uu8s bit_mask_[N >= BIT_SEARCH_TRESHHOLD ? (
sizeof(K) == 1 ? 32 : 64) : 0]{};
5938 template<
typename ... Repl>
requires (
sizeof...(Repl) == N * 2)
5939 constexpr expr_replace_const_symbols(str_src<K> source, Repl&& ... repl) : expr_replace_const_symbols(0, source, std::forward<Repl>(repl)...) {}
5941 size_t length()
const {
5942 size_t l = source_.length();
5943 auto [fnd, num] = find_first_of(source_.str, source_.len);
5944 if (fnd == str::npos) {
5947 l += replaces_[num].len - 1;
5948 if constexpr (UseVectorForReplace) {
5949 search_results_.reserve((l >> 4) + 8);
5950 search_results_.emplace_back(fnd, num);
5951 for (
size_t start = fnd + 1;;) {
5952 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
5953 if (fnd == str::npos) {
5956 search_results_.emplace_back(fnd, idx);
5958 l += replaces_[idx].len - 1;
5961 const size_t max_store = std::size(search_results_.replaces_);
5962 search_results_.replaces_[0] = {fnd, num};
5963 search_results_.count_++;
5964 for (
size_t start = fnd + 1;;) {
5965 auto [found, idx] = find_first_of(source_.str, source_.len, start);
5966 if (found == str::npos) {
5969 if (search_results_.count_ < max_store) {
5970 search_results_.replaces_[search_results_.count_] = {found, idx};
5972 l += replaces_[idx].len - 1;
5973 search_results_.count_++;
5979 K* place(K* ptr)
const noexcept {
5981 const K* text = source_.str;
5982 if constexpr (UseVectorForReplace) {
5983 for (
const auto& [pos, num] : search_results_) {
5984 size_t delta = pos - start;
5985 ch_traits<K>::copy(ptr, text + start, delta);
5987 ptr = replaces_[num].place(ptr);
5991 const size_t max_store = std::size(search_results_.replaces_);
5992 size_t founded = search_results_.count_;
5993 for (
size_t idx = 0, stop = std::min(founded, max_store); idx < stop; idx++) {
5994 const auto [pos, num] = search_results_.replaces_[idx];
5995 size_t delta = pos - start;
5996 ch_traits<K>::copy(ptr, text + start, delta);
5998 ptr = replaces_[num].place(ptr);
6001 if (founded > max_store) {
6002 founded -= max_store;
6004 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6005 size_t delta = fnd - start;
6006 ch_traits<K>::copy(ptr, text + start, delta);
6008 ptr = replaces_[idx].place(ptr);
6013 size_t tail = source_.len - start;
6014 ch_traits<K>::copy(ptr, text + start, tail);
6019 template<
typename ... Repl>
6020 constexpr expr_replace_const_symbols(
int, str_src<K> source, K s, str_src<K> r, Repl&&... repl) :
6021 expr_replace_const_symbols(0, source, std::forward<Repl>(repl)..., std::make_pair(s, r)){}
6023 template<
typename ... Repl>
requires (
sizeof...(Repl) == N)
6024 constexpr expr_replace_const_symbols(
int, str_src<K> source, Repl&&... repl) :
6025 source_(source), pattern_ {repl.first...}, replaces_{repl.second...}
6027 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
6028 for (
size_t idx = 0; idx < N; idx++) {
6029 uu8s s =
static_cast<uu8s
>(pattern_[idx]);
6030 if constexpr (
sizeof(K) == 1) {
6031 bit_mask_[s >> 3] |= 1 << (s & 7);
6033 if (std::make_unsigned_t<const K>(pattern_[idx]) > 255) {
6034 bit_mask_[32 + (s >> 3)] |= 1 << (s & 7);
6036 bit_mask_[s >> 3] |= 1 << (s & 7);
6043 template<
size_t Idx>
6044 size_t index_of(K s)
const {
6045 if constexpr (Idx < N) {
6046 return pattern_[Idx] == s ? Idx : index_of<Idx + 1>(s);
6050 bool is_in_mask(uu8s s)
const {
6051 return (bit_mask_[s >> 3] & (1 <<(s & 7))) != 0;
6053 bool is_in_mask2(uu8s s)
const {
6054 return (bit_mask_[32 + (s >> 3)] & (1 <<(s & 7))) != 0;
6056 bool is_in_pattern(K s,
size_t& idx)
const {
6057 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
6058 if constexpr (
sizeof(K) == 1) {
6059 if (is_in_mask(s)) {
6060 idx = index_of<0>(s);
6064 if (std::make_unsigned_t<const K>(s) > 255) {
6065 if (is_in_mask2(s)) {
6066 return (idx = index_of<0>(s)) != -1;
6069 if (is_in_mask(s)) {
6070 idx = index_of<0>(s);
6078 std::pair<size_t, size_t> find_first_of(
const K* text,
size_t len,
size_t offset = 0)
const {
6079 if constexpr (N >= BIT_SEARCH_TRESHHOLD) {
6081 while (offset < len) {
6082 if (is_in_pattern(text[offset], idx)) {
6083 return {offset, idx};
6088 while (offset < len) {
6089 if (
size_t idx = index_of<0>(text[offset]); idx != -1) {
6090 return {offset, idx};
6138template<
bool UseVector = false, StrSource A,
typename K = symb_type_from_src_t<A>,
typename ... Repl>
6139 requires (
sizeof...(Repl) % 2 == 0)
6141 return expr_replace_const_symbols<K,
sizeof...(Repl) / 2, UseVector>(std::forward<A>(src), std::forward<Repl>(other)...);
6183template<
typename K,
bool UseVectorForReplace = false>
6185 using symb_type = K;
6186 using str_t =
typename simple_str_selector<K>::type;
6187 inline static const int BIT_SEARCH_TRESHHOLD = 4;
6190 const std::vector<std::pair<K, str_t>>& replaces_;
6192 std::basic_string<K, ch_traits<K>, std::allocator<K>> pattern_;
6194 mutable replace_search_result_store<UseVectorForReplace> search_results_;
6196 uu8s bit_mask_[
sizeof(K) == 1 ? 32 : 64]{};
6225 : source_(source), replaces_(repl)
6227 size_t pattern_len = replaces_.size();
6228 pattern_.resize(pattern_len);
6229 K* pattern = pattern_.data();
6231 for (
size_t idx = 0; idx < replaces_.size(); idx++) {
6232 *pattern++ = replaces_[idx].first;
6235 if (pattern_len >= BIT_SEARCH_TRESHHOLD) {
6236 for (
size_t idx = 0; idx < pattern_len; idx++) {
6237 uu8s s =
static_cast<uu8s
>(pattern_[idx]);
6238 if constexpr (
sizeof(K) == 1) {
6239 bit_mask_[s >> 3] |= (1 << (s & 7));
6241 if (std::make_unsigned_t<K>(pattern_[idx]) > 255) {
6242 bit_mask_[32 + (s >> 3)] |= (1 << (s & 7));
6244 bit_mask_[s >> 3] |= (1 << (s & 7));
6251 size_t length()
const {
6252 size_t l = source_.
length();
6253 auto [fnd, num] = find_first_of(source_.str, source_.len);
6254 if (fnd == str::npos) {
6257 l += replaces_[num].second.len - 1;
6258 if constexpr (UseVectorForReplace) {
6259 search_results_.reserve((l >> 4) + 8);
6260 search_results_.emplace_back(fnd, num);
6261 for (
size_t start = fnd + 1;;) {
6262 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6263 if (fnd == str::npos) {
6266 search_results_.emplace_back(fnd, idx);
6268 l += replaces_[idx].second.len - 1;
6271 const size_t max_store = std::size(search_results_.replaces_);
6272 search_results_.replaces_[0] = {fnd, num};
6273 search_results_.count_++;
6274 for (
size_t start = fnd + 1;;) {
6275 auto [found, idx] = find_first_of(source_.str, source_.len, start);
6276 if (found == str::npos) {
6279 if (search_results_.count_ < max_store) {
6280 search_results_.replaces_[search_results_.count_] = {found, idx};
6282 l += replaces_[idx].second.len - 1;
6283 search_results_.count_++;
6289 K* place(K* ptr)
const noexcept {
6291 const K* text = source_.str;
6292 if constexpr (UseVectorForReplace) {
6293 for (
const auto& [pos, num] : search_results_) {
6294 size_t delta = pos - start;
6295 ch_traits<K>::copy(ptr, text + start, delta);
6297 ptr = replaces_[num].second.place(ptr);
6301 const size_t max_store = std::size(search_results_.replaces_);
6302 size_t founded = search_results_.count_;
6303 for (
size_t idx = 0, stop = std::min(founded, max_store); idx < stop; idx++) {
6304 const auto [pos, num] = search_results_.replaces_[idx];
6305 size_t delta = pos - start;
6306 ch_traits<K>::copy(ptr, text + start, delta);
6308 ptr = replaces_[num].second.place(ptr);
6311 if (founded > max_store) {
6312 founded -= max_store;
6314 auto [fnd, idx] = find_first_of(source_.str, source_.len, start);
6315 size_t delta = fnd - start;
6316 ch_traits<K>::copy(ptr, text + start, delta);
6318 ptr = replaces_[idx].second.place(ptr);
6323 size_t tail = source_.len - start;
6324 ch_traits<K>::copy(ptr, text + start, tail);
6329 size_t index_of(K s)
const {
6330 return pattern_.find(s);
6333 bool is_in_mask(uu8s s)
const {
6334 return (bit_mask_[s >> 3] & (1 << (s & 7))) != 0;
6336 bool is_in_mask2(uu8s s)
const {
6337 return (bit_mask_[32 + (s >> 3)] & (1 << (s & 7))) != 0;
6340 bool is_in_pattern(K s,
size_t& idx)
const {
6341 if constexpr (
sizeof(K) == 1) {
6342 if (is_in_mask(s)) {
6347 if (std::make_unsigned_t<const K>(s) > 255) {
6348 if (is_in_mask2(s)) {
6349 return (idx = index_of(s)) != -1;
6352 if (is_in_mask(s)) {
6361 std::pair<size_t, size_t> find_first_of(
const K* text,
size_t len,
size_t offset = 0)
const {
6362 size_t pl = pattern_.length();
6363 if (pl >= BIT_SEARCH_TRESHHOLD) {
6365 while (offset < len) {
6366 if (is_in_pattern(text[offset], idx)) {
6367 return {offset, idx};
6372 while (offset < len) {
6373 if (
size_t idx = index_of(text[offset]); idx != -1) {
6374 return {offset, idx};
6383template<
typename K, StrExprForType<K> T>
6386 force_copy(
const T& t) : t_(t){}
6389template<
typename K,
typename T>
6390struct symb_type_from_src<force_copy<K, T>> {
6396force_copy(T&&) -> force_copy<typename T::symb_type, T>;
6398template<
typename K,
typename T>
6399constexpr auto to_subst(T&& t) {
6400 return to_strexpr<K>(std::forward<T>(t));
6403template<
typename K,
typename T,
size_t N>
6404constexpr auto to_subst(
const T(&t)[N]) {
6405 return expr_literal<T, N - 1>{t};
6408template<
typename K, StrExprForType<K> T>
6409constexpr decltype(
auto) to_subst(T&& t) {
6410 return std::forward<T>(t);
6413template<
typename K,
typename T>
6414constexpr T to_subst(
const force_copy<K, T>& t) {
6418template<
typename K,
typename T>
6419constexpr T to_subst(force_copy<K, T>&& t) {
6423template<
typename K,
typename T>
6424constexpr T to_subst(force_copy<K, T>& t) {
6428template<
typename K,
typename T>
6429using to_str_exp_t =
decltype(to_subst<K>(std::declval<T>()));
6438template<
typename K,
typename G,
typename Arg,
typename...Args>
6440 using symb_type = K;
6441 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
6442 using arg_t = to_str_exp_t<K, Arg>;
6443 to_str_exp_t<K, G> glue_;
6446 mutable size_t glue_len_;
6480 : glue_(to_subst<K>(
std::forward<G>(glue)))
6481 , arg_(to_subst<K>(
std::forward<Arg>(arg)))
6482 , args_(to_subst<K>(
std::forward<Args>(args))...) {}
6484 constexpr size_t length() const noexcept {
6485 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
6486 glue_len_ = glue_.length();
6487 size_t l = arg_.length() + glue_len_ *
sizeof...(Args);
6488 ((l += std::get<Indexes>(args_).length()),...);
6490 }(std::make_index_sequence<
sizeof...(Args)>());
6492 constexpr K* place(K* ptr)
const noexcept {
6493 return [
this]<
size_t...Indexes>(K* ptr, std::index_sequence<Indexes...>) {
6494 ptr = (K*)arg_.place((
typename std::remove_cvref_t<arg_t>::symb_type*)ptr);
6495 const K* glueStart = ptr;
6496 ptr = glue_.place(ptr);
6499 ptr = (K*)std::get<Indexes>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Indexes, store_t>>::symb_type*)ptr),
6500 glue_len_ > 0 && Indexes <
sizeof...(Args) - 1 ? (ch_traits<K>::copy(ptr, glueStart, glue_len_), ptr += glue_len_) :
nullptr
6504 }(ptr, std::make_index_sequence<
sizeof...(Args)>());
6508template<
typename T,
typename ... Args>
requires (
sizeof...(Args) > 1)
6509e_concat(T&&, Args&&...) -> e_concat<symb_type_from_src_t<T>, T, Args...>;
6511struct parse_subst_string_error {
6512 parse_subst_string_error(
const char*){}
6517template<
typename K,
size_t NParams>
6518constexpr size_t parse_pattern_string(str_src<K> pattern,
auto&& add_part,
auto&& add_param) {
6519 char used_args[NParams] = {0};
6520 const K* first = pattern.begin(), *last = pattern.end(), *start = first;
6523 auto find = [](
const K* from,
const K* last, K s) {
6524 while (from != last) {
6532 size_t idx_in_params = 0;
6534 while (first != last) {
6535 const K* open_pos = first;
6536 if (*first !=
'{') {
6537 open_pos = find(first, last,
'{');
6540 const K* close_pos = find(first, open_pos,
'}');
6541 if (close_pos == open_pos) {
6542 unsigned len = open_pos - first;
6543 add_part(first - start, len);
6548 if (close_pos == open_pos || *close_pos !=
'}') {
6549 throw parse_subst_string_error{
"unescaped }"};
6551 unsigned len = close_pos - first;
6552 add_part(first - start, len);
6554 first = ++close_pos;
6556 if (open_pos == last) {
6560 if (++open_pos == last) {
6561 throw parse_subst_string_error{
"unescaped {"};
6563 if (*open_pos ==
'}') {
6564 if (idx_in_params == -1) {
6565 throw parse_subst_string_error{
"already used param ids"};
6567 if (idx_in_params == NParams) {
6568 throw parse_subst_string_error{
"too many params"};
6570 used_args[idx_in_params] = 1;
6571 add_param(idx_in_params++);
6572 first = open_pos + 1;
6573 }
else if (*open_pos ==
'{') {
6574 add_part(open_pos - start, 1);
6576 first = open_pos + 1;
6578 if (idx_in_params != 0 && idx_in_params != -1) {
6579 throw parse_subst_string_error{
"already used non id params"};
6582 const K* end = find(open_pos, last,
'}');
6584 throw parse_subst_string_error{
"not found }"};
6586 auto [p, err, _] = str_src<K>(open_pos, end - open_pos).template to_int<unsigned, true, 10, false, false>();
6587 if (err != IntConvertResult::Success || p < 1 || p > NParams) {
6588 throw parse_subst_string_error{
"bad param id"};
6595 for (
auto c : used_args) {
6597 throw parse_subst_string_error{
"unused param"};
6606 unsigned is_param: 1;
6608 portion() =
default;
6610 constexpr void set_param(
unsigned param) {
6611 if (param >= (1 << 16)) {
6612 throw parse_subst_string_error{
"the parameter id is too large"};
6617 constexpr void set_part(
unsigned from,
unsigned l) {
6618 if (from >= (1 << 16) || len >= (1 << 15)) {
6619 throw parse_subst_string_error{
"the string part is too large"};
6627template<
typename K,
size_t PtLen,
size_t NParams>
6628struct subst_params {
6629 const K(&source_)[PtLen];
6630 unsigned all_len_{};
6634 portion portions_[1 + ((PtLen - 2) * 2 / 3)]{};
6636 consteval subst_params(
const K(&pattern)[PtLen]) : source_(pattern) {
6637 all_len_ = parse_pattern_string<K, NParams>(pattern,
6638 [
this](
unsigned from,
unsigned len) {
6639 portions_[actual_++].set_part(from, len);
6640 }, [
this](
unsigned param) {
6641 portions_[actual_++].set_param(param);
6653template<
typename K,
size_t PtLen,
typename ... Args>
6655 inline static constexpr size_t NParams =
sizeof...(Args);
6656 using symb_type = K;
6657 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
6659 const details::subst_params<K, PtLen, NParams>& subst_;
6701 constexpr e_subst(
const details::subst_params<K, PtLen, NParams>& subst, Args&&...args)
6703 , args_(to_subst<K>(
std::forward<Args>(args))...){}
6705 constexpr size_t length() const noexcept {
6706 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
6708 size_t expr_length_[NParams] = {};
6709 ((expr_length_[idx++] = std::get<Indexes>(args_).length()),...);
6710 size_t l = subst_.all_len_;
6711 for (idx = 0; idx < subst_.actual_; idx++) {
6712 if (subst_.portions_[idx].is_param) {
6713 l += expr_length_[subst_.portions_[idx].start];
6717 }(std::make_index_sequence<
sizeof...(Args)>());
6719 template<
size_t Idx>
6720 constexpr K* place_idx(K* ptr,
size_t idx)
const noexcept {
6722 return (K*)std::get<Idx>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Idx, store_t>>::symb_type*)ptr);
6724 if constexpr (Idx < NParams - 1) {
6725 return place_idx<Idx + 1>(ptr, idx);
6729 constexpr K* place(K* ptr)
const noexcept {
6730 for (
size_t idx = 0; idx < subst_.actual_; idx++) {
6731 if (subst_.portions_[idx].is_param) {
6732 ptr = place_idx<0>(ptr, subst_.portions_[idx].start);
6734 ch_traits<K>::copy(ptr, subst_.source_ + subst_.portions_[idx].start, subst_.portions_[idx].len);
6735 ptr += subst_.portions_[idx].len;
6743template<
typename K,
size_t N,
typename...Args>
requires (
sizeof...(Args) > 0)
6744e_subst(
const K(&)[N], Args&&...) -> e_subst<K, N, Args...>;
6751template<
typename K,
typename ... Args>
6753 inline static constexpr size_t Nparams =
sizeof...(Args);
6754 using symb_type = K;
6755 using store_t = std::tuple<to_str_exp_t<K, Args>...>;
6757 details::portion portions_[Nparams * 3];
6758 std::vector<details::portion> more_portions_;
6802 , args_(to_subst<K>(
std::forward<Args>(args))...) {
6804 all_len_ = details::parse_pattern_string<K, Nparams>(pattern_, [
this](
unsigned from,
unsigned len) {
6805 if (actual_ < std::size(portions_)) {
6806 portions_[actual_++].set_part(from, len);
6808 if (actual_ == std::size(portions_)) {
6809 more_portions_.reserve((pattern_.len - 1) * 2 / 3 - std::size(portions_));
6811 more_portions_.emplace_back().set_part(from, len);
6813 }, [
this](
unsigned param) {
6814 if (actual_ < std::size(portions_)) {
6815 portions_[actual_++].set_param(param);
6817 if (actual_ == std::size(portions_)) {
6818 more_portions_.reserve((pattern_.len - 1) * 2 / 3 - std::size(portions_));
6820 more_portions_.emplace_back().set_param(param);
6825 constexpr size_t length() const noexcept {
6826 return [
this]<
size_t...Indexes>(std::index_sequence<Indexes...>) {
6828 size_t expr_length_[Nparams] = {};
6829 ((expr_length_[idx++] = std::get<Indexes>(args_).length()),...);
6830 size_t l = all_len_;
6831 for (idx = 0; idx < actual_; idx++) {
6832 if (portions_[idx].is_param) {
6833 l += expr_length_[portions_[idx].start];
6836 for (
const auto& p : more_portions_) {
6838 l += expr_length_[p.start];
6842 }(std::make_index_sequence<
sizeof...(Args)>());
6844 template<
size_t Idx>
6845 constexpr K* place_idx(K* ptr,
size_t idx)
const noexcept {
6847 return (K*)std::get<Idx>(args_).place((
typename std::remove_cvref_t<std::tuple_element_t<Idx, store_t>>::symb_type*)ptr);
6849 if constexpr (Idx < Nparams - 1) {
6850 return place_idx<Idx + 1>(ptr, idx);
6854 constexpr K* place(K* ptr)
const noexcept {
6855 for (
size_t idx = 0; idx < actual_; idx++) {
6856 if (portions_[idx].is_param) {
6857 ptr = place_idx<0>(ptr, portions_[idx].start);
6859 ch_traits<K>::copy(ptr, pattern_.
symbols() + portions_[idx].start, portions_[idx].len);
6860 ptr += portions_[idx].len;
6863 for (
const auto& p : more_portions_) {
6865 ptr = place_idx<0>(ptr, p.start);
6867 const K* from = pattern_.
symbols() + p.start;
6868 for (
size_t idx = p.len; idx--;) {
6879template<StrSourceNoLiteral T,
typename...Args>
requires (
sizeof...(Args) > 0)
6880e_vsubst(T&&, Args&&...) -> e_vsubst<symb_type_from_src_t<T>, Args...>;
6882template<is_one_of_
char_v K,
bool upper>
6883struct expr_change_case_ascii : expr_to_std_string<expr_change_case_ascii<K, upper>>{
6884 using symb_type = K;
6888 template<StrSource S>
6889 expr_change_case_ascii(S&& s) : src_(std::forward<S>(s)){}
6891 constexpr size_t length() const noexcept {
6892 return src_.length();
6894 constexpr K* place(K* ptr)
const noexcept {
6895 const K* read = src_.str;
6896 for (
size_t l = src_.len; l--;) {
6897 if constexpr (upper) {
6898 *ptr++ = makeAsciiUpper(*read++);
6900 *ptr++ = makeAsciiLower(*read++);
6921template<is_one_of_
char_v K>
6923 using base = expr_change_case_ascii<K, true>;
6927template<StrSource S>
6944template<is_one_of_
char_v K>
6946 using base = expr_change_case_ascii<K, false>;
6950template<StrSource S>
6991template<
typename K,
typename A, StrExprForType<K> E>
6992std::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) {
6993 size_t expr_length = expr.length();
6995 str.erase(from, count);
6998 size_t str_length =
str.length();
6999 if (from > str_length) {
7002 if (count > str_length || from + count > str_length) {
7003 count = str_length - from;
7005 size_t new_length = str_length - count + expr_length;
7006 size_t tail_length = str_length - count - from;
7008 if (new_length <= str_length) {
7009 K* data =
str.data();
7010 expr.place((
typename E::symb_type*)data + from);
7011 if (expr_length < count) {
7013 std::char_traits<K>::move(data + from + expr_length, data + from + count, tail_length);
7015 str.resize(new_length);
7018 auto fill = [&](K* data, size_t) ->
size_t {
7020 std::char_traits<K>::move(data + from + expr_length, data + from + count, tail_length);
7022 expr.place((
typename E::symb_type*)data + from);
7025 if constexpr (
requires{
str.resize_and_overwrite(new_length, fill);}) {
7026 str.resize_and_overwrite(new_length, fill);
7027 }
else if constexpr (
requires{
str._Resize_and_overwrite(new_length, fill);}) {
7028 str._Resize_and_overwrite(new_length, fill);
7030 str.resize(new_length);
7031 fill(
str.data(), 0);
7064template<
typename K,
typename A, StrExprForType<K> E>
7065std::basic_string<K, std::char_traits<K>, A>&
append(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
7097template<
typename K,
typename A, StrExprForType<K> E>
7098std::basic_string<K, std::char_traits<K>, A>&
prepend(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
7132template<
typename K,
typename A, StrExprForType<K> E>
7133std::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) {
7161template<
typename K,
typename A, StrExprForType<K> E>
7162std::basic_string<K, std::char_traits<K>, A>&
overwrite(std::basic_string<K, std::char_traits<K>, A>&
str,
const E& expr) {
7163 if (
size_t expr_length = expr.length()) {
7164 if (expr_length <=
str.length()) {
7165 K* data =
str.data();
7166 expr.place((
typename E::symb_type*)data);
7167 str.resize(expr_length);
7169 auto fill = [&](K* data, size_t) ->
size_t {
7170 expr.place((
typename E::symb_type*)data);
7173 if constexpr (
requires{
str.resize_and_overwrite(expr_length, fill);}) {
7174 str.resize_and_overwrite(expr_length, fill);
7175 }
else if constexpr (
requires{
str._Resize_and_overwrite(expr_length, fill);}) {
7176 str._Resize_and_overwrite(expr_length, fill);
7178 str.resize(expr_length);
7179 expr.place((
typename E::symb_type*)
str.data());
7190template<
typename K,
typename A,
typename E>
7191struct replace_grow_helper {
7192 using my_type = std::basic_string<K, std::char_traits<K>, A>;
7194 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)
7195 :
str(src), source(src), pattern(p), repl(const_cast<K*>(r)), replLen(rl), maxCount(mc), delta(d), expr(e) {}
7198 const str_src<K> source;
7199 const str_src<K> pattern;
7201 const size_t replLen;
7208 K* reserve_for_copy{};
7209 size_t end_of_piece{};
7210 size_t total_length{};
7212 std::optional<my_type> dst;
7215 size_t found[16] = {offset};
7218 offset += pattern.len;
7221 for (; idx < std::size(found) && maxCount > 0; idx++, maxCount--) {
7222 found[idx] = source.find(pattern, offset);
7223 if (found[idx] == npos) {
7226 offset = found[idx] + pattern.len;
7229 if (idx == std::size(found) && maxCount > 0 && (offset = source.find(pattern, offset)) != str::npos) {
7234 if (!reserve_for_copy) {
7237 end_of_piece = source.length();
7238 total_length = end_of_piece + all_delta;
7240 if (total_length <= str.capacity()) {
7245 dst_str = &dst.emplace();
7247 auto fill = [
this](K* p, size_t) ->
size_t {
7248 reserve_for_copy = p;
7249 return total_length;
7251 if constexpr (
requires{dst_str->_Resize_and_overwrite(total_length, fill);}) {
7252 dst_str->_Resize_and_overwrite(total_length, fill);
7253 }
else if constexpr (
requires{dst_str->resize_and_overwrite(total_length, fill);}) {
7254 dst_str->resize_and_overwrite(total_length, fill);
7256 dst_str->resize(total_length);
7257 reserve_for_copy = dst_str->data();
7260 const K* src_start = str.c_str();
7262 size_t pos = found[idx] + pattern.len;
7263 size_t lenOfPiece = end_of_piece - pos;
7264 ch_traits<K>::move(reserve_for_copy + pos + all_delta, src_start + pos, lenOfPiece);
7265 if constexpr (std::is_same_v<E, int>) {
7266 ch_traits<K>::copy(reserve_for_copy + pos + all_delta - replLen, repl, replLen);
7269 repl = reserve_for_copy + pos + all_delta - replLen;
7272 ch_traits<K>::copy(reserve_for_copy + pos + all_delta - replLen, repl, replLen);
7276 end_of_piece = found[idx];
7278 if (!all_delta && reserve_for_copy != src_start) {
7279 ch_traits<K>::copy(reserve_for_copy, src_start, found[0]);
7280 str = std::move(*dst);
7321template<
typename K,
typename A, StrExprForType<K> E,
typename T>
7322requires (std::is_constructible_v<str_src<K>, T>)
7323std::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) {
7328 str_src<K> spattern{std::forward<T>(pattern)};
7329 offset = src.find(pattern, offset);
7330 if (offset == npos) {
7333 size_t replLen = repl.length();
7335 if (spattern.len == replLen) {
7338 K* ptr =
str.data();
7339 replStart = ptr + offset;
7340 repl.place(replStart);
7342 while (--max_count) {
7343 offset = src.find(spattern, offset + replLen);
7346 ch_traits<K>::copy(ptr + offset, replStart, replLen);
7348 }
else if (spattern.len > replLen) {
7351 K* ptr =
str.data();
7352 replStart = ptr + offset;
7353 repl.place(replStart);
7354 size_t posWrite = offset + replLen;
7355 offset += spattern.len;
7357 while (--max_count) {
7358 size_t idx = src.find(spattern, offset);
7361 size_t lenOfPiece = idx - offset;
7362 ch_traits<K>::move(ptr + posWrite, ptr + offset, lenOfPiece);
7363 posWrite += lenOfPiece;
7364 ch_traits<K>::copy(ptr + posWrite, replStart, replLen);
7365 posWrite += replLen;
7366 offset = idx + spattern.len;
7368 size_t tailLen = src.len - offset;
7369 ch_traits<K>::move(ptr + posWrite, ptr + offset, tailLen);
7370 str.resize(posWrite + tailLen);
7372 details::replace_grow_helper<K, A, E>(
str, spattern,
nullptr, replLen, max_count, replLen - spattern.len, repl).replace(offset);
7397template<
typename K,
typename A>
7398std::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) {
7403 offset = src.find(pattern, offset);
7404 if (offset == npos) {
7407 if (pattern.len == repl.len) {
7410 K* ptr =
str.data();
7411 while (max_count--) {
7412 ch_traits<K>::copy(ptr + offset, repl.str, repl.len);
7413 offset = src.find(pattern, offset + repl.len);
7417 }
else if (pattern.len > repl.len) {
7420 K* ptr =
str.data();
7421 ch_traits<K>::copy(ptr + offset, repl.str, repl.len);
7422 size_t posWrite = offset + repl.len;
7423 offset += pattern.len;
7425 while (--max_count) {
7426 size_t idx = src.find(pattern, offset);
7429 size_t lenOfPiece = idx - offset;
7430 ch_traits<K>::move(ptr + posWrite, ptr + offset, lenOfPiece);
7431 posWrite += lenOfPiece;
7432 ch_traits<K>::copy(ptr + posWrite, repl.str, repl.len);
7433 posWrite += repl.len;
7434 offset = idx + pattern.len;
7436 size_t tailLen = src.len - offset;
7437 ch_traits<K>::move(ptr + posWrite, ptr + offset, tailLen);
7438 str.resize(posWrite + tailLen);
7440 details::replace_grow_helper<K, A, int>(
str, pattern, repl.str, repl.len, max_count, repl.len - pattern.len, 0).replace(offset);
7445template<
typename K,
typename A,
typename T,
typename M>
7446requires (std::is_constructible_v<str_src<K>, T> && std::is_constructible_v<str_src<K>, M>)
7447std::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) {
7448 return replace(
str,
str_src<K>{std::forward<T>(pattern)}, str_src<K>{std::forward<M>(repl)}, offset, max_count);
7463template<
typename K,
typename A>
7464std::basic_string<K, std::char_traits<K>, A>&
make_ascii_upper(std::basic_string<K, std::char_traits<K>, A>&
str,
size_t from = 0,
size_t to = -1) {
7465 for (K *ptr =
str.data() + std::min(from,
str.length()), *end =
str.data() + std::min(to,
str.length()); ptr < end; ptr++) {
7467 if (isAsciiLower(s)) {
7486template<
typename K,
typename A>
7487std::basic_string<K, std::char_traits<K>, A>&
make_ascii_lower(std::basic_string<K, std::char_traits<K>, A>&
str,
size_t from = 0,
size_t to = -1) {
7488 for (K *ptr =
str.data() + std::min(from,
str.length()), *end =
str.data() + std::min(to,
str.length()); ptr < end; ptr++) {
7490 if (isAsciiUpper(s)) {
7525template<simstr::StdStrSource T>
7557template<
typename K,
typename A, simstr::StrExprForType<K> E>
7558std::basic_string<K, std::char_traits<K>, A>& operator |=(std::basic_string<K, std::char_traits<K>, A>& str,
const E& expr) {
7589template<
typename K,
typename A, simstr::StrExprForType<K> E>
7590std::basic_string<K, std::char_traits<K>, A>& operator ^=(std::basic_string<K, std::char_traits<K>, A>& str,
const E& expr) {
Class for sequentially obtaining substrings by a given delimiter.
Definition strexpr.h:3234
constexpr bool is_done() const
Find out if substrings are running out.
Definition strexpr.h:3245
constexpr str_t next()
Get the next substring.
Definition strexpr.h:3254
constexpr R trimmed_right_with_spaces(str_piece pattern) const
Get a string, removing characters specified by another string, as well as whitespace characters,...
Definition strexpr.h:4923
constexpr size_t find_last(K s, size_t offset=-1) const noexcept
Find the last occurrence of a character in this string.
Definition strexpr.h:3973
constexpr int compare_ia(str_piece text) const noexcept
Compare strings character by character and not case sensitive ASCII characters.
Definition strexpr.h:3655
constexpr int compare(str_piece o) const
Compare strings character by character.
Definition strexpr.h:3540
constexpr size_t find(K s, size_t offset=0) const noexcept
Find a character in this string.
Definition strexpr.h:3877
constexpr std::optional< R > strip_suffix(str_piece suffix) const
Get a string without a suffix if it ends with one.
Definition strexpr.h:4636
constexpr bool ends_with(str_piece suffix) const noexcept
Whether the string ends with the specified substring.
Definition strexpr.h:4473
constexpr bool operator==(const base &other) const noexcept
Operator comparing strings for equality.
Definition strexpr.h:3591
constexpr std::basic_string_view< D > to_sv() const noexcept
Convert to std::basic_string_view.
Definition strexpr.h:3374
constexpr bool starts_with_ia_and_ws(str_piece prefix) const noexcept
Check if a string begins with the specified case-insensitive ASCII substring followed by a whitespace...
Definition strexpr.h:4419
constexpr R trimmed_right() const
Get a string with whitespace removed on the right.
Definition strexpr.h:4719
constexpr R trimmed_prefix_ia(str_piece prefix, size_t max_count=0) const
Returns a string with the beginning of the string removed if it begins with the specified prefix,...
Definition strexpr.h:4962
constexpr size_t find_end_or_all(str_piece pattern, size_t offset=0) const noexcept
Find the end of the first occurrence of a substring in this string, or the end of a string.
Definition strexpr.h:3773
constexpr bool starts_with(str_piece prefix) const noexcept
Whether the string begins with the given substring.
Definition strexpr.h:4355
constexpr bool equal(str_piece other) const noexcept
String comparison for equality.
Definition strexpr.h:3580
void copy_to(K *buffer, size_t bufSize)
Copy the string to the specified buffer.
Definition strexpr.h:3352
constexpr size_t find_or_throw(str_piece pattern, size_t offset=0, Args &&... args) const noexcept
Find the beginning of the first occurrence of a substring in this string or throw an exception.
Definition strexpr.h:3729
constexpr str_piece until(str_piece pattern, size_t offset=0) const noexcept
Get the substring str_src from the beginning to the first found occurrence of the specified substring...
Definition strexpr.h:3502
constexpr R trimmed(str_piece pattern) const
Get a string with characters specified by another string removed, left and right.
Definition strexpr.h:4841
constexpr T as_int() const noexcept
Convert a string to a number of the given type.
Definition strexpr.h:4119
constexpr bool less_ia(str_piece text) const noexcept
Whether a string is smaller than another string, character-by-character-insensitive,...
Definition strexpr.h:3678
constexpr T split(str_piece delimiter, size_t offset=0) const
Split a string into substrings using a given delimiter.
Definition strexpr.h:4340
constexpr R trimmed_right_with_spaces(T &&pattern) const
Get a string with the characters specified by the string literal removed, as well as whitespace chara...
Definition strexpr.h:4824
constexpr str_piece mid(size_t from, size_t len=-1) const noexcept
Get part of a string as "string chunk".
Definition strexpr.h:3467
constexpr my_type substr(ptrdiff_t from, ptrdiff_t len=0) const
Get a substring. Works similarly to operator(), only the result is the same type as the method applie...
Definition strexpr.h:4074
R upperred_only_ascii() const
Get a copy of the string in uppercase ASCII characters.
Definition strexpr.h:4550
constexpr str_piece to_str() const noexcept
Convert itself to a "string chunk" that includes the entire string.
Definition strexpr.h:3422
constexpr bool starts_with_and_ws(str_piece prefix) const noexcept
Check if a string begins with the specified substring followed by a whitespace ASCII character.
Definition strexpr.h:4364
constexpr str_piece from_to(size_t from, size_t to) const noexcept
Get the substring str_src from position from to position to (not including it).
Definition strexpr.h:3489
constexpr R trimmed_left_with_spaces(str_piece pattern) const
Get a string, removing characters specified by another string, as well as whitespace characters,...
Definition strexpr.h:4905
R replaced(str_piece pattern, str_piece repl, size_t offset=0, size_t maxCount=0) const
Get a copy of the string with occurrences of substrings replaced.
Definition strexpr.h:4582
constexpr int strcmp(const K *text) const
Compare with C-string character by character.
Definition strexpr.h:3551
constexpr R trimmed_left() const
Get a string with whitespace removed on the left.
Definition strexpr.h:4707
constexpr bool ends_with_ia(str_piece suffix) const noexcept
Whether the string ends with the specified substring in a case-insensitive ASCII character.
Definition strexpr.h:4499
constexpr size_t find_first_not_of(str_piece pattern, size_t offset=0) const noexcept
Find the first occurrence of a character not from the given character set.
Definition strexpr.h:4020
constexpr size_t find_first_of(str_piece pattern, size_t offset=0) const noexcept
Find the first occurrence of a character from a given character set.
Definition strexpr.h:3992
constexpr R trimmed_right(str_piece pattern) const
Get a string with characters specified by another string removed to the right.
Definition strexpr.h:4869
constexpr R trimmed_with_spaces(T &&pattern) const
Get a string with the characters specified by the string literal removed, as well as whitespace chara...
Definition strexpr.h:4786
constexpr size_t find_last_or_all(str_piece pattern, size_t offset=-1) const noexcept
Find the beginning of the last occurrence of a substring in this string or the end of the string.
Definition strexpr.h:3836
constexpr R trimmed_prefix(str_piece prefix, size_t max_count=0) const
Returns a string with the beginning of the string removed if it begins with the specified prefix.
Definition strexpr.h:4939
constexpr bool starts_with_ia(str_piece prefix) const noexcept
Whether the string begins with the given substring in a case-insensitive ASCII character.
Definition strexpr.h:4410
constexpr R trimmed_left_with_spaces(T &&pattern) const
Get a string with the characters specified by the string literal removed, as well as whitespace chara...
Definition strexpr.h:4805
constexpr size_t find_last(str_piece pattern, size_t offset=-1) const noexcept
Find the beginning of the last occurrence of a substring in this string.
Definition strexpr.h:3809
constexpr size_t find_last_of(str_piece pattern, size_t offset=str::npos) const noexcept
Find the last occurrence of a character from a given character set.
Definition strexpr.h:4033
constexpr size_t find_or_all(K s, size_t offset=0) const noexcept
Find a character in this string or the end of a string.
Definition strexpr.h:3896
constexpr size_t find_last_not_of(str_piece pattern, size_t offset=str::npos) const noexcept
Find the last occurrence of a character not from the given character set.
Definition strexpr.h:4061
std::optional< double > to_double() const noexcept
Convert string to double.
Definition strexpr.h:4164
constexpr void for_all_finded(const Op &op, str_piece pattern, size_t offset=0, size_t maxCount=0) const
Call a functor on all found occurrences of a substring in this string.
Definition strexpr.h:3931
constexpr size_t find_end(str_piece pattern, size_t offset=0) const noexcept
Find the end of the occurrence of a substring in this string.
Definition strexpr.h:3745
std::optional< double > to_double_hex() const noexcept
Convert string in hex form to double.
Definition strexpr.h:4199
constexpr std::optional< R > strip_prefix(str_piece prefix) const
Get a string without a prefix if it starts with one.
Definition strexpr.h:4598
constexpr bool operator!() const noexcept
Check for emptiness.
Definition strexpr.h:3509
constexpr R trimmed() const
Get a string with whitespace removed on the left and right.
Definition strexpr.h:4695
constexpr size_t size() const
The size of the string in characters.
Definition strexpr.h:3363
constexpr To find_all(str_piece pattern, size_t offset=0, size_t maxCount=0) const
Find all occurrences of a substring in this string.
Definition strexpr.h:3954
constexpr my_type str_mid(size_t from, size_t len=-1) const
Get part of a string with an object of the same type to which the method is applied,...
Definition strexpr.h:4087
constexpr size_t find_end_of_last(str_piece pattern, size_t offset=-1) const noexcept
Find the end of the last occurrence of a substring in this string.
Definition strexpr.h:3822
constexpr std::pair< size_t, size_t > find_first_of_idx(str_piece pattern, size_t offset=0) const noexcept
Find the first occurrence of a character from a given character set.
Definition strexpr.h:4005
constexpr bool is_ascii() const noexcept
Whether the string contains only ASCII characters.
Definition strexpr.h:4506
constexpr size_t find(str_piece pattern, size_t offset=0) const noexcept
Find the beginning of the first occurrence of a substring in this string.
Definition strexpr.h:3709
constexpr SplitterBase< K, str_piece > splitter(str_piece delimiter) const
Retrieve a Splitter object by the given splitter, which allows sequential get substrings using the ne...
Definition strexpr.h:5022
constexpr std::pair< size_t, size_t > find_last_of_idx(str_piece pattern, size_t offset=str::npos) const noexcept
Find the last occurrence of a character from a given character set.
Definition strexpr.h:4046
constexpr R trimmed_left(T &&pattern) const
Get a string with the characters specified by the string literal removed from the left.
Definition strexpr.h:4749
constexpr size_t find_or_all(str_piece pattern, size_t offset=0) const noexcept
Find the beginning of the first occurrence of a substring in this string or the end of the string.
Definition strexpr.h:3759
constexpr R trimmed_left(str_piece pattern) const
Get a string with characters specified by another string removed from the left.
Definition strexpr.h:4855
constexpr bool operator==(T &&other) const noexcept
Operator for comparing a string and a string literal for equality.
Definition strexpr.h:3610
constexpr auto operator<=>(const base &other) const noexcept
String comparison operator.
Definition strexpr.h:3600
constexpr bool contains(str_piece pattern, size_t offset=0) const noexcept
Whether the string contains the specified substring.
Definition strexpr.h:3864
constexpr R trimmed_suffix_ia(str_piece suffix) const
Returns a string with the end of the string removed if it ends with the specified suffix,...
Definition strexpr.h:5005
constexpr str_piece operator()(ptrdiff_t from, ptrdiff_t len=0) const noexcept
Get part of a string as "str_src".
Definition strexpr.h:3448
constexpr K at(ptrdiff_t idx) const
Get the character at the given position.
Definition strexpr.h:3522
R lowered_only_ascii() const
Get a copy of the string in lowercase ASCII characters.
Definition strexpr.h:4562
constexpr R trimmed_with_spaces(str_piece pattern) const
Get a string, removing characters specified by another string, as well as whitespace characters,...
Definition strexpr.h:4887
constexpr auto operator<=>(T &&other) const noexcept
Comparison operator between a string and a string literal.
Definition strexpr.h:3620
constexpr std::basic_string< D, Traits, Allocator > to_string() const
Convert to std::basic_string.
Definition strexpr.h:3394
constexpr R trimmed_right(T &&pattern) const
Get a string with the characters specified by the string literal removed from the right.
Definition strexpr.h:4764
constexpr T splitf(str_piece delimiter, const Op &beforeFunc, size_t offset=0) const
Split a string into parts at a given delimiter, possibly applying a functor to each substring.
Definition strexpr.h:4324
constexpr R trimmed(T &&pattern) const
Get a string with the characters specified by the string literal removed from the left and right.
Definition strexpr.h:4734
constexpr size_t find_end_of_last_or_all(str_piece pattern, size_t offset=-1) const noexcept
Find the end of the last occurrence of a substring in this string, or the end of a string.
Definition strexpr.h:3850
constexpr bool prefix_in(str_piece text) const noexcept
Whether this string is the beginning of another string.
Definition strexpr.h:4458
constexpr std::optional< R > strip_prefix_ia(str_piece prefix) const
Get a string without a prefix if it starts with it, insensitive to ASCII characters.
Definition strexpr.h:4617
constexpr bool starts_with_ia_and_oneof(str_piece prefix, str_piece next_symbol) const noexcept
Check if a string begins with the specified case-insensitive ASCII substring followed by one of the s...
Definition strexpr.h:4432
constexpr std::optional< R > strip_suffix_ia(str_piece suffix) const
Get a string without a suffix if it ends with one in case-insensitive ASCII characters.
Definition strexpr.h:4655
constexpr R trimmed_suffix(str_piece suffix) const
Returns a string with the beginning of the string removed if it begins with the specified prefix.
Definition strexpr.h:4985
constexpr K * place(K *ptr) const noexcept
Copy the string to the specified buffer.
Definition strexpr.h:3337
constexpr convert_result< T > to_int() const noexcept
Convert a string to a number of the given type.
Definition strexpr.h:4152
constexpr bool equal_ia(str_piece text) const noexcept
Whether a string is equal to another string, character-by-character-insensitive, of ASCII characters.
Definition strexpr.h:3667
constexpr void as_number(T &t) const
Convert a string to an integer.
Definition strexpr.h:4227
constexpr bool starts_with_and_oneof(str_piece prefix, str_piece next_symbol) const noexcept
Check if a string begins with the specified substring followed by one of the specified characters.
Definition strexpr.h:4377
The concept of a string expression compatible with a given character type.
Definition strexpr.h:525
Concept of "String Expressions".
Definition strexpr.h:507
Base concept of string object.
Definition strexpr.h:311
Checks whether two types are compatible string types.
Definition strexpr.h:172
constexpr expr_if< A > e_if(bool c, const A &a)
Creating a conditional string expression expr_if.
Definition strexpr.h:1544
simstr::expr_stdstr< typename T::value_type, T > operator+(const T &str)
Unary operator + for converting standard strings to string expressions.
Definition strexpr.h:7526
constexpr expr_spaces< uws, N > e_spcw()
Generates a string of N wchar_t spaces.
Definition strexpr.h:1104
expr_fill< K, A, true > e_fill_left(const A &a, size_t width, K symbol=K(' '))
Creates an expression that expands the specified string expression to the specified length given char...
Definition strexpr.h:2699
constexpr empty_expr< uws > eew
Empty string expression of type wchar_t.
Definition strexpr.h:862
constexpr expr_spaces< u8s, N > e_spca()
Generates a string of N char spaces.
Definition strexpr.h:1086
constexpr empty_expr< u32s > eeuu
Empty string expression of type char32_t.
Definition strexpr.h:874
constexpr expr_num< K, T > e_num(T t)
Convert an integer to a string expression.
Definition strexpr.h:1720
HexFlags
Flags for the e_hex function.
Definition strexpr.h:2527
constexpr auto e_hex(T v)
Creates an object that can be converted to a string expression that generates a hexadecimal represent...
Definition strexpr.h:2584
constexpr strexprjoin< A, B > operator+(const A &a, const B &b)
An addition operator for two arbitrary string expressions of the same character type.
Definition strexpr.h:719
constexpr expr_repeat_lit< K, M - 1 > e_repeat(T &&s, size_t l)
Generate a string from l string constants s of type K.
Definition strexpr.h:1218
constexpr expr_literal< typename const_lit< T >::symb_type, static_cast< size_t >(N - 1)> e_t(T &&s)
Converts a string literal to a string expression.
Definition strexpr.h:991
expr_fill< K, A, false > e_fill_right(const A &a, size_t width, K symbol=K(' '))
Creates an expression that expands the specified string expression to the specified length given char...
Definition strexpr.h:2725
constexpr expr_choice< A, B > e_choice(bool c, const A &a, const B &b)
Create a conditional string expression expr_choice.
Definition strexpr.h:1466
constexpr expr_char< K > e_char(K s)
Generates a string of 1 given character.
Definition strexpr.h:918
constexpr empty_expr< u8s > eea
Empty string expression of type char.
Definition strexpr.h:850
constexpr expr_pad< K > e_c(size_t l, K s)
Generates a string of l characters s of type K.
Definition strexpr.h:1149
constexpr empty_expr< u16s > eeu
Empty string expression of type char16_t.
Definition strexpr.h:868
auto e_repl_const_symbols(A &&src, Repl &&... other)
Returns a string expression that generates a string containing the given characters replaced with giv...
Definition strexpr.h:6140
constexpr auto e_int(T v)
Creates an object that is converted to a string expression that generates a string representation of ...
Definition strexpr.h:2383
constexpr empty_expr< u8s > eeb
Empty string expression of type char8_t.
Definition strexpr.h:856
constexpr auto e_repl(A &&w, T &&p, X &&r)
Get a string expression that generates a string with all occurrences of a given substring replaced.
Definition strexpr.h:5647
constexpr auto e_join(const T &s, L &&d)
Get a string expression concatenating the strings in the container into a single string with the give...
Definition strexpr.h:2803
@ Short
without leading zeroes
Definition strexpr.h:2528
Small namespace for standard string methods.
Definition 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)
Append a string expression to a standard string.
Definition strexpr.h:7065
std::basic_string< K, std::char_traits< K >, A > & prepend(std::basic_string< K, std::char_traits< K >, A > &str, const E &expr)
Insert a string expression at the beginning of a standard string.
Definition strexpr.h:7098
std::basic_string< K, std::char_traits< K >, A > & make_ascii_upper(std::basic_string< K, std::char_traits< K >, A > &str, size_t from=0, size_t to=-1)
Change lowercase ASCII string characters (a-z) to uppercase.
Definition strexpr.h:7464
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)
Replace a portion of a standard string with the given string expression.
Definition strexpr.h:6992
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)
A function for searching for substrings in a standard string and replacing the found occurrences with...
Definition strexpr.h:7323
std::basic_string< K, std::char_traits< K >, A > & make_ascii_lower(std::basic_string< K, std::char_traits< K >, A > &str, size_t from=0, size_t to=-1)
Change uppercase ASCII string characters (A-Z) to lowercase.
Definition strexpr.h:7487
std::basic_string< K, std::char_traits< K >, A > & overwrite(std::basic_string< K, std::char_traits< K >, A > &str, const E &expr)
Rewrite the entire string with the given string expression, resizing the string if necessary.
Definition strexpr.h:7162
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)
Insert a string expression at the specified position in a standard string.
Definition strexpr.h:7133
Library namespace.
Definition sstring.cpp:12
IntConvertResult
Enumeration with possible results of converting a string to an integer.
Definition strexpr.h:2870
@ Overflow
Переполнение, число не помещается в заданный тип
Definition strexpr.h:2873
@ Success
Успешно
Definition strexpr.h:2871
@ NotNumber
Вообще не число
Definition strexpr.h:2874
@ BadSymbolAtTail
Число закончилось не числовым символом
Definition strexpr.h:2872
Some methods for working with standard strings.
Definition strexpr.h:7505
Generate a string based on the original one, replacing all ASCII uppercase letters (A-Z) with lowerca...
Definition strexpr.h:6945
Generate a string based on the original one, replacing all ASCII lowercase letters (a-z) with upperca...
Definition strexpr.h:6922
constexpr e_concat(G &&glue, Arg &&arg, Args &&...args)
Create a string expression concatenating the specified string expressions using the specified delimit...
Definition strexpr.h:6479
constexpr e_subst(const details::subst_params< K, PtLen, NParams > &subst, Args &&...args)
Creates a string expression that substitutes the values of the passed string expressions into the s...
Definition strexpr.h:6701
constexpr e_vsubst(str_src< K > pattern, Args &&...args)
Creates a string expression that substitutes the values of the passed string expressions into the s...
Definition strexpr.h:6800
An "empty" string expression.
Definition strexpr.h:835
Conditional selection string expression.
Definition strexpr.h:1345
Conditional selection string expression.
Definition strexpr.h:1411
Conditional selection string expression.
Definition strexpr.h:1254
Conditional selection string expression.
Definition strexpr.h:1283
A type of string expression that returns N specified characters.
Definition strexpr.h:1120
constexpr expr_replace_symbols(str_t source, const std::vector< std::pair< K, str_t > > &repl)
Expression constructor.
Definition strexpr.h:6224
A string expression that generates a string replacing all occurrences of the given substring to strin...
Definition strexpr.h:5765
constexpr expr_replaced_e(str_src< K > w, str_src< K > p, const E &e)
Constructor.
Definition strexpr.h:5784
A string expression that generates a string replacing all occurrences of the given substring to anoth...
Definition strexpr.h:5659
constexpr expr_replaced(str_src< K > w, str_src< K > p, str_src< K > r)
Constructor.
Definition strexpr.h:5677
A type of string expression that returns N specified characters.
Definition strexpr.h:1060
A type for using std::basic_string and std::basic_string_view as sources in string expressions.
Definition strexpr.h:1569
Base class for converting string expressions to standard strings.
Definition strexpr.h:659
A class that claims to refer to a null-terminated string.
Definition strexpr.h:5193
constexpr my_type to_nts(size_t from)
Get a null-terminated string by shifting the start by the specified number of characters.
Definition strexpr.h:5256
constexpr str_src_nt(T &&v) noexcept
Constructor from a string literal.
Definition strexpr.h:5227
constexpr str_src_nt(T &&p) noexcept
Explicit constructor from C-string.
Definition strexpr.h:5218
constexpr str_src_nt(const std::basic_string< K, std::char_traits< K >, A > &s) noexcept
Constructor from std::basic_string.
Definition strexpr.h:5245
constexpr str_src_nt(const K *p, size_t l) noexcept
Constructor from pointer and length.
Definition strexpr.h:5233
The simplest class of an immutable non-owning string.
Definition strexpr.h:5057
constexpr str_src(const std::basic_string< K, std::char_traits< K >, A > &s) noexcept
Constructor from std::basic_string.
Definition strexpr.h:5086
constexpr bool is_empty() const noexcept
Check if a string is empty.
Definition strexpr.h:5111
constexpr size_t length() const noexcept
Get the length of the string.
Definition strexpr.h:5097
constexpr K operator[](size_t idx) const
Get the character from the specified position. Bounds checking is not performed.
Definition strexpr.h:5140
constexpr my_type & remove_prefix(size_t delta)
Shifts the start of a string by the specified number of characters.
Definition strexpr.h:5151
constexpr str_src(const K *p, size_t l) noexcept
Constructor from pointer and length.
Definition strexpr.h:5076
constexpr bool is_same(str_src< K > other) const noexcept
Check if two objects point to the same string.
Definition strexpr.h:5120
constexpr str_src(const std::basic_string_view< K, std::char_traits< K > > &s) noexcept
Constructor from std::basic_string_view.
Definition strexpr.h:5091
constexpr const symb_type * symbols() const noexcept
Get a pointer to a constant buffer containing string characters.
Definition strexpr.h:5104
constexpr my_type & remove_suffix(size_t delta)
Shortens the string by the specified number of characters.
Definition strexpr.h:5164
constexpr bool is_part_of(str_src< K > other) const noexcept
Check if a string is part of another string.
Definition strexpr.h:5129
constexpr str_src(T &&v) noexcept
Constructor from a string literal.
Definition strexpr.h:5070
Concatenation of a reference to a string expression and the value of the string expression.
Definition strexpr.h:744
Template class for concatenating two string expressions into one using operator +
Definition strexpr.h:682