hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3a6cbff2f6d01f28865063018090b918bec3a545
parent e7420e022fdae54e2b2291f0a8b540f9415b28ae
Author: Vlad-Stefan Harbuz <vlad@vladh.net>
Date:   Fri, 13 May 2022 16:41:21 +0100

regex: update free_*() functions

Signed-off-by: Vlad-Stefan Harbuz <vlad@vladh.net>

Diffstat:
Mregex/README | 4++--
Mregex/regex.ha | 9+++++++--
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/regex/README b/regex/README @@ -24,7 +24,7 @@ the longest match among the leftmost matches. match (first_match) { case void => void; case let captures: []regex::capture => - defer free(captures); + defer regex::free_captures(captures); // captures[0]: The full matching string. // captures[1...]: A capture for every capture group. fmt::printfln("{} ({}, {})", captures[0].content, @@ -36,7 +36,7 @@ the longest match among the leftmost matches. match (all_matches) { case void => void; case let matches: [][]regex::capture => - defer regex::freeall(matches); + defer regex::free_matches(matches); // matches[0]: All captures for the first match. // matches[0][0]: The full matching string for the first match. // matches[0][1...]: A capture for every capture group in the diff --git a/regex/regex.ha b/regex/regex.ha @@ -805,10 +805,15 @@ export fn findall(re: *regex, string: str) (void | [][]capture | error) = { return res; }; +// Frees a slice of captures. +export fn free_captures(s: []capture) void = { + free(s); +}; + // Frees each match in a slice of matches, as well as the slice itself. -export fn freeall(s: [][]capture) void = { +export fn free_matches(s: [][]capture) void = { for (let i = 0z; i < len(s); i += 1) { - free(s[i]); + free_captures(s[i]); }; free(s); };