changeset 16314:c72b7ee606a3

(split-string): New function.
author Richard M. Stallman <rms@gnu.org>
date Tue, 24 Sep 1996 21:19:03 +0000
parents 36813fc30f3e
children cca1c6324cab
files lisp/subr.el
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Tue Sep 24 20:31:40 1996 +0000
+++ b/lisp/subr.el	Tue Sep 24 21:19:03 1996 +0000
@@ -779,6 +779,27 @@
 	  (substring string (match-beginning num) (match-end num))
 	(buffer-substring (match-beginning num) (match-end num)))))
 
+(defun split-string (string &optional separators)
+  "Splits STRING into substrings where there are matches for SEPARATORS.
+Each match for SEPARATORS is a splitting point.
+The substrings between the splitting points are made into a list
+which is returned.
+If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
+  (let ((rexp (or separators "[ \f\t\n\r\v]+"))
+	(start 0)
+	(list nil))
+    (while (string-match rexp string start)
+      (or (eq start 0)
+	  (setq list
+		(cons (substring string start (match-beginning 0))
+		      list)))
+      (setq start (match-end 0)))
+    (or (eq start (length string))
+	(setq list
+	      (cons (substring string start)
+		    list)))
+    (nreverse list)))
+
 (defun shell-quote-argument (argument)
   "Quote an argument for passing as argument to an inferior shell."
   (if (eq system-type 'ms-dos)