17 #ifndef SHARED_STRINGTRANSFORM_H
18 #define SHARED_STRINGTRANSFORM_H
21 #include <boost/config.hpp>
23 #include <string_view>
36 const boost::regex& reg_expr,
37 const std::function<
void(std::string&,
const boost::smatch&)>& shim_fn);
40 template <
typename... Ts>
42 std::ostringstream oss;
43 (oss << ... << std::forward<Ts>(
args));
59 std::vector<std::pair<size_t, size_t>>
const& literal_positions);
63 std::string
join(
T const& container, std::string
const& delim) {
65 if (!container.empty()) {
66 ss << *container.cbegin();
67 for (
auto itr = std::next(container.cbegin()); itr != container.cend(); ++itr) {
76 std::ostringstream oss;
93 inline std::string
to_upper(
const std::string& str) {
95 std::transform(str_uc.begin(), str_uc.end(), str_uc.begin(), ::toupper);
99 inline std::string
to_lower(
const std::string& str) {
101 std::transform(str_lc.begin(), str_lc.end(), str_lc.begin(), ::tolower);
108 std::vector<std::string>
split(std::string_view str,
110 std::string_view delim = {},
111 std::optional<size_t> maxsplit = std::nullopt);
114 std::string_view
sv_strip(std::string_view str);
117 std::string
strip(std::string_view str);
120 std::pair<std::string_view, const char*>
substring(
const std::string& str,
121 size_t substr_length);
126 std::string& str) noexcept;
143 template <
typename T>
146 if constexpr (std::is_base_of_v<std::string,
147 std::remove_reference_t<decltype(parm)>>) {
148 return std::forward<T>(parm);
152 }
else if constexpr (std::is_array_v<
153 std::remove_reference_t<decltype(parm)>>) {
154 return std::forward<T>(parm);
158 }
else if constexpr (std::is_same_v<std::remove_reference_t<decltype(parm)>,
160 std::is_same_v<std::remove_reference_t<decltype(parm)>,
162 return std::forward<T>(parm);
166 }
else if constexpr (std::is_integral_v<std::remove_reference_t<decltype(parm)>> ||
167 std::is_floating_point_v<
168 std::remove_reference_t<decltype(parm)>>) {
174 static_assert(std::is_base_of_v<
void, decltype(parm)>);
175 return std::string();
181 template <
typename... Types>
188 void append(std::string_view moretxt) { txt += moretxt; }
191 (j.append(
stringlike(std::forward<Types>(parms))), ...);
192 return std::move(j.txt);
195 template <
typename... Types>
196 std::string
concat_with(std::string_view with, Types&&... parms) {
198 JoinerWith(std::string_view
join) :
join(join), first(
true) {}
200 std::string_view
join;
204 void append(std::string_view moretxt) {
214 (j.append(
stringlike(std::forward<Types>(parms))), ...);
215 return std::move(j.txt);
219 #endif // SHARED_STRINGTRANSFORM_H
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
OUTPUT transform(INPUT const &input, FUNC const &func)
std::string filename(char const *path)