aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Roberts2007-07-08 06:49:02 +0000
committerNick Roberts2007-07-08 06:49:02 +0000
commitd0b15d36793fd0ecb79f8dec78afb46b7e674af1 (patch)
treeba0505097bde3cc6c184c6c837bbff87aa08cb74
parenta80a334ec31740354c57622739c681431830ade4 (diff)
downloademacs-d0b15d36793fd0ecb79f8dec78afb46b7e674af1.tar.gz
emacs-d0b15d36793fd0ecb79f8dec78afb46b7e674af1.zip
* pcvs-util.el (cvs-strings->string, cvs-string->strings):
Rename and move to... * subr.el (strings->string, string->strings): ...here.
-rw-r--r--lisp/pcvs-util.el31
-rw-r--r--lisp/subr.el30
2 files changed, 31 insertions, 30 deletions
diff --git a/lisp/pcvs-util.el b/lisp/pcvs-util.el
index 3945d7ba67c..58c605a19d2 100644
--- a/lisp/pcvs-util.el
+++ b/lisp/pcvs-util.el
@@ -186,35 +186,6 @@ arguments. If ARGS is not a list, no argument will be passed."
186 "Tell whether STR1 is a prefix of STR2." 186 "Tell whether STR1 is a prefix of STR2."
187 (eq t (compare-strings str2 nil (length str1) str1 nil nil))) 187 (eq t (compare-strings str2 nil (length str1) str1 nil nil)))
188 188
189;; (string->strings (strings->string X)) == X
190(defun cvs-strings->string (strings &optional separator)
191 "Concatenate the STRINGS, adding the SEPARATOR (default \" \").
192This tries to quote the strings to avoid ambiguity such that
193 (cvs-string->strings (cvs-strings->string strs)) == strs
194Only some SEPARATORs will work properly."
195 (let ((sep (or separator " ")))
196 (mapconcat
197 (lambda (str)
198 (if (string-match "[\\\"]" str)
199 (concat "\"" (replace-regexp-in-string "[\\\"]" "\\\\\\&" str) "\"")
200 str))
201 strings sep)))
202
203;; (string->strings (strings->string X)) == X
204(defun cvs-string->strings (string &optional separator)
205 "Split the STRING into a list of strings.
206It understands elisp style quoting within STRING such that
207 (cvs-string->strings (cvs-strings->string strs)) == strs
208The SEPARATOR regexp defaults to \"\\s-+\"."
209 (let ((sep (or separator "\\s-+"))
210 (i (string-match "[\"]" string)))
211 (if (null i) (split-string string sep t) ; no quoting: easy
212 (append (unless (eq i 0) (split-string (substring string 0 i) sep t))
213 (let ((rfs (read-from-string string i)))
214 (cons (car rfs)
215 (cvs-string->strings (substring string (cdr rfs))
216 sep)))))))
217
218;;;; 189;;;;
219;;;; file names 190;;;; file names
220;;;; 191;;;;
@@ -240,7 +211,7 @@ The SEPARATOR regexp defaults to \"\\s-+\"."
240(defconst cvs-qtypedesc-string1 (cvs-qtypedesc-create 'identity 'identity t)) 211(defconst cvs-qtypedesc-string1 (cvs-qtypedesc-create 'identity 'identity t))
241(defconst cvs-qtypedesc-string (cvs-qtypedesc-create 'identity 'identity)) 212(defconst cvs-qtypedesc-string (cvs-qtypedesc-create 'identity 'identity))
242(defconst cvs-qtypedesc-strings 213(defconst cvs-qtypedesc-strings
243 (cvs-qtypedesc-create 'cvs-string->strings 'cvs-strings->string nil)) 214 (cvs-qtypedesc-create 'string->strings 'strings->string nil))
244 215
245(defun cvs-query-read (default prompt qtypedesc &optional hist-sym) 216(defun cvs-query-read (default prompt qtypedesc &optional hist-sym)
246 (let* ((qtypedesc (or qtypedesc cvs-qtypedesc-strings)) 217 (let* ((qtypedesc (or qtypedesc cvs-qtypedesc-strings))
diff --git a/lisp/subr.el b/lisp/subr.el
index a05c1d15780..9ce4758a746 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2759,6 +2759,36 @@ Modifies the match data; use `save-match-data' if necessary."
2759 (cons (substring string start) 2759 (cons (substring string start)
2760 list))) 2760 list)))
2761 (nreverse list))) 2761 (nreverse list)))
2762
2763;; (string->strings (strings->string X)) == X
2764(defun strings->string (strings &optional separator)
2765 "Concatenate the STRINGS, adding the SEPARATOR (default \" \").
2766This tries to quote the strings to avoid ambiguity such that
2767 (string->strings (strings->string strs)) == strs
2768Only some SEPARATORs will work properly."
2769 (let ((sep (or separator " ")))
2770 (mapconcat
2771 (lambda (str)
2772 (if (string-match "[\\\"]" str)
2773 (concat "\"" (replace-regexp-in-string "[\\\"]" "\\\\\\&" str) "\"")
2774 str))
2775 strings sep)))
2776
2777;; (string->strings (strings->string X)) == X
2778(defun string->strings (string &optional separator)
2779 "Split the STRING into a list of strings.
2780It understands elisp style quoting within STRING such that
2781 (string->strings (strings->string strs)) == strs
2782The SEPARATOR regexp defaults to \"\\s-+\"."
2783 (let ((sep (or separator "\\s-+"))
2784 (i (string-match "[\"]" string)))
2785 (if (null i) (split-string string sep t) ; no quoting: easy
2786 (append (unless (eq i 0) (split-string (substring string 0 i) sep t))
2787 (let ((rfs (read-from-string string i)))
2788 (cons (car rfs)
2789 (string->strings (substring string (cdr rfs))
2790 sep)))))))
2791
2762 2792
2763;;;; Replacement in strings. 2793;;;; Replacement in strings.
2764 2794