28 const std::regex re{pattern};
29 return std::regex_match(str, re);
31 catch (
const std::regex_error &e) {
32 panic(fmt::format(
"regex error: {}", e.what()));
45inline void trim(std::string &
string)
49 string.begin(), std::ranges::find_if(
string, [](
const unsigned char ch) {
return !std::isspace(ch); }));
53 std::ranges::find_if(
string.rbegin(),
string.rend(), [](
const unsigned char ch) {
return !std::isspace(ch); })
70inline std::vector<std::string>
split(std::string input,
const std::string &delimiter)
72 std::vector<std::string> result;
74 while ((pos = input.find(delimiter)) != std::string::npos) {
75 std::string token = input.substr(0, pos);
76 result.push_back(token);
77 input.erase(0, pos + delimiter.length());
79 result.push_back(input);
95 while (!line.empty() && (line.back() ==
'\r' || line.back() ==
'\n')) {
114 std::string result = line;
115 while (!result.empty() && (result.back() ==
'\r' || result.back() ==
'\n')) {
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
void trim(std::string &string)
Removes leading and trailing whitespace from a string in-place.
std::vector< std::string > split(std::string input, const std::string &delimiter)
Splits a string into tokens based on a delimiter.
bool check_full_string_match(const std::string &str, const std::string &pattern)
Checks if a string fully matches a regular expression pattern.
std::string & trim_line_ending(std::string &line)
Removes line ending characters from a string in-place.