Function: s-split-up-to

s-split-up-to is a byte-compiled function defined in s.el.

Signature

(s-split-up-to SEPARATOR S N &optional OMIT-NULLS)

Documentation

Split S up to N times into substrings bounded by matches for regexp SEPARATOR.

If OMIT-NULLS is non-nil, zero-length substrings are omitted.

See also s-split.

Source Code

;; Defined in ~/.emacs.d/elpa/s-20220902.1511/s.el
(defun s-split-up-to (separator s n &optional omit-nulls)
  "Split S up to N times into substrings bounded by matches for regexp SEPARATOR.

If OMIT-NULLS is non-nil, zero-length substrings are omitted.

See also `s-split'."
  (declare (side-effect-free t))
  (save-match-data
    (let ((op 0)
          (r nil))
      (with-temp-buffer
        (insert s)
        (setq op (goto-char (point-min)))
        (while (and (re-search-forward separator nil t)
                    (< 0 n))
          (let ((sub (buffer-substring op (match-beginning 0))))
            (unless (and omit-nulls
                         (equal sub ""))
              (push sub r)))
          (setq op (goto-char (match-end 0)))
          (setq n (1- n)))
        (let ((sub (buffer-substring op (point-max))))
          (unless (and omit-nulls
                       (equal sub ""))
            (push sub r))))
      (nreverse r))))