[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] irregex and callbacks
From: |
Andy Bennett |
Subject: |
Re: [Chicken-users] irregex and callbacks |
Date: |
Thu, 02 Oct 2014 13:47:15 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.8.1 |
Hi,
> You could use submatch info and check which submatch matched.
> This would keep the matching as a single regexp, but you'd then
> need a linear scan to see which submatch succeeded.
Thanks Alex!
I'm trying to avoid the linear scan as there are several tens of
thousand entries in the database. How expensive do you think it would be?
> (define (irregex-merge-vector vec)
> (irregex `(or ,@(map (lambda (x) `(=> alt ,x)) (vector->list vec)))))
>
> (define ua-vec ...)
> (define all-ua-rx (irregex-merge-vector ua-vec))
>
> (define (maybe-match-ua ua)
> (cond
> ((irregex-match all-ua-rx ua)
> => (lambda (m)
> (vector-reg ua-vec (irregex-match-numeric-index 'match-ua m
> '(alt)))))
> (else
> #f)))
>
> although I believe irregex-match-numeric-index is not exported.
> It's worth having a utility for this idiom.
Regards,
@ndy
--
address@hidden
http://www.ashurst.eu.org/
0x7EBA75FF