Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
a9853251
Commit
a9853251
authored
Mar 08, 2000
by
Stefan Monnier
Browse files
(replace-regexps-in-string): Properly handle the case where
we match an empty string.
parent
433d16a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
17 deletions
+16
-17
lisp/subr.el
lisp/subr.el
+16
-17
No files found.
lisp/subr.el
View file @
a9853251
...
...
@@ -1229,23 +1229,22 @@ To replace a single match, make REGEXP match up to \\'."
(
while
(
and
(
<
start
l
)
(
string-match
regexp
string
start
))
(
setq
mb
(
match-beginning
0
)
me
(
match-end
0
))
(
if
(
=
me
mb
)
(
setq
start
l
; Matched empty string -- bail out.
matches
(
list
string
))
;; Generate a replacement for the matched substring.
;; Operate only on the substring to minimize string consing.
;; Set up match data for the substring for replacement;
;; presumably this is likely to be faster than munging the
;; match data directly in Lisp.
(
string-match
regexp
(
setq
str
(
substring
string
mb
me
)))
(
setq
matches
(
cons
(
replace-match
(
if
(
stringp
rep
)
rep
(
funcall
rep
(
match-string
0
str
)))
fixedcase
literal
str
subexp
)
(
cons
(
substring
string
start
mb
)
; unmatched prefix
matches
)))
(
setq
start
me
)))
;; If we matched the empty string, make sure we advance by one char
(
when
(
=
me
mb
)
(
setq
me
(
min
l
(
1+
mb
))))
;; Generate a replacement for the matched substring.
;; Operate only on the substring to minimize string consing.
;; Set up match data for the substring for replacement;
;; presumably this is likely to be faster than munging the
;; match data directly in Lisp.
(
string-match
regexp
(
setq
str
(
substring
string
mb
me
)))
(
setq
matches
(
cons
(
replace-match
(
if
(
stringp
rep
)
rep
(
funcall
rep
(
match-string
0
str
)))
fixedcase
literal
str
subexp
)
(
cons
(
substring
string
start
mb
)
; unmatched prefix
matches
)))
(
setq
start
me
))
;; Reconstruct a string from the pieces.
(
setq
matches
(
cons
(
substring
string
start
l
)
matches
))
; leftover
(
apply
#'
concat
(
nreverse
matches
)))))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment