Node: Strings, Next: , Previous: Methods, Up: About CNI


CNI provides a number of utility functions for working with Java Java String objects. The names and interfaces are analogous to those of JNI.

jstring JvNewString (const char* chars, jsize len) Function
Returns a Java String object with characters from the C string chars up to the index len in that array.

jstring JvNewStringLatin1 (const char* bytes, jsize len) Function
Returns a Java String made up of len bytes from bytes.

jstring JvNewStringLatin1 (const char* bytes) Function
As above but the length of the String is strlen(bytes).

jstring JvNewStringUTF (const char* bytes) Function
Returns a String which is made up of the UTF encoded characters present in the C string bytes.

jchar* JvGetStringChars (jstring str) Function
Returns a pointer to an array of characters making up the String str.

int JvGetStringUTFLength (jstring str) Function
Returns the number of bytes required to encode the contents of the String str in UTF-8.

jsize JvGetStringUTFRegion (jstring str, jsize start, jsize len, char* buf) Function
Puts the UTF-8 encoding of a region of the String str into the buffer buf. The region to fetch is marked by start and len.

Note that buf is a buffer, not a C string. It is not null terminated.