clean up special char definitions in AccountName.hs
This commit is contained in:
parent
dfe59676fb
commit
4d53fac9a3
@ -11,20 +11,24 @@ import Ledger.Utils
|
|||||||
import Ledger.Types
|
import Ledger.Types
|
||||||
|
|
||||||
|
|
||||||
sepchar = ':'
|
-- change to permit options anywhere on the command line. ^ is a good choice
|
||||||
|
negativepatternchar = '-'
|
||||||
|
|
||||||
|
-- change to use a different separator for nested accounts
|
||||||
|
acctsepchar = ':'
|
||||||
|
|
||||||
accountNameComponents :: AccountName -> [String]
|
accountNameComponents :: AccountName -> [String]
|
||||||
accountNameComponents = splitAtElement sepchar
|
accountNameComponents = splitAtElement acctsepchar
|
||||||
|
|
||||||
accountNameFromComponents :: [String] -> AccountName
|
accountNameFromComponents :: [String] -> AccountName
|
||||||
accountNameFromComponents = concat . intersperse [sepchar]
|
accountNameFromComponents = concat . intersperse [acctsepchar]
|
||||||
|
|
||||||
accountLeafName :: AccountName -> String
|
accountLeafName :: AccountName -> String
|
||||||
accountLeafName = last . accountNameComponents
|
accountLeafName = last . accountNameComponents
|
||||||
|
|
||||||
accountNameLevel :: AccountName -> Int
|
accountNameLevel :: AccountName -> Int
|
||||||
accountNameLevel "" = 0
|
accountNameLevel "" = 0
|
||||||
accountNameLevel a = (length $ filter (==sepchar) a) + 1
|
accountNameLevel a = (length $ filter (==acctsepchar) a) + 1
|
||||||
|
|
||||||
-- | ["a:b:c","d:e"] -> ["a","a:b","a:b:c","d","d:e"]
|
-- | ["a:b:c","d:e"] -> ["a","a:b","a:b:c","d","d:e"]
|
||||||
expandAccountNames :: [AccountName] -> [AccountName]
|
expandAccountNames :: [AccountName] -> [AccountName]
|
||||||
@ -45,7 +49,7 @@ parentAccountNames a = parentAccountNames' $ parentAccountName a
|
|||||||
parentAccountNames' a = [a] ++ (parentAccountNames' $ parentAccountName a)
|
parentAccountNames' a = [a] ++ (parentAccountNames' $ parentAccountName a)
|
||||||
|
|
||||||
isAccountNamePrefixOf :: AccountName -> AccountName -> Bool
|
isAccountNamePrefixOf :: AccountName -> AccountName -> Bool
|
||||||
p `isAccountNamePrefixOf` s = ((p ++ [sepchar]) `isPrefixOf` s)
|
p `isAccountNamePrefixOf` s = ((p ++ [acctsepchar]) `isPrefixOf` s)
|
||||||
|
|
||||||
isSubAccountNameOf :: AccountName -> AccountName -> Bool
|
isSubAccountNameOf :: AccountName -> AccountName -> Bool
|
||||||
s `isSubAccountNameOf` p =
|
s `isSubAccountNameOf` p =
|
||||||
@ -167,7 +171,6 @@ match_negative_pats pats str = (not $ null ns) && (any match ns)
|
|||||||
match "" = True
|
match "" = True
|
||||||
match p = matchregex (abspat p) str
|
match p = matchregex (abspat p) str
|
||||||
|
|
||||||
negativepatternchar = '-'
|
|
||||||
isnegativepat pat = (== [negativepatternchar]) $ take 1 pat
|
isnegativepat pat = (== [negativepatternchar]) $ take 1 pat
|
||||||
abspat pat = if isnegativepat pat then drop 1 pat else pat
|
abspat pat = if isnegativepat pat then drop 1 pat else pat
|
||||||
positivepats = filter (not . isnegativepat)
|
positivepats = filter (not . isnegativepat)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user