lib: allow trailing whitespace in regex account aliases
Trailing whitespace in the replacement part of a regular expression account alias is now significant. Eg, slightly flattening some bank accounts: --alias '/:somebank:/=somebank '
This commit is contained in:
parent
4a5d10eb2d
commit
5c85a1dd1c
@ -321,7 +321,7 @@ basicaliasp = do
|
||||
old <- rstrip <$> (some $ noneOf ("=" :: [Char]))
|
||||
char '='
|
||||
many spacenonewline
|
||||
new <- rstrip <$> anyChar `manyTill` eolof -- don't require a final newline, good for cli options
|
||||
new <- rstrip <$> anyChar `manyTill` eolof -- eol in journal, eof in command lines, normally
|
||||
return $ BasicAlias (T.pack old) (T.pack new)
|
||||
|
||||
regexaliasp :: TextParser m AccountAlias
|
||||
@ -333,7 +333,7 @@ regexaliasp = do
|
||||
many spacenonewline
|
||||
char '='
|
||||
many spacenonewline
|
||||
repl <- rstrip <$> anyChar `manyTill` eolof
|
||||
repl <- anyChar `manyTill` eolof
|
||||
return $ RegexAlias re repl
|
||||
|
||||
endaliasesdirectivep :: JournalParser m ()
|
||||
|
||||
@ -672,8 +672,6 @@ inside an account name, the matched part will be replaced by
|
||||
REPLACEMENT.
|
||||
If REGEX contains parenthesised match groups, these can be referenced
|
||||
by the usual numeric backreferences in REPLACEMENT.
|
||||
Note, currently regular expression aliases may cause noticeable slow-downs.
|
||||
(And if you use Ledger on your hledger file, they will be ignored.)
|
||||
Eg:
|
||||
|
||||
```journal
|
||||
@ -681,6 +679,9 @@ alias /^(.+):bank:([^:]+)(.*)/ = \1:\2 \3
|
||||
# rewrites "assets:bank:wells fargo:checking" to "assets:wells fargo checking"
|
||||
```
|
||||
|
||||
Also note that REPLACEMENT continues to the end of line (or on command line,
|
||||
to end of option argument), so it can contain trailing whitespace.
|
||||
|
||||
#### Multiple aliases
|
||||
|
||||
You can define as many aliases as you like using directives or command-line options.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user