module Lambdabot.Regex (
regex,
matches,
regex',
matches',
module Text.Regex.Posix.ByteString
) where
import Data.ByteString.Char8
import Text.Regex.Posix.ByteString
import System.IO.Unsafe (unsafePerformIO)
regex' :: String -> Regex
regex :: ByteString -> Regex
matches' :: Regex -> String -> Bool
matches :: Regex -> ByteString -> Bool
regex' s = regex (pack s)
regex p = unsafePerformIO $ do
res <- compile compileFlags execFlags p
case res of
Left err -> error $ "regex failed: " ++ show err
Right r -> return r
where
compileFlags = compExtended
execFlags = 0
matches' r s = matches r (pack s)
matches r p = unsafePerformIO $ do
res <- execute r p
case res of
Left err -> error $ "regex execute failed: " ++ show err
Right Nothing -> return False
Right (Just _) -> return True