java/String: add static method Optional()
This commit is contained in:
parent
b90e32fe4e
commit
1aa3c1e543
@ -89,6 +89,16 @@ public:
|
||||
String(JNIEnv *_env, const char *_value) noexcept
|
||||
:LocalRef<jstring>(_env, _env->NewStringUTF(_value)) {}
|
||||
|
||||
/**
|
||||
* This constructor allows passing a nullptr value, which maps
|
||||
* to a "null" in Java.
|
||||
*/
|
||||
static String Optional(JNIEnv *_env, const char *_value) noexcept {
|
||||
return _value != nullptr
|
||||
? String{_env, _value}
|
||||
: String{};
|
||||
}
|
||||
|
||||
static StringUTFChars GetUTFChars(JNIEnv *env, jstring s) noexcept {
|
||||
return {env, s, env->GetStringUTFChars(s, nullptr)};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user