Translate submatches according to CRE:TVEC, fixing submatch bug
reported by Michel Schinz.
This commit is contained in:
parent
5f936e3a80
commit
dce89b2fa8
|
@ -83,7 +83,29 @@
|
||||||
(if (not ret)
|
(if (not ret)
|
||||||
#f
|
#f
|
||||||
(make-regexp-match str
|
(make-regexp-match str
|
||||||
(list->vector ret))))))))
|
(translate-submatches ret
|
||||||
|
(cre:tvec cre)
|
||||||
|
start-vec))))))))
|
||||||
|
|
||||||
|
(define (translate-submatches matches trans-vec match-vec)
|
||||||
|
(let ((n-virtual-submatches (vector-length trans-vec)))
|
||||||
|
(let loop ((virtual-index 0)
|
||||||
|
(match-index 0)
|
||||||
|
(matches matches))
|
||||||
|
(cond
|
||||||
|
((> virtual-index n-virtual-submatches)
|
||||||
|
match-vec)
|
||||||
|
((if (zero? virtual-index)
|
||||||
|
0
|
||||||
|
(vector-ref trans-vec (- virtual-index 1)))
|
||||||
|
=> (lambda (actual-index)
|
||||||
|
(if (= match-index actual-index)
|
||||||
|
(begin
|
||||||
|
(vector-set! match-vec virtual-index (car matches))
|
||||||
|
(loop (+ 1 virtual-index) (+ 1 match-index) (cdr matches)))
|
||||||
|
(loop virtual-index (+ 1 match-index) (cdr matches)))))
|
||||||
|
(else
|
||||||
|
(loop (+ 1 virtual-index) match-index matches))))))
|
||||||
|
|
||||||
(define (cre-search? cre str start)
|
(define (cre-search? cre str start)
|
||||||
(let ((re-str (cre:string cre))) ;; RE-STR = #F => empty match.
|
(let ((re-str (cre:string cre))) ;; RE-STR = #F => empty match.
|
||||||
|
|
Loading…
Reference in New Issue