aboutsummaryrefslogtreecommitdiff
path: root/stdlib/patterns.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-10-27 20:18:30 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-10-27 20:35:30 -0400
commit052316261a94f2846e7547b65b2bb089979ce5ba (patch)
treec8fb81d6657ac3931ef0212976f2346fc84e3f54 /stdlib/patterns.c
parent41c0ea851a542bcd7d54b8c5c06d70e1e00095e1 (diff)
Finish deprecating stack refs with &
Diffstat (limited to 'stdlib/patterns.c')
-rw-r--r--stdlib/patterns.c16
1 files changed, 8 insertions, 8 deletions
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;