move regexp utilities to Utils
This commit is contained in:
parent
a12d1b1c43
commit
1a608044d9
@ -35,6 +35,24 @@ import Data.Time.Clock (UTCTime, diffUTCTime)
|
|||||||
import Data.Time.Format (ParseTime, parseTime, formatTime)
|
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
|
-- time
|
||||||
|
|
||||||
-- | Parse a date-time string to a time type, or raise an error.
|
-- | Parse a date-time string to a time type, or raise an error.
|
||||||
@ -66,7 +84,6 @@ splitAtElement e l =
|
|||||||
|
|
||||||
-- trees
|
-- trees
|
||||||
|
|
||||||
-- aliases
|
|
||||||
root = rootLabel
|
root = rootLabel
|
||||||
branches = subForest
|
branches = subForest
|
||||||
|
|
||||||
|
|||||||
14
Options.hs
14
Options.hs
@ -6,9 +6,6 @@ ledgerFilePathFromOpts,
|
|||||||
beginDateFromOpts,
|
beginDateFromOpts,
|
||||||
endDateFromOpts,
|
endDateFromOpts,
|
||||||
parseAccountDescriptionArgs,
|
parseAccountDescriptionArgs,
|
||||||
regexFor,
|
|
||||||
nullpats,
|
|
||||||
wildcard,
|
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import System
|
import System
|
||||||
@ -113,17 +110,6 @@ parseAccountDescriptionArgs args = (as, ds')
|
|||||||
where (as, ds) = break (=="--") args
|
where (as, ds) = break (=="--") args
|
||||||
ds' = dropWhile (=="--") ds
|
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 RequireOrder ["foo","-v"]
|
||||||
-- testoptions Permute ["foo","-v"]
|
-- testoptions Permute ["foo","-v"]
|
||||||
-- testoptions (ReturnInOrder Arg) ["foo","-v"]
|
-- testoptions (ReturnInOrder Arg) ["foo","-v"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user