From 0b9acf3a25952e587c2364d46b29f5b08e3268ab Mon Sep 17 00:00:00 2001 From: Alpyne Date: Tue, 20 Jun 2023 00:09:09 +0100 Subject: [PATCH] [util] Add str::split Used by d3d8 --- src/util/util_string.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/util/util_string.h b/src/util/util_string.h index 43607378c..87b74af17 100644 --- a/src/util/util_string.h +++ b/src/util/util_string.h @@ -212,5 +212,31 @@ namespace dxvk::str { dst[count - 1] = '\0'; } } - + + /** + * \brief Split string at one or more delimiters characters + * + * \param [in] string String to split + * \param [in] delims Delimiter characters + * \returns Vector of substring views + */ + inline std::vector split(std::string_view string, std::string_view delims = " ") { + std::vector tokens; + + for (size_t start = 0; start < string.size(); ) { + // Find first delimiter + const auto end = string.find_first_of(delims, start); + + // Add non-empty tokens + if (start != end) + tokens.emplace_back(string.substr(start, end-start)); + + // Break at the end of string + if (end == std::string_view::npos) + break; + + start = end + 1; + } + return tokens; + } }