Part of fixing bug 1055.
Add machinery to convert hateful legacy Windows encodings to UTF-8.
This commit is contained in:
@@ -300,6 +300,40 @@ namespace simgear {
|
||||
return rslt;
|
||||
}
|
||||
|
||||
|
||||
#ifdef SG_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
std::string convertWindowsLocal8BitToUtf8(const std::string& a)
|
||||
{
|
||||
#ifdef SG_WINDOWS
|
||||
DWORD flags = 0;
|
||||
std::vector<wchar_t> wideString;
|
||||
|
||||
// call to query transform size
|
||||
int requiredWideChars = MultiByteToWideChar(CP_ACP, flags, a.c_str(), a.size(),
|
||||
NULL, 0);
|
||||
// allocate storage and call for real
|
||||
wideString.resize(requiredWideChars);
|
||||
MultiByteToWideChar(CP_ACP, flags, a.c_str(), a.size(),
|
||||
wideString.data(), wideString.size());
|
||||
|
||||
// now convert back down to UTF-8
|
||||
std::vector<char> result;
|
||||
int requiredUTF8Chars = WideCharToMultiByte(CP_UTF8, flags,
|
||||
wideString.data(), wideString.size(),
|
||||
NULL, 0, NULL, NULL);
|
||||
result.resize(requiredUTF8Chars);
|
||||
WideCharToMultiByte(CP_UTF8, flags,
|
||||
wideString.data(), wideString.size(),
|
||||
result.data(), result.size(), NULL, NULL);
|
||||
return std::string(result.data(), result.size());
|
||||
#else
|
||||
return a;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // end namespace strutils
|
||||
|
||||
} // end namespace simgear
|
||||
|
||||
@@ -149,6 +149,12 @@ namespace simgear {
|
||||
*/
|
||||
std::string uppercase(const std::string &s);
|
||||
|
||||
/**
|
||||
* convert a string in the local Windows 8-bit encoding to UTF-8
|
||||
* (no-op on other platforms)
|
||||
*/
|
||||
std::string convertWindowsLocal8BitToUtf8(const std::string& a);
|
||||
|
||||
} // end namespace strutils
|
||||
} // end namespace simgear
|
||||
|
||||
|
||||
Reference in New Issue
Block a user