From be2673ef2b102c49c4db3e0079b9269b787d821f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 2 Nov 2024 13:51:58 -0400 Subject: Make Text:find() return an optional int --- stdlib/patterns.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'stdlib/patterns.c') diff --git a/stdlib/patterns.c b/stdlib/patterns.c index b8f204f4..fdc7a79f 100644 --- a/stdlib/patterns.c +++ b/stdlib/patterns.c @@ -796,15 +796,15 @@ 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) +public OptionalInt_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); + return NULL_INT; int64_t found = _find(text, pattern, first-1, text.length-1, NULL); - return I(found+1); + return found == -1 ? NULL_INT : I(found+1); } PUREFUNC public bool Text$has(Text_t text, Pattern_t pattern) -- cgit v1.2.3