From c720d0f6f71d2a66ae39782c8884c81bdb22513d Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Wed, 30 Nov 2011 17:54:15 -0500 Subject: [PATCH] Add regexp-filter to unstable/string. --- collects/unstable/scribblings/string.scrbl | 9 +++++++++ collects/unstable/string.rkt | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/collects/unstable/scribblings/string.scrbl b/collects/unstable/scribblings/string.scrbl index d695ddea9c..f6c76c0d79 100644 --- a/collects/unstable/scribblings/string.scrbl +++ b/collects/unstable/scribblings/string.scrbl @@ -27,3 +27,12 @@ string?]{ @racket[write]s @racket[v] to a string and returns it. } + + +@addition{Vincent St-Amour} + +@defproc[(regexp-filter [pattern (or/c string? bytes? regexp? byte-regexp?)] + [lst (listof (or/c string? bytes? path? input-port?))]) + (listof (or/c string? bytes? path? input-port?))]{ +Keeps only the elements of @racket[lst] that match @racket[pattern]. +} diff --git a/collects/unstable/string.rkt b/collects/unstable/string.rkt index 9fed06bbcb..1f80ff3930 100644 --- a/collects/unstable/string.rkt +++ b/collects/unstable/string.rkt @@ -33,3 +33,14 @@ [lowercase-symbol! ((or/c string? bytes?) . -> . symbol?)] [read/string (string? . -> . serializable?)] [write/string (serializable? . -> . string?)]) + + +;; added by stamourv + +(define (regexp-filter r log) + (for/list ([l (in-list log)] #:when (regexp-match r l)) + l)) +(provide/contract + [regexp-filter ((or/c string? bytes? regexp? byte-regexp?) + (listof (or/c string? bytes? path? input-port?)) + . -> . (listof (or/c string? bytes? path? input-port?)))])