chickadee » chicken » irregex » irregex-match/chunked

irregex-search/chunked <irx> <chunker> <chunk> #!optional <start>procedure
irregex-match/chunked <irx> <chunker> <chunk> #!optional <start>procedure

These return normal match-data objects.

Example:

To match against a simple, flat list of strings use:

  (define (rope->string rope1 start rope2 end)
    (if (eq? rope1 rope2)
        (substring (car rope1) start end)
        (let loop ((rope (cdr rope1))
                   (res (list (substring (car rope1) start))))
           (if (eq? rope rope2)
               (string-concatenate-reverse      ; from SRFI-13
                (cons (substring (car rope) 0 end) res))
               (loop (cdr rope) (cons (car rope) res))))))

  (define rope-chunker
    (make-irregex-chunker (lambda (x) (and (pair? (cdr x)) (cdr x)))
                          car
                          (lambda (x) 0)
                          (lambda (x) (string-length (car x)))
                          rope->string))

  (irregex-search/chunked <pat> rope-chunker <list-of-strings>)

Here we are just using the default start, end and substring behaviors, so the above chunker could simply be defined as:

  (define rope-chunker
    (make-irregex-chunker (lambda (x) (and (pair? (cdr x)) (cdr x))) car))