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
16 #include "Numbertext.hxx"
18 #ifdef NUMBERTEXT_BOOST
21 bool readfile(const std::string& filename, std::wstring& result)
24 + std::ifstream ifs(filename);
27 + std::stringstream ss;
29 + result = Numbertext::string2wstring(ss.str());
31 std::wifstream wif(filename);
34 @@ -29,6 +44,7 @@ bool readfile(const std::string& filename, std::wstring& result)
35 std::wstringstream wss;
44 std::wstring Numbertext::string2wstring(const std::string& s)
46 -#ifndef NUMBERTEXT_BOOST
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);
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 );
58 std::string Numbertext::wstring2string(const std::wstring& s)
60 -#ifndef NUMBERTEXT_BOOST
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);
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 );