This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: Bug in regexp-substitute/global
- To: Greg Badros <gjb AT cs.washington dot edu>
- Subject: Re: Bug in regexp-substitute/global
- From: Jim Blandy <jimb AT red-bean dot com>
- Date: 16 Sep 1999 09:38:45 -0500
- Cc: guile AT sourceware.cygnus dot com, scwm-discuss AT scwm.mit dot edu
- References: <qrrwvtrl8rn.fsf@elwha.cs.washington.edu>
> Old (correct, IMO) behaviour:
>
> (regexp-substitute/global #f "x" "string" 'pre "y" 'post)
> => "string" ;; no substitutions applied
>
>
> New (in CVS), buggy behaviour:
> => "" ;; empty string? what gives!?!?
>
> If a (any!) substitution is made, then the result is correct.
Yes; the old code got some border cases wrong, and I rewrote it.
I even wrote a bunch of test cases, but forgot this one.
1999-09-16 Jim Blandy <jimb@savonarola.red-bean.com>
* regex.scm (regexp-substitute/global): Handle the end of the
match list and an empty match list identically. (Thanks to Greg
Badros.)
I think this patch makes a more consistent general structure, in that
you only handle the tail in one place. (I also flipped the sense of
the if, but that's just cosmetic.)
Index: regex.scm
===================================================================
RCS file: /egcs/carton/guile-home/cvsfiles/guile/guile-core/ice-9/regex.scm,v
retrieving revision 1.4
diff -c -c -b -F'^(' -r1.4 regex.scm
*** regex.scm 1999/09/11 17:38:31 1.4
--- regex.scm 1999/09/16 14:36:21
***************
*** 166,172 ****
;; Walk the set of non-overlapping, maximal matches.
(let next-match ((matches (list-matches regexp string))
(start 0))
! (if (pair? matches)
(let ((m (car matches)))
;; Process all of the items for this match. Don't use
--- 166,173 ----
;; Walk the set of non-overlapping, maximal matches.
(let next-match ((matches (list-matches regexp string))
(start 0))
! (if (null? matches)
! (display (make-shared-substring string start) port)
(let ((m (car matches)))
;; Process all of the items for this match. Don't use
***************
*** 184,194 ****
(make-shared-substring string start (match:start m))
port))
((eq? item 'post)
! (if (pair? (cdr matches))
! (next-match (cdr matches) (match:end m))
! (display
! (make-shared-substring string (match:end m))
! port)))
(else (error 'wrong-type-arg item))))
(if (pair? items)
--- 185,191 ----
(make-shared-substring string start (match:start m))
port))
((eq? item 'post)
! (next-match (cdr matches) (match:end m)))
(else (error 'wrong-type-arg item))))
(if (pair? items)