Added "format" value expression function

This function evaluates formatting strings, returning a string.  For
example:

  format("%(amount)")

This is equivalent to "to_string(amount)".
This commit is contained in:
John Wiegley 2010-06-24 20:33:52 -04:00
parent 011bf030a2
commit 8a29c03490
2 changed files with 11 additions and 0 deletions

View file

@ -549,6 +549,14 @@ value_t report_t::fn_trim(call_scope_t& args)
}
}
value_t report_t::fn_format(call_scope_t& args)
{
format_t format(args.get<string>(0));
std::ostringstream out;
out << format(args);
return string_value(out.str());
}
value_t report_t::fn_print(call_scope_t& args)
{
std::ostream& out(output_stream);
@ -1178,6 +1186,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
case 'f':
if (is_eq(p, "format_date"))
return MAKE_FUNCTOR(report_t::fn_format_date);
else if (is_eq(p, "format"))
return MAKE_FUNCTOR(report_t::fn_format);
else if (is_eq(p, "floor"))
return MAKE_FUNCTOR(report_t::fn_floor);
break;

View file

@ -151,6 +151,7 @@ public:
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_format(call_scope_t& scope);
value_t fn_print(call_scope_t& scope);
value_t fn_scrub(call_scope_t& scope);
value_t fn_quantity(call_scope_t& scope);