Skip to content

Commit

Permalink
Expose java_string_create(JNIEnv *, const char *, size_t) publicly.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox authored and gershnik committed May 3, 2024
1 parent 80600b2 commit 8528b15
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions inc/smjni/java_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace smjni
return jattach(env, ret);
}

local_java_ref<jstring> java_string_create(JNIEnv * env, const char * str, size_t size);
local_java_ref<jstring> java_string_create(JNIEnv * env, const char * str);
local_java_ref<jstring> java_string_create(JNIEnv * env, const std::string & str);

Expand Down
2 changes: 1 addition & 1 deletion src/java_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace smjni;
static thread_local std::vector<jchar> g_utf16_buffer;
static constexpr size_t g_max_buffer_size = 64 * 1024;

static local_java_ref<jstring> java_string_create(JNIEnv * env, const char * str, size_t size)
local_java_ref<jstring> 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));
Expand Down
3 changes: 3 additions & 0 deletions tests/src/cpp/string_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 8528b15

Please sign in to comment.