MCPcopy Create free account
hub / github.com/Snapchat/Valdi / newJavaStringUTF8

Function newJavaStringUTF8

valdi_core/src/valdi_core/jni/JavaUtils.cpp:292–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290 switch (str.encoding()) {
291 case Valdi::StaticString::Encoding::UTF8:
292 return newJavaStringUTF8(str.utf8StringView());
293 case Valdi::StaticString::Encoding::UTF16:
294 return newJavaStringUTF16(str.utf16StringView());
295 case Valdi::StaticString::Encoding::UTF32: {
296 auto storage = str.utf16Storage();
297 return newJavaStringUTF16(storage.toStringView());
298 }
299 }
300}
301
302djinni::LocalRef<jstring> newJavaStringUTF8(const std::string_view& str) {
303 size_t length;
304 auto modifiedLength = facebook::jni::detail::modifiedLength(reinterpret_cast<const uint8_t*>(str.data()), &length);
305
306 if (modifiedLength == str.size()) {
307 return JavaEnv::accessEnvRetRef([&](JNIEnv& env) { return env.NewStringUTF(str.data()); });
308 } else {
309 Valdi::SmallVector<uint8_t, 128> buffer;
310 // Need additional byte for \0 at the end
311 buffer.resize(modifiedLength + 1);
312

Callers 4

toJavaObjectFunction · 0.85
newJavaStringFunction · 0.85
getModuleEntryMethod · 0.85
newStringUTF8Method · 0.85

Calls 5

modifiedLengthFunction · 0.85
utf8ToModifiedUTF8Function · 0.85
dataMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected