Next: , Previous: Methods, Up: About CNI

12.12 Strings

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

— Function: jstring JvNewString (const char* chars, jsize len)

Returns a Java String object with characters from the C string chars up to the index len in that array.

— Function: jstring JvNewStringLatin1 (const char* bytes, jsize len)

Returns a Java String made up of len bytes from bytes.

— Function: jstring JvNewStringLatin1 (const char* bytes)

As above but the length of the String is strlen(bytes).

— Function: jstring JvNewStringUTF (const char* bytes)

Returns a String which is made up of the UTF encoded characters present in the C string bytes.

— Function: jchar* JvGetStringChars (jstring str)

Returns a pointer to an array of characters making up the String str.

— Function: int JvGetStringUTFLength (jstring str)

Returns the number of bytes required to encode the contents of the String str in UTF-8.

— Function: jsize JvGetStringUTFRegion (jstring str, jsize start, jsize len, char* buf)

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.