Skip to content

Commit eb80768

Browse files
SessionHero01SessionHero01
authored andcommitted
Counting codepoints in utf-16
1 parent d680da4 commit eb80768

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

library/src/main/cpp/util.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <android/log.h>
1010

11+
#include <simdutf.h>
12+
1113
#define LOG_TAG "libsession_util"
1214

1315
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
@@ -337,4 +339,12 @@ Java_network_loki_messenger_libsession_1util_util_Util_lengthForCodepoints(JNIEn
337339
max_codepoints
338340
);
339341
});
342+
}
343+
344+
extern "C"
345+
JNIEXPORT jint JNICALL
346+
Java_network_loki_messenger_libsession_1util_util_Util_countCodepoints(JNIEnv *env, jobject thiz,
347+
jstring str) {
348+
jni_utils::JavaCharsRef str_ref(env, str);
349+
return simdutf::count_utf16(reinterpret_cast<const char16_t*>(str_ref.chars()), str_ref.size());
340350
}

library/src/main/java/network/loki/messenger/libsession_util/util/Util.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ object Util : LibSessionUtilCApi() {
77

88
fun truncateCodepoints(str: String, maxCodepoints: Int): String =
99
str.take(lengthForCodepoints(str, maxCodepoints))
10+
11+
external fun countCodepoints(str: String): Int
1012
}

0 commit comments

Comments
 (0)