aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-07-31 23:05:01 +0200
committerFilippos Karapetis2019-08-24 18:12:45 +0300
commit93c6b2fafc69d14436cfcc537989aa44430f040a (patch)
tree73434ebc45ce519bc007840afedf56ce04797cc6 /backends/platform
parent613613568cbeee923a23400716c743be01d3906e (diff)
downloadscummvm-rg350-93c6b2fafc69d14436cfcc537989aa44430f040a.tar.gz
scummvm-rg350-93c6b2fafc69d14436cfcc537989aa44430f040a.tar.bz2
scummvm-rg350-93c6b2fafc69d14436cfcc537989aa44430f040a.zip
WIN32: Implement conversion to and from UTF-32
UTF-32 is used in transliteration in Common::Encoding, so it is pretty important encoding and Windows should be the only thing, that cannot convert it.
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/sdl/win32/win32.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index f2447b2638..e1f7964ab3 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -51,6 +51,8 @@
#include "backends/dialogs/win32/win32-dialogs.h"
#include "common/memstream.h"
+#include "common/ustr.h"
+#include "common/encoding.h"
#define DEFAULT_CONFIG_FILE "scummvm.ini"
@@ -389,8 +391,22 @@ char *OSystem_Win32::convertEncoding(const char* to, const char *from, const cha
char *result = OSystem_SDL::convertEncoding(to, from, string, length);
if (result != nullptr)
return result;
- if (Common::String(from).equalsIgnoreCase("utf-32"))
- return nullptr;
+
+ // UTF-32 is really important for us, because it is used for the
+ // transliteration in Common::Encoding and Win32 cannot convert it
+ if (Common::String(from).hasPrefixIgnoreCase("utf-32")) {
+ Common::U32String UTF32Str((const uint32 *)string, length / 4);
+ Common::String UTF8Str = Common::convertUtf32ToUtf8(UTF32Str);
+ return Common::Encoding::convert(to, "utf-8", UTF8Str.c_str(), UTF8Str.size());
+ }
+ if (Common::String(to).hasPrefixIgnoreCase("utf-32")) {
+ char *UTF8Str = Common::Encoding::convert("utf-8", from, string, length);
+ Common::U32String UTF32Str = Common::convertUtf8ToUtf32(UTF8Str);
+ free(UTF8Str);
+ result = (char *) malloc((UTF32Str.size() + 1) * 4);
+ memcpy(result, UTF32Str.c_str(), (UTF32Str.size() + 1) * 4);
+ return result;
+ }
WCHAR *tmpStr;
if (Common::String(from).equalsIgnoreCase("utf-16")) {
@@ -408,7 +424,7 @@ char *OSystem_Win32::convertEncoding(const char* to, const char *from, const cha
if (Common::String(to).equalsIgnoreCase("utf-16"))
return (char *) tmpStr;
else {
- char *result = Win32::unicodeToAnsi(tmpStr, Win32::getCodePageId(to));
+ result = Win32::unicodeToAnsi(tmpStr, Win32::getCodePageId(to));
free(tmpStr);
return result;
}