diff options
Diffstat (limited to '')
-rw-r--r-- | src/util/string.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/util/string.h b/src/util/string.h index 40ef3e4d3..c77c5a6f9 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -519,6 +519,38 @@ std::basic_string<T> unescape_enriched(const std::basic_string<T> &s) return output; } +template <typename T> +std::vector<std::basic_string<T> > split(const std::basic_string<T> &s, T delim) +{ + std::vector<std::basic_string<T> > tokens; + + std::basic_string<T> current; + bool last_was_escape = false; + for (size_t i = 0; i < s.length(); i++) { + T si = s[i]; + if (last_was_escape) { + current += '\\'; + current += si; + last_was_escape = false; + } else { + if (si == delim) { + tokens.push_back(current); + current = std::basic_string<T>(); + last_was_escape = false; + } else if (si == '\\') { + last_was_escape = true; + } else { + current += si; + last_was_escape = false; + } + } + } + //push last element + tokens.push_back(current); + + return tokens; +} + /** * Checks that all characters in \p to_check are a decimal digits. * |