A first pass to correctly convert between c char strings to Java Strings.

This commit is contained in:
Adam Murdoch
2012-09-09 10:01:53 +10:00
parent 182efebb40
commit b8d0830d44
6 changed files with 89 additions and 11 deletions

View File

@@ -22,6 +22,63 @@ extern void mark_failed_with_errno(JNIEnv *env, const char* message, jobject res
*/
extern void mark_failed_with_code(JNIEnv *env, const char* message, int error_code, jobject result);
typedef struct wchar_struct {
// Not NULL terminated
wchar_t* chars;
// number of characters in the string
size_t len;
jstring source;
JNIEnv *env;
} wchar_str;
/*
* Converts the given Java string to a wchar_str. Should call wchar_str_free() when finished.
*
* Returns NULL on failure.
*/
extern wchar_str*
java_to_wchar_str(JNIEnv *env, jstring string, jobject result);
/*
* Releases resources used by the given string.
*/
extern void wchar_str_free(wchar_str* str);
/*
* Converts the given wchar_t string to a Java string.
*
* Returns NULL on failure.
*/
extern jstring wchar_to_java(JNIEnv* env, const wchar_t* chars, size_t len, jobject result);
typedef struct char_struct {
// NULL terminated
char* chars;
// Number of chars in the string, excluding the NULL terminator
size_t len;
jstring source;
JNIEnv *env;
} char_str;
/*
* Converts the given Java string to a char_str. Should call char_str_free() when finished.
*
* Returns NULL on failure.
*/
extern char_str* java_to_char_str(JNIEnv *env, jstring string, jobject result);
/*
* Releases resources used by the given string.
*/
extern void char_str_free(char_str* str);
/*
* Converts the given NULL terminated char string to a Java string.
*
* Returns NULL on failure.
*/
extern jstring char_to_java(JNIEnv* env, const char* chars, jobject result);
#ifdef __cplusplus
}
#endif