]> git.eshelyaron.com Git - emacs.git/commitdiff
(subst-char-in-string): New function.
authorAndrew Innes <andrewi@gnu.org>
Sun, 17 Jan 1999 18:55:53 +0000 (18:55 +0000)
committerAndrew Innes <andrewi@gnu.org>
Sun, 17 Jan 1999 18:55:53 +0000 (18:55 +0000)
lisp/subr.el

index cdbb06b4b5d6bde806ea7facf9340bac6a4cbf3d..e4c2c1e697825df5fb70eaaa221889e2afca815d 100644 (file)
@@ -1092,6 +1092,17 @@ at the end of STRING, we don't include a null substring for that."
              (cons (substring string start)
                    list)))
     (nreverse list)))
+
+(defun subst-char-in-string (fromchar tochar string &optional inplace)
+  "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
+Unless optional argument INPLACE is non-nil, return a new string."
+  (let ((i (length string))
+       (newstr (if inplace string (copy-sequence string))))
+    (while (> i 0)
+      (setq i (1- i))
+      (if (eq (aref newstr i) fromchar)
+         (aset newstr i tochar)))
+    newstr))
 \f
 (defun shell-quote-argument (argument)
   "Quote an argument for passing as argument to an inferior shell."