summaryrefslogtreecommitdiffhomepage
path: root/FoundationEx
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-10 22:26:21 +0200
committerAki <please@ignore.pl>2022-04-10 22:26:21 +0200
commita9401f2b085bbb576021ed844e941beb9bf14c0f (patch)
tree311e100a7d3dbcde768a65e60cf42d2fa275178d /FoundationEx
parent014ec9abb825fc91366ae54945187d01e2c92e55 (diff)
downloadstarshatter-a9401f2b085bbb576021ed844e941beb9bf14c0f.zip
starshatter-a9401f2b085bbb576021ed844e941beb9bf14c0f.tar.gz
starshatter-a9401f2b085bbb576021ed844e941beb9bf14c0f.tar.bz2
Fixed Text.replace in *.* case
Diffstat (limited to 'FoundationEx')
-rw-r--r--FoundationEx/Text.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/FoundationEx/Text.cpp b/FoundationEx/Text.cpp
index a09f333..df828f7 100644
--- a/FoundationEx/Text.cpp
+++ b/FoundationEx/Text.cpp
@@ -634,22 +634,23 @@ Text::replace(const char* pattern, const char* substitution)
Text result;
if (rep->length && pattern && *pattern) {
- int index = 0;
+ const char* pos = rep->data;
+ const char* bound = rep->data + rep->length;
int skip = std::strlen(pattern);
do {
- const char* p = std::strstr(rep->data + index, pattern);
+ const char* p = std::strstr(pos, pattern);
if (p) {
- int len = (p - rep->data + index);
- result.append(substring(index, len));
+ int len = p - pos;
+ result.append(Text(pos, len));
result.append(substitution);
- index += len + skip;
+ pos = p + skip;
}
- else if (index < rep->length) {
- result.append(substring(index, rep->length-index));
- index = -1;
+ else if (pos < bound) {
+ result.append(pos);
+ break;
}
}
- while (index >= 0 && index < rep->length);
+ while (pos < bound);
}
return result;