java :: JavaString
java.lang.String
Converted to a Nit string using to_s
, or to a C string with to_cstring
.
Created using String::to_java_string
or CString::to_java_string
.
java :: JavaString :: defaultinit
java :: JavaString :: to_cstring
Get the string from Java and copy it to Nit memoryjava $ JavaString :: SELF
Type of this instance, automatically specialized in every classcore :: Pointer :: address_is_null
Is the address behind this Object at NULL?core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Pointer :: defaultinit
core :: Object :: defaultinit
java :: JavaString :: defaultinit
jvm :: JavaObject :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
jvm :: JavaObject :: new_global_ref
Returns a global reference to the Java object behind this referencecore :: Object :: output_class_name
Display class name on stdout (debug only).jvm :: JavaObject :: pop_from_local_frame
Pops the current local reference frame and return a valid reference to selfjvm :: JavaObject :: pop_from_local_frame_with_env
Java implementation ofpop_from_local_frame
java :: JavaString :: to_cstring
Get the string from Java and copy it to Nit memoryjvm :: JavaObject :: to_java_string
JavaString
representation of self
using Java's toString
# A standard Java string `java.lang.String`
#
# Converted to a Nit string using `to_s`, or to a C string with `to_cstring`.
# Created using `String::to_java_string` or `CString::to_java_string`.
extern class JavaString in "Java" `{ java.lang.String `}
super JavaObject
# Get the string from Java and copy it to Nit memory
fun to_cstring: CString import sys, Sys.jni_env `{
Sys sys = JavaString_sys(self);
JNIEnv *env = Sys_jni_env(sys);
// Get the data from Java
const char *java_cstr = (*env)->GetStringUTFChars(env, self, NULL);
jsize len = (*env)->GetStringUTFLength(env, self);
// Copy it in control of Nit
char *nit_cstr = (char*)malloc(len+1);
memcpy(nit_cstr, java_cstr, len);
nit_cstr[len] = '\0';
// Free JNI ref and return
(*env)->ReleaseStringUTFChars(env, self, java_cstr);
return nit_cstr;
`}
redef fun to_s
do
if is_java_null then return "<{inspect_head}:null>"
return to_cstring.to_s
end
end
lib/java/ffi_support.nit:89,1--120,3
redef class JavaString
private fun native_open_in_browser(context: NativeContext)
in "Java" `{
android.content.Intent intent = new android.content.Intent(
android.content.Intent.ACTION_VIEW,
android.net.Uri.parse(self));
context.startActivity(intent);
`}
end
lib/android/ui/ui.nit:371,1--379,3