summaryrefslogtreecommitdiff
path: root/src/textual.cc
diff options
context:
space:
mode:
authorChristophe Rhodes <csr21@cantab.net>2014-05-13 16:08:10 +0100
committerChristophe Rhodes <csr21@cantab.net>2014-05-13 16:08:10 +0100
commitda51f5b51051bdc6a0fe10325a3b8b1a2f30d21d (patch)
tree291f2a32b099aca4842d03273abb349ff98d0572 /src/textual.cc
parentbcb28b066f626a551e71fd0ef544e33c55770ea4 (diff)
downloadfork-ledger-da51f5b51051bdc6a0fe10325a3b8b1a2f30d21d.tar.gz
fork-ledger-da51f5b51051bdc6a0fe10325a3b8b1a2f30d21d.tar.bz2
fork-ledger-da51f5b51051bdc6a0fe10325a3b8b1a2f30d21d.zip
support payee uuid directive
The semantics of this are a little bit tricky: we want, if we come across a transaction with exactly the given UUID, to set the transaction's payee to be the specified one. We need to set that payee before the first post in the transaction is parsed, otherwise that post will inherit the wrong payee; however, we need to do it after the transaction's tags have been parsed. The implementation as it is in this commit is potentially a little wasteful, if there are post-like (non-comment non-assertion) entries in the transaction that don't successfully parse as posts.
Diffstat (limited to 'src/textual.cc')
-rw-r--r--src/textual.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/textual.cc b/src/textual.cc
index 0a590e08..60250007 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -155,6 +155,7 @@ namespace {
void payee_directive(char * line);
void payee_alias_directive(const string& payee, string alias);
+ void payee_uuid_directive(const string& payee, string uuid);
void commodity_directive(char * line);
void commodity_alias_directive(commodity_t& comm, string alias);
@@ -1035,6 +1036,8 @@ void instance_t::payee_directive(char * line)
string keyword(p);
if (keyword == "alias")
payee_alias_directive(payee, b);
+ if (keyword == "uuid")
+ payee_uuid_directive(payee, b);
}
}
@@ -1045,6 +1048,13 @@ void instance_t::payee_alias_directive(const string& payee, string alias)
.push_back(payee_alias_mapping_t(mask_t(alias), payee));
}
+void instance_t::payee_uuid_directive(const string& payee, string uuid)
+{
+ trim(uuid);
+ context.journal->payee_uuid_mappings
+ .push_back(payee_uuid_mapping_t(uuid, payee));
+}
+
void instance_t::commodity_directive(char * line)
{
char * p = skip_ws(line);
@@ -1862,6 +1872,17 @@ xact_t * instance_t::parse_xact(char * line,
else {
reveal_context = false;
+ if (!last_post) {
+ if (xact->has_tag(_("UUID"))) {
+ string uuid = xact->get_tag(_("UUID"))->to_string();
+ foreach (payee_uuid_mapping_t value, context.journal->payee_uuid_mappings) {
+ if (value.first.compare(uuid) == 0) {
+ xact->payee = value.second;
+ }
+ }
+ }
+ }
+
if (post_t * post =
parse_post(p, len - (p - line), account, xact.get())) {
reveal_context = true;