fix regexp-replace*

This commit is contained in:
Matthew Flatt 2010-04-16 17:27:53 -04:00
parent 9eaa749f5e
commit 9ca5f6b340
2 changed files with 3 additions and 2 deletions

View File

@ -328,9 +328,8 @@
"expected a byte string result: ")
v))
v))
(define rx:sub #rx#"^(?:[^&\\]*[\\][&\\])*[^&\\]*(?:&|[\\](?=[^&\\]|$))")
(define need-replac? (and (not (procedure? replacement))
(regexp-match? rx:sub replacement)))
(regexp-match? #rx#"[\\&]" replacement)))
(define (replac ms str)
(if need-replac?
((if (string? str) bytes->string/utf-8 values)

View File

@ -1071,6 +1071,8 @@
(test "==1=2===3==4==" regexp-replace* "2*" "1234" (lambda (s) (string-append "=" s "=")))
(test "x&b\\ab=cy&w\\aw=z" regexp-replace* #rx"a(.)" "xabcyawz" "\\&\\1\\\\&\\99=")
(test "x&cy&z" regexp-replace* #rx"a(.)" "xabcyawz" "\\&")
(test "x\\cy\\z" regexp-replace* #rx"a(.)" "xabcyawz" "\\\\")
;; Test weird port offsets:
(define (test-weird-offset regexp-match regexp-match-positions)