From 89383cff1ba5d8a928262fcb4c40382a981c78c8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 11 Jun 2021 04:51:03 +0200 Subject: Remove dependency on youtube-dl for streaming youtube, resulting in faster video startup --- src/StringUtils.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 0345558..8ed142f 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -2,7 +2,8 @@ #include namespace QuickMedia { - void string_split(const std::string &str, char delimiter, StringSplitCallback callback_func) { + template + static void string_split_t(const std::string &str, const T &delimiter, StringSplitCallback callback_func) { size_t index = 0; while(index < str.size()) { size_t new_index = str.find(delimiter, index); @@ -12,10 +13,21 @@ namespace QuickMedia { if(!callback_func(str.data() + index, new_index - index)) break; - index = new_index + 1; + if constexpr(std::is_same::value) + index = new_index + 1; + else + index = new_index + delimiter.size(); } } + void string_split(const std::string &str, const std::string &delimiter, StringSplitCallback callback_func) { + string_split_t(str, delimiter, callback_func); + } + + void string_split(const std::string &str, char delimiter, StringSplitCallback callback_func) { + string_split_t(str, delimiter, callback_func); + } + size_t string_replace_all(std::string &str, char old_char, char new_char) { size_t num_replaced_substrings = 0; for(char &c : str) { -- cgit v1.2.3