"Stephen J. Turnbull" <stephen(a)xemacs.org> writes:
Ville Skyttä writes:
> replace-regexp-in-string with SUBEXP in 21.5.28 is broken; for example the
> example given in the docstring fails.
The whole Emacs matching API really sucks. :-(
> What should happen according to the example:
>
> (replace-regexp-in-string "\\(foo\\).*\\'" "bar" "
foo foo" nil nil 1)
> " bar foo"
Does so in Emacs.
but this is only used in the rare case that rep is a function. I
actually don't think this makes sense. Consider this example:
(defun rep (s)
(if (string= s "foo") "bar" s))
(replace-regexp-in-string "\\(foo\\).*\\'" 'rep " foo foo"
nil nil 1)
I would expect that to result in " bar foo", but as written
here (and
as specified in the docstring) that results in " foo foo" because
(match-string 0 str) is " foo foo" here. We should look at GNU's
implementatation to see what they do.
" foo foo foo". It is possible that this may be a bug, but the DOC
string of replace-regexp-in-string makes my eyes glaze over, anyway.
If you have a good definite idea about what would be the correct
behavior and why, and you care about keeping code divergence to a
minimum, you might make and report a test case.
For another thing, I discovered either `match-end' or
`\'' appears
broken on strings:
(let ((s " foo foo"))
;; my-rris is `replace-regexp-in-string' without saving match data
(list (my-rris "\\(foo\\).*\\'" "bar" s nil nil 1)
(match-string 0 s)
(match-string 1 s)
(length s)
(match-beginning 0)
(match-end 0)
(match-beginning 1)
(match-end 1)))
=> (" bar" " foo fo" " fo" 8 0 7 0 3)
The first element is the bug that Ville reported but the rest is,
well, disturbing. Anybody know what's going on here?
Emacs: (" bar foo" " foo fo" " fo" 8 0 7 0 3)
I am not sure about the relevance of "rris without match-data" though.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-beta