]> git.eshelyaron.com Git - emacs.git/commitdiff
(split-string): New function.
authorRichard M. Stallman <rms@gnu.org>
Tue, 24 Sep 1996 21:19:03 +0000 (21:19 +0000)
committerRichard M. Stallman <rms@gnu.org>
Tue, 24 Sep 1996 21:19:03 +0000 (21:19 +0000)
lisp/subr.el

index 34cd3e7abe0b0dc4bad4fed589015bb7b31da2db..30b5ca6703d3861935bca6801177cae6ecd2a37c 100644 (file)
@@ -779,6 +779,27 @@ STRING should be given if the last search was by `string-match' on STRING."
          (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)