diff --git a/inc/smjni/java_string.h b/inc/smjni/java_string.h index fccba6d..4e9b177 100644 --- a/inc/smjni/java_string.h +++ b/inc/smjni/java_string.h @@ -37,6 +37,7 @@ namespace smjni return jattach(env, ret); } + local_java_ref java_string_create(JNIEnv * env, const char * str, size_t size); local_java_ref java_string_create(JNIEnv * env, const char * str); local_java_ref java_string_create(JNIEnv * env, const std::string & str); diff --git a/src/java_string.cpp b/src/java_string.cpp index 1e74a00..3bc4564 100644 --- a/src/java_string.cpp +++ b/src/java_string.cpp @@ -27,7 +27,7 @@ using namespace smjni; static thread_local std::vector g_utf16_buffer; static constexpr size_t g_max_buffer_size = 64 * 1024; -static local_java_ref java_string_create(JNIEnv * env, const char * str, size_t size) +local_java_ref smjni::java_string_create(JNIEnv * env, const char * str, size_t size) { g_utf16_buffer.clear(); utf8_to_utf16(str, str + size, std::back_inserter(g_utf16_buffer)); diff --git a/tests/src/cpp/string_tests.cpp b/tests/src/cpp/string_tests.cpp index ebc9683..01dfb65 100644 --- a/tests/src/cpp/string_tests.cpp +++ b/tests/src/cpp/string_tests.cpp @@ -36,6 +36,9 @@ TEST_CASE( "testString" ) auto str3 = java_string_create(env, std::string("hello")); CHECK(5 == java_string_get_length(env, str3)); CHECK("hello" == java_string_to_cpp(env, str3)); + auto str4 = java_string_create(env, "hello world", 5); + CHECK(5 == java_string_get_length(env, str4)); + CHECK("hello" == java_string_to_cpp(env, str4)); auto empty = java_string_create(env, nullptr); CHECK(0 == java_string_get_length(env, empty));