findall ( subject obj -- matches )


Vocabulary
pcre2

Inputs
subjectan object
objan object


Outputs
matchesan object


Definition

GENERIC: findall ( subject obj -- matches )


Methods

M:: pcre2 findall ( subject obj -- matches )
[
subject utf8 encode
:> subject_bytes subject_bytes length :> subject_length
obj handle>> :> re re pcre2-utf? :> utf? re pcre2-crlf?
:> crlf? re f pcre2_match_data_create_from_pattern
&pcre2_match_data_free :> match_data 0 :> start_offset!
0 :> options! re subject_bytes subject_length
start_offset options match_data f pcre2_match
:> rc re pcre2-name-count :> name_count name_count
[ f ] [
re pcre2-name-table re pcre2-name-entry-size
[ rot * memory>byte-array ] [ <groups> ] bi
[ 2 cut [ be> ] [ utf8 alien>string ] bi* ] { }
map>assoc sort-keys
] if-zero :> name_table rc 0 < [
rc
{ { PCRE2_ERROR_NOMATCH [ ~array~ ] } [ throw ] }
case
] [
rc name_count 1 + assert=
match_data pcre2_get_ovector_pointer rc
assert-positive 2 * PCRE2_SIZE <c-direct-array>
:> ovector [
[
f ovector first2 subject subseq 2array ,
name_table [
ovector rot 2 * tail-slice
first2 subject subseq 2array ,
] assoc-each
] { } make , [
f :> break?! 0 options! ovector second
start_offset! ovector first2 = [
ovector first subject_length =
2147483656 options!
] [
match_data pcre2_get_startchar
:> startchar start_offset startchar <=
~quotation~ ~quotation~ if
] if
[ f ] [
re subject_bytes subject_length
start_offset options match_data f
pcre2_match
:> rc rc PCRE2_ERROR_NOMATCH =
~quotation~ ~quotation~ if
] if
] loop
] { } make
] if
] with-destructors ;