summaryrefslogtreecommitdiffstats
path: root/icu/src/main/native
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-01-21 18:32:19 -0800
committerElliott Hughes <enh@google.com>2010-01-21 20:33:19 -0800
commit4722f161d49b5c483aa7aec0daad7bfee18578bb (patch)
tree882bc7ee56958862e191e65ed92d076a8ce41c32 /icu/src/main/native
parentb56d4f145a425910db1f6201edc593b61127ca83 (diff)
downloadlibcore-4722f161d49b5c483aa7aec0daad7bfee18578bb.zip
libcore-4722f161d49b5c483aa7aec0daad7bfee18578bb.tar.gz
libcore-4722f161d49b5c483aa7aec0daad7bfee18578bb.tar.bz2
Minor tidy-up of some of the ICU interface.
Dead code, a class that shouldn't be instantiated, work that's probably better done all on the native side, and some slightly improved error reporting.
Diffstat (limited to 'icu/src/main/native')
-rw-r--r--icu/src/main/native/BreakIteratorInterface.c50
-rw-r--r--icu/src/main/native/CollationInterface.c34
-rw-r--r--icu/src/main/native/ConverterInterface.c12
-rw-r--r--icu/src/main/native/ConverterInterface.h299
-rw-r--r--icu/src/main/native/ResourceInterface.cpp2
5 files changed, 46 insertions, 351 deletions
diff --git a/icu/src/main/native/BreakIteratorInterface.c b/icu/src/main/native/BreakIteratorInterface.c
index 021ace1..d4bf0c1 100644
--- a/icu/src/main/native/BreakIteratorInterface.c
+++ b/icu/src/main/native/BreakIteratorInterface.c
@@ -1,18 +1,17 @@
/*
- * Copyright 2006 The Android Open Source Project
+ * Copyright (C) 2006 The Android Open Source Project
*
- * Internal native functions. All of the functions defined here make
- * direct use of VM functions or data structures, so they can't be written
- * with JNI and shouldn't really be in a shared library.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * All functions here either complete quickly or are used to enter a wait
- * state, so we don't set the thread status to THREAD_NATIVE when executing
- * these methods. This means that the GC will wait for these functions
- * to finish. DO NOT perform long operations or blocking I/O in here.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * In some cases we're following the division of labor defined by GNU
- * ClassPath, e.g. java.lang.Thread has "Thread" and "VMThread", with
- * the VM-specific behavior isolated in VMThread.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
#include "JNIHelp.h"
@@ -22,16 +21,20 @@
#include "unicode/putil.h"
#include <stdlib.h>
-static jstring getAvailableLocalesImpl(JNIEnv *env, jclass clazz, jint index) {
-
- const char * locale = ubrk_getAvailable(index);
-
- return (*env)->NewStringUTF(env, locale);
-
-}
-
-static jint getAvailableLocalesCountImpl(JNIEnv *env, jclass clazz) {
- return ubrk_countAvailable();
+static jobjectArray getAvailableLocalesImpl(JNIEnv *env, jclass clazz) {
+ jclass stringClass = (*env)->FindClass(env, "java/lang/String");
+ if (stringClass == NULL) {
+ return NULL;
+ }
+ size_t count = ubrk_countAvailable();
+ jobjectArray result = (*env)->NewObjectArray(env, count, stringClass, NULL);
+ size_t i = 0;
+ for (; i < count; ++i) {
+ jstring s = (*env)->NewStringUTF(env, ubrk_getAvailable(i));
+ (*env)->SetObjectArrayElement(env, result, i, s);
+ (*env)->DeleteLocalRef(env, s);
+ }
+ return result;
}
static jint getCharacterInstanceImpl(JNIEnv *env, jclass clazz, jstring locale) {
@@ -223,10 +226,7 @@ static jint lastImpl(JNIEnv *env, jclass clazz, jint address) {
*/
static JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
- { "getAvailableLocalesImpl", "(I)Ljava/lang/String;",
- (void*) getAvailableLocalesImpl },
- { "getAvailableLocalesCountImpl", "()I",
- (void*) getAvailableLocalesCountImpl },
+ { "getAvailableLocalesImpl", "()[Ljava/lang/String;", (void*) getAvailableLocalesImpl },
{ "getCharacterInstanceImpl", "(Ljava/lang/String;)I",
(void*) getCharacterInstanceImpl },
{ "getLineInstanceImpl", "(Ljava/lang/String;)I",
diff --git a/icu/src/main/native/CollationInterface.c b/icu/src/main/native/CollationInterface.c
index c669649..14cda90 100644
--- a/icu/src/main/native/CollationInterface.c
+++ b/icu/src/main/native/CollationInterface.c
@@ -525,29 +525,25 @@ static void setText(JNIEnv *env, jclass obj, jint address,
icu4jni_error(env, status);
}
-// BEGIN android-added
-static jstring getAvailableLocalesImpl(JNIEnv *env, jclass clazz, jint index) {
-
- const char * locale = ucol_getAvailable(index);
-
- return (*env)->NewStringUTF(env, locale);
-
-}
-
-static jint getAvailableLocalesCountImpl(JNIEnv *env, jclass clazz) {
- return ucol_countAvailable();
+static jobjectArray getAvailableLocalesImpl(JNIEnv *env, jclass clazz) {
+ jclass stringClass = (*env)->FindClass(env, "java/lang/String");
+ if (stringClass == NULL) {
+ return NULL;
+ }
+ size_t count = ucol_countAvailable();
+ jobjectArray result = (*env)->NewObjectArray(env, count, stringClass, NULL);
+ size_t i = 0;
+ for (; i < count; ++i) {
+ jstring s = (*env)->NewStringUTF(env, ucol_getAvailable(i));
+ (*env)->SetObjectArrayElement(env, result, i, s);
+ (*env)->DeleteLocalRef(env, s);
+ }
+ return result;
}
-// END android-added
-/*
- * JNI registratio
- */
static JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
- // BEGIN android-added
- { "getAvailableLocalesImpl", "(I)Ljava/lang/String;", (void*) getAvailableLocalesImpl },
- { "getAvailableLocalesCountImpl", "()I", (void*) getAvailableLocalesCountImpl },
- // END android-added
+ { "getAvailableLocalesImpl", "()[Ljava/lang/String;", (void*) getAvailableLocalesImpl },
{ "openCollator", "()I", (void*) openCollator__ },
{ "openCollator", "(Ljava/lang/String;)I", (void*) openCollator__Ljava_lang_String_2 },
{ "openCollatorFromRules", "(Ljava/lang/String;II)I", (void*) openCollatorFromRules },
diff --git a/icu/src/main/native/ConverterInterface.c b/icu/src/main/native/ConverterInterface.c
index d7f5c9b..d7a159b 100644
--- a/icu/src/main/native/ConverterInterface.c
+++ b/icu/src/main/native/ConverterInterface.c
@@ -15,7 +15,6 @@
* @author: Ram Viswanadha
*/
-#include "ConverterInterface.h"
#include "JNIHelp.h"
#include "AndroidSystemNatives.h"
#include "unicode/utypes.h" /* Basic ICU data types */
@@ -27,6 +26,10 @@
#include <stdlib.h>
#include <string.h>
+#define com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK 0L
+#define com_ibm_icu4jni_converters_NativeConverter_SKIP_CALLBACK 1L
+#define com_ibm_icu4jni_converters_NativeConverter_SUBSTITUTE_CALLBACK 2L
+
// BEGIN android-removed
// #define UTF_16BE "UTF-16BE"
// #define UTF_16 "UTF-16"
@@ -699,10 +702,6 @@ static jboolean canDecode(JNIEnv *env, jclass jClass, jlong handle, jbyteArray s
return (jboolean)FALSE;
}
-static jint countAvailable(JNIEnv *env, jclass jClass) {
- return ucnv_countAvailable();
-}
-
int32_t copyString(char* dest, int32_t destCapacity, int32_t startIndex,
const char* src, UErrorCode* status) {
int32_t srcLen = 0, i=0;
@@ -1358,7 +1357,6 @@ static JNINativeMethod gMethods[] = {
{ "getSubstitutionBytes", "(J)[B", (void*) getSubstitutionBytes },
{ "canEncode", "(JI)Z", (void*) canEncode },
{ "canDecode", "(J[B)Z", (void*) canDecode },
- { "countAvailable", "()I", (void*) countAvailable },
{ "getAvailable", "()[Ljava/lang/String;", (void*) getAvailable },
{ "countAliases", "(Ljava/lang/String;)I", (void*) countAliases },
{ "getAliases", "(Ljava/lang/String;)[Ljava/lang/String;", (void*) getAliases },
@@ -1374,5 +1372,3 @@ int register_com_ibm_icu4jni_converters_NativeConverter(JNIEnv *_env) {
return jniRegisterNativeMethods(_env, "com/ibm/icu4jni/charset/NativeConverter",
gMethods, NELEM(gMethods));
}
-
-
diff --git a/icu/src/main/native/ConverterInterface.h b/icu/src/main/native/ConverterInterface.h
deleted file mode 100644
index e9dbf6b..0000000
--- a/icu/src/main/native/ConverterInterface.h
+++ /dev/null
@@ -1,299 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class com_ibm_icu4jni_converters_NativeConverter */
-
-#ifndef _Included_com_ibm_icu4jni_converters_NativeConverter
-#define _Included_com_ibm_icu4jni_converters_NativeConverter
-#ifdef __cplusplus
-extern "C" {
-#endif
-#undef com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK
-#define com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK 0L
-#undef com_ibm_icu4jni_converters_NativeConverter_SKIP_CALLBACK
-#define com_ibm_icu4jni_converters_NativeConverter_SKIP_CALLBACK 1L
-#undef com_ibm_icu4jni_converters_NativeConverter_SUBSTITUTE_CALLBACK
-#define com_ibm_icu4jni_converters_NativeConverter_SUBSTITUTE_CALLBACK 2L
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: convertByteToChar
- * Signature: (J[BI[CI[IZ)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_convertByteToChar
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jcharArray, jint, jintArray, jboolean);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: decode
- * Signature: (J[BI[CI[IZ)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_decode
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jcharArray, jint, jintArray, jboolean);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: convertCharToByte
- * Signature: (J[CI[BI[IZ)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_convertCharToByte
- (JNIEnv *, jclass, jlong, jcharArray, jint, jbyteArray, jint, jintArray, jboolean);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: encode
- * Signature: (J[CI[BI[IZ)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_encode
- (JNIEnv *, jclass, jlong, jcharArray, jint, jbyteArray, jint, jintArray, jboolean);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: flushCharToByte
- * Signature: (J[BI[I)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_flushCharToByte
- (JNIEnv *, jclass, jlong, jbyteArray, jint, jintArray);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: flushByteToChar
- * Signature: (J[CI[I)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_flushByteToChar
- (JNIEnv *, jclass, jlong, jcharArray, jint, jintArray);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: openConverter
- * Signature: ([JLjava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_openConverter
- (JNIEnv *, jclass, jlongArray, jstring);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: resetByteToChar
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_resetByteToChar
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: resetCharToByte
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_resetCharToByte
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: closeConverter
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_closeConverter
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: setSubstitutionChars
- * Signature: (J[CI)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_setSubstitutionChars
- (JNIEnv *, jclass, jlong, jcharArray, jint);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: setSubstitutionBytes
- * Signature: (J[BI)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_setSubstitutionBytes
- (JNIEnv *, jclass, jlong, jbyteArray, jint);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: setSubstitutionModeCharToByte
- * Signature: (JZ)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_setSubstitutionModeCharToByte
- (JNIEnv *, jclass, jlong, jboolean);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: setSubstitutionModeByteToChar
- * Signature: (JZ)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_setSubstitutionModeByteToChar
- (JNIEnv *, jclass, jlong, jboolean);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: countInvalidBytes
- * Signature: (J[I)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_countInvalidBytes
- (JNIEnv *, jclass, jlong, jintArray);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: countInvalidChars
- * Signature: (J[I)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_countInvalidChars
- (JNIEnv *, jclass, jlong, jintArray);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getMaxBytesPerChar
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getMaxBytesPerChar
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getMinBytesPerChar
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getMinBytesPerChar
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getAveBytesPerChar
- * Signature: (J)F
- */
-JNIEXPORT jfloat JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getAveBytesPerChar
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getMaxCharsPerByte
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getMaxCharsPerByte
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getAveCharsPerByte
- * Signature: (J)F
- */
-JNIEXPORT jfloat JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getAveCharsPerByte
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: contains
- * Signature: (JJ)Z
- */
-JNIEXPORT jboolean JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_contains
- (JNIEnv *, jclass, jlong, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getSubstitutionBytes
- * Signature: (J)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getSubstitutionBytes
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: canEncode
- * Signature: (JI)Z
- */
-JNIEXPORT jboolean JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_canEncode
- (JNIEnv *, jclass, jlong, jint);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: canDecode
- * Signature: (J[B)Z
- */
-JNIEXPORT jboolean JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_canDecode
- (JNIEnv *, jclass, jlong, jbyteArray);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: countAvailable
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_countAvailable
- (JNIEnv *, jclass);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getAvailable
- * Signature: ()[Ljava/lang/String;
- */
-JNIEXPORT jobjectArray JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getAvailable
- (JNIEnv *, jclass);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: countAliases
- * Signature: (Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_countAliases
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getAliases
- * Signature: (Ljava/lang/String;)[Ljava/lang/String;
- */
-JNIEXPORT jobjectArray JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getAliases
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getCanonicalName
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getCanonicalName
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getICUCanonicalName
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getICUCanonicalName
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: getJavaCanonicalName
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_getJavaCanonicalName
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: setCallbackDecode
- * Signature: (JII[CI)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_setCallbackDecode
- (JNIEnv *, jclass, jlong, jint, jint, jcharArray, jint);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: setCallbackEncode
- * Signature: (JII[BI)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_setCallbackEncode
- (JNIEnv *, jclass, jlong, jint, jint, jbyteArray, jint);
-
-/*
- * Class: com_ibm_icu4jni_converters_NativeConverter
- * Method: safeClone
- * Signature: (J[J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_converters_NativeConverter_safeClone
- (JNIEnv *, jclass, jlong, jlongArray);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/icu/src/main/native/ResourceInterface.cpp b/icu/src/main/native/ResourceInterface.cpp
index 3cb4224..68ecf95 100644
--- a/icu/src/main/native/ResourceInterface.cpp
+++ b/icu/src/main/native/ResourceInterface.cpp
@@ -615,11 +615,13 @@ static jboolean initLocaleDataImpl(JNIEnv* env, jclass clazz, jstring locale, jo
ScopedResourceBundle calendar(ures_getByKey(root.get(), "calendar", NULL, &status));
if (U_FAILURE(status)) {
+ LOGE("Error getting ICU calendar resource bundle: %s", u_errorName(status));
return JNI_FALSE;
}
ScopedResourceBundle gregorian(ures_getByKey(calendar.get(), "gregorian", NULL, &status));
if (U_FAILURE(status)) {
+ LOGE("Error getting ICU gregorian resource bundle: %s", u_errorName(status));
return JNI_FALSE;
}