Skip to content

Commit

Permalink
Test regexp_matched_num PR (#257)
Browse files Browse the repository at this point in the history
* Add regexp_matched_num

* Is this an "anti-typo"?

* Cool spot

---------

Co-authored-by: ALANVF <[email protected]>
  • Loading branch information
RblSb and ALANVF authored Mar 26, 2023
1 parent 84a45ee commit 98fe136
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libs/regexp/regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,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->n_groups);
}

void regexp_main() {
id_pos = val_id("pos");
id_len = val_id("len");
Expand All @@ -312,6 +326,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);

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

0 comments on commit 98fe136

Please sign in to comment.