mirror of https://github.com/orefkov/simstr.git
Add `e_repeat` expression. Update version.
This commit is contained in:
parent
b593eeb540
commit
bde616b8f4
|
|
@ -5,7 +5,7 @@ include(FetchContent)
|
||||||
|
|
||||||
project(
|
project(
|
||||||
simstr
|
simstr
|
||||||
VERSION 1.2.8
|
VERSION 1.2.9
|
||||||
DESCRIPTION "Yet another modern C++ string library"
|
DESCRIPTION "Yet another modern C++ string library"
|
||||||
HOMEPAGE_URL "https://github.com/orefkov/simstr"
|
HOMEPAGE_URL "https://github.com/orefkov/simstr"
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
|
|
@ -27,6 +27,7 @@ endif()
|
||||||
|
|
||||||
option(SIMSTR_BUILD_TESTS "Build tests" ON)
|
option(SIMSTR_BUILD_TESTS "Build tests" ON)
|
||||||
option(SIMSTR_BENCHMARKS "Build benchmarks" Off)
|
option(SIMSTR_BENCHMARKS "Build benchmarks" Off)
|
||||||
|
option(USE_SYSTEM_DEPS "Use system dependencies" Off)
|
||||||
cmake_dependent_option(SIMSTR_LINK_NATVIS "Link natvis file" On CAN_LINK_NATVIS Off)
|
cmake_dependent_option(SIMSTR_LINK_NATVIS "Link natvis file" On CAN_LINK_NATVIS Off)
|
||||||
|
|
||||||
add_library(simstr_simstr
|
add_library(simstr_simstr
|
||||||
|
|
@ -92,7 +93,11 @@ function(add_simdutf)
|
||||||
FetchContent_MakeAvailable(simdutf)
|
FetchContent_MakeAvailable(simdutf)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
add_simdutf()
|
if (USE_SYSTEM_DEPS)
|
||||||
|
find_package(simdutf REQUIRED)
|
||||||
|
else ()
|
||||||
|
add_simdutf()
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(simstr_simstr PUBLIC simdutf::simdutf)
|
target_link_libraries(simstr_simstr PUBLIC simdutf::simdutf)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ PROJECT_NAME = "simstr"
|
||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER = 1.2.8
|
PROJECT_NUMBER = 1.2.9
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewers a
|
# for a project that appears at the top of each page and should give viewers a
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ PROJECT_NAME = "simstr"
|
||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER = 1.2.8
|
PROJECT_NUMBER = 1.2.9
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewers a
|
# for a project that appears at the top of each page and should give viewers a
|
||||||
|
|
|
||||||
|
|
@ -474,6 +474,11 @@ The number of characters and the symbol can be specified at runtime. Shorthand n
|
||||||
|
|
||||||
e_c(NumberOfCharacters, Symbol)
|
e_c(NumberOfCharacters, Symbol)
|
||||||
|
|
||||||
|
#### e_repeat{Str, count}
|
||||||
|
Generates a repetition of a string literal or expression `Str` `count` times.
|
||||||
|
|
||||||
|
e_repeat("aa", 10);
|
||||||
|
|
||||||
#### e_choice(bool Condition, StrExpr1, StrExpr2)
|
#### e_choice(bool Condition, StrExpr1, StrExpr2)
|
||||||
If Condition == true, the result will be StrExpr1, otherwise StrExpr2.
|
If Condition == true, the result will be StrExpr1, otherwise StrExpr2.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -476,6 +476,11 @@
|
||||||
|
|
||||||
e_c(КоличествоСимволов, Символ)
|
e_c(КоличествоСимволов, Символ)
|
||||||
|
|
||||||
|
#### e_repeat{Str, count}
|
||||||
|
Генерирует повторение строкового литерала или выражения `Str` `count` раз.
|
||||||
|
|
||||||
|
e_repeat("aa", 10);
|
||||||
|
|
||||||
#### e_choice(bool Condition, StrExpr1, StrExpr2)
|
#### e_choice(bool Condition, StrExpr1, StrExpr2)
|
||||||
Если Condition == true, результат будет равен StrExpr1, иначе StrExpr2.
|
Если Condition == true, результат будет равен StrExpr1, иначе StrExpr2.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -814,6 +814,75 @@ constexpr inline auto e_c(size_t l, K s) {
|
||||||
return expr_pad<K>{ l, s };
|
return expr_pad<K>{ l, s };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename K, size_t N>
|
||||||
|
struct expr_repeat_lit {
|
||||||
|
using symb_type = K;
|
||||||
|
size_t repeat_;
|
||||||
|
const K (&s)[N + 1];
|
||||||
|
constexpr size_t length() const noexcept {
|
||||||
|
return N * repeat_;
|
||||||
|
}
|
||||||
|
constexpr symb_type* place(symb_type* p) const noexcept {
|
||||||
|
for (size_t i = 0; i < repeat_; i++) {
|
||||||
|
std::char_traits<K>::copy(p, s, N);
|
||||||
|
p += N;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<StrExpr A>
|
||||||
|
struct expr_repeat_expr {
|
||||||
|
using symb_type = typename A::symb_type;
|
||||||
|
size_t repeat_;
|
||||||
|
const A& expr_;
|
||||||
|
constexpr size_t length() const noexcept {
|
||||||
|
return repeat_ * expr_.length();
|
||||||
|
}
|
||||||
|
constexpr symb_type* place(symb_type* p) const noexcept {
|
||||||
|
for (size_t i = 0; i < repeat_; i++) {
|
||||||
|
p = expr_.place(p);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @ingroup StrExprs
|
||||||
|
* @ru @brief Генерирует строку из l строковых констант s типа K
|
||||||
|
* @tparam K - тип символа
|
||||||
|
* @param l - количество повторов
|
||||||
|
* @param s - строковый литерал
|
||||||
|
* @return строковое выражение, генерирующее строку из l строк s
|
||||||
|
* @en @brief Generate a string from l string constants s of type K
|
||||||
|
* @tparam K - character type
|
||||||
|
* @param l - number of repetitions
|
||||||
|
* @param s - string literal
|
||||||
|
* @return a string expression generating a string of l strings s
|
||||||
|
*/
|
||||||
|
template<typename T, typename K = const_lit<T>::symb_type, size_t M = const_lit<T>::Count> requires (M > 0)
|
||||||
|
constexpr inline auto e_repeat(T&& s, size_t l) {
|
||||||
|
return expr_repeat_lit<K, M - 1>{ l, s };
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @ingroup StrExprs
|
||||||
|
* @ru @brief Генерирует строку из l строковых выражений s типа K
|
||||||
|
* @tparam K - тип символа
|
||||||
|
* @param l - количество повторов
|
||||||
|
* @param s - строковое выражение
|
||||||
|
* @return строковое выражение, генерирующее строку из l строковых выражений s
|
||||||
|
* @en @brief Generate a string from l string expressions s of type K
|
||||||
|
* @tparam K - character type
|
||||||
|
* @param l - number of repetitions
|
||||||
|
* @param s - string expression
|
||||||
|
* @return a string expression generating a string of l string expressions s
|
||||||
|
*/
|
||||||
|
template<StrExpr A>
|
||||||
|
constexpr inline auto e_repeat(const A& s, size_t l) {
|
||||||
|
return expr_repeat_expr<A>{ l, s };
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @ingroup StrExprs
|
* @ingroup StrExprs
|
||||||
* @ru @brief Строковое выражение условного выбора.
|
* @ru @brief Строковое выражение условного выбора.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# simstr - String object and function library
|
# simstr - String object and function library
|
||||||
[](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml)
|
[](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml)
|
||||||
|
|
||||||
Version 1.2.8.
|
Version 1.2.9.
|
||||||
|
|
||||||
<span class="obfuscator"><a href="readme_ru.md">On Russian | По-русски</a></span>
|
<span class="obfuscator"><a href="readme_ru.md">On Russian | По-русски</a></span>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# simstr - библиотека строковых объектов и функций
|
# simstr - библиотека строковых объектов и функций
|
||||||
[](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml)
|
[](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml)
|
||||||
|
|
||||||
Версия 1.2.8.
|
Версия 1.2.9.
|
||||||
|
|
||||||
<span class="obfuscator"><a href="readme.md">On English | По-английски</a></span>
|
<span class="obfuscator"><a href="readme.md">On English | По-английски</a></span>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1769,4 +1769,10 @@ TEST(SimStr, HashStrMapAt) {
|
||||||
EXPECT_EQ(test.find("Test")->second, 2);
|
EXPECT_EQ(test.find("Test")->second, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(SimStr, ExprRepeat) {
|
||||||
|
EXPECT_EQ(stringa{e_repeat("aa", 3)}, "aaaaaa");
|
||||||
|
int t = 1;
|
||||||
|
EXPECT_EQ(lstringa<40>{e_repeat("aa"_ss + t + "_", 3)}, "aa1_aa1_aa1_");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace simstr::tests
|
} // namespace simstr::tests
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue