I have a Java string literal with Unicode characters that needs to be transferred into a C string literal, that is loadable with JNIEnv.NewString
.
Unfortunately, the above method takes a pointer to an array of unsigned short
(jchar). I have tried using code like the following:
unsigned short str[] = {65, 66, 67};
jstring java_str = (*env)->NewString(env, str, 3);
However, this takes a lot of room, is not human readable, and is difficult to maintain.
Is there a way to convert a string literal into a unsigned short[]
in C, whilst still being able to use Java's UTF-16 characters?
Can this escaping be done programatically? i.e. convert a java.lang.String
into a string literal that would work in C source code.