std::string/wstring conversion: use correct functions wrt. wchar_t size

On Windows `wchar_t` is only two bytes long, not four; meaning
`std::wstring` are actually UTF-16 encoded.

Part of the fix of #2516.
parent 82b8b1ba
......@@ -12,6 +12,7 @@
## Bug fixes
* all: fixed handling of Unicode code points > U+FFFF. Fixes #2516.
* MKVToolNix GUI: the portable mode wasn't detected correctly when the current
working directory the GUI was started from wasn't the directory the GUI's
executable file was located it. Examples for when this is the case are
......
......@@ -49,7 +49,10 @@ std::wstring
to_wide(const std::string &source) {
std::wstring destination;
::utf8::utf8to32(source.begin(), source.end(), back_inserter(destination));
if (4 == sizeof(wchar_t))
::utf8::utf8to32(source.begin(), source.end(), back_inserter(destination));
else
::utf8::utf8to16(source.begin(), source.end(), back_inserter(destination));
return destination;
}
......@@ -58,7 +61,10 @@ std::string
to_utf8(const std::wstring &source) {
std::string destination;
::utf8::utf32to8(source.begin(), source.end(), back_inserter(destination));
if (4 == sizeof(wchar_t))
::utf8::utf32to8(source.begin(), source.end(), back_inserter(destination));
else
::utf8::utf16to8(source.begin(), source.end(), back_inserter(destination));
return destination;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment