diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-02 13:51:58 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-02 13:51:58 -0400 |
| commit | be2673ef2b102c49c4db3e0079b9269b787d821f (patch) | |
| tree | cc6ab972c658c3c06dc234642cb702b243170f41 /stdlib/patterns.c | |
| parent | a60e0e5e9a5fc0e625ece0151328cde6147e8abf (diff) | |
Make Text:find() return an optional int
Diffstat (limited to 'stdlib/patterns.c')
| -rw-r--r-- | stdlib/patterns.c | 6 |
1 files changed, 3 insertions, 3 deletions
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) |
