diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-25 02:48:58 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-25 02:48:58 -0500 |
commit | a7424c1df9b565e77ff25fee46f8a79d2638f42c (patch) | |
tree | 17bd490111af25474545ffdadc01f2eadb54b6a5 /src | |
parent | 4141afbfae0cfeb55b67efea603962b88b885043 (diff) | |
download | fork-ledger-a7424c1df9b565e77ff25fee46f8a79d2638f42c.tar.gz fork-ledger-a7424c1df9b565e77ff25fee46f8a79d2638f42c.tar.bz2 fork-ledger-a7424c1df9b565e77ff25fee46f8a79d2638f42c.zip |
Added a trim() value expression function
Diffstat (limited to 'src')
-rw-r--r-- | src/report.cc | 28 | ||||
-rw-r--r-- | src/report.h | 1 |
2 files changed, 29 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")) diff --git a/src/report.h b/src/report.h index d942038b..94d39215 100644 --- a/src/report.h +++ b/src/report.h @@ -143,6 +143,7 @@ public: value_t fn_get_at(call_scope_t& scope); value_t fn_is_seq(call_scope_t& scope); value_t fn_strip(call_scope_t& scope); + value_t fn_trim(call_scope_t& scope); value_t fn_scrub(call_scope_t& scope); value_t fn_quantity(call_scope_t& scope); value_t fn_rounded(call_scope_t& scope); |