diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-06-11 04:51:03 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-06-11 04:51:03 +0200 |
commit | 89383cff1ba5d8a928262fcb4c40382a981c78c8 (patch) | |
tree | da8b6062cc6770fd37e7a6f7b8c09fb61f46f7b2 /src/StringUtils.cpp | |
parent | 5b3becc79461d4ecf015e33515871cc09e26e04e (diff) |
Remove dependency on youtube-dl for streaming youtube, resulting in faster video startup
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r-- | src/StringUtils.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
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 <string.h> namespace QuickMedia { - void string_split(const std::string &str, char delimiter, StringSplitCallback callback_func) { + template <typename T> + 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<char, T>::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) { |