Skip to content

Commit 82a3f99

Browse files
authored
Merge pull request #836 from MihailRis/fixes
std::locale
2 parents df99701 + 30dc02a commit 82a3f99

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/util/stringutil.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,25 @@
77
#include <sstream>
88
#include <stdexcept>
99

10-
static std::locale locale("en_US.UTF-8");
10+
static std::locale get_utf8_locale() {
11+
std::vector<std::string> candidates = {
12+
"C.UTF-8",
13+
"en_US.UTF-8",
14+
"en_US.utf8",
15+
".UTF8",
16+
};
17+
18+
for (const auto& name : candidates) {
19+
try {
20+
return std::locale(name);
21+
} catch (const std::runtime_error&) {
22+
continue;
23+
}
24+
}
25+
return std::locale::classic();
26+
}
27+
28+
static std::locale locale = get_utf8_locale();
1129

1230
std::string util::escape(std::string_view s, bool escapeUnicode) {
1331
std::stringstream ss;

0 commit comments

Comments
 (0)