summaryrefslogtreecommitdiff
path: root/Source/Core/Common/StringUtil.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2020-06-28 19:16:23 +0200
committerJosJuice <josjuice@gmail.com>2020-07-08 14:52:05 +0200
commitf5da6e07d7405d89cc550b8c02f39a432f7888a3 (patch)
tree1d369c87fa5c4cb8116c87baf5e3e8a6e267623a /Source/Core/Common/StringUtil.cpp
parent38791eec1879b0a66d6ae920cfd6b42d9ae66dee (diff)
Android: Use correct encoding when converting strings
The functions with "UTF" in the name use "modified UTF-8" rather than the standard UTF-8 which Dolphin uses, at least according to Oracle's documentation, so it is incorrect for us to use them. This change fixes the problem by converting between UTF-8 and UTF-16 manually instead of letting JNI do it for us.
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
-rw-r--r--Source/Core/Common/StringUtil.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp
index e3c6f692f6..6c236de587 100644
--- a/Source/Core/Common/StringUtil.cpp
+++ b/Source/Core/Common/StringUtil.cpp
@@ -5,6 +5,7 @@
#include "Common/StringUtil.h"
#include <algorithm>
+#include <codecvt>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
@@ -33,7 +34,6 @@
constexpr u32 CODEPAGE_SHIFT_JIS = 932;
constexpr u32 CODEPAGE_WINDOWS_1252 = 1252;
#else
-#include <codecvt>
#include <errno.h>
#include <iconv.h>
#include <locale.h>
@@ -590,6 +590,18 @@ std::string UTF16BEToUTF8(const char16_t* str, size_t max_size)
#endif
+std::string UTF16ToUTF8(std::u16string_view input)
+{
+ std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
+ return converter.to_bytes(input.data(), input.data() + input.size());
+}
+
+std::u16string UTF8ToUTF16(std::string_view input)
+{
+ std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
+ return converter.from_bytes(input.data(), input.data() + input.size());
+}
+
#ifdef HAS_STD_FILESYSTEM
// This is a replacement for path::u8path, which is deprecated starting with C++20.
std::filesystem::path StringToPath(std::string_view path)