Skip to content

Commit d8f82b6

Browse files
committed
Use facets so locale change doesn't affect numbers
1 parent 29f5647 commit d8f82b6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/suggest.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "suggest.hpp"
19+
#include <locale>
1920

2021
namespace divvun {
2122

@@ -1099,7 +1100,10 @@ void Suggest::mk_errs(Sentence& sentence) {
10991100
vector<Err> Suggest::run_errs(std::istream& is) {
11001101
std::locale old_locale = std::locale();
11011102
try {
1102-
old_locale = std::locale::global(std::locale("")); // Would prefer C.UTF-8, but that doesn't always exist
1103+
// Use environment locale (we expect some UTF-8 locale) for toUpper/toLower etc.
1104+
// but C for numbers (to avoid any comma-as-decimal-separator nonsense)
1105+
std::locale mixed(std::locale(""), std::locale::classic(), std::locale::numeric);
1106+
old_locale = std::locale::global(mixed);
11031107
}
11041108
catch (const std::runtime_error& e) {
11051109
std::cerr
@@ -1226,7 +1230,10 @@ RunState Suggest::run_cg(std::istream& is, std::ostream& os) {
12261230
void Suggest::run(std::istream& is, std::ostream& os, RunMode mode) {
12271231
std::locale old_locale = std::locale();
12281232
try {
1229-
old_locale = std::locale::global(std::locale("")); // Would prefer C.UTF-8, but that doesn't always exist
1233+
// Use environment locale (we expect some UTF-8 locale) for toUpper/toLower etc.
1234+
// but C for numbers (to avoid any comma-as-decimal-separator nonsense)
1235+
std::locale mixed(std::locale(""), std::locale::classic(), std::locale::numeric);
1236+
old_locale = std::locale::global(mixed);
12301237
}
12311238
catch (const std::runtime_error& e) {
12321239
std::cerr

0 commit comments

Comments
 (0)