aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-28 13:32:34 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-28 13:32:34 +0200
commit4277763df5c1dac8ff389d3bfd138f03acc7f1e2 (patch)
treeb0c3fc77ea601f105308d42840adb1ce2050b414 /src/StringUtils.cpp
parenta16cfdc4f6cd14d576760c100a817c08f45be394 (diff)
Implement text editing with navigation and multilingual fonts
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r--src/StringUtils.cpp10
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;