Skip to content

Commit 98265a5

Browse files
committed
Correct parsing for non-default locales
1 parent 2bcf48a commit 98265a5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

include/decimal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ decimal<Prec, RoundPolicy> decimal_cast(const char (&arg)[N]) {
16611661
};
16621662

16631663
template<typename StreamType>
1664-
basic_decimal_format format_from_stream(StreamType &stream) {
1664+
decimal_format format_from_stream(StreamType &stream) {
16651665
using namespace std;
16661666
const numpunct<char> *facet =
16671667
has_facet<numpunct<char> >(stream.getloc()) ?

tests/decimalTestString.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,21 @@ BOOST_AUTO_TEST_CASE(decimalFromStringWithFormat) {
9191
BOOST_CHECK_EQUAL(d2a, d2b);
9292
}
9393

94+
struct italiano_separators : std::numpunct<char> {
95+
char do_thousands_sep() const { return '.'; } // separate with dot
96+
std::string do_grouping() const { return "\3"; } // groups of 3 digits
97+
char do_decimal_point() const { return ','; } // separate with comma
98+
};
99+
100+
BOOST_AUTO_TEST_CASE(decimalItalianoParsing) {
101+
std::locale new_locale(std::cout.getloc(), new italiano_separators);
102+
std::locale prior_locale = std::locale::global(new_locale);
103+
std::stringstream ss("1.234,56");
104+
dec::decimal<2> ret;
105+
dec::fromStream(ss, ret);
106+
std::locale::global(prior_locale);
107+
dec::DEC_INT64 beforeValue, afterValue;
108+
ret.unpack(beforeValue, afterValue);
109+
BOOST_CHECK_EQUAL(beforeValue, 1234);
110+
BOOST_CHECK_EQUAL(afterValue, 56);
111+
}

0 commit comments

Comments
 (0)