Changed --european option to --decimal-comma
Fixes #211 / 1736ACA5-5DE6-4826-AEB4-DB5B2A2217AC
This commit is contained in:
parent
d513c71236
commit
038c24357e
8 changed files with 59 additions and 60 deletions
|
|
@ -165,8 +165,8 @@ namespace {
|
||||||
|
|
||||||
for (const char * p = buf; *p; p++) {
|
for (const char * p = buf; *p; p++) {
|
||||||
if (*p == '.') {
|
if (*p == '.') {
|
||||||
if (commodity_t::european_by_default ||
|
if (commodity_t::decimal_comma_by_default ||
|
||||||
(comm && comm->has_flags(COMMODITY_STYLE_EUROPEAN)))
|
(comm && comm->has_flags(COMMODITY_STYLE_DECIMAL_COMMA)))
|
||||||
out << ',';
|
out << ',';
|
||||||
else
|
else
|
||||||
out << *p;
|
out << *p;
|
||||||
|
|
@ -179,8 +179,8 @@ namespace {
|
||||||
out << *p;
|
out << *p;
|
||||||
|
|
||||||
if (integer_digits > 3 && --integer_digits % 3 == 0) {
|
if (integer_digits > 3 && --integer_digits % 3 == 0) {
|
||||||
if (commodity_t::european_by_default ||
|
if (commodity_t::decimal_comma_by_default ||
|
||||||
(comm && comm->has_flags(COMMODITY_STYLE_EUROPEAN)))
|
(comm && comm->has_flags(COMMODITY_STYLE_DECIMAL_COMMA)))
|
||||||
out << '.';
|
out << '.';
|
||||||
else
|
else
|
||||||
out << ',';
|
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_commas = false;
|
||||||
bool no_more_periods = false;
|
bool no_more_periods = false;
|
||||||
bool european_style = (commodity_t::european_by_default ||
|
bool decimal_comma_style
|
||||||
commodity().has_flags(COMMODITY_STYLE_EUROPEAN));
|
= (commodity_t::decimal_comma_by_default ||
|
||||||
|
commodity().has_flags(COMMODITY_STYLE_DECIMAL_COMMA));
|
||||||
|
|
||||||
new_quantity->prec = 0;
|
new_quantity->prec = 0;
|
||||||
|
|
||||||
|
|
@ -1043,16 +1044,16 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
|
||||||
if (no_more_periods)
|
if (no_more_periods)
|
||||||
throw_(amount_error, _("Too many periods in amount"));
|
throw_(amount_error, _("Too many periods in amount"));
|
||||||
|
|
||||||
if (european_style) {
|
if (decimal_comma_style) {
|
||||||
if (decimal_offset % 3 != 0)
|
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;
|
comm_flags |= COMMODITY_STYLE_THOUSANDS;
|
||||||
no_more_commas = true;
|
no_more_commas = true;
|
||||||
} else {
|
} else {
|
||||||
if (last_comma != string::npos) {
|
if (last_comma != string::npos) {
|
||||||
european_style = true;
|
decimal_comma_style = true;
|
||||||
if (decimal_offset % 3 != 0)
|
if (decimal_offset % 3 != 0)
|
||||||
throw_(amount_error, _("Incorrect use of european-style period"));
|
throw_(amount_error, _("Incorrect use of thousand-mark period"));
|
||||||
} else {
|
} else {
|
||||||
no_more_periods = true;
|
no_more_periods = true;
|
||||||
new_quantity->prec = decimal_offset;
|
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)
|
if (no_more_commas)
|
||||||
throw_(amount_error, _("Too many commas in amount"));
|
throw_(amount_error, _("Too many commas in amount"));
|
||||||
|
|
||||||
if (european_style) {
|
if (decimal_comma_style) {
|
||||||
if (last_period != string::npos) {
|
if (last_period != string::npos) {
|
||||||
throw_(amount_error, _("Incorrect use of european-style comma"));
|
throw_(amount_error, _("Incorrect use of decimal comma"));
|
||||||
} else {
|
} else {
|
||||||
no_more_commas = true;
|
no_more_commas = true;
|
||||||
new_quantity->prec = decimal_offset;
|
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 (decimal_offset % 3 != 0) {
|
||||||
if (last_comma != string::npos ||
|
if (last_comma != string::npos ||
|
||||||
last_period != 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 {
|
} else {
|
||||||
european_style = true;
|
decimal_comma_style = true;
|
||||||
no_more_commas = true;
|
no_more_commas = true;
|
||||||
new_quantity->prec = decimal_offset;
|
new_quantity->prec = decimal_offset;
|
||||||
decimal_offset = 0;
|
decimal_offset = 0;
|
||||||
|
|
@ -1100,8 +1101,8 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (european_style)
|
if (decimal_comma_style)
|
||||||
comm_flags |= COMMODITY_STYLE_EUROPEAN;
|
comm_flags |= COMMODITY_STYLE_DECIMAL_COMMA;
|
||||||
|
|
||||||
if (flags.has_flags(PARSE_NO_MIGRATE)) {
|
if (flags.has_flags(PARSE_NO_MIGRATE)) {
|
||||||
// Can't call set_keep_precision here, because it assumes that `quantity'
|
// Can't call set_keep_precision here, because it assumes that `quantity'
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
namespace ledger {
|
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,
|
void commodity_t::history_t::add_price(commodity_t& source,
|
||||||
const datetime_t& date,
|
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_SUFFIXED))) out << 'P';
|
||||||
if (comm.has_flags(COMMODITY_STYLE_SEPARATED)) out << 'S';
|
if (comm.has_flags(COMMODITY_STYLE_SEPARATED)) out << 'S';
|
||||||
if (comm.has_flags(COMMODITY_STYLE_THOUSANDS)) out << 'T';
|
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 << '"';
|
out << '"';
|
||||||
|
|
||||||
x.close_attrs();
|
x.close_attrs();
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ protected:
|
||||||
#define COMMODITY_STYLE_DEFAULTS 0x000
|
#define COMMODITY_STYLE_DEFAULTS 0x000
|
||||||
#define COMMODITY_STYLE_SUFFIXED 0x001
|
#define COMMODITY_STYLE_SUFFIXED 0x001
|
||||||
#define COMMODITY_STYLE_SEPARATED 0x002
|
#define COMMODITY_STYLE_SEPARATED 0x002
|
||||||
#define COMMODITY_STYLE_EUROPEAN 0x004
|
#define COMMODITY_STYLE_DECIMAL_COMMA 0x004
|
||||||
#define COMMODITY_STYLE_THOUSANDS 0x008
|
#define COMMODITY_STYLE_THOUSANDS 0x008
|
||||||
#define COMMODITY_NOMARKET 0x010
|
#define COMMODITY_NOMARKET 0x010
|
||||||
#define COMMODITY_BUILTIN 0x020
|
#define COMMODITY_BUILTIN 0x020
|
||||||
|
|
@ -179,8 +179,8 @@ protected:
|
||||||
public:
|
public:
|
||||||
explicit base_t(const string& _symbol)
|
explicit base_t(const string& _symbol)
|
||||||
: supports_flags<uint_least16_t>
|
: supports_flags<uint_least16_t>
|
||||||
(commodity_t::european_by_default ?
|
(commodity_t::decimal_comma_by_default ?
|
||||||
static_cast<uint_least16_t>(COMMODITY_STYLE_EUROPEAN) :
|
static_cast<uint_least16_t>(COMMODITY_STYLE_DECIMAL_COMMA) :
|
||||||
static_cast<uint_least16_t>(COMMODITY_STYLE_DEFAULTS)),
|
static_cast<uint_least16_t>(COMMODITY_STYLE_DEFAULTS)),
|
||||||
symbol(_symbol), precision(0), searched(false) {
|
symbol(_symbol), precision(0), searched(false) {
|
||||||
TRACE_CTOR(base_t, "const string&");
|
TRACE_CTOR(base_t, "const string&");
|
||||||
|
|
@ -228,7 +228,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool european_by_default;
|
static bool decimal_comma_by_default;
|
||||||
|
|
||||||
virtual ~commodity_t() {
|
virtual ~commodity_t() {
|
||||||
TRACE_DTOR(commodity_t);
|
TRACE_DTOR(commodity_t);
|
||||||
|
|
|
||||||
|
|
@ -315,7 +315,7 @@ void export_commodity()
|
||||||
scope().attr("COMMODITY_STYLE_DEFAULTS") = COMMODITY_STYLE_DEFAULTS;
|
scope().attr("COMMODITY_STYLE_DEFAULTS") = COMMODITY_STYLE_DEFAULTS;
|
||||||
scope().attr("COMMODITY_STYLE_SUFFIXED") = COMMODITY_STYLE_SUFFIXED;
|
scope().attr("COMMODITY_STYLE_SUFFIXED") = COMMODITY_STYLE_SUFFIXED;
|
||||||
scope().attr("COMMODITY_STYLE_SEPARATED") = COMMODITY_STYLE_SEPARATED;
|
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_STYLE_THOUSANDS") = COMMODITY_STYLE_THOUSANDS;
|
||||||
scope().attr("COMMODITY_NOMARKET") = COMMODITY_NOMARKET;
|
scope().attr("COMMODITY_NOMARKET") = COMMODITY_NOMARKET;
|
||||||
scope().attr("COMMODITY_BUILTIN") = COMMODITY_BUILTIN;
|
scope().attr("COMMODITY_BUILTIN") = COMMODITY_BUILTIN;
|
||||||
|
|
@ -334,9 +334,9 @@ void export_commodity()
|
||||||
.def("drop_flags", &delegates_flags<uint_least16_t>::drop_flags)
|
.def("drop_flags", &delegates_flags<uint_least16_t>::drop_flags)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
.add_static_property("european_by_default",
|
.add_static_property("decimal_comma_by_default",
|
||||||
make_getter(&commodity_t::european_by_default),
|
make_getter(&commodity_t::decimal_comma_by_default),
|
||||||
make_setter(&commodity_t::european_by_default))
|
make_setter(&commodity_t::decimal_comma_by_default))
|
||||||
|
|
||||||
.def("__str__", &commodity_t::symbol)
|
.def("__str__", &commodity_t::symbol)
|
||||||
.def("__unicode__", py_commodity_unicode)
|
.def("__unicode__", py_commodity_unicode)
|
||||||
|
|
|
||||||
|
|
@ -196,9 +196,7 @@ option_t<session_t> * session_t::lookup_option(const char * p)
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
OPT(download); // -Q
|
OPT(download); // -Q
|
||||||
break;
|
else OPT(decimal_comma);
|
||||||
case 'e':
|
|
||||||
OPT(european);
|
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
OPT_(file_); // -f
|
OPT_(file_); // -f
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ public:
|
||||||
{
|
{
|
||||||
HANDLER(cache_).report(out);
|
HANDLER(cache_).report(out);
|
||||||
HANDLER(download).report(out);
|
HANDLER(download).report(out);
|
||||||
HANDLER(european).report(out);
|
HANDLER(decimal_comma).report(out);
|
||||||
HANDLER(file_).report(out);
|
HANDLER(file_).report(out);
|
||||||
HANDLER(input_date_format_).report(out);
|
HANDLER(input_date_format_).report(out);
|
||||||
HANDLER(master_account_).report(out);
|
HANDLER(master_account_).report(out);
|
||||||
|
|
@ -101,8 +101,8 @@ public:
|
||||||
OPTION(session_t, cache_);
|
OPTION(session_t, cache_);
|
||||||
OPTION(session_t, download); // -Q
|
OPTION(session_t, download); // -Q
|
||||||
|
|
||||||
OPTION_(session_t, european, DO() {
|
OPTION_(session_t, decimal_comma, DO() {
|
||||||
commodity_t::european_by_default = true;
|
commodity_t::decimal_comma_by_default = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
OPTION__
|
OPTION__
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
print --european
|
print --decimal-comma
|
||||||
<<<
|
<<<
|
||||||
2008/12/31 Market
|
2008/12/31 Market
|
||||||
Expenses:Food ($10,00 + $2,50)
|
Expenses:Food ($10,00 + $2,50)
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,9 @@ void AmountTestCase::testParser()
|
||||||
x16.parse("$2000,00");
|
x16.parse("$2000,00");
|
||||||
assertEqual(string("$2.000,00"), x16.to_string());
|
assertEqual(string("$2.000,00"), x16.to_string());
|
||||||
|
|
||||||
// Since European-ness is an additive quality, we must switch back
|
// Since use of a decimal-comma is an additive quality, we must switch back
|
||||||
// to American-ness manually
|
// to decimal-period manually.
|
||||||
x15.commodity().drop_flags(COMMODITY_STYLE_EUROPEAN);
|
x15.commodity().drop_flags(COMMODITY_STYLE_DECIMAL_COMMA);
|
||||||
|
|
||||||
amount_t x17("$1,000,000.00"); // parsing this switches back to American
|
amount_t x17("$1,000,000.00"); // parsing this switches back to American
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue