diff options
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r-- | src/StringUtils.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index f255971..111822e 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -4,10 +4,10 @@ namespace QuickMedia { void string_split(const std::string &str, char delimiter, StringSplitCallback callback_func) { size_t index = 0; - while(true) { + while(index < str.size()) { size_t new_index = str.find(delimiter, index); if(new_index == std::string::npos) - break; + new_index = str.size(); if(!callback_func(str.data() + index, new_index - index)) break; @@ -19,11 +19,12 @@ namespace QuickMedia { size_t string_replace_all(std::string &str, char old_char, const std::string &new_str) { size_t num_replaced_substrings = 0; size_t index = 0; - while(true) { + while(index < str.size()) { index = str.find(old_char, index); if(index == std::string::npos) break; str.replace(index, 1, new_str); + index += new_str.size(); ++num_replaced_substrings; } return num_replaced_substrings; @@ -32,11 +33,12 @@ namespace QuickMedia { size_t string_replace_all(std::string &str, const std::string &old_str, const std::string &new_str) { size_t num_replaced_substrings = 0; size_t index = 0; - while(true) { + while(index < str.size()) { index = str.find(old_str, index); if(index == std::string::npos) break; str.replace(index, old_str.size(), new_str); + index += new_str.size(); ++num_replaced_substrings; } return num_replaced_substrings; |