From: John Benediktsson Date: Wed, 10 Aug 2022 04:25:10 +0000 (-0700) Subject: xmode.marker: more correct faster update-match-group X-Git-Tag: 0.99~1145 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=4984d1766c441d1dc2fa74f4f1f5ec794556c045 xmode.marker: more correct faster update-match-group --- diff --git a/basis/xmode/marker/marker.factor b/basis/xmode/marker/marker.factor index 32fae3c324..a93283e290 100644 --- a/basis/xmode/marker/marker.factor +++ b/basis/xmode/marker/marker.factor @@ -110,8 +110,12 @@ M: regexp text-matches? : nth-match ( match regexp n -- slice/f ) match-group-regexp [ skip-first-match ] [ first-match ] bi* ; -: update-match-group ( str match regexp n -- str' ) - [ nth-match ] [ CHAR: 1 + "$%c" sprintf ] bi swap replace ; +:: update-match-group ( str match regexp n -- str' ) + n H{ } [ CHAR: 1 + CHAR: $ swap "" 2sequence ] cache :> x + x str subseq-range :> ( from to ) + from [ + to str snip-slice match regexp n nth-match glue + ] [ str ] if* ; : update-match-groups ( str match regexp -- str' ) [ >string ] dip