diff options
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/subr-x.el | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 09c4649817a..8a9424cbb3d 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -308,19 +308,16 @@ If OMIT-NULLS, empty lines will be removed from the results." (defun string-slice (string regexp) "Split STRING at REGEXP boundaries and return a list of slices. -The boundaries that match REGEXP are included in the result." - (let ((start-substring 0) - (start-search 0) - (result nil)) - (save-match-data - (while (string-match regexp string start-search) - (if (zerop (match-beginning 0)) - (setq start-search (match-end 0)) - (push (substring string start-substring (match-beginning 0)) result) - (setq start-substring (match-beginning 0) - start-search (match-end 0)))) - (push (substring string start-substring) result) - (nreverse result)))) +The boundaries that match REGEXP are included in the result. + +Also see `split-string'." + (if (zerop (length string)) + (list "") + (let ((i (string-match-p regexp string 1))) + (if i + (cons (substring string 0 i) + (string-slice (substring string i) regexp)) + (list string))))) (defun string-pad (string length &optional padding start) "Pad STRING to LENGTH using PADDING. |