25#ifndef HARNESS_STRING_INCLUDED
26#define HARNESS_STRING_INCLUDED
28#include "harness_export.h"
38std::vector<std::string> HARNESS_EXPORT
wrap_string(
const std::string &to_wrap,
40 std::size_t indent_size);
49 const std::string &suffix);
58 const std::string &prefix);
61MY_ATTRIBUTE((format(printf, 1, 2)))
67template <
class Container,
class T>
69 static std::string
impl(Container,
const std::string &);
72template <
class Container>
74 static std::string
impl(Container cont,
const std::string &delim) {
75 if (cont.begin() == cont.end())
return {};
77 std::string o(*(cont.begin()));
82 const size_t delim_size = delim.size();
84 std::accumulate(std::next(cont.begin()), cont.end(), o.size(),
85 [delim_size](
size_t sum,
const std::string &b) {
86 return sum + delim_size + b.size();
94 return std::accumulate(std::next(cont.begin()), cont.end(), o,
95 [&delim](std::string a,
const std::string &b) {
96 return a.append(delim).append(b);
100 auto it = std::next(cont.begin());
101 const auto last = cont.end();
104 for (; it !=
last; ++it) {
115template <
class Container>
116struct Join<Container, const char *> {
117 static std::string
impl(Container cont,
const std::string &delim) {
118 if (cont.begin() == cont.end())
return {};
120 return std::accumulate(std::next(cont.begin()), cont.end(),
121 std::string(*(cont.begin())),
122 [&delim](
const std::string &a,
const char *b) {
123 return a + delim + b;
149template <
class Container>
150std::string
join(Container cont,
const std::string &delim) {
158 if (v == k)
return true;
Header for compiler-dependent features.
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1085
Definition: ut0tuple.h:56
HARNESS_EXPORT std::string string_format(const char *format,...)
Definition: utilities.cc:63
std::vector< std::string > HARNESS_EXPORT wrap_string(const std::string &to_wrap, std::size_t width, std::size_t indent_size)
bool HARNESS_EXPORT ends_with(const std::string &str, const std::string &suffix)
Checks whether string ends with the specified suffix.
Definition: utilities.cc:121
bool HARNESS_EXPORT starts_with(const std::string &str, const std::string &prefix)
Checks whether string starts with the specified prefix.
Definition: utilities.cc:128
constexpr bool str_in_collection(const T &t, const std::string_view &k)
Definition: string.h:156
std::string join(Container cont, const std::string &delim)
join elements of an container into a string separated by a delimiter.
Definition: string.h:150
Definition: varlen_sort.h:183
static std::string impl(Container cont, const std::string &delim)
Definition: string.h:117
static std::string impl(Container cont, const std::string &delim)
Definition: string.h:74
static std::string impl(Container, const std::string &)