Strings

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

jstring JvNewString(const jchar *chars, jsize len);

Creates a new Java String object, where chars are the contents, and len is the number of characters.

jstring JvNewStringLatin1(const char *bytes, jsize len);

Creates a new Java String object, where bytes are the Latin-1 encoded characters, and len is the length of bytes, in bytes.

jstring JvNewStringLatin1(const char *bytes);

Like the first JvNewStringLatin1, but computes len using strlen.

jstring JvNewStringUTF(const char *bytes);

Creates a new Java String object, where bytes are the UTF-8 encoded characters of the string, terminated by a null byte.

jchar *JvGetStringChars(jstring str);

Returns a pointer to the array of characters which make up a string.

int JvGetStringUTFLength(jstring str);

Returns number of bytes required to encode contents of str as UTF-8.

jsize JvGetStringUTFRegion(jstring str, jsize start, jsize len, char *buf);

This puts the UTF-8 encoding of a region of the string str into the buffer buf. The region of the string to fetch is specifued by start and len. It is assumed that buf is big enough to hold the result. Note that buf is not null-terminated.