summaryrefslogtreecommitdiffhomepage
path: root/FoundationEx/Text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'FoundationEx/Text.cpp')
-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;