From 4277763df5c1dac8ff389d3bfd138f03acc7f1e2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 28 Sep 2020 13:32:34 +0200 Subject: Implement text editing with navigation and multilingual fonts --- src/StringUtils.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/StringUtils.cpp') 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; -- cgit v1.2.3