tdf#153972 Fix color filter when cells have no content
[LibreOffice.git] / external / libnumbertext / MSVCNonBMPBug.patch1
blob8ced22165bcc37d72772453bb05840f77d75cca7
1 MSVC's std::codecvt_utf8 has a bug converting non-BMP codepoints like U+10CFA.
2 Use MultiByteToWideChar/WideCharToMultiByte instead on Windows.
4 diff --git a/src/Numbertext.cxx b/src/Numbertext.cxx
5 index 5f05b48579af..eb83e59f366f 100755
6 --- a/src/Numbertext.cxx
7 +++ b/src/Numbertext.cxx
8 @@ -7,6 +7,10 @@
9  #include <sstream>
10  #include <fstream>
12 +#ifdef _WIN32
13 +#include <Windows.h>
14 +#endif
16  #include "Numbertext.hxx"
18  #ifdef NUMBERTEXT_BOOST
19 @@ -22,6 +26,14 @@
21  bool readfile(const std::string& filename, std::wstring& result)
22  {
23 +#ifdef _WIN32
24 +    std::ifstream ifs(filename);
25 +    if (ifs.fail())
26 +        return false;
27 +    std::stringstream ss;
28 +    ss << ifs.rdbuf();
29 +    result = Numbertext::string2wstring(ss.str());
30 +#else
31      std::wifstream wif(filename);
32      if (wif.fail())
33          return false;
34 @@ -29,6 +44,7 @@ bool readfile(const std::string& filename, std::wstring& result)
35      std::wstringstream wss;
36      wss << wif.rdbuf();
37      result = wss.str();
38 +#endif
39      return true;
40  }
42 @@ -99,7 +112,12 @@
44  std::wstring Numbertext::string2wstring(const std::string& s)
45  {
46 -#ifndef NUMBERTEXT_BOOST
47 +#ifdef _WIN32
48 +    int nSize = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0);
49 +    std::unique_ptr<wchar_t[]> wstr(new wchar_t[nSize]);
50 +    MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, wstr.get(), nSize);
51 +    return wstr.get();
52 +#elif !defined NUMBERTEXT_BOOST
53      typedef std::codecvt_utf8<wchar_t> convert_type;
54      std::wstring_convert<convert_type, wchar_t> converter;
55      return converter.from_bytes( s );
56 @@ -110,7 +128,12 @@
58  std::string Numbertext::wstring2string(const std::wstring& s)
59  {
60 -#ifndef NUMBERTEXT_BOOST
61 +#ifdef _WIN32
62 +    int nSize = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, nullptr, 0, nullptr, nullptr);
63 +    std::unique_ptr<char[]> str(new char[nSize]);
64 +    WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, str.get(), nSize, nullptr, nullptr);
65 +    return str.get();
66 +#elif !defined NUMBERTEXT_BOOST
67      typedef std::codecvt_utf8<wchar_t> convert_type;
68      std::wstring_convert<convert_type, wchar_t> converter;
69      return converter.to_bytes( s );