Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test regexp_matched_num PR #257

Merged
merged 3 commits into from
Mar 26, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libs/regexp/regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,20 @@ static value regexp_matched_pos( value o, value n ) {
}
}

/**
regexp_matched_num : 'regexp -> int
<doc>Return the total number of matched groups, or -1 if the regexp has not
been matched yet</doc>
**/
static value regexp_matched_num( value o ) {
pcredata *d;
val_check_kind(o,k_regexp);
d = PCRE(o);
if( val_is_null(d->str) )
return alloc_int(-1);
return alloc_int(d->nmatchs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this field to n_groups while porting because I found it confusing (and because of the typo). Changing this from nmatchs to n_groups should be the fix.

}

void regexp_main() {
id_pos = val_id("pos");
id_len = val_id("len");
Expand All @@ -316,6 +330,7 @@ DEFINE_PRIM(regexp_replace_all,3);
DEFINE_PRIM(regexp_replace_fun,3);
DEFINE_PRIM(regexp_matched,2);
DEFINE_PRIM(regexp_matched_pos,2);
DEFINE_PRIM(regexp_matched_num,1);
DEFINE_ENTRY_POINT(regexp_main);

/* ************************************************************************ */