diff options
author | Elliott Hughes <enh@google.com> | 2009-09-11 10:58:44 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2009-09-11 10:58:44 -0700 |
commit | c742cadc9b62ba3d62cec09fd8b457b5aa787379 (patch) | |
tree | 53fb39723231eb9558be9673d97e216e3a7ccbf6 /icu/src/main/native | |
parent | a6bd22ee1d45bb47c9957d3bc032db395873073a (diff) | |
download | libcore-c742cadc9b62ba3d62cec09fd8b457b5aa787379.zip libcore-c742cadc9b62ba3d62cec09fd8b457b5aa787379.tar.gz libcore-c742cadc9b62ba3d62cec09fd8b457b5aa787379.tar.bz2 |
Remove duplicate copies of ICU error translation.
For want of an 'extern "C"', we seem to have grown several duplicates of
icu4jni_error.
Diffstat (limited to 'icu/src/main/native')
-rw-r--r-- | icu/src/main/native/DecimalFormatInterface.cpp | 53 | ||||
-rw-r--r-- | icu/src/main/native/ErrorCode.h | 8 | ||||
-rw-r--r-- | icu/src/main/native/RBNFInterface.cpp | 36 | ||||
-rw-r--r-- | icu/src/main/native/ResourceInterface.cpp | 26 |
4 files changed, 26 insertions, 97 deletions
diff --git a/icu/src/main/native/DecimalFormatInterface.cpp b/icu/src/main/native/DecimalFormatInterface.cpp index d2bacb8..252ec33 100644 --- a/icu/src/main/native/DecimalFormatInterface.cpp +++ b/icu/src/main/native/DecimalFormatInterface.cpp @@ -29,33 +29,6 @@ #include <string.h> #include "cutils/log.h" - -static UBool icuError(JNIEnv *env, UErrorCode errorcode) -{ - const char *emsg = u_errorName(errorcode); - jclass exception; - - if (U_FAILURE(errorcode)) {// errorcode > U_ZERO_ERROR && errorcode < U_ERROR_LIMIT) { - switch (errorcode) { - case U_ILLEGAL_ARGUMENT_ERROR : - exception = env->FindClass("java/lang/IllegalArgumentException"); - break; - case U_INDEX_OUTOFBOUNDS_ERROR : - case U_BUFFER_OVERFLOW_ERROR : - exception = env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); - break; - case U_UNSUPPORTED_ERROR : - exception = env->FindClass("java/lang/UnsupportedOperationException"); - break; - default : - exception = env->FindClass("java/lang/RuntimeException"); - } - - return (env->ThrowNew(exception, emsg) != 0); - } - return 0; -} - static jint openDecimalFormatImpl(JNIEnv *env, jclass clazz, jstring locale, jstring pattern) { @@ -78,7 +51,7 @@ static jint openDecimalFormatImpl(JNIEnv *env, jclass clazz, jstring locale, env->ReleaseStringUTFChars(locale, localeChars); // check for an error - if ( icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { return 0; } @@ -115,8 +88,8 @@ static void setSymbol(JNIEnv *env, jclass clazz, jint addr, jint symbol, // release previously allocated space env->ReleaseStringChars(text, textChars); - // check if an error occured - icuError(env, status); + // check if an error occurred + icu4jni_error(env, status); } static jstring getSymbol(JNIEnv *env, jclass clazz, jint addr, jint symbol) { @@ -144,7 +117,7 @@ static jstring getSymbol(JNIEnv *env, jclass clazz, jint addr, jint symbol) { reslenneeded=unum_getSymbol(fmt, (UNumberFormatSymbol) symbol, result, resultlength, &status); } - if (icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { return NULL; } @@ -189,7 +162,7 @@ static void setTextAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol, env->ReleaseStringChars(text, textChars); - icuError(env, status); + icu4jni_error(env, status); } static jstring getTextAttribute(JNIEnv *env, jclass clazz, jint addr, @@ -219,7 +192,7 @@ static jstring getTextAttribute(JNIEnv *env, jclass clazz, jint addr, (UNumberFormatTextAttribute) symbol, result, resultlength, &status); } - if (icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { return NULL; } @@ -246,7 +219,7 @@ static void applyPatternImpl(JNIEnv *env, jclass clazz, jint addr, env->ReleaseStringChars(pattern, pattChars); - icuError(env, status); + icu4jni_error(env, status); } static jstring toPatternImpl(JNIEnv *env, jclass clazz, jint addr, @@ -274,7 +247,7 @@ static jstring toPatternImpl(JNIEnv *env, jclass clazz, jint addr, reslenneeded=unum_toPattern(fmt, localized, result, resultlength, &status); } - if (icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { return NULL; } @@ -335,7 +308,7 @@ static jstring formatLong(JNIEnv *env, jclass clazz, jint addr, jlong value, res->extract(result, reslenneeded + 1, status); } - if (icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { free(attrBuffer->buffer); free(attrBuffer); free(result); @@ -444,7 +417,7 @@ static jstring formatDouble(JNIEnv *env, jclass clazz, jint addr, jdouble value, res->extract(result, reslenneeded + 1, status); } - if (icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { free(attrBuffer->buffer); free(attrBuffer); free(result); @@ -510,7 +483,7 @@ static jstring formatDigitList(JNIEnv *env, jclass clazz, jint addr, jstring val // env->ReleaseStringUTFChars(value, valueUTF); if (scale < 0) { - icuError(env, U_ILLEGAL_ARGUMENT_ERROR); + icu4jni_error(env, U_ILLEGAL_ARGUMENT_ERROR); return NULL; } @@ -582,7 +555,7 @@ static jstring formatDigitList(JNIEnv *env, jclass clazz, jint addr, jstring val res.extract(result, reslenneeded + 1, status); - if (icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { if(fieldType != NULL) { env->ReleaseStringUTFChars(fieldType, fieldName); } @@ -786,7 +759,7 @@ static jint cloneImpl(JNIEnv *env, jclass clazz, jint addr) { UNumberFormat *result = unum_clone(fmt, &status); - if(icuError(env, status) != FALSE) { + if(icu4jni_error(env, status) != FALSE) { return 0; } diff --git a/icu/src/main/native/ErrorCode.h b/icu/src/main/native/ErrorCode.h index a5bbfc6..e42a519 100644 --- a/icu/src/main/native/ErrorCode.h +++ b/icu/src/main/native/ErrorCode.h @@ -13,6 +13,10 @@ #include "unicode/utypes.h" #include "unicode/putil.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * Checks if an error has occured. * Throws a generic Java RuntimeException if an error has occured. @@ -24,4 +28,8 @@ */ UBool icu4jni_error(JNIEnv *env, UErrorCode errorcode); +#ifdef __cplusplus +} +#endif + #endif diff --git a/icu/src/main/native/RBNFInterface.cpp b/icu/src/main/native/RBNFInterface.cpp index 62e0cb4..c7486e1 100644 --- a/icu/src/main/native/RBNFInterface.cpp +++ b/icu/src/main/native/RBNFInterface.cpp @@ -25,32 +25,6 @@ #include <stdlib.h> #include <string.h> -static UBool icuError(JNIEnv *env, UErrorCode errorcode) -{ - const char *emsg = u_errorName(errorcode); - jclass exception; - - if (errorcode > U_ZERO_ERROR && errorcode < U_ERROR_LIMIT) { - switch (errorcode) { - case U_ILLEGAL_ARGUMENT_ERROR : - exception = env->FindClass("java/lang/IllegalArgumentException"); - break; - case U_INDEX_OUTOFBOUNDS_ERROR : - case U_BUFFER_OVERFLOW_ERROR : - exception = env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); - break; - case U_UNSUPPORTED_ERROR : - exception = env->FindClass("java/lang/UnsupportedOperationException"); - break; - default : - exception = env->FindClass("java/lang/RuntimeException"); - } - - return (env->ThrowNew(exception, emsg) != 0); - } - return 0; -} - static jint openRBNFImpl1(JNIEnv* env, jclass clazz, jint type, jstring locale) { @@ -72,7 +46,7 @@ static jint openRBNFImpl1(JNIEnv* env, jclass clazz, } else if(type == 3) { style = URBNF_COUNT; } else { - icuError(env, U_ILLEGAL_ARGUMENT_ERROR); + icu4jni_error(env, U_ILLEGAL_ARGUMENT_ERROR); } Locale loc = Locale::createFromName(localeChars); @@ -84,7 +58,7 @@ static jint openRBNFImpl1(JNIEnv* env, jclass clazz, env->ReleaseStringUTFChars(locale, localeChars); // check for an error - if ( icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { return 0; } @@ -117,7 +91,7 @@ static jint openRBNFImpl2(JNIEnv* env, jclass clazz, env->ReleaseStringUTFChars(locale, localeChars); // check for an error - if ( icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { return 0; } @@ -183,7 +157,7 @@ static jstring formatLongRBNFImpl(JNIEnv *env, jclass clazz, jint addr, jlong va res.extract(result, reslenneeded + 1, status); } - if (icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { free(result); return NULL; } @@ -245,7 +219,7 @@ static jstring formatDoubleRBNFImpl(JNIEnv *env, jclass clazz, jint addr, jdoubl res.extract(result, reslenneeded + 1, status); } - if (icuError(env, status) != FALSE) { + if (icu4jni_error(env, status) != FALSE) { free(result); return NULL; } diff --git a/icu/src/main/native/ResourceInterface.cpp b/icu/src/main/native/ResourceInterface.cpp index a88e15c..731cf3f 100644 --- a/icu/src/main/native/ResourceInterface.cpp +++ b/icu/src/main/native/ResourceInterface.cpp @@ -40,32 +40,6 @@ jclass string_class; -static UBool icuError(JNIEnv *env, UErrorCode errorcode) -{ - const char *emsg = u_errorName(errorcode); - jclass exception; - - if (U_FAILURE(errorcode)) { - switch (errorcode) { - case U_ILLEGAL_ARGUMENT_ERROR : - exception = env->FindClass("java/lang/IllegalArgumentException"); - break; - case U_INDEX_OUTOFBOUNDS_ERROR : - case U_BUFFER_OVERFLOW_ERROR : - exception = env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); - break; - case U_UNSUPPORTED_ERROR : - exception = env->FindClass("java/lang/UnsupportedOperationException"); - break; - default : - exception = env->FindClass("java/lang/RuntimeException"); - } - - return (env->ThrowNew(exception, emsg) != 0); - } - return 0; -} - static Locale getLocale(JNIEnv *env, jstring locale) { const char *name = env->GetStringUTFChars(locale, NULL); Locale result = Locale::createFromName(name); |