Skip to content

Commit ff9ff7d

Browse files
committed
Convert converion to c locale to use C++ locale or C global
1 parent a5ee370 commit ff9ff7d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

include/boost/decimal/detail/io.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ auto operator>>(std::basic_istream<charT, traits>& is, DecimalType& d)
7979
std::memcpy(buffer, t_buffer.c_str(), t_buffer.size());
8080
}
8181

82-
detail::convert_string_to_c_locale(buffer);
82+
detail::convert_string_to_c_locale(buffer, is.getloc());
8383

8484
auto fmt {chars_format::general};
8585
const auto flags {is.flags()};

include/boost/decimal/detail/locale_conversion.hpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ namespace boost {
1515
namespace decimal {
1616
namespace detail {
1717

18-
inline void convert_string_to_c_locale(char* buffer) noexcept
18+
inline void convert_string_to_c_locale(char* buffer, const std::locale& loc) noexcept
1919
{
20-
const auto* lconv {std::localeconv()};
21-
const auto locale_decimal_point {*lconv->decimal_point};
22-
auto locale_thousands_sep {*lconv->thousands_sep};
20+
const std::numpunct<char>& np = std::use_facet<std::numpunct<char>>(loc);
21+
22+
const auto locale_decimal_point {np.decimal_point()};
23+
auto locale_thousands_sep {np.thousands_sep()};
2324
if (locale_thousands_sep == -30)
2425
{
25-
// Locales like french use a space, but thousands_sep does not give a space character
2626
locale_thousands_sep = ' ';
2727
}
28-
const bool has_grouping {lconv->grouping && lconv->grouping[0] > 0};
28+
const bool has_grouping {!np.grouping().empty() && np.grouping()[0] > 0};
29+
const int grouping_size {has_grouping ? np.grouping()[0] : 0};
2930

3031
// Remove thousands separator if it exists and grouping is enabled
3132
if (has_grouping && locale_thousands_sep != '\0')
@@ -73,6 +74,11 @@ inline void convert_string_to_c_locale(char* buffer) noexcept
7374
}
7475
}
7576

77+
inline void convert_string_to_c_locale(char* buffer) noexcept
78+
{
79+
convert_string_to_c_locale(buffer, std::locale());
80+
}
81+
7682
inline int convert_pointer_pair_to_local_locale(char* first, char* last, const std::locale& loc) noexcept
7783
{
7884
const std::numpunct<char>& np = std::use_facet<std::numpunct<char>>(loc);

0 commit comments

Comments
 (0)