Skip to content

Commit 08dcfd3

Browse files
authored
Parse JVM String as utf8 (#809)
1 parent 0911b46 commit 08dcfd3

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/jni/env.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ namespace jni {
3434
return JClass(cls);
3535
}
3636

37-
JObject Env::new_string(const char* str) {
38-
auto jstr = env->NewStringUTF(str);
39-
handle_exception();
40-
return JObject(jstr);
41-
}
42-
4337
bool Env::exception_check() {
4438
return env->ExceptionCheck();
4539
}
@@ -85,10 +79,16 @@ namespace jni {
8579
return env->IsSameObject(obj_1.obj, obj_2.obj);
8680
}
8781

82+
JObject Env::new_string(const char* str) {
83+
auto jstr = env->NewStringUTF(str);
84+
handle_exception();
85+
return JObject(jstr);
86+
}
87+
8888
String Env::from_jstring(jni::JString str) {
8989
auto jstr = (jstring) str.obj;
9090
auto utfString = env->GetStringUTFChars(jstr, nullptr);
91-
auto ret = String(utfString);
91+
String ret = String::utf8(utfString);
9292
handle_exception();
9393
env->ReleaseStringUTFChars(jstr, utfString);
9494
return ret;

src/kt_variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ class BufferToVariant {
215215
} else {
216216
uint32_t size {decode_uint32(byte_buffer->get_cursor())};
217217
byte_buffer->increment_position(INT_SIZE);
218-
String str;
219-
str.parse_utf8(reinterpret_cast<const char*>(byte_buffer->get_cursor()), size);
218+
String str = String::utf8(reinterpret_cast<const char*>(byte_buffer->get_cursor()), size);
220219
byte_buffer->increment_position(size);
221220
return Variant(str);
222221
}

0 commit comments

Comments
 (0)