Plaster
New
List
Login
common-lisp
default
scymtym
2023.10.18 10:40:31
(cl:in-package #:text.editing) (defstruct search-input cursor index) (defun buffer-length (input) (c:item-count (c:buffer (search-input-cursor input)))) (defun buffer-ref (input index) (let* ((cursor (search-input-cursor input)) (old-index (search-input-index input)) (diff (- index old-index))) (format *trace-output* "~D -> ~D~%" old-index index) (cond ((zerop diff)) ((plusp diff) (loop :repeat diff :do (forward-item* cursor)) (setf (search-input-index input) index)) ((minusp diff) (loop :repeat diff :do (backward-item* cursor)) (setf (search-input-index input) index))) (item-after-cursor* cursor))) (defun make-buffer-layout () (one-more-re-nightmare::make-layout :array-type 'search-input :length 'buffer-length :ref 'buffer-ref)) (text.editing.test::call-with-buffer (lambda (buffer) (let ((input (make-search-input :cursor (point buffer) :index 0))) (one-more-re-nightmare:first-match "f«o+» *«b$+»" input :layout (make-buffer-layout)))) "foo bar") ; => #(0 7 1 3 4 7)
Raw
Annotate
Repaste