4using namespace std::literals;
25 static_assert(std::is_same_v<std::string, kblib::detail::str_type_t<double>>,
26 "arithmetic types are converted to std::string");
31 std::string val =
"1";
32 const char* type =
"bool";
34 ==
"\"1\" is not a bool");
37 std::string_view val =
"1";
38 const char* type =
"bool";
40 ==
"\"1\" is not a bool");
45 std::vector<std::string> vec{
"Hello",
"world!",
"How",
"do",
"you",
"do?"};
47 REQUIRE(joined ==
"Hello world! How do you do?");
49 REQUIRE(split == vec);
53 std::vector<std::tuple<std::string, std::vector<std::string>>> tests{
57 {
"abc def", {
"abc",
"def"}},
61 {
"abc def", {
"abc",
"def"}},
62 {
"abc def ", {
"abc",
"def"}},
66 {
"abc\t\tdef", {
"abc",
"def"}},
67 {
"abc\tdef\t", {
"abc",
"def"}},
70 {
"\v abc\t ", {
"abc"}},
71 {
"abc \t def", {
"abc",
"def"}},
72 {
"abc\n def ", {
"abc",
"def"}},
73 {
" abc def ", {
"abc",
"def"}},
74 {
" abc def", {
"abc",
"def"}},
75 {
" abc def ", {
"abc",
"def"}},
76 {
" abc def ghi", {
"abc",
"def",
"ghi"}},
78 for (
const auto& [
test, result] : tests) {
83 std::vector<std::pair<std::string, std::vector<std::string>>> tests{
87 {
"abc def", {
"abc",
"def"}},
91 {
"abc def", {
"abc",
"def"}},
92 {
"abc def ", {
"abc",
"def"}},
93 {
" abc def ", {
"abc",
"def"}},
94 {
" abc def", {
"abc",
"def"}},
95 {
" abc def ", {
"abc",
"def"}},
96 {
" abc def ghi", {
"abc",
"def",
"ghi"}},
98 for (
const auto& [
test, result] : tests) {
104 std::vector<std::pair<std::string, std::vector<std::string>>> tests{
108 {
"abc,def", {
"abc",
"def"}},
109 {
",abc", {
"",
"abc"}},
110 {
"abc,", {
"abc",
""}},
111 {
",abc,", {
"",
"abc",
""}},
112 {
"abc,,def", {
"abc",
"",
"def"}},
113 {
"abc,def,", {
"abc",
"def",
""}},
114 {
",abc,,def,", {
"",
"abc",
"",
"def",
""}},
115 {
",abc,def", {
"",
"abc",
"def"}},
116 {
",,abc,,,,def,,", {
"",
"",
"abc",
"",
"",
"",
"def",
"",
""}},
117 {
",abc,def,ghi", {
"",
"abc",
"def",
"ghi"}},
119 for (
const auto& [
test, result] : tests) {
constexpr auto test() noexcept -> bool
auto split_tokens(const String &in, Predicate spacer) -> return_assert_t< is_callable< Predicate, typename Container::value_type::value_type >::value, Container >
Split a string on all condensed delimiters.
auto kbsplit2(const String &in, char delim=' ') -> Container
auto concat(F &&f, S &&... ins) -> string
Returns a string consisting of the concatenation of all arguments.
auto join(const range &in, const string &joiner="")
Concatenates all elements of a range together with an optional joiner.
auto split_dsv(const String &str, char delim) -> Container
Split a string on all instances of delim.
Provides utilities for performing common operations on strings.