fix simple aliases that match the whole account name
This commit is contained in:
parent
c138852dab
commit
46bbc9e0aa
@ -59,6 +59,7 @@ parentAccountNames a = parentAccountNames' $ parentAccountName a
|
|||||||
parentAccountNames' "" = []
|
parentAccountNames' "" = []
|
||||||
parentAccountNames' a = a : parentAccountNames' (parentAccountName a)
|
parentAccountNames' a = a : parentAccountNames' (parentAccountName a)
|
||||||
|
|
||||||
|
-- | Is the first account a parent or other ancestor of (and not the same as) the second ?
|
||||||
isAccountNamePrefixOf :: AccountName -> AccountName -> Bool
|
isAccountNamePrefixOf :: AccountName -> AccountName -> Bool
|
||||||
isAccountNamePrefixOf = isPrefixOf . (++ [acctsepchar])
|
isAccountNamePrefixOf = isPrefixOf . (++ [acctsepchar])
|
||||||
|
|
||||||
|
|||||||
@ -226,7 +226,7 @@ accountNameApplyAliases aliases a = accountNameWithPostingType atype aname'
|
|||||||
where
|
where
|
||||||
(aname,atype) = (accountNameWithoutPostingType a, accountNamePostingType a)
|
(aname,atype) = (accountNameWithoutPostingType a, accountNamePostingType a)
|
||||||
aname' = foldl
|
aname' = foldl
|
||||||
(\acct alias -> dbg6 "got" $ aliasReplace (dbg6 "alias" alias) acct)
|
(\acct alias -> dbg6 "result" $ aliasReplace (dbg6 "alias" alias) (dbg6 "account" acct))
|
||||||
aname
|
aname
|
||||||
aliases
|
aliases
|
||||||
|
|
||||||
@ -235,8 +235,9 @@ accountNameApplyAliases aliases a = accountNameWithPostingType atype aname'
|
|||||||
-- aliasMatches (RegexAlias re _) a = regexMatchesCI re a
|
-- aliasMatches (RegexAlias re _) a = regexMatchesCI re a
|
||||||
|
|
||||||
aliasReplace :: AccountAlias -> AccountName -> AccountName
|
aliasReplace :: AccountAlias -> AccountName -> AccountName
|
||||||
aliasReplace (BasicAlias old new) a | old `isAccountNamePrefixOf` a = new ++ drop (length old) a
|
aliasReplace (BasicAlias old new) a
|
||||||
| otherwise = a
|
| old `isAccountNamePrefixOf` a || old == a = new ++ drop (length old) a
|
||||||
|
| otherwise = a
|
||||||
aliasReplace (RegexAlias re repl) a = regexReplaceCI re repl a
|
aliasReplace (RegexAlias re repl) a = regexReplaceCI re repl a
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
# alias-related tests
|
# alias-related tests
|
||||||
|
|
||||||
|
# simple aliases
|
||||||
|
|
||||||
# simple alias directive
|
# simple alias directive
|
||||||
hledgerdev -f- accounts
|
hledgerdev -f- accounts
|
||||||
<<<
|
<<<
|
||||||
@ -23,6 +25,18 @@ A:B:c
|
|||||||
a:bb:d
|
a:bb:d
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
|
# a simple alias matching the whole account name works
|
||||||
|
hledgerdev -f- accounts
|
||||||
|
<<<
|
||||||
|
alias a:b = A:B
|
||||||
|
1/1
|
||||||
|
(a:b) 1
|
||||||
|
>>>
|
||||||
|
A:B
|
||||||
|
>>>=0
|
||||||
|
|
||||||
|
# regular expression aliases
|
||||||
|
|
||||||
# regex alias directive
|
# regex alias directive
|
||||||
hledgerdev -f- accounts
|
hledgerdev -f- accounts
|
||||||
<<<
|
<<<
|
||||||
@ -68,6 +82,8 @@ alias /A (.)/=\1
|
|||||||
|
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
|
# CLI
|
||||||
|
|
||||||
# --alias command-line options are applied in the order written.
|
# --alias command-line options are applied in the order written.
|
||||||
# Spaces are allowed if quoted.
|
# Spaces are allowed if quoted.
|
||||||
#
|
#
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user