diff options
| author | Richard M. Stallman | 2007-08-12 17:59:40 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2007-08-12 17:59:40 +0000 |
| commit | e80b38498cc1c021d665993e219ec643e9009598 (patch) | |
| tree | 1d5cf41f0a86236aab316f70b2039832a234562b | |
| parent | ba6f8422340d7652908cd759bfaf8d6918754d75 (diff) | |
| download | emacs-e80b38498cc1c021d665993e219ec643e9009598.tar.gz emacs-e80b38498cc1c021d665993e219ec643e9009598.zip | |
(combine-and-quote-strings): Renamed from strings->string.
(split-string-and-unquote): Renamed from string->strings.
| -rw-r--r-- | lisp/subr.el | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 84f216b0861..8de09b032f5 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -2760,11 +2760,10 @@ Modifies the match data; use `save-match-data' if necessary." | |||
| 2760 | list))) | 2760 | list))) |
| 2761 | (nreverse list))) | 2761 | (nreverse list))) |
| 2762 | 2762 | ||
| 2763 | ;; (string->strings (strings->string X)) == X | 2763 | (defun combine-and-quote-strings (strings &optional separator) |
| 2764 | (defun strings->string (strings &optional separator) | ||
| 2765 | "Concatenate the STRINGS, adding the SEPARATOR (default \" \"). | 2764 | "Concatenate the STRINGS, adding the SEPARATOR (default \" \"). |
| 2766 | This tries to quote the strings to avoid ambiguity such that | 2765 | This tries to quote the strings to avoid ambiguity such that |
| 2767 | (string->strings (strings->string strs)) == strs | 2766 | (split-string-and-unquote (combine-and-quote-strings strs)) == strs |
| 2768 | Only some SEPARATORs will work properly." | 2767 | Only some SEPARATORs will work properly." |
| 2769 | (let ((sep (or separator " "))) | 2768 | (let ((sep (or separator " "))) |
| 2770 | (mapconcat | 2769 | (mapconcat |
| @@ -2774,20 +2773,20 @@ Only some SEPARATORs will work properly." | |||
| 2774 | str)) | 2773 | str)) |
| 2775 | strings sep))) | 2774 | strings sep))) |
| 2776 | 2775 | ||
| 2777 | ;; (string->strings (strings->string X)) == X | 2776 | (defun split-string-and-unquote (string &optional separator) |
| 2778 | (defun string->strings (string &optional separator) | ||
| 2779 | "Split the STRING into a list of strings. | 2777 | "Split the STRING into a list of strings. |
| 2780 | It understands elisp style quoting within STRING such that | 2778 | It understands Emacs Lisp quoting within STRING, such that |
| 2781 | (string->strings (strings->string strs)) == strs | 2779 | (split-string-and-unquote (combine-and-quote-strings strs)) == strs |
| 2782 | The SEPARATOR regexp defaults to \"\\s-+\"." | 2780 | The SEPARATOR regexp defaults to \"\\s-+\"." |
| 2783 | (let ((sep (or separator "\\s-+")) | 2781 | (let ((sep (or separator "\\s-+")) |
| 2784 | (i (string-match "[\"]" string))) | 2782 | (i (string-match "[\"]" string))) |
| 2785 | (if (null i) (split-string string sep t) ; no quoting: easy | 2783 | (if (null i) |
| 2784 | (split-string string sep t) ; no quoting: easy | ||
| 2786 | (append (unless (eq i 0) (split-string (substring string 0 i) sep t)) | 2785 | (append (unless (eq i 0) (split-string (substring string 0 i) sep t)) |
| 2787 | (let ((rfs (read-from-string string i))) | 2786 | (let ((rfs (read-from-string string i))) |
| 2788 | (cons (car rfs) | 2787 | (cons (car rfs) |
| 2789 | (string->strings (substring string (cdr rfs)) | 2788 | (split-string-and-unquote (substring string (cdr rfs)) |
| 2790 | sep))))))) | 2789 | sep))))))) |
| 2791 | 2790 | ||
| 2792 | 2791 | ||
| 2793 | ;;;; Replacement in strings. | 2792 | ;;;; Replacement in strings. |