MTCT
Design Automation and Optimization for ETCS Railway Networks
Loading...
Searching...
No Matches
StringHelper.hpp
Go to the documentation of this file.
1#ifndef CDA_RAIL_STRINGHELPER_HPP
2#define CDA_RAIL_STRINGHELPER_HPP
3
4#include <algorithm>
5#include <cctype>
6#include <initializer_list>
7#include <optional>
8#include <string>
9#include <string_view>
10
11namespace cda_rail {
12
19[[nodiscard]] std::string
20concatenate_string_views(std::initializer_list<std::string_view> parts);
21
30inline bool case_insensitive_str_equal(std::string_view a, std::string_view b) {
31 return std::ranges::equal(a, b, [](char const c1, char const c2) {
32 // Cast to unsigned char to avoid UB with extended ASCII
33 return std::tolower(static_cast<unsigned char>(c1)) ==
34 std::tolower(static_cast<unsigned char>(c2));
35 });
36}
37
47void to_bool_optional_inplace(std::string_view s_view, std::optional<bool>& b);
48
58std::string sanitize(std::string s);
59
60} // namespace cda_rail
61
62#endif // CDA_RAIL_STRINGHELPER_HPP
Definition CustomExceptions.hpp:15
std::string sanitize(std::string s)
Replaces every non-alphanumeric character by a hyphen.
Definition StringHelper.cpp:34
bool case_insensitive_str_equal(std::string_view a, std::string_view b)
Compares two strings for equality, ignoring case.
Definition StringHelper.hpp:30
void to_bool_optional_inplace(std::string_view s_view, std::optional< bool > &b)
Parses a textual boolean value into an optional in place.
Definition StringHelper.cpp:26
std::string concatenate_string_views(std::initializer_list< std::string_view > parts)
Concatenates multiple string views into a single string.
Definition StringHelper.cpp:11