File: MSVCNonBMPBug.patch

package info (click to toggle)
libreoffice 4%3A26.2.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,838,464 kB
  • sloc: cpp: 4,398,766; xml: 499,253; java: 254,438; python: 81,885; ansic: 33,826; perl: 30,297; javascript: 19,722; sh: 12,042; makefile: 10,848; cs: 8,865; yacc: 8,549; objc: 2,131; lex: 1,385; asm: 1,231; awk: 996; pascal: 914; csh: 20; sed: 5
file content (69 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download | duplicates (11)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
MSVC's std::codecvt_utf8 has a bug converting non-BMP codepoints like U+10CFA.
Use MultiByteToWideChar/WideCharToMultiByte instead on Windows.

diff --git a/src/Numbertext.cxx b/src/Numbertext.cxx
index 5f05b48579af..eb83e59f366f 100755
--- a/src/Numbertext.cxx
+++ b/src/Numbertext.cxx
@@ -7,6 +7,10 @@
 #include <sstream>
 #include <fstream>
 
+#ifdef _WIN32
+#include <Windows.h>
+#endif
+
 #include "Numbertext.hxx"
 
 #ifdef NUMBERTEXT_BOOST
@@ -22,6 +26,14 @@
 
 bool readfile(const std::string& filename, std::wstring& result)
 {
+#ifdef _WIN32
+    std::ifstream ifs(filename);
+    if (ifs.fail())
+        return false;
+    std::stringstream ss;
+    ss << ifs.rdbuf();
+    result = Numbertext::string2wstring(ss.str());
+#else
     std::wifstream wif(filename);
     if (wif.fail())
         return false;
@@ -29,6 +44,7 @@ bool readfile(const std::string& filename, std::wstring& result)
     std::wstringstream wss;
     wss << wif.rdbuf();
     result = wss.str();
+#endif
     return true;
 }
 
@@ -99,7 +112,12 @@
 
 std::wstring Numbertext::string2wstring(const std::string& s)
 {
-#ifndef NUMBERTEXT_BOOST
+#ifdef _WIN32
+    int nSize = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0);
+    std::unique_ptr<wchar_t[]> wstr(new wchar_t[nSize]);
+    MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, wstr.get(), nSize);
+    return wstr.get();
+#elif !defined NUMBERTEXT_BOOST
     typedef std::codecvt_utf8<wchar_t> convert_type;
     std::wstring_convert<convert_type, wchar_t> converter;
     return converter.from_bytes( s );
@@ -110,7 +128,12 @@
 
 std::string Numbertext::wstring2string(const std::wstring& s)
 {
-#ifndef NUMBERTEXT_BOOST
+#ifdef _WIN32
+    int nSize = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, nullptr, 0, nullptr, nullptr);
+    std::unique_ptr<char[]> str(new char[nSize]);
+    WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, str.get(), nSize, nullptr, nullptr);
+    return str.get();
+#elif !defined NUMBERTEXT_BOOST
     typedef std::codecvt_utf8<wchar_t> convert_type;
     std::wstring_convert<convert_type, wchar_t> converter;
     return converter.to_bytes( s );