Bugfix for text replacement

This commit is contained in:
Bruce Hill 2024-03-24 18:19:59 -04:00
parent ad94012695
commit d07d2f2530

View File

@ -223,10 +223,10 @@ public find_result_t Text__find(CORD str, CORD pat)
public CORD Text__replace(CORD text, CORD pat, CORD replacement, int64_t limit)
{
if (!text || !pat) return text;
CORD ret = NULL;
CORD ret = CORD_EMPTY;
size_t pos = 0, pat_len = CORD_len(pat);
for (size_t found; limit > 0 && (found=CORD_str(text, pos, pat)) != CORD_NOT_FOUND; --limit) {
ret = CORD_all(ret, CORD_substr(text, pos, found), replacement);
ret = CORD_all(ret, CORD_substr(text, pos, found - pos), replacement);
pos = found + pat_len;
}
size_t str_len = CORD_len(text);