替代StringToJavaString函数,解决jni里string乱码的问题
| 436 | |
| 437 | // 替代StringToJavaString函数,解决jni里string乱码的问题 |
| 438 | jstring jniStringFromUTF8(JNIEnv * env, const std::string & str) { |
| 439 | std::u16string utf16; |
| 440 | utf16.reserve(str.length()); // likely overallocate |
| 441 | for (std::string::size_type i = 0; i < str.length(); ) |
| 442 | utf16_encode(utf8_decode(str, i), utf16); |
| 443 | |
| 444 | jstring res = env->NewString( |
| 445 | reinterpret_cast<const jchar *>(utf16.data()), jsize(utf16.length())); |
| 446 | return res; |
| 447 | } |
| 448 | |
| 449 | /* |
| 450 | std::string GetJavaExceptionInfo(JNIEnv *env, jthrowable java_throwable) |
nothing calls this directly
no test coverage detected