From 052316261a94f2846e7547b65b2bb089979ce5ba Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 27 Oct 2024 20:18:30 -0400 Subject: Finish deprecating stack refs with & --- stdlib/patterns.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'stdlib/patterns.c') diff --git a/stdlib/patterns.c b/stdlib/patterns.c index 875ea372..6acb58a2 100644 --- a/stdlib/patterns.c +++ b/stdlib/patterns.c @@ -796,14 +796,14 @@ static int64_t _find(Text_t text, Pattern_t pattern, int64_t first, int64_t last return -1; } -public Int_t Text$find(Text_t text, Pattern_t pattern, Int_t from_index, int64_t *match_length) +public Int_t Text$find(Text_t text, Pattern_t pattern, Int_t from_index) { int64_t first = Int_to_Int64(from_index, false); if (first == 0) fail("Invalid index: 0"); if (first < 0) first = text.length + first + 1; if (first > text.length || first < 1) return I(0); - int64_t found = _find(text, pattern, first-1, text.length-1, match_length); + int64_t found = _find(text, pattern, first-1, text.length-1, NULL); return I(found+1); } @@ -1081,17 +1081,17 @@ public Array_t Text$split(Text_t text, Pattern_t pattern) Array_t chunks = {}; - Int_t i = I_small(1); + int64_t i = 0; for (;;) { int64_t len = 0; - Int_t found = Text$find(text, pattern, i, &len); - if (I_is_zero(found)) break; - Text_t chunk = Text$slice(text, i, Int$minus(found, I_small(1))); + int64_t found = _find(text, pattern, i, text.length-1, &len); + if (found < 0) break; + Text_t chunk = Text$slice(text, I(i+1), I(found)); Array$insert(&chunks, &chunk, I_small(0), sizeof(Text_t)); - i = Int$plus(found, I(MAX(len, 1))); + i = found + MAX(len, 1); } - Text_t last_chunk = Text$slice(text, i, I(text.length)); + Text_t last_chunk = Text$slice(text, I(i+1), I(text.length)); Array$insert(&chunks, &last_chunk, I_small(0), sizeof(Text_t)); return chunks; -- cgit v1.2.3