Use jstring2string for more strings

This commit is contained in:
Aleksandras Kostarevas 2024-05-16 12:07:16 -05:00
parent 1eea6cb36d
commit 09a6a30d8b
2 changed files with 11 additions and 8 deletions

View File

@ -977,15 +977,14 @@ namespace latinime {
size_t inputSize = env->GetArrayLength(inComposeX);
const char* cstr = env->GetStringUTFChars(context, nullptr);
std::string contextString(cstr);
env->ReleaseStringUTFChars(context, cstr);
std::string contextString = "";
if(context != nullptr) {
contextString = jstring2string(env, context);
}
std::string partialWordString;
std::string partialWordString = "";
if(partialWord != nullptr){
const char* pwstr = env->GetStringUTFChars(partialWord, nullptr);
partialWordString = std::string(pwstr);
env->ReleaseStringUTFChars(partialWord, pwstr);
partialWordString = jstring2string(env, partialWord);
}
if(partialWordString.size() < inputSize) inputSize = partialWordString.size();

View File

@ -7,9 +7,13 @@
#include "defines.h"
std::string jstring2string(JNIEnv *env, jstring jStr) {
if(jStr == nullptr) {
AKLOGE("jstring is null!");
return "";
}
const jsize stringUtf8Length = env->GetStringUTFLength(jStr);
if (stringUtf8Length <= 0) {
AKLOGE("Can't get jStr");
return "";
}
char stringChars[stringUtf8Length + 1];