Function: combine-and-quote-strings
combine-and-quote-strings is a byte-compiled function defined in
subr.el.gz.
Signature
(combine-and-quote-strings STRINGS &optional SEPARATOR)
Documentation
Concatenate the STRINGS, adding the SEPARATOR (default " ").
This tries to quote the strings to avoid ambiguity such that
(split-string-and-unquote (combine-and-quote-strings strs)) == strs
Only some SEPARATORs will work properly.
Note that this is not intended to protect STRINGS from
interpretation by shells, use shell-quote-argument for that.
Probably introduced at or before Emacs version 22.2.
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun combine-and-quote-strings (strings &optional separator)
"Concatenate the STRINGS, adding the SEPARATOR (default \" \").
This tries to quote the strings to avoid ambiguity such that
(split-string-and-unquote (combine-and-quote-strings strs)) == strs
Only some SEPARATORs will work properly.
Note that this is not intended to protect STRINGS from
interpretation by shells, use `shell-quote-argument' for that."
(let* ((sep (or separator " "))
(re (concat "[\\\"]" "\\|" (regexp-quote sep))))
(mapconcat
(lambda (str)
(if (string-match re str)
(concat "\"" (replace-regexp-in-string "[\\\"]" "\\\\\\&" str) "\"")
str))
strings sep)))