14#include <unordered_map>
34 static std::string
concat(
const std::string &a,
const std::string &b)
noexcept;
40 static bool contains(
const std::string &str,
const std::string &substr)
noexcept;
51 static bool ends_with(
const std::string &str,
const std::string &suffix)
noexcept;
57 static bool find(std::string_view sv,
char c)
noexcept;
63 static std::string_view
find_first_of(
const std::string_view &s,
const std::string_view &chars)
noexcept;
69 static std::string_view
strip(
const std::string_view &s,
const std::string_view &to_strip_from_s =
" ") noexcept;
73 template <typename T, typename =
void>
74 struct has_push_back : std::false_type
79 struct has_push_back<T, std::void_t<decltype(std::declval<T>().push_back(std::declval<typename T::value_type>()))>> : std::true_type
84 static constexpr auto eq = [](
const auto &el,
const auto &sep) ->
bool
86 using std::is_convertible_v;
89 using ElType = std::decay_t<
decltype(el)>;
90 using SepType = std::decay_t<
decltype(sep)>;
92 if constexpr (is_same_v<ElType, SepType>)
97 else if constexpr (is_convertible_v<ElType, SepType>)
100 return static_cast<SepType
>(el) == sep;
102 else if constexpr (is_convertible_v<SepType, ElType>)
105 return el ==
static_cast<ElType
>(sep);
126 template <
typename It,
typename Oc,
typename V,
typename Pred>
127 static It
split(It it,
const It end_it, Oc &dest,
const V &sep, Pred f)
130 using std::is_same_v;
133 using SliceContainer =
typename Oc::value_type;
138 SliceContainer dest_elm{};
142 while (slice != end_it)
149 if constexpr (is_same_v<SliceContainer, string>)
154 else if constexpr (has_push_back<SliceContainer>::value)
157 dest_elm.push_back(*slice);
163 static_assert(is_same_v<SliceContainer, string> || has_push_back<SliceContainer>::value,
164 "SliceContainer must be std::string or have a push_back method");
169 dest.push_back(dest_elm);
191 template <
typename It,
typename Oc,
typename V>
192 static It
split(It it,
const It end_it, Oc &dest,
const V &sep)
195 return split(it, end_it, dest, sep, eq);
206 template <
typename Cin,
typename Cout,
typename V>
207 static Cout &
strsplit(
const Cin &str, Cout &dest,
const V &sep)
210 split(str.begin(), str.end(), dest, sep, eq);
219 template <
typename T>
223 using std::is_same_v;
224 using std::string_view;
227 constexpr string_view whitespace_chars =
" \t\r\n\v\f";
230 if constexpr (is_same_v<T, char>)
232 return whitespace_chars.find(c) != string_view::npos;
237 return c ==
static_cast<T
>(
' ') ||
238 c ==
static_cast<T
>(
'\t') ||
239 c ==
static_cast<T
>(
'\r') ||
240 c ==
static_cast<T
>(
'\n') ||
241 c ==
static_cast<T
>(
'\v') ||
242 c ==
static_cast<T
>(
'\f');
255 string outputString{s};
257 auto its = unique(outputString.begin(), outputString.end(),
258 [](
const auto &a,
const auto &b)
260 return is_whitespace(a) && is_whitespace(b);
263 outputString.erase(its, outputString.end());
265 outputString.shrink_to_fit();
275 template <
typename... Args>
276 static std::string
format(std::string_view format_str,
const Args &...
args)
noexcept;
Command-line argument handler with JSON support.
Definition args.h:20
String helper class.
Definition string_utils.h:27
static std::string format(std::string_view format_str, const Args &...args) noexcept
Simple wrapper for fmt::format using runtime format strings (string_view)
static std::string get_file_extension(const std::string &filename) noexcept
Extract file extension from a filename.
static bool find(std::string_view sv, char c) noexcept
Find a character in a string_view.
static std::string_view strip(const std::string_view &s, const std::string_view &to_strip_from_s=" ") noexcept
Strip specific characters from the beginning and end of a string view.
static bool contains(const std::string &str, const std::string &substr) noexcept
Check if a string contains a substring.
static std::string_view find_first_of(const std::string_view &s, const std::string_view &chars) noexcept
Find the first occurrence of any character from a set in a string view.
static std::string concat(const std::string &a, const std::string &b) noexcept
Combine and return two strings.
static bool is_whitespace(const T &c)
Checks if a character is a whitespace character.
Definition string_utils.h:220
static Cout & strsplit(const Cin &str, Cout &dest, const V &sep)
High-level string split function using containers.
Definition string_utils.h:207
static bool ends_with(const std::string &str, const std::string &suffix) noexcept
Check if a string ends with a specific suffix.
static std::string strip_whitespace(const std::string &s)
Removes consecutive whitespace characters from a string, leaving only single whitespace between non-w...
Definition string_utils.h:249
static It split(It it, const It end_it, Oc &dest, const V &sep, Pred f)
Splits a range into slices based on a separator and stores the results in a destination container.
Definition string_utils.h:127
static It split(It it, const It end_it, Oc &dest, const V &sep)
Generic split function with default equality predicate.
Definition string_utils.h:192
Namespace for the maze builder.
Definition algo_interface.h:6