From 4d53fac9a35f37cccbbed27b8aa763ab4885b7cc Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 24 Nov 2008 00:22:47 +0000 Subject: [PATCH] clean up special char definitions in AccountName.hs --- Ledger/AccountName.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Ledger/AccountName.hs b/Ledger/AccountName.hs index b2c7e9e1a..ace77d78b 100644 --- a/Ledger/AccountName.hs +++ b/Ledger/AccountName.hs @@ -11,20 +11,24 @@ import Ledger.Utils 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 = splitAtElement sepchar +accountNameComponents = splitAtElement acctsepchar accountNameFromComponents :: [String] -> AccountName -accountNameFromComponents = concat . intersperse [sepchar] +accountNameFromComponents = concat . intersperse [acctsepchar] accountLeafName :: AccountName -> String accountLeafName = last . accountNameComponents accountNameLevel :: AccountName -> Int 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"] expandAccountNames :: [AccountName] -> [AccountName] @@ -45,7 +49,7 @@ parentAccountNames a = parentAccountNames' $ parentAccountName a parentAccountNames' a = [a] ++ (parentAccountNames' $ parentAccountName a) isAccountNamePrefixOf :: AccountName -> AccountName -> Bool -p `isAccountNamePrefixOf` s = ((p ++ [sepchar]) `isPrefixOf` s) +p `isAccountNamePrefixOf` s = ((p ++ [acctsepchar]) `isPrefixOf` s) isSubAccountNameOf :: AccountName -> AccountName -> Bool s `isSubAccountNameOf` p = @@ -167,7 +171,6 @@ match_negative_pats pats str = (not $ null ns) && (any match ns) match "" = True match p = matchregex (abspat p) str -negativepatternchar = '-' isnegativepat pat = (== [negativepatternchar]) $ take 1 pat abspat pat = if isnegativepat pat then drop 1 pat else pat positivepats = filter (not . isnegativepat)