: search-range ( i string reverse? -- seq )
[ drop 0 [a,b] ] [ length [a,b) ] if ; inline
-:: next-match ( i string quot reverse? -- i slice/f )
+: match>result ( match reverse? -- i start end string )
+ over [
+ [ [ i>> ] [ j>> tuck ] [ seq>> ] tri ] dip
+ [ [ swap [ 1+ ] bi@ ] dip ] when
+ ] [ 2drop f f f f ] if ; inline
+
+:: next-match ( i string quot reverse? -- i start end string )
i string reverse? search-range
[ string quot match-slice ] map-find drop
- [ dup [ reverse? [ from>> ] [ to>> ] if ] when ] keep ; inline
+ reverse? match>result ; inline
+
+: do-next-match ( i string regexp -- i start end string )
+ dup next-match>>
- execute( i string regexp -- i start end string ) ;
++ execute-unsafe( i string regexp -- i start end string ) ;
-: do-next-match ( i string regexp -- i match/f )
- dup next-match>> execute-unsafe( i string regexp -- i match/f ) ; inline
+: next-slice ( i string regexp -- i/f slice/f )
+ do-next-match
+ [ slice boa ] [ drop ] if* ; inline
PRIVATE>