17 inline auto split(
const std::string &str,
const std::string &delim,
18 size_t assert_length = UINT64_MAX) {
19 std::vector<std::string> result;
20 size_t prev = 0, pos = 0;
23 pos = str.find(delim, prev);
25 if (pos == std::string::npos) pos = str.length();
27 std::string token = str.substr(prev, pos - prev);
29 if (!token.empty()) result.push_back(token);
31 prev = pos + delim.length();
32 }
while (pos < str.length() && prev < str.length());
34 if (assert_length != UINT64_MAX) {
35 NVSL_ASSERT(result.size() == assert_length,
"Not enough tokens");
42 inline auto zip(
const std::vector<std::string> arr,
43 const std::string join_str) {
44 std::string result =
"";
47 for (
const auto &tok : arr) {
50 if (iter++ != arr.size() - 1) result += join_str;
57 inline auto is_suffix(
const std::string &suffix,
const std::string &str) {
59 std::mismatch(suffix.rbegin(), suffix.rend(), str.rbegin()).first;
60 return mismatch == suffix.rend();
64 inline auto is_prefix(
const std::string &prefix,
const std::string &str) {
66 std::mismatch(prefix.begin(), prefix.end(), str.begin()).first;
67 return mismatch == prefix.end();
70 inline const std::string S(
const char *c) {
return std::string(c); }
72 inline std::string ltrim(
const std::string &str) {
73 const auto start = str.find_first_not_of(
" \t\n");
75 if (start == std::string::npos)
return str;
77 return str.substr(start, str.size() - start);
80 inline std::string rtrim(
const std::string &str) {
81 const auto end = str.find_last_not_of(
" \t\n");
83 if (end == std::string::npos)
return str;
85 return str.substr(0, end + 1);
88 inline std::string trim(
const std::string &str) {
return ltrim(rtrim(str)); }