Skip to content
Snippets Groups Projects
Commit 0755a7d9 authored by Simon Marlow's avatar Simon Marlow
Browse files

[project @ 1999-04-26 15:19:28 by simonm]

Add simple high-level interface to Regex (snaffled from my nofib log
analyser).
parent 1e9b030f
No related merge requests found
-----------------------------------------------------------------------------
RegexString.lhs
A simple high-level interface to Regex
(c) Simon Marlow 1997
-----------------------------------------------------------------------------
> module RegexString (Regex(..), mkRegex, matchRegex) where
> import Regex
> import PackedString
> import Array
> import GlaExts
> type Regex = PatBuffer
>
> mkRegex :: String -> Regex
> mkRegex s = unsafePerformPrimIO (
> re_compile_pattern (packString s) False False)
>
> matchRegex :: Regex -> String -> Maybe [String]
> matchRegex p s = unsafePerformPrimIO (
> re_match p str 0 True >>= \m ->
> case m of
> Nothing -> return Nothing
> Just m -> return (Just (matches m str))
> )
> where
> str = packString s
>
> matches (REmatch arr _ _ _ _) s =
> [ unpackPS (substrPS s beg (end-1)) |
> index <- [1..], let (beg,end) = arr ! index ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment