summaryrefslogtreecommitdiff
path: root/src/report.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-25 02:48:58 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-25 02:48:58 -0500
commita7424c1df9b565e77ff25fee46f8a79d2638f42c (patch)
tree17bd490111af25474545ffdadc01f2eadb54b6a5 /src/report.cc
parent4141afbfae0cfeb55b67efea603962b88b885043 (diff)
downloadfork-ledger-a7424c1df9b565e77ff25fee46f8a79d2638f42c.tar.gz
fork-ledger-a7424c1df9b565e77ff25fee46f8a79d2638f42c.tar.bz2
fork-ledger-a7424c1df9b565e77ff25fee46f8a79d2638f42c.zip
Added a trim() value expression function
Diffstat (limited to 'src/report.cc')
-rw-r--r--src/report.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/report.cc b/src/report.cc
index 894e0d89..2d9d7cc6 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -380,6 +380,32 @@ value_t report_t::fn_strip(call_scope_t& args)
return args.value().strip_annotations(what_to_keep());
}
+value_t report_t::fn_trim(call_scope_t& args)
+{
+ string temp(args.value().to_string());
+ scoped_array<char> buf(new char[temp.length() + 1]);
+ std::strcpy(buf.get(), temp.c_str());
+
+ const char * p = buf.get();
+ while (*p && std::isspace(*p))
+ p++;
+
+ const char * e = buf.get() + temp.length();
+ while (e > p && std::isspace(*e))
+ e--;
+
+ if (e == p) {
+ return string_value(empty_string);
+ }
+ else if (e < p) {
+ assert(false);
+ return string_value(empty_string);
+ }
+ else {
+ return string_value(string(p, e - p));
+ }
+}
+
value_t report_t::fn_scrub(call_scope_t& args)
{
value_t temp(args.value().strip_annotations(what_to_keep()));
@@ -1078,6 +1104,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return MAKE_FUNCTOR(report_t::fn_today);
else if (is_eq(p, "t"))
return MAKE_FUNCTOR(report_t::fn_display_amount);
+ else if (is_eq(p, "trim"))
+ return MAKE_FUNCTOR(report_t::fn_trim);
else if (is_eq(p, "to_boolean"))
return MAKE_FUNCTOR(report_t::fn_to_boolean);
else if (is_eq(p, "to_int"))