14#ifndef DUMUX_COMMON_STRING_UTILITIES_HH
15#define DUMUX_COMMON_STRING_UTILITIES_HH
38std::vector<std::string_view>
tokenize(std::string_view str, std::string_view delim)
40 const auto token = [&](std::size_t pos){
41 const auto start = str.find_first_not_of(delim, pos);
42 const auto end = str.find_first_of(delim, start);
43 return std::make_pair(start, end);
46 std::vector<std::string_view> tokens;
47 for (
auto [start, end] = token(0); start != end; std::tie(start, end) = token(end))
48 tokens.emplace_back(str.substr(start, end-start));
68std::vector<std::string_view>
split(std::string_view str, std::string_view delim,
bool removeEmpty =
false)
70 const auto token = [&](std::size_t pos){
71 const auto end = str.find(delim, pos);
72 return std::make_pair(pos, end);
75 std::vector<std::string_view>
split;
76 for (
auto [start, end] = token(0); start != std::string::npos; std::tie(start, end) = token(start))
78 if (
auto&& sub = str.substr(start, end-start); !removeEmpty || !sub.empty())
79 split.emplace_back(std::move(sub));
82 start = (end != std::string::npos) ? end + delim.size() : end;
std::vector< std::string_view > split(std::string_view str, std::string_view delim, bool removeEmpty=false)
Definition: stringutilities.hh:68
std::vector< std::string_view > tokenize(std::string_view str, std::string_view delim)
Definition: stringutilities.hh:38