* lisp/subr.el (string-replace): Add dashes to arg names (bug#50644)
* lisp/net/tramp-compat.el (tramp-compat-string-replace): Idem. * doc/lispref/searching.texi (Search and Replace): Idem.
This commit is contained in:
parent
acba74a395
commit
4b3dc7a139
3 changed files with 15 additions and 15 deletions
|
@ -2620,9 +2620,9 @@ replacement string. The match data at this point are the result
|
|||
of matching @var{regexp} against a substring of @var{string}.
|
||||
@end defun
|
||||
|
||||
@defun string-replace fromstring tostring instring
|
||||
This function replaces all occurrences of @var{fromstring} with
|
||||
@var{tostring} in @var{instring} and returns the result. It may
|
||||
@defun string-replace from-string to-string in-string
|
||||
This function replaces all occurrences of @var{from-string} with
|
||||
@var{to-string} in @var{in-string} and returns the result. It may
|
||||
return one of its arguments unchanged, a constant string or a new
|
||||
string. Case is significant, and text properties are ignored.
|
||||
@end defun
|
||||
|
|
|
@ -359,10 +359,10 @@ CONDITION can also be a list of error conditions."
|
|||
(defalias 'tramp-compat-string-replace
|
||||
(if (fboundp 'string-replace)
|
||||
#'string-replace
|
||||
(lambda (fromstring tostring instring)
|
||||
(lambda (from-string to-string in-string)
|
||||
(let ((case-fold-search nil))
|
||||
(replace-regexp-in-string
|
||||
(regexp-quote fromstring) tostring instring t t)))))
|
||||
(regexp-quote from-string) to-string in-string t t)))))
|
||||
|
||||
;; Function `string-search' is new in Emacs 28.1.
|
||||
(defalias 'tramp-compat-string-search
|
||||
|
|
20
lisp/subr.el
20
lisp/subr.el
|
@ -4937,25 +4937,25 @@ Unless optional argument INPLACE is non-nil, return a new string."
|
|||
(aset newstr i tochar)))
|
||||
newstr))
|
||||
|
||||
(defun string-replace (fromstring tostring instring)
|
||||
"Replace FROMSTRING with TOSTRING in INSTRING each time it occurs."
|
||||
(defun string-replace (from-string to-string in-string)
|
||||
"Replace FROM-STRING with TO-STRING in IN-STRING each time it occurs."
|
||||
(declare (pure t) (side-effect-free t))
|
||||
(when (equal fromstring "")
|
||||
(when (equal from-string "")
|
||||
(signal 'wrong-length-argument '(0)))
|
||||
(let ((start 0)
|
||||
(result nil)
|
||||
pos)
|
||||
(while (setq pos (string-search fromstring instring start))
|
||||
(while (setq pos (string-search from-string in-string start))
|
||||
(unless (= start pos)
|
||||
(push (substring instring start pos) result))
|
||||
(push tostring result)
|
||||
(setq start (+ pos (length fromstring))))
|
||||
(push (substring in-string start pos) result))
|
||||
(push to-string result)
|
||||
(setq start (+ pos (length from-string))))
|
||||
(if (null result)
|
||||
;; No replacements were done, so just return the original string.
|
||||
instring
|
||||
in-string
|
||||
;; Get any remaining bit.
|
||||
(unless (= start (length instring))
|
||||
(push (substring instring start) result))
|
||||
(unless (= start (length in-string))
|
||||
(push (substring in-string start) result))
|
||||
(apply #'concat (nreverse result)))))
|
||||
|
||||
(defun replace-regexp-in-string (regexp rep string &optional
|
||||
|
|
Loading…
Add table
Reference in a new issue