New display flag AMOUNT_PRINT_ELIDE_COMMODITY_QUOTES
This is used by reports like register and balance so that separated commodities without spaces in them needed be surrounded by quotes. It will still occur in most other places. Fixes #200 / F82CF11F-BFD9-4512-A562-202B04B68051
This commit is contained in:
parent
da2f415f14
commit
8637dd6ccf
6 changed files with 22 additions and 13 deletions
|
|
@ -1233,7 +1233,7 @@ void amount_t::print(std::ostream& _out, const uint_least8_t flags) const
|
|||
commodity_t& comm(commodity());
|
||||
|
||||
if (! comm.has_flags(COMMODITY_STYLE_SUFFIXED)) {
|
||||
comm.print(out);
|
||||
comm.print(out, flags & AMOUNT_PRINT_ELIDE_COMMODITY_QUOTES);
|
||||
if (comm.has_flags(COMMODITY_STYLE_SEPARATED))
|
||||
out << " ";
|
||||
}
|
||||
|
|
@ -1244,7 +1244,7 @@ void amount_t::print(std::ostream& _out, const uint_least8_t flags) const
|
|||
if (comm.has_flags(COMMODITY_STYLE_SUFFIXED)) {
|
||||
if (comm.has_flags(COMMODITY_STYLE_SEPARATED))
|
||||
out << " ";
|
||||
comm.print(out);
|
||||
comm.print(out, flags & AMOUNT_PRINT_ELIDE_COMMODITY_QUOTES);
|
||||
}
|
||||
|
||||
// If there are any annotations associated with this commodity, output them
|
||||
|
|
|
|||
|
|
@ -680,6 +680,7 @@ public:
|
|||
#define AMOUNT_PRINT_RIGHT_JUSTIFY 0x01
|
||||
#define AMOUNT_PRINT_COLORIZE 0x02
|
||||
#define AMOUNT_PRINT_NO_COMPUTED_ANNOTATIONS 0x04
|
||||
#define AMOUNT_PRINT_ELIDE_COMMODITY_QUOTES 0x08
|
||||
|
||||
void print(std::ostream& out,
|
||||
const uint_least8_t flags = AMOUNT_PRINT_NO_FLAGS) const;
|
||||
|
|
|
|||
|
|
@ -642,6 +642,17 @@ void commodity_t::parse_symbol(char *& p, string& symbol)
|
|||
throw_(amount_error, _("Failed to parse commodity"));
|
||||
}
|
||||
|
||||
void commodity_t::print(std::ostream& out, bool elide_quotes) const
|
||||
{
|
||||
string sym = symbol();
|
||||
if (elide_quotes && has_flags(COMMODITY_STYLE_SEPARATED) &&
|
||||
! sym.empty() && sym[0] == '"' && ! std::strchr(sym.c_str(), ' ')) {
|
||||
DEBUG("foo", "contracting " << sym << " to " << string(sym, 1, sym.length() - 2));
|
||||
out << string(sym, 1, sym.length() - 2);
|
||||
} else
|
||||
out << sym;
|
||||
}
|
||||
|
||||
bool commodity_t::valid() const
|
||||
{
|
||||
if (symbol().empty() && this != pool().null_commodity) {
|
||||
|
|
|
|||
|
|
@ -391,10 +391,7 @@ public:
|
|||
return temp;
|
||||
}
|
||||
|
||||
void print(std::ostream& out) const {
|
||||
out << symbol();
|
||||
}
|
||||
|
||||
void print(std::ostream& out, bool elide_quotes = false) const;
|
||||
bool valid() const;
|
||||
|
||||
struct compare_by_commodity {
|
||||
|
|
|
|||
|
|
@ -598,7 +598,7 @@ value_t report_t::fn_justify(call_scope_t& scope)
|
|||
{
|
||||
interactive_t args(scope, "vl&lbb");
|
||||
|
||||
uint_least8_t flags(AMOUNT_PRINT_NO_FLAGS);
|
||||
uint_least8_t flags(AMOUNT_PRINT_ELIDE_COMMODITY_QUOTES);
|
||||
|
||||
if (args.has(3) && args.get<bool>(3))
|
||||
flags |= AMOUNT_PRINT_RIGHT_JUSTIFY;
|
||||
|
|
|
|||
|
|
@ -4,16 +4,16 @@
|
|||
>>>2
|
||||
While parsing file "$sourcepath/src/amount.h", line 66:
|
||||
Error: No quantity specified for amount
|
||||
While parsing file "$sourcepath/src/amount.h", line 725:
|
||||
While parsing file "$sourcepath/src/amount.h", line 726:
|
||||
Error: Invalid date/time: line amount_t amoun
|
||||
While parsing file "$sourcepath/src/amount.h", line 731:
|
||||
While parsing file "$sourcepath/src/amount.h", line 732:
|
||||
Error: Invalid date/time: line string amount_
|
||||
While parsing file "$sourcepath/src/amount.h", line 737:
|
||||
While parsing file "$sourcepath/src/amount.h", line 738:
|
||||
Error: Invalid date/time: line string amount_
|
||||
While parsing file "$sourcepath/src/amount.h", line 743:
|
||||
While parsing file "$sourcepath/src/amount.h", line 744:
|
||||
Error: Invalid date/time: line string amount_
|
||||
While parsing file "$sourcepath/src/amount.h", line 749:
|
||||
While parsing file "$sourcepath/src/amount.h", line 750:
|
||||
Error: Invalid date/time: line std::ostream&
|
||||
While parsing file "$sourcepath/src/amount.h", line 756:
|
||||
While parsing file "$sourcepath/src/amount.h", line 757:
|
||||
Error: Invalid date/time: line std::istream&
|
||||
=== 7
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue