summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2005-02-14 00:58:36 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:40:59 -0400
commit83f0d1455bc7a279fb10547b2ea7b5569428436c (patch)
tree114f9adb29f6f1bfbc150f59caeb5ef05689efaa
parentff489920672e64f42d8847baae1d60da2f2e679b (diff)
downloadfork-ledger-83f0d1455bc7a279fb10547b2ea7b5569428436c.tar.gz
fork-ledger-83f0d1455bc7a279fb10547b2ea7b5569428436c.tar.bz2
fork-ledger-83f0d1455bc7a279fb10547b2ea7b5569428436c.zip
Added the capability for value expression regexps targetted at
specific parts of a transaction: c// (entry code), p// (payee), w// (short account name), W// (full account name), and e// (transaction note).
-rw-r--r--valexpr.cc78
-rw-r--r--valexpr.h2
2 files changed, 65 insertions, 15 deletions
diff --git a/valexpr.cc b/valexpr.cc
index ee02dafe..9091672f 100644
--- a/valexpr.cc
+++ b/valexpr.cc
@@ -233,6 +233,14 @@ void value_expr_t::compute(value_t& result, const details_t& details) const
break;
}
+ case F_CODE_MASK:
+ assert(mask);
+ if (details.entry)
+ result = mask->match(details.entry->code);
+ else
+ result = false;
+ break;
+
case F_PAYEE_MASK:
assert(mask);
if (details.entry)
@@ -241,6 +249,14 @@ void value_expr_t::compute(value_t& result, const details_t& details) const
result = false;
break;
+ case F_NOTE_MASK:
+ assert(mask);
+ if (details.xact)
+ result = mask->match(details.xact->note);
+ else
+ result = false;
+ break;
+
case F_ACCOUNT_MASK:
assert(mask);
if (details.account)
@@ -495,32 +511,54 @@ value_expr_t * parse_value_term(std::istream& in)
break;
// Other
+ case 'c':
+ case 'p':
+ case 'w':
+ case 'W':
+ case 'e':
case '/': {
- bool payee_mask = false;
- bool short_account_mask = false;
+ bool code_mask = c == 'c';
+ bool payee_mask = c == 'p';
+ bool note_mask = c == 'e';
+ bool short_account_mask = c == 'w';
- c = peek_next_nonws(in);
if (c == '/') {
- in.get(c);
- c = in.peek();
+ c = peek_next_nonws(in);
if (c == '/') {
in.get(c);
c = in.peek();
- short_account_mask = true;
- } else {
- payee_mask = true;
+ if (c == '/') {
+ in.get(c);
+ c = in.peek();
+ short_account_mask = true;
+ } else {
+ payee_mask = true;
+ }
}
+ } else {
+ in.get(c);
}
+ // Read in the regexp
READ_INTO(in, buf, 255, c, c != '/');
if (c != '/')
unexpected(c, '/');
+ value_expr_t::kind_t kind;
+
+ if (short_account_mask)
+ kind = value_expr_t::F_SHORT_ACCOUNT_MASK;
+ else if (code_mask)
+ kind = value_expr_t::F_CODE_MASK;
+ else if (payee_mask)
+ kind = value_expr_t::F_PAYEE_MASK;
+ else if (note_mask)
+ kind = value_expr_t::F_NOTE_MASK;
+ else
+ kind = value_expr_t::F_ACCOUNT_MASK;
+
in.get(c);
- node.reset(new value_expr_t(short_account_mask ?
- value_expr_t::F_SHORT_ACCOUNT_MASK :
- (payee_mask ? value_expr_t::F_PAYEE_MASK :
- value_expr_t::F_ACCOUNT_MASK)));
+ node.reset(new value_expr_t(kind));
node->mask = new mask_t(buf);
break;
}
@@ -825,19 +863,29 @@ void dump_value_expr(std::ostream& out, const value_expr_t * node)
out << ')';
break;
+ case value_expr_t::F_CODE_MASK:
+ assert(node->mask);
+ out << "M_CODE(" << node->mask->pattern << ')';
+ break;
+
case value_expr_t::F_PAYEE_MASK:
assert(node->mask);
- out << "P_MASK(" << node->mask->pattern << ')';
+ out << "M_PAYEE(" << node->mask->pattern << ')';
+ break;
+
+ case value_expr_t::F_NOTE_MASK:
+ assert(node->mask);
+ out << "M_NOTE(" << node->mask->pattern << ')';
break;
case value_expr_t::F_ACCOUNT_MASK:
assert(node->mask);
- out << "A_MASK(" << node->mask->pattern << ')';
+ out << "M_ACCT(" << node->mask->pattern << ')';
break;
case value_expr_t::F_SHORT_ACCOUNT_MASK:
assert(node->mask);
- out << "A_SMASK(" << node->mask->pattern << ')';
+ out << "M_SACCT(" << node->mask->pattern << ')';
break;
case value_expr_t::F_VALUE:
diff --git a/valexpr.h b/valexpr.h
index 938ce27d..de4a7a19 100644
--- a/valexpr.h
+++ b/valexpr.h
@@ -69,7 +69,9 @@ struct value_expr_t
F_NEG,
F_ABS,
F_STRIP,
+ F_CODE_MASK,
F_PAYEE_MASK,
+ F_NOTE_MASK,
F_ACCOUNT_MASK,
F_SHORT_ACCOUNT_MASK,
F_INTERP_FUNC,