mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
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)
|
||||
|
||||
|
||||
-- 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
|
||||
|
||||
|
14
Options.hs
14
Options.hs
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user