Changed --european option to --decimal-comma

Fixes #211 / 1736ACA5-5DE6-4826-AEB4-DB5B2A2217AC
This commit is contained in:
John Wiegley 2010-06-01 17:44:28 -04:00
parent d513c71236
commit 038c24357e
8 changed files with 59 additions and 60 deletions

View file

@ -165,8 +165,8 @@ namespace {
for (const char * p = buf; *p; p++) {
if (*p == '.') {
if (commodity_t::european_by_default ||
(comm && comm->has_flags(COMMODITY_STYLE_EUROPEAN)))
if (commodity_t::decimal_comma_by_default ||
(comm && comm->has_flags(COMMODITY_STYLE_DECIMAL_COMMA)))
out << ',';
else
out << *p;
@ -179,8 +179,8 @@ namespace {
out << *p;
if (integer_digits > 3 && --integer_digits % 3 == 0) {
if (commodity_t::european_by_default ||
(comm && comm->has_flags(COMMODITY_STYLE_EUROPEAN)))
if (commodity_t::decimal_comma_by_default ||
(comm && comm->has_flags(COMMODITY_STYLE_DECIMAL_COMMA)))
out << '.';
else
out << ',';
@ -1031,8 +1031,9 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
bool no_more_commas = false;
bool no_more_periods = false;
bool european_style = (commodity_t::european_by_default ||
commodity().has_flags(COMMODITY_STYLE_EUROPEAN));
bool decimal_comma_style
= (commodity_t::decimal_comma_by_default ||
commodity().has_flags(COMMODITY_STYLE_DECIMAL_COMMA));
new_quantity->prec = 0;
@ -1043,16 +1044,16 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
if (no_more_periods)
throw_(amount_error, _("Too many periods in amount"));
if (european_style) {
if (decimal_comma_style) {
if (decimal_offset % 3 != 0)
throw_(amount_error, _("Incorrect use of european-style period"));
throw_(amount_error, _("Incorrect use of thousand-mark period"));
comm_flags |= COMMODITY_STYLE_THOUSANDS;
no_more_commas = true;
} else {
if (last_comma != string::npos) {
european_style = true;
decimal_comma_style = true;
if (decimal_offset % 3 != 0)
throw_(amount_error, _("Incorrect use of european-style period"));
throw_(amount_error, _("Incorrect use of thousand-mark period"));
} else {
no_more_periods = true;
new_quantity->prec = decimal_offset;
@ -1067,9 +1068,9 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
if (no_more_commas)
throw_(amount_error, _("Too many commas in amount"));
if (european_style) {
if (decimal_comma_style) {
if (last_period != string::npos) {
throw_(amount_error, _("Incorrect use of european-style comma"));
throw_(amount_error, _("Incorrect use of decimal comma"));
} else {
no_more_commas = true;
new_quantity->prec = decimal_offset;
@ -1079,9 +1080,9 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
if (decimal_offset % 3 != 0) {
if (last_comma != string::npos ||
last_period != string::npos) {
throw_(amount_error, _("Incorrect use of American-style comma"));
throw_(amount_error, _("Incorrect use of thousand-mark comma"));
} else {
european_style = true;
decimal_comma_style = true;
no_more_commas = true;
new_quantity->prec = decimal_offset;
decimal_offset = 0;
@ -1100,8 +1101,8 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
}
}
if (european_style)
comm_flags |= COMMODITY_STYLE_EUROPEAN;
if (decimal_comma_style)
comm_flags |= COMMODITY_STYLE_DECIMAL_COMMA;
if (flags.has_flags(PARSE_NO_MIGRATE)) {
// Can't call set_keep_precision here, because it assumes that `quantity'

View file

@ -38,7 +38,7 @@
namespace ledger {
bool commodity_t::european_by_default = false;
bool commodity_t::decimal_comma_by_default = false;
void commodity_t::history_t::add_price(commodity_t& source,
const datetime_t& date,
@ -666,7 +666,7 @@ void to_xml(std::ostream& out, const commodity_t& comm,
if (! (comm.has_flags(COMMODITY_STYLE_SUFFIXED))) out << 'P';
if (comm.has_flags(COMMODITY_STYLE_SEPARATED)) out << 'S';
if (comm.has_flags(COMMODITY_STYLE_THOUSANDS)) out << 'T';
if (comm.has_flags(COMMODITY_STYLE_EUROPEAN)) out << 'E';
if (comm.has_flags(COMMODITY_STYLE_DECIMAL_COMMA)) out << 'D';
out << '"';
x.close_attrs();

View file

@ -158,7 +158,7 @@ protected:
#define COMMODITY_STYLE_DEFAULTS 0x000
#define COMMODITY_STYLE_SUFFIXED 0x001
#define COMMODITY_STYLE_SEPARATED 0x002
#define COMMODITY_STYLE_EUROPEAN 0x004
#define COMMODITY_STYLE_DECIMAL_COMMA 0x004
#define COMMODITY_STYLE_THOUSANDS 0x008
#define COMMODITY_NOMARKET 0x010
#define COMMODITY_BUILTIN 0x020
@ -179,8 +179,8 @@ protected:
public:
explicit base_t(const string& _symbol)
: supports_flags<uint_least16_t>
(commodity_t::european_by_default ?
static_cast<uint_least16_t>(COMMODITY_STYLE_EUROPEAN) :
(commodity_t::decimal_comma_by_default ?
static_cast<uint_least16_t>(COMMODITY_STYLE_DECIMAL_COMMA) :
static_cast<uint_least16_t>(COMMODITY_STYLE_DEFAULTS)),
symbol(_symbol), precision(0), searched(false) {
TRACE_CTOR(base_t, "const string&");
@ -228,7 +228,7 @@ protected:
}
public:
static bool european_by_default;
static bool decimal_comma_by_default;
virtual ~commodity_t() {
TRACE_DTOR(commodity_t);

View file

@ -315,7 +315,7 @@ void export_commodity()
scope().attr("COMMODITY_STYLE_DEFAULTS") = COMMODITY_STYLE_DEFAULTS;
scope().attr("COMMODITY_STYLE_SUFFIXED") = COMMODITY_STYLE_SUFFIXED;
scope().attr("COMMODITY_STYLE_SEPARATED") = COMMODITY_STYLE_SEPARATED;
scope().attr("COMMODITY_STYLE_EUROPEAN") = COMMODITY_STYLE_EUROPEAN;
scope().attr("COMMODITY_STYLE_DECIMAL_COMMA") = COMMODITY_STYLE_DECIMAL_COMMA;
scope().attr("COMMODITY_STYLE_THOUSANDS") = COMMODITY_STYLE_THOUSANDS;
scope().attr("COMMODITY_NOMARKET") = COMMODITY_NOMARKET;
scope().attr("COMMODITY_BUILTIN") = COMMODITY_BUILTIN;
@ -334,9 +334,9 @@ void export_commodity()
.def("drop_flags", &delegates_flags<uint_least16_t>::drop_flags)
#endif
.add_static_property("european_by_default",
make_getter(&commodity_t::european_by_default),
make_setter(&commodity_t::european_by_default))
.add_static_property("decimal_comma_by_default",
make_getter(&commodity_t::decimal_comma_by_default),
make_setter(&commodity_t::decimal_comma_by_default))
.def("__str__", &commodity_t::symbol)
.def("__unicode__", py_commodity_unicode)

View file

@ -196,9 +196,7 @@ option_t<session_t> * session_t::lookup_option(const char * p)
break;
case 'd':
OPT(download); // -Q
break;
case 'e':
OPT(european);
else OPT(decimal_comma);
break;
case 'f':
OPT_(file_); // -f

View file

@ -80,7 +80,7 @@ public:
{
HANDLER(cache_).report(out);
HANDLER(download).report(out);
HANDLER(european).report(out);
HANDLER(decimal_comma).report(out);
HANDLER(file_).report(out);
HANDLER(input_date_format_).report(out);
HANDLER(master_account_).report(out);
@ -101,8 +101,8 @@ public:
OPTION(session_t, cache_);
OPTION(session_t, download); // -Q
OPTION_(session_t, european, DO() {
commodity_t::european_by_default = true;
OPTION_(session_t, decimal_comma, DO() {
commodity_t::decimal_comma_by_default = true;
});
OPTION__

View file

@ -1,4 +1,4 @@
print --european
print --decimal-comma
<<<
2008/12/31 Market
Expenses:Food ($10,00 + $2,50)

View file

@ -64,9 +64,9 @@ void AmountTestCase::testParser()
x16.parse("$2000,00");
assertEqual(string("$2.000,00"), x16.to_string());
// Since European-ness is an additive quality, we must switch back
// to American-ness manually
x15.commodity().drop_flags(COMMODITY_STYLE_EUROPEAN);
// Since use of a decimal-comma is an additive quality, we must switch back
// to decimal-period manually.
x15.commodity().drop_flags(COMMODITY_STYLE_DECIMAL_COMMA);
amount_t x17("$1,000,000.00"); // parsing this switches back to American