summaryrefslogtreecommitdiff
path: root/src/report.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-25 14:20:07 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-25 14:20:07 -0500
commite8a14d31b6aefe421796fca1e50f4ea1e3816536 (patch)
tree77ccfc5c88c9569b9ad02790c754d8d498b7240b /src/report.cc
parent98ea23cd59cf959f3561632cc38043ab2d89f164 (diff)
parenta3338a2a67a793ddbbc1b0f93901d9a978dc1a8c (diff)
downloadfork-ledger-e8a14d31b6aefe421796fca1e50f4ea1e3816536.tar.gz
fork-ledger-e8a14d31b6aefe421796fca1e50f4ea1e3816536.tar.bz2
fork-ledger-e8a14d31b6aefe421796fca1e50f4ea1e3816536.zip
Merge branch 'next'
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"))