From 8c95f13d8c5cd9aee31a2b29c6298031244892be Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sat, 22 Jun 2024 10:12:05 +0200 Subject: [PATCH] Add String split method --- openVulkanoCpp/Base/Utils.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/openVulkanoCpp/Base/Utils.hpp b/openVulkanoCpp/Base/Utils.hpp index 2d7e28c..48060a5 100644 --- a/openVulkanoCpp/Base/Utils.hpp +++ b/openVulkanoCpp/Base/Utils.hpp @@ -140,6 +140,22 @@ namespace OpenVulkano else return {str.substr(0, pos), str.substr(pos + 1)}; } + static std::vector Split(const std::string_view& str, char separator) + { + std::vector subs; + size_t startPos = 0; + size_t pos = std::string::npos; + while ((pos = str.find(separator, startPos)) != std::string::npos) + { + if (startPos == pos) { startPos++; continue; } + subs.emplace_back(str.substr(startPos, pos)); + startPos = pos; + } + if (startPos != str.length() - 1) + subs.emplace_back(str.substr(startPos)); + return subs; + } + static Array ReadFile(const std::string& filePath, bool emptyOnMissing = false); template