mirror of
https://github.com/libretro/dolphin
synced 2025-01-09 14:17:00 +00:00
f5da6e07d7
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.
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
// Copyright 2018 Dolphin Emulator Project
|
|
// Licensed under GPLv2+
|
|
// Refer to the license.txt file included.
|
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
#include <jni.h>
|
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
std::string GetJString(JNIEnv* env, jstring jstr)
|
|
{
|
|
const jchar* jchars = env->GetStringChars(jstr, nullptr);
|
|
const jsize length = env->GetStringLength(jstr);
|
|
const std::u16string_view string_view(reinterpret_cast<const char16_t*>(jchars), length);
|
|
const std::string converted_string = UTF16ToUTF8(string_view);
|
|
env->ReleaseStringChars(jstr, jchars);
|
|
return converted_string;
|
|
}
|
|
|
|
jstring ToJString(JNIEnv* env, const std::string& str)
|
|
{
|
|
const std::u16string converted_string = UTF8ToUTF16(str);
|
|
return env->NewString(reinterpret_cast<const jchar*>(converted_string.data()),
|
|
converted_string.size());
|
|
}
|
|
|
|
std::vector<std::string> JStringArrayToVector(JNIEnv* env, jobjectArray array)
|
|
{
|
|
const jsize size = env->GetArrayLength(array);
|
|
std::vector<std::string> result;
|
|
result.reserve(size);
|
|
|
|
for (jsize i = 0; i < size; ++i)
|
|
result.push_back(GetJString(env, (jstring)env->GetObjectArrayElement(array, i)));
|
|
|
|
return result;
|
|
}
|