diff options
| author | Nick Roberts | 2007-06-28 01:35:10 +0000 |
|---|---|---|
| committer | Nick Roberts | 2007-06-28 01:35:10 +0000 |
| commit | 0b93ff3a2c2cec8987fa64255558558c278fb7b6 (patch) | |
| tree | 9052064016b0045dc49f62ba24eaf5608aafa46d | |
| parent | 7f87eddbacb85cc63128e535fda4d9a31fab3f73 (diff) | |
| download | emacs-0b93ff3a2c2cec8987fa64255558558c278fb7b6.tar.gz emacs-0b93ff3a2c2cec8987fa64255558558c278fb7b6.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/subr.el | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 7ce7071f2f7..86616265c59 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -2768,6 +2768,36 @@ Modifies the match data; use `save-match-data' if necessary." | |||
| 2768 | (cons (substring string start) | 2768 | (cons (substring string start) |
| 2769 | list))) | 2769 | list))) |
| 2770 | (nreverse list))) | 2770 | (nreverse list))) |
| 2771 | |||
| 2772 | ;; (string->strings (strings->string X)) == X | ||
| 2773 | (defun strings->string (strings &optional separator) | ||
| 2774 | "Concatenate the STRINGS, adding the SEPARATOR (default \" \"). | ||
| 2775 | This tries to quote the strings to avoid ambiguity such that | ||
| 2776 | (string->strings (strings->string strs)) == strs | ||
| 2777 | Only some SEPARATORs will work properly." | ||
| 2778 | (let ((sep (or separator " "))) | ||
| 2779 | (mapconcat | ||
| 2780 | (lambda (str) | ||
| 2781 | (if (string-match "[\\\"]" str) | ||
| 2782 | (concat "\"" (replace-regexp-in-string "[\\\"]" "\\\\\\&" str) "\"") | ||
| 2783 | str)) | ||
| 2784 | strings sep))) | ||
| 2785 | |||
| 2786 | ;; (string->strings (strings->string X)) == X | ||
| 2787 | (defun string->strings (string &optional separator) | ||
| 2788 | "Split the STRING into a list of strings. | ||
| 2789 | It understands elisp style quoting within STRING such that | ||
| 2790 | (string->strings (strings->string strs)) == strs | ||
| 2791 | The SEPARATOR regexp defaults to \"\\s-+\"." | ||
| 2792 | (let ((sep (or separator "\\s-+")) | ||
| 2793 | (i (string-match "[\"]" string))) | ||
| 2794 | (if (null i) (split-string string sep t) ; no quoting: easy | ||
| 2795 | (append (unless (eq i 0) (split-string (substring string 0 i) sep t)) | ||
| 2796 | (let ((rfs (read-from-string string i))) | ||
| 2797 | (cons (car rfs) | ||
| 2798 | (string->strings (substring string (cdr rfs)) | ||
| 2799 | sep))))))) | ||
| 2800 | |||
| 2771 | 2801 | ||
| 2772 | ;;;; Replacement in strings. | 2802 | ;;;; Replacement in strings. |
| 2773 | 2803 | ||