Function: majutsu--split-fields

majutsu--split-fields is a natively compiled function defined in majutsu-base.el.

Signature

(majutsu--split-fields VALUE SEPARATOR &optional MAX-FIELDS)

Documentation

Split VALUE at one-character SEPARATOR, preserving empty fields.

When MAX-FIELDS is non-nil, split at most MAX-FIELDS fields and leave the remaining text in the last field. Text properties are preserved.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-base.el
(defun majutsu--split-fields (value separator &optional max-fields)
  "Split VALUE at one-character SEPARATOR, preserving empty fields.
When MAX-FIELDS is non-nil, split at most MAX-FIELDS fields and leave the
remaining text in the last field.  Text properties are preserved."
  (when (stringp value)
    (let ((start 0)
          (len (length value))
          (sep (if (characterp separator) separator (aref separator 0)))
          out)
      (catch 'done
        (dotimes (idx len)
          (when (and max-fields
                     (>= (length out) (1- max-fields)))
            (throw 'done nil))
          (when (eq (aref value idx) sep)
            (push (substring value start idx) out)
            (setq start (1+ idx)))))
      (push (substring value start len) out)
      (nreverse out))))