move regexp utilities to Utils

This commit is contained in:
Simon Michael 2008-10-09 07:08:36 +00:00
parent a12d1b1c43
commit 1a608044d9
2 changed files with 18 additions and 15 deletions

View File

@ -35,6 +35,24 @@ import Data.Time.Clock (UTCTime, diffUTCTime)
import Data.Time.Format (ParseTime, parseTime, formatTime)
-- regexps
instance Show Regex where show r = "a Regex"
-- | convert a list of strings to a regular expression matching any of them,
-- or a wildcard if there are none.
regexFor :: [String] -> Regex
regexFor [] = wildcard
regexFor ss = mkRegex $ concat $ ["("] ++ (intersperse "|" ss) ++ [")"]
wildcard :: Regex
wildcard = mkRegex ".*"
containsRegex :: Regex -> String -> Bool
containsRegex r s = case matchRegex r s of
Just _ -> True
otherwise -> False
-- time
-- | Parse a date-time string to a time type, or raise an error.
@ -66,7 +84,6 @@ splitAtElement e l =
-- trees
-- aliases
root = rootLabel
branches = subForest

View File

@ -6,9 +6,6 @@ ledgerFilePathFromOpts,
beginDateFromOpts,
endDateFromOpts,
parseAccountDescriptionArgs,
regexFor,
nullpats,
wildcard,
)
where
import System
@ -113,17 +110,6 @@ parseAccountDescriptionArgs args = (as, ds')
where (as, ds) = break (=="--") args
ds' = dropWhile (=="--") ds
-- | convert a list of strings to a regular expression matching any of them,
-- or a wildcard if there are none.
regexFor :: [String] -> Regex
regexFor [] = wildcard
regexFor ss = mkRegex $ concat $ ["("] ++ (intersperse "|" ss) ++ [")"]
wildcard :: Regex
wildcard = mkRegex ".*"
nullpats = (wildcard,wildcard)
-- testoptions RequireOrder ["foo","-v"]
-- testoptions Permute ["foo","-v"]
-- testoptions (ReturnInOrder Arg) ["foo","-v"]