summaryrefslogtreecommitdiff
path: root/src/filters.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/filters.cc')
-rw-r--r--src/filters.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/filters.cc b/src/filters.cc
index 1385a3f0..b818c7d0 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -36,6 +36,7 @@
#include "journal.h"
#include "report.h"
#include "compare.h"
+#include "pool.h"
namespace ledger {
@@ -216,6 +217,43 @@ namespace {
}
}
+void anonymize_posts::render_commodity(amount_t& amt)
+{
+ commodity_t& comm(amt.commodity());
+
+ std::size_t id;
+ bool newly_added = false;
+
+ commodity_index_map::iterator i = comms.find(&comm);
+ if (i == comms.end()) {
+ id = next_comm_id++;
+ newly_added = true;
+ comms.insert(commodity_index_map::value_type(&comm, id));
+ } else {
+ id = (*i).second;
+ }
+
+ std::ostringstream buf;
+ do {
+ buf << static_cast<char>('A' + (id % 26));
+ id /= 26;
+ }
+ while (id > 0);
+
+ if (amt.has_annotation())
+ amt.set_commodity
+ (*commodity_pool_t::current_pool->find_or_create(buf.str(),
+ amt.annotation()));
+ else
+ amt.set_commodity
+ (*commodity_pool_t::current_pool->find_or_create(buf.str()));
+
+ if (newly_added) {
+ amt.commodity().set_flags(comm.flags());
+ amt.commodity().set_precision(comm.precision());
+ }
+}
+
void anonymize_posts::operator()(post_t& post)
{
SHA1 sha;
@@ -258,6 +296,20 @@ void anonymize_posts::operator()(post_t& post)
temp.note = none;
temp.add_flags(POST_ANONYMIZED);
+ DEBUG("foo", "1.rendering amount: " << temp.amount);
+ render_commodity(temp.amount);
+ DEBUG("foo", "2.rendering amount: " << temp.amount);
+ if (temp.amount.has_annotation()) {
+ temp.amount.annotation().tag = none;
+ if (temp.amount.annotation().price)
+ render_commodity(*temp.amount.annotation().price);
+ }
+
+ if (temp.cost)
+ render_commodity(*temp.cost);
+ if (temp.assigned_amount)
+ render_commodity(*temp.assigned_amount);
+
(*handler)(temp);
}