1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
From 59a04cb70b261ad77baf671d5059a836ba339bbd Mon Sep 17 00:00:00 2001
From: Stephan Bergmann <sbergman@redhat.com>
Date: Tue, 30 Oct 2018 13:51:02 +0100
Subject: [PATCH] Don't depend on en_US.UTF-8 locale
Instead, create locale with codecvt_utf8 facet on all platforms (even if
codecvt_utf8 is deprecated since C++17). There is no guarantee that
"en_US.UTF-8" is a supported locale name, so the locale constructor might throw
a runtime_error. (See the discussion in the comments to
<https://gerrit.libreoffice.org/#/c/62508/> "Add check for en_US.utf8 locale"
for a real-live example of issues caused by that.)
(And the <codecvt> and <locale> headers apparently need to be included always,
regardless of NUMBERTEXT_BOOST.)
---
src/Numbertext.cxx | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/Numbertext.cxx b/src/Numbertext.cxx
index 8cf5198..5f05b48 100644
--- a/src/Numbertext.cxx
+++ b/src/Numbertext.cxx
@@ -2,6 +2,8 @@
* 2018 (c) László Németh
* License: LGPL/BSD dual license */
+#include <codecvt>
+#include <locale>
#include <sstream>
#include <fstream>
@@ -11,8 +13,6 @@
#include <boost/locale/encoding_utf.hpp>
using namespace boost;
#else
- #include <codecvt>
- #include <locale>
using namespace std;
#endif
@@ -25,11 +25,7 @@ bool readfile(const std::string& filename, std::wstring& result)
std::wifstream wif(filename);
if (wif.fail())
return false;
-#ifdef _MSC_VER
wif.imbue(std::locale(std::locale(), new std::codecvt_utf8<wchar_t>));
-#else
- wif.imbue(std::locale("en_US.UTF-8"));
-#endif
std::wstringstream wss;
wss << wif.rdbuf();
result = wss.str();
--
2.19.1
|