diff options
-rw-r--r-- | src/amount.cc | 39 | ||||
-rw-r--r-- | src/commodity.cc | 10 | ||||
-rw-r--r-- | src/commodity.h | 26 | ||||
-rw-r--r-- | src/py_commodity.cc | 26 | ||||
-rw-r--r-- | src/session.cc | 4 | ||||
-rw-r--r-- | src/session.h | 6 | ||||
-rw-r--r-- | test/baseline/cmd-print.test | 2 | ||||
-rw-r--r-- | test/unit/t_amount.cc | 6 |
8 files changed, 59 insertions, 60 deletions
diff --git a/src/amount.cc b/src/amount.cc index a16d287e..13f30755 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -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,12 +1080,12 @@ 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; - no_more_commas = true; - new_quantity->prec = decimal_offset; - decimal_offset = 0; + decimal_comma_style = true; + no_more_commas = true; + new_quantity->prec = decimal_offset; + decimal_offset = 0; } } else { comm_flags |= COMMODITY_STYLE_THOUSANDS; @@ -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' diff --git a/src/commodity.cc b/src/commodity.cc index b4220354..1b85910f 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -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, @@ -663,10 +663,10 @@ void to_xml(std::ostream& out, const commodity_t& comm, push_xml x(out, "commodity", true); out << " flags=\""; - 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_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_DECIMAL_COMMA)) out << 'D'; out << '"'; x.close_attrs(); diff --git a/src/commodity.h b/src/commodity.h index 10f209fa..53e3033f 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -155,16 +155,16 @@ protected: class base_t : public noncopyable, public supports_flags<uint_least16_t> { public: -#define COMMODITY_STYLE_DEFAULTS 0x000 -#define COMMODITY_STYLE_SUFFIXED 0x001 -#define COMMODITY_STYLE_SEPARATED 0x002 -#define COMMODITY_STYLE_EUROPEAN 0x004 -#define COMMODITY_STYLE_THOUSANDS 0x008 -#define COMMODITY_NOMARKET 0x010 -#define COMMODITY_BUILTIN 0x020 -#define COMMODITY_WALKED 0x040 -#define COMMODITY_KNOWN 0x080 -#define COMMODITY_PRIMARY 0x100 +#define COMMODITY_STYLE_DEFAULTS 0x000 +#define COMMODITY_STYLE_SUFFIXED 0x001 +#define COMMODITY_STYLE_SEPARATED 0x002 +#define COMMODITY_STYLE_DECIMAL_COMMA 0x004 +#define COMMODITY_STYLE_THOUSANDS 0x008 +#define COMMODITY_NOMARKET 0x010 +#define COMMODITY_BUILTIN 0x020 +#define COMMODITY_WALKED 0x040 +#define COMMODITY_KNOWN 0x080 +#define COMMODITY_PRIMARY 0x100 string symbol; amount_t::precision_t precision; @@ -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); diff --git a/src/py_commodity.cc b/src/py_commodity.cc index d89a7151..fc7e8c3e 100644 --- a/src/py_commodity.cc +++ b/src/py_commodity.cc @@ -312,16 +312,16 @@ void export_commodity() scope().attr("commodities") = commodity_pool_t::current_pool; - 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_THOUSANDS") = COMMODITY_STYLE_THOUSANDS; - scope().attr("COMMODITY_NOMARKET") = COMMODITY_NOMARKET; - scope().attr("COMMODITY_BUILTIN") = COMMODITY_BUILTIN; - scope().attr("COMMODITY_WALKED") = COMMODITY_WALKED; - scope().attr("COMMODITY_KNOWN") = COMMODITY_KNOWN; - scope().attr("COMMODITY_PRIMARY") = COMMODITY_PRIMARY; + 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_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; + scope().attr("COMMODITY_WALKED") = COMMODITY_WALKED; + scope().attr("COMMODITY_KNOWN") = COMMODITY_KNOWN; + scope().attr("COMMODITY_PRIMARY") = COMMODITY_PRIMARY; class_< commodity_t, boost::noncopyable > ("Commodity", no_init) #if 1 @@ -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) diff --git a/src/session.cc b/src/session.cc index 8e5536b0..f8befde4 100644 --- a/src/session.cc +++ b/src/session.cc @@ -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 diff --git a/src/session.h b/src/session.h index de1771ad..10f636bb 100644 --- a/src/session.h +++ b/src/session.h @@ -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__ diff --git a/test/baseline/cmd-print.test b/test/baseline/cmd-print.test index 759a2334..6099b39f 100644 --- a/test/baseline/cmd-print.test +++ b/test/baseline/cmd-print.test @@ -1,4 +1,4 @@ -print --european +print --decimal-comma <<< 2008/12/31 Market Expenses:Food ($10,00 + $2,50) diff --git a/test/unit/t_amount.cc b/test/unit/t_amount.cc index 2c91ee98..63d82675 100644 --- a/test/unit/t_amount.cc +++ b/test/unit/t_amount.cc @@ -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 |