diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-24 18:19:59 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-24 18:19:59 -0400 |
| commit | d07d2f2530aa1f25dc2cd34796f2a29d9b467b0d (patch) | |
| tree | 7321c7c57548129e168033f70667f6cb73e7c9d5 | |
| parent | ad940126956db2f5aa8e6965b3e4c4f09e7f797e (diff) | |
Bugfix for text replacement
| -rw-r--r-- | builtins/text.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/builtins/text.c b/builtins/text.c index a0d2f6bc..f2a7c2f9 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -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); |
