diff options
Diffstat (limited to 'icu/src/main/native')
-rw-r--r-- | icu/src/main/native/BidiWrapper.cpp | 180 | ||||
-rw-r--r-- | icu/src/main/native/ErrorCode.cpp | 39 | ||||
-rw-r--r-- | icu/src/main/native/ErrorCode.h | 35 | ||||
-rw-r--r-- | icu/src/main/native/ICU.cpp | 710 | ||||
-rw-r--r-- | icu/src/main/native/NativeBreakIterator.cpp | 143 | ||||
-rw-r--r-- | icu/src/main/native/NativeCollation.cpp | 199 | ||||
-rw-r--r-- | icu/src/main/native/NativeConverter.cpp | 1019 | ||||
-rw-r--r-- | icu/src/main/native/NativeDecimalFormat.cpp | 608 | ||||
-rw-r--r-- | icu/src/main/native/NativeIDN.cpp | 66 | ||||
-rw-r--r-- | icu/src/main/native/NativeNormalizer.cpp | 50 | ||||
-rw-r--r-- | icu/src/main/native/NativeRegEx.cpp | 356 | ||||
-rw-r--r-- | icu/src/main/native/ScopedJavaUnicodeString.h | 57 | ||||
-rw-r--r-- | icu/src/main/native/UCharacter.cpp | 203 | ||||
-rw-r--r-- | icu/src/main/native/sub.mk | 31 |
14 files changed, 0 insertions, 3696 deletions
diff --git a/icu/src/main/native/BidiWrapper.cpp b/icu/src/main/native/BidiWrapper.cpp deleted file mode 100644 index 03efa92..0000000 --- a/icu/src/main/native/BidiWrapper.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ -#define LOG_TAG "BidiWrapper" - -#include <JNIHelp.h> -#include "ErrorCode.h" -#include "UniquePtr.h" -#include "unicode/ubidi.h" -#include <stdlib.h> -#include <string.h> - -struct BiDiData { - BiDiData(UBiDi* biDi) : mBiDi(biDi), mEmbeddingLevels(NULL) { - } - - ~BiDiData() { - ubidi_close(mBiDi); - } - - UBiDiLevel* embeddingLevels() { - return reinterpret_cast<UBiDiLevel*>(&mEmbeddingLevels[0]); - } - - void setEmbeddingLevels(jbyte* newEmbeddingLevels) { - mEmbeddingLevels.reset(newEmbeddingLevels); - } - - UBiDi* uBiDi() { - return mBiDi; - } - -private: - UBiDi* mBiDi; - UniquePtr<jbyte[]> mEmbeddingLevels; - - // Disallow copy and assignment. - BiDiData(const BiDiData&); - void operator=(const BiDiData&); -}; - -static BiDiData* biDiData(jlong ptr) { - return reinterpret_cast<BiDiData*>(static_cast<uintptr_t>(ptr)); -} - -static UBiDi* uBiDi(jlong ptr) { - return reinterpret_cast<BiDiData*>(static_cast<uintptr_t>(ptr))->uBiDi(); -} - -static jlong BidiWrapper_ubidi_open(JNIEnv* env, jclass) { - return reinterpret_cast<uintptr_t>(new BiDiData(ubidi_open())); -} - -static void BidiWrapper_ubidi_close(JNIEnv* env, jclass, jlong ptr) { - delete biDiData(ptr); -} - -static void BidiWrapper_ubidi_setPara(JNIEnv* env, jclass, jlong ptr, jcharArray text, jint length, jbyte paraLevel, jbyteArray newEmbeddingLevels) { - BiDiData* data = biDiData(ptr); - // Copy the new embedding levels from the Java heap to the native heap. - if (newEmbeddingLevels != NULL) { - jbyte* dst; - data->setEmbeddingLevels(dst = new jbyte[length]); - env->GetByteArrayRegion(newEmbeddingLevels, 0, length, dst); - } else { - data->setEmbeddingLevels(NULL); - } - UErrorCode err = U_ZERO_ERROR; - jchar* chars = env->GetCharArrayElements(text, NULL); - ubidi_setPara(data->uBiDi(), chars, length, paraLevel, data->embeddingLevels(), &err); - env->ReleaseCharArrayElements(text, chars, 0); - icu4jni_error(env, err); -} - -static jlong BidiWrapper_ubidi_setLine(JNIEnv* env, jclass, jlong ptr, jint start, jint limit) { - UErrorCode err = U_ZERO_ERROR; - UBiDi* sized = ubidi_openSized(limit - start, 0, &err); - if (icu4jni_error(env, err) != FALSE) { - return 0; - } - UniquePtr<BiDiData> lineData(new BiDiData(sized)); - ubidi_setLine(uBiDi(ptr), start, limit, lineData->uBiDi(), &err); - icu4jni_error(env, err); - return reinterpret_cast<uintptr_t>(lineData.release()); -} - -static jint BidiWrapper_ubidi_getDirection(JNIEnv * env, jclass clazz, jlong ptr) { - return ubidi_getDirection(uBiDi(ptr)); -} - -static jint BidiWrapper_ubidi_getLength(JNIEnv* env, jclass, jlong ptr) { - return ubidi_getLength(uBiDi(ptr)); -} - -static jbyte BidiWrapper_ubidi_getParaLevel(JNIEnv* env, jclass, jlong ptr) { - return ubidi_getParaLevel(uBiDi(ptr)); -} - -static jbyteArray BidiWrapper_ubidi_getLevels(JNIEnv* env, jclass, jlong ptr) { - UErrorCode err = U_ZERO_ERROR; - const UBiDiLevel* levels = ubidi_getLevels(uBiDi(ptr), &err); - if (icu4jni_error(env, err)) { - return NULL; - } - int len = ubidi_getLength(uBiDi(ptr)); - jbyteArray result = env->NewByteArray(len); - env->SetByteArrayRegion(result, 0, len, reinterpret_cast<const jbyte*>(levels)); - return result; -} - -static jint BidiWrapper_ubidi_countRuns(JNIEnv* env, jclass, jlong ptr) { - UErrorCode err = U_ZERO_ERROR; - int count = ubidi_countRuns(uBiDi(ptr), &err); - icu4jni_error(env, err); - return count; -} - -static jobjectArray BidiWrapper_ubidi_getRuns(JNIEnv* env, jclass, jlong ptr) { - UBiDi* ubidi = uBiDi(ptr); - UErrorCode err = U_ZERO_ERROR; - int runCount = ubidi_countRuns(ubidi, &err); - if (icu4jni_error(env, err)) { - return NULL; - } - jclass bidiRunClass = env->FindClass("org/apache/harmony/text/BidiRun"); - jmethodID bidiRunConstructor = env->GetMethodID(bidiRunClass, "<init>", "(III)V"); - jobjectArray runs = env->NewObjectArray(runCount, bidiRunClass, NULL); - UBiDiLevel level = 0; - int start = 0; - int limit = 0; - for (int i = 0; i < runCount; ++i) { - ubidi_getLogicalRun(ubidi, start, &limit, &level); - jobject run = env->NewObject(bidiRunClass, bidiRunConstructor, start, limit, level); - env->SetObjectArrayElement(runs, i, run); - start = limit; - } - return runs; -} - -static jintArray BidiWrapper_ubidi_reorderVisual(JNIEnv* env, jclass, jbyteArray levels, jint length) { - UniquePtr<int[]> local_indexMap(new int[length]); - jbyte* local_levelBytes = env->GetByteArrayElements(levels, NULL); - UBiDiLevel* local_levels = reinterpret_cast<UBiDiLevel*>(local_levelBytes); - ubidi_reorderVisual(local_levels, length, &local_indexMap[0]); - jintArray result = env->NewIntArray(length); - env->SetIntArrayRegion(result, 0, length, &local_indexMap[0]); - env->ReleaseByteArrayElements(levels, local_levelBytes, 0); - return result; -} - -static JNINativeMethod gMethods[] = { - { "ubidi_close", "(J)V", (void*) BidiWrapper_ubidi_close }, - { "ubidi_countRuns", "(J)I", (void*) BidiWrapper_ubidi_countRuns }, - { "ubidi_getDirection", "(J)I", (void*) BidiWrapper_ubidi_getDirection }, - { "ubidi_getLength", "(J)I", (void*) BidiWrapper_ubidi_getLength }, - { "ubidi_getLevels", "(J)[B", (void*) BidiWrapper_ubidi_getLevels }, - { "ubidi_getParaLevel", "(J)B", (void*) BidiWrapper_ubidi_getParaLevel }, - { "ubidi_getRuns", "(J)[Lorg/apache/harmony/text/BidiRun;", (void*) BidiWrapper_ubidi_getRuns }, - { "ubidi_open", "()J", (void*) BidiWrapper_ubidi_open }, - { "ubidi_reorderVisual", "([BI)[I", (void*) BidiWrapper_ubidi_reorderVisual }, - { "ubidi_setLine", "(JII)J", (void*) BidiWrapper_ubidi_setLine }, - { "ubidi_setPara", "(J[CIB[B)V", (void*) BidiWrapper_ubidi_setPara }, -}; -int register_org_apache_harmony_text_BidiWrapper(JNIEnv* env) { - return jniRegisterNativeMethods(env, "org/apache/harmony/text/BidiWrapper", - gMethods, NELEM(gMethods)); -} diff --git a/icu/src/main/native/ErrorCode.cpp b/icu/src/main/native/ErrorCode.cpp deleted file mode 100644 index a9d0691..0000000 --- a/icu/src/main/native/ErrorCode.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** -******************************************************************************* -* Copyright (C) 1996-2005, International Business Machines Corporation and * -* others. All Rights Reserved. * -******************************************************************************* -* -******************************************************************************* -*/ - -#include "ErrorCode.h" -#include "JNIHelp.h" - -/** -* Checks if an error has occurred, throwing a suitable exception if so. -* @param env JNI environment -* @param errorCode code to determine if it is an error -* @return 0 if errorCode is not an error, 1 if errorCode is an error, but the -* creation of the exception to be thrown fails - * @exception thrown if errorCode represents an error -*/ -UBool icu4jni_error(JNIEnv *env, UErrorCode errorCode) -{ - const char* message = u_errorName(errorCode); - if (errorCode <= U_ZERO_ERROR || errorCode >= U_ERROR_LIMIT) { - return 0; - } - - switch (errorCode) { - case U_ILLEGAL_ARGUMENT_ERROR: - return jniThrowException(env, "java/lang/IllegalArgumentException", message); - case U_INDEX_OUTOFBOUNDS_ERROR: - case U_BUFFER_OVERFLOW_ERROR: - return jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", message); - case U_UNSUPPORTED_ERROR: - return jniThrowException(env, "java/lang/UnsupportedOperationException", message); - default: - return jniThrowRuntimeException(env, message); - } -} diff --git a/icu/src/main/native/ErrorCode.h b/icu/src/main/native/ErrorCode.h deleted file mode 100644 index e42a519..0000000 --- a/icu/src/main/native/ErrorCode.h +++ /dev/null @@ -1,35 +0,0 @@ -/** -******************************************************************************* -* Copyright (C) 1996-2005, International Business Machines Corporation and * -* others. All Rights Reserved. * -******************************************************************************* -******************************************************************************* -*/ - -#ifndef ERRORCODE_H -#define ERRORCODE_H - -#include <jni.h> -#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. -* @param env JNI environment variable -* @param errorcode code to determine if it is an erro -* @return 0 if errorcode is not an error, 1 if errorcode is an error, but the -* creation of the exception to be thrown fails -* @exception thrown if errorcode represents an error -*/ -UBool icu4jni_error(JNIEnv *env, UErrorCode errorcode); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/icu/src/main/native/ICU.cpp b/icu/src/main/native/ICU.cpp deleted file mode 100644 index 4f08513..0000000 --- a/icu/src/main/native/ICU.cpp +++ /dev/null @@ -1,710 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#define LOG_TAG "ICU" - -#include "JNIHelp.h" -#include "ScopedUtfChars.h" -#include "UniquePtr.h" -#include "cutils/log.h" -#include "unicode/numfmt.h" -#include "unicode/locid.h" -#include "unicode/ubrk.h" -#include "unicode/ucal.h" -#include "unicode/ucol.h" -#include "unicode/udat.h" -#include "unicode/gregocal.h" -#include "unicode/ucurr.h" -#include "unicode/calendar.h" -#include "unicode/datefmt.h" -#include "unicode/dtfmtsym.h" -#include "unicode/decimfmt.h" -#include "unicode/dcfmtsym.h" -#include "unicode/uclean.h" -#include "unicode/smpdtfmt.h" -#include "unicode/strenum.h" -#include "unicode/ustring.h" -#include "unicode/timezone.h" -#include "ErrorCode.h" -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <sys/time.h> - -static jclass string_class; - -class ScopedResourceBundle { -public: - ScopedResourceBundle(UResourceBundle* bundle) : mBundle(bundle) { - } - - ~ScopedResourceBundle() { - if (mBundle != NULL) { - ures_close(mBundle); - } - } - - UResourceBundle* get() { - return mBundle; - } - -private: - UResourceBundle* mBundle; - - // Disallow copy and assignment. - ScopedResourceBundle(const ScopedResourceBundle&); - void operator=(const ScopedResourceBundle&); -}; - -static Locale getLocale(JNIEnv* env, jstring localeName) { - return Locale::createFromName(ScopedUtfChars(env, localeName).c_str()); -} - -static jint getCurrencyFractionDigitsNative(JNIEnv* env, jclass, jstring currencyCode) { - UErrorCode status = U_ZERO_ERROR; - UniquePtr<NumberFormat> fmt(NumberFormat::createCurrencyInstance(status)); - if (U_FAILURE(status)) { - return -1; - } - const jchar* cCode = env->GetStringChars(currencyCode, NULL); - fmt->setCurrency(cCode, status); - env->ReleaseStringChars(currencyCode, cCode); - if (U_FAILURE(status)) { - return -1; - } - // for CurrencyFormats the minimum and maximum fraction digits are the same. - return fmt->getMinimumFractionDigits(); -} - -static jstring getCurrencyCodeNative(JNIEnv* env, jclass, jstring key) { - UErrorCode status = U_ZERO_ERROR; - ScopedResourceBundle supplData(ures_openDirect(NULL, "supplementalData", &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ScopedResourceBundle currencyMap(ures_getByKey(supplData.get(), "CurrencyMap", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - const char* keyChars = env->GetStringUTFChars(key, NULL); - ScopedResourceBundle currency(ures_getByKey(currencyMap.get(), keyChars, NULL, &status)); - env->ReleaseStringUTFChars(key, keyChars); - if (U_FAILURE(status)) { - return NULL; - } - - ScopedResourceBundle currencyElem(ures_getByIndex(currency.get(), 0, NULL, &status)); - if (U_FAILURE(status)) { - return env->NewStringUTF("None"); - } - - // check if there is a 'to' date. If there is, the currency isn't used anymore. - ScopedResourceBundle currencyTo(ures_getByKey(currencyElem.get(), "to", NULL, &status)); - if (!U_FAILURE(status)) { - // return and let the caller throw an exception - return NULL; - } - // We need to reset 'status'. It works like errno in that ICU doesn't set it - // to U_ZERO_ERROR on success: it only touches it on error, and the test - // above means it now holds a failure code. - status = U_ZERO_ERROR; - - ScopedResourceBundle currencyId(ures_getByKey(currencyElem.get(), "id", NULL, &status)); - if (U_FAILURE(status)) { - // No id defined for this country - return env->NewStringUTF("None"); - } - - int length; - const jchar* id = ures_getString(currencyId.get(), &length, &status); - if (U_FAILURE(status) || length == 0) { - return env->NewStringUTF("None"); - } - return env->NewString(id, length); -} - -static jstring getCurrencySymbolNative(JNIEnv* env, jclass, jstring locale, jstring currencyCode) { - // LOGI("ENTER getCurrencySymbolNative"); - - const char* locName = env->GetStringUTFChars(locale, NULL); - UErrorCode status = U_ZERO_ERROR; - ScopedResourceBundle root(ures_open(NULL, locName, &status)); - env->ReleaseStringUTFChars(locale, locName); - if (U_FAILURE(status)) { - return NULL; - } - - ScopedResourceBundle currencies(ures_getByKey(root.get(), "Currencies", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - const char* currName = env->GetStringUTFChars(currencyCode, NULL); - ScopedResourceBundle currencyElems(ures_getByKey(currencies.get(), currName, NULL, &status)); - env->ReleaseStringUTFChars(currencyCode, currName); - if (U_FAILURE(status)) { - return NULL; - } - - int currSymbL; - const jchar* currSymbU = ures_getStringByIndex(currencyElems.get(), 0, &currSymbL, &status); - if (U_FAILURE(status)) { - return NULL; - } - - return (currSymbL == 0) ? NULL : env->NewString(currSymbU, currSymbL); -} - -static jstring getDisplayCountryNative(JNIEnv* env, jclass, jstring targetLocale, jstring locale) { - - Locale loc = getLocale(env, locale); - Locale targetLoc = getLocale(env, targetLocale); - - UnicodeString str; - targetLoc.getDisplayCountry(loc, str); - return env->NewString(str.getBuffer(), str.length()); -} - -static jstring getDisplayLanguageNative(JNIEnv* env, jclass, jstring targetLocale, jstring locale) { - - Locale loc = getLocale(env, locale); - Locale targetLoc = getLocale(env, targetLocale); - - UnicodeString str; - targetLoc.getDisplayLanguage(loc, str); - return env->NewString(str.getBuffer(), str.length()); -} - -static jstring getDisplayVariantNative(JNIEnv* env, jclass, jstring targetLocale, jstring locale) { - Locale loc = getLocale(env, locale); - Locale targetLoc = getLocale(env, targetLocale); - UnicodeString str; - targetLoc.getDisplayVariant(loc, str); - return env->NewString(str.getBuffer(), str.length()); -} - -static jstring getISO3CountryNative(JNIEnv* env, jclass, jstring locale) { - Locale loc = getLocale(env, locale); - return env->NewStringUTF(loc.getISO3Country()); -} - -static jstring getISO3LanguageNative(JNIEnv* env, jclass, jstring locale) { - Locale loc = getLocale(env, locale); - return env->NewStringUTF(loc.getISO3Language()); -} - -static jobjectArray toStringArray(JNIEnv* env, const char* const* strings) { - size_t count = 0; - while (strings[count] != NULL) { - ++count; - } - jobjectArray result = env->NewObjectArray(count, string_class, NULL); - for (size_t i = 0; i < count; ++i) { - jstring s = env->NewStringUTF(strings[i]); - env->SetObjectArrayElement(result, i, s); - env->DeleteLocalRef(s); - } - return result; -} - -static jobjectArray getISOCountriesNative(JNIEnv* env, jclass) { - return toStringArray(env, Locale::getISOCountries()); -} - -static jobjectArray getISOLanguagesNative(JNIEnv* env, jclass) { - return toStringArray(env, Locale::getISOLanguages()); -} - -template <typename Counter, typename Getter> -static jobjectArray getAvailableLocales(JNIEnv* env, Counter* counter, Getter* getter) { - size_t count = (*counter)(); - jobjectArray result = env->NewObjectArray(count, string_class, NULL); - for (size_t i = 0; i < count; ++i) { - jstring s = env->NewStringUTF((*getter)(i)); - env->SetObjectArrayElement(result, i, s); - env->DeleteLocalRef(s); - } - return result; -} - -static jobjectArray getAvailableLocalesNative(JNIEnv* env, jclass) { - return getAvailableLocales(env, uloc_countAvailable, uloc_getAvailable); -} - -static jobjectArray getAvailableBreakIteratorLocalesNative(JNIEnv* env, jclass) { - return getAvailableLocales(env, ubrk_countAvailable, ubrk_getAvailable); -} - -static jobjectArray getAvailableCalendarLocalesNative(JNIEnv* env, jclass) { - return getAvailableLocales(env, ucal_countAvailable, ucal_getAvailable); -} - -static jobjectArray getAvailableCollatorLocalesNative(JNIEnv* env, jclass) { - return getAvailableLocales(env, ucol_countAvailable, ucol_getAvailable); -} - -static jobjectArray getAvailableDateFormatLocalesNative(JNIEnv* env, jclass) { - return getAvailableLocales(env, udat_countAvailable, udat_getAvailable); -} - -static jobjectArray getAvailableNumberFormatLocalesNative(JNIEnv* env, jclass) { - return getAvailableLocales(env, unum_countAvailable, unum_getAvailable); -} - -static TimeZone* timeZoneFromId(JNIEnv* env, jstring id) { - const jchar* chars = env->GetStringChars(id, NULL); - const UnicodeString zoneID(reinterpret_cast<const UChar*>(chars), env->GetStringLength(id)); - env->ReleaseStringChars(id, chars); - return TimeZone::createTimeZone(zoneID); -} - -static jstring formatDate(JNIEnv* env, const SimpleDateFormat& fmt, const UDate& when) { - UnicodeString str; - fmt.format(when, str); - return env->NewString(str.getBuffer(), str.length()); -} - -static void getTimeZonesNative(JNIEnv* env, jclass, jobjectArray outerArray, jstring locale) { - // get all timezone objects - jobjectArray zoneIdArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 0); - int count = env->GetArrayLength(zoneIdArray); - TimeZone* zones[count]; - for(int i = 0; i < count; i++) { - jstring id = (jstring) env->GetObjectArrayElement(zoneIdArray, i); - zones[i] = timeZoneFromId(env, id); - env->DeleteLocalRef(id); - } - - Locale loc = getLocale(env, locale); - - UErrorCode status = U_ZERO_ERROR; - UnicodeString longPattern("zzzz",""); - SimpleDateFormat longFormat(longPattern, loc, status); - UnicodeString shortPattern("z",""); - SimpleDateFormat shortFormat(shortPattern, loc, status); - - jobjectArray longStdTimeArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 1); - jobjectArray shortStdTimeArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 2); - jobjectArray longDlTimeArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 3); - jobjectArray shortDlTimeArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 4); - - // 15th January 2008 - UDate date1 = 1203105600000.0; - // 15th July 2008 - UDate date2 = 1218826800000.0; - - for (int i = 0; i < count; ++i) { - TimeZone* tz = zones[i]; - longFormat.setTimeZone(*tz); - shortFormat.setTimeZone(*tz); - - int32_t daylightOffset; - int32_t rawOffset; - tz->getOffset(date1, false, rawOffset, daylightOffset, status); - UDate standardDate; - UDate daylightSavingDate; - if (daylightOffset != 0) { - // The Timezone is reporting that we are in daylight time - // for the winter date. The dates are for the wrong hemisphere, - // swap them. - standardDate = date2; - daylightSavingDate = date1; - } else { - standardDate = date1; - daylightSavingDate = date2; - } - - jstring content = formatDate(env, shortFormat, daylightSavingDate); - env->SetObjectArrayElement(shortDlTimeArray, i, content); - env->DeleteLocalRef(content); - - content = formatDate(env, shortFormat, standardDate); - env->SetObjectArrayElement(shortStdTimeArray, i, content); - env->DeleteLocalRef(content); - - content = formatDate(env, longFormat, daylightSavingDate); - env->SetObjectArrayElement(longDlTimeArray, i, content); - env->DeleteLocalRef(content); - - content = formatDate(env, longFormat, standardDate); - env->SetObjectArrayElement(longStdTimeArray, i, content); - env->DeleteLocalRef(content); - - delete tz; - } -} - -static jstring getDisplayTimeZoneNative(JNIEnv* env, jclass, jstring zoneId, jboolean isDST, jint style, jstring localeId) { - UniquePtr<TimeZone> zone(timeZoneFromId(env, zoneId)); - Locale locale = getLocale(env, localeId); - // Try to get the display name of the TimeZone according to the Locale - UnicodeString displayName; - zone->getDisplayName((UBool)isDST, (style == 0 ? TimeZone::SHORT : TimeZone::LONG), locale, displayName); - return env->NewString(displayName.getBuffer(), displayName.length()); -} - -static bool getDayIntVector(JNIEnv* env, UResourceBundle* gregorian, int* values) { - // get the First day of week and the minimal days in first week numbers - UErrorCode status = U_ZERO_ERROR; - ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "DateTimeElements", NULL, &status)); - if (U_FAILURE(status)) { - return false; - } - - int intVectSize; - const int* result = ures_getIntVector(gregorianElems.get(), &intVectSize, &status); - if (U_FAILURE(status) || intVectSize != 2) { - return false; - } - - values[0] = result[0]; - values[1] = result[1]; - return true; -} - -static jobjectArray getAmPmMarkers(JNIEnv* env, UResourceBundle* gregorian) { - UErrorCode status = U_ZERO_ERROR; - ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "AmPmMarkers", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ures_resetIterator(gregorianElems.get()); - - int lengthAm, lengthPm; - const jchar* am = ures_getStringByIndex(gregorianElems.get(), 0, &lengthAm, &status); - const jchar* pm = ures_getStringByIndex(gregorianElems.get(), 1, &lengthPm, &status); - - if (U_FAILURE(status)) { - return NULL; - } - - jobjectArray amPmMarkers = env->NewObjectArray(2, string_class, NULL); - jstring amU = env->NewString(am, lengthAm); - env->SetObjectArrayElement(amPmMarkers, 0, amU); - env->DeleteLocalRef(amU); - jstring pmU = env->NewString(pm, lengthPm); - env->SetObjectArrayElement(amPmMarkers, 1, pmU); - env->DeleteLocalRef(pmU); - - return amPmMarkers; -} - -static jobjectArray getEras(JNIEnv* env, UResourceBundle* gregorian) { - UErrorCode status = U_ZERO_ERROR; - ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "eras", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ScopedResourceBundle eraElems(ures_getByKey(gregorianElems.get(), "abbreviated", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - int eraCount = ures_getSize(eraElems.get()); - jobjectArray eras = env->NewObjectArray(eraCount, string_class, NULL); - - ures_resetIterator(eraElems.get()); - for (int i = 0; i < eraCount; ++i) { - int eraLength; - const jchar* era = ures_getStringByIndex(eraElems.get(), i, &eraLength, &status); - if (U_FAILURE(status)) { - return NULL; - } - jstring eraU = env->NewString(era, eraLength); - env->SetObjectArrayElement(eras, i, eraU); - env->DeleteLocalRef(eraU); - } - return eras; -} - -static jobjectArray getMonthNames(JNIEnv* env, UResourceBundle* gregorian, bool longNames) { - UErrorCode status = U_ZERO_ERROR; - ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "monthNames", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ScopedResourceBundle monthNameElems(ures_getByKey(gregorianElems.get(), "format", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ScopedResourceBundle monthNameElemsFormat(ures_getByKey(monthNameElems.get(), longNames ? "wide" : "abbreviated", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ures_resetIterator(monthNameElemsFormat.get()); - int monthCount = ures_getSize(monthNameElemsFormat.get()); - // the array length is +1 because the harmony locales had an empty string at the end of their month name array - jobjectArray months = env->NewObjectArray(monthCount + 1, string_class, NULL); - for (int i = 0; i < monthCount; ++i) { - int monthNameLength; - const jchar* month = ures_getStringByIndex(monthNameElemsFormat.get(), i, &monthNameLength, &status); - if (U_FAILURE(status)) { - return NULL; - } - jstring monthU = env->NewString(month, monthNameLength); - env->SetObjectArrayElement(months, i, monthU); - env->DeleteLocalRef(monthU); - } - - jstring monthU = env->NewStringUTF(""); - env->SetObjectArrayElement(months, monthCount, monthU); - env->DeleteLocalRef(monthU); - - return months; -} - -static jobjectArray getLongMonthNames(JNIEnv* env, UResourceBundle* gregorian) { - return getMonthNames(env, gregorian, true); -} - -static jobjectArray getShortMonthNames(JNIEnv* env, UResourceBundle* gregorian) { - return getMonthNames(env, gregorian, false); -} - -static jobjectArray getWeekdayNames(JNIEnv* env, UResourceBundle* gregorian, bool longNames) { - UErrorCode status = U_ZERO_ERROR; - ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "dayNames", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ScopedResourceBundle dayNameElems(ures_getByKey(gregorianElems.get(), "format", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ScopedResourceBundle dayNameElemsFormat(ures_getByKey(dayNameElems.get(), longNames ? "wide" : "abbreviated", NULL, &status)); - if (U_FAILURE(status)) { - return NULL; - } - - ures_resetIterator(dayNameElemsFormat.get()); - int dayCount = ures_getSize(dayNameElemsFormat.get()); - jobjectArray weekdays = env->NewObjectArray(dayCount + 1, string_class, NULL); - // first entry in the weekdays array is an empty string - env->SetObjectArrayElement(weekdays, 0, env->NewStringUTF("")); - for(int i = 0; i < dayCount; i++) { - int dayNameLength; - const jchar* day = ures_getStringByIndex(dayNameElemsFormat.get(), i, &dayNameLength, &status); - if(U_FAILURE(status)) { - return NULL; - } - jstring dayU = env->NewString(day, dayNameLength); - env->SetObjectArrayElement(weekdays, i + 1, dayU); - env->DeleteLocalRef(dayU); - } - return weekdays; -} - -static jobjectArray getLongWeekdayNames(JNIEnv* env, UResourceBundle* gregorian) { - return getWeekdayNames(env, gregorian, true); -} - -static jobjectArray getShortWeekdayNames(JNIEnv* env, UResourceBundle* gregorian) { - return getWeekdayNames(env, gregorian, false); -} - -static jstring getIntCurrencyCode(JNIEnv* env, jstring locale) { - ScopedUtfChars localeChars(env, locale); - - // Extract the 2-character country name. - if (strlen(localeChars.c_str()) < 5) { - return NULL; - } - if (localeChars[3] < 'A' || localeChars[3] > 'Z' || localeChars[4] < 'A' || localeChars[4] > 'Z') { - return NULL; - } - - char country[3] = { localeChars[3], localeChars[4], 0 }; - return getCurrencyCodeNative(env, NULL, env->NewStringUTF(country)); -} - -static void setIntegerField(JNIEnv* env, jobject obj, const char* fieldName, int value) { - // Convert our int to a java.lang.Integer. - // TODO: switch to Integer.valueOf, add error checking. - jclass integerClass = env->FindClass("java/lang/Integer"); - jmethodID constructor = env->GetMethodID(integerClass, "<init>", "(I)V"); - jobject integerValue = env->NewObject(integerClass, constructor, value); - // Set the field. - jclass localeDataClass = env->FindClass("com/ibm/icu4jni/util/LocaleData"); - jfieldID fid = env->GetFieldID(localeDataClass, fieldName, "Ljava/lang/Integer;"); - env->SetObjectField(obj, fid, integerValue); -} - -static void setStringField(JNIEnv* env, jobject obj, const char* fieldName, jstring value) { - jclass localeDataClass = env->FindClass("com/ibm/icu4jni/util/LocaleData"); - jfieldID fid = env->GetFieldID(localeDataClass, fieldName, "Ljava/lang/String;"); - env->SetObjectField(obj, fid, value); -} - -static void setStringArrayField(JNIEnv* env, jobject obj, const char* fieldName, jobjectArray value) { - jclass localeDataClass = env->FindClass("com/ibm/icu4jni/util/LocaleData"); - jfieldID fid = env->GetFieldID(localeDataClass, fieldName, "[Ljava/lang/String;"); - env->SetObjectField(obj, fid, value); -} - -static void setStringField(JNIEnv* env, jobject obj, const char* fieldName, UResourceBundle* bundle, int index) { - UErrorCode status = U_ZERO_ERROR; - int charCount; - const UChar* chars = ures_getStringByIndex(bundle, index, &charCount, &status); - if (U_SUCCESS(status)) { - setStringField(env, obj, fieldName, env->NewString(chars, charCount)); - } else { - LOGE("Error setting String field %s from ICU resource: %s", fieldName, u_errorName(status)); - } -} - -static void setCharField(JNIEnv* env, jobject obj, const char* fieldName, UResourceBundle* bundle, int index) { - UErrorCode status = U_ZERO_ERROR; - int charCount; - const UChar* chars = ures_getStringByIndex(bundle, index, &charCount, &status); - if (U_SUCCESS(status)) { - jclass localeDataClass = env->FindClass("com/ibm/icu4jni/util/LocaleData"); - jfieldID fid = env->GetFieldID(localeDataClass, fieldName, "C"); - env->SetCharField(obj, fid, chars[0]); - } else { - LOGE("Error setting char field %s from ICU resource: %s", fieldName, u_errorName(status)); - } -} - -static jboolean initLocaleDataImpl(JNIEnv* env, jclass, jstring locale, jobject localeData) { - const char* loc = env->GetStringUTFChars(locale, NULL); - UErrorCode status = U_ZERO_ERROR; - ScopedResourceBundle root(ures_openU(NULL, loc, &status)); - env->ReleaseStringUTFChars(locale, loc); - if (U_FAILURE(status)) { - LOGE("Error getting ICU resource bundle: %s", u_errorName(status)); - status = U_ZERO_ERROR; - return JNI_FALSE; - } - - 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; - } - - int firstDayVals[2]; - if (getDayIntVector(env, gregorian.get(), firstDayVals)) { - setIntegerField(env, localeData, "firstDayOfWeek", firstDayVals[0]); - setIntegerField(env, localeData, "minimalDaysInFirstWeek", firstDayVals[1]); - } - - setStringArrayField(env, localeData, "amPm", getAmPmMarkers(env, gregorian.get())); - setStringArrayField(env, localeData, "eras", getEras(env, gregorian.get())); - - setStringArrayField(env, localeData, "longMonthNames", getLongMonthNames(env, gregorian.get())); - setStringArrayField(env, localeData, "shortMonthNames", getShortMonthNames(env, gregorian.get())); - setStringArrayField(env, localeData, "longWeekdayNames", getLongWeekdayNames(env, gregorian.get())); - setStringArrayField(env, localeData, "shortWeekdayNames", getShortWeekdayNames(env, gregorian.get())); - - ScopedResourceBundle gregorianElems(ures_getByKey(gregorian.get(), "DateTimePatterns", NULL, &status)); - if (U_SUCCESS(status)) { - setStringField(env, localeData, "fullTimeFormat", gregorianElems.get(), 0); - setStringField(env, localeData, "longTimeFormat", gregorianElems.get(), 1); - setStringField(env, localeData, "mediumTimeFormat", gregorianElems.get(), 2); - setStringField(env, localeData, "shortTimeFormat", gregorianElems.get(), 3); - setStringField(env, localeData, "fullDateFormat", gregorianElems.get(), 4); - setStringField(env, localeData, "longDateFormat", gregorianElems.get(), 5); - setStringField(env, localeData, "mediumDateFormat", gregorianElems.get(), 6); - setStringField(env, localeData, "shortDateFormat", gregorianElems.get(), 7); - } - status = U_ZERO_ERROR; - - ScopedResourceBundle numberElements(ures_getByKey(root.get(), "NumberElements", NULL, &status)); - if (U_SUCCESS(status) && ures_getSize(numberElements.get()) >= 11) { - setCharField(env, localeData, "zeroDigit", numberElements.get(), 4); - setCharField(env, localeData, "digit", numberElements.get(), 5); - setCharField(env, localeData, "decimalSeparator", numberElements.get(), 0); - setCharField(env, localeData, "groupingSeparator", numberElements.get(), 1); - setCharField(env, localeData, "patternSeparator", numberElements.get(), 2); - setCharField(env, localeData, "percent", numberElements.get(), 3); - setCharField(env, localeData, "perMill", numberElements.get(), 8); - setCharField(env, localeData, "monetarySeparator", numberElements.get(), 0); - setCharField(env, localeData, "minusSign", numberElements.get(), 6); - setStringField(env, localeData, "exponentSeparator", numberElements.get(), 7); - setStringField(env, localeData, "infinity", numberElements.get(), 9); - setStringField(env, localeData, "NaN", numberElements.get(), 10); - } - status = U_ZERO_ERROR; - - jstring internationalCurrencySymbol = getIntCurrencyCode(env, locale); - jstring currencySymbol = NULL; - if (internationalCurrencySymbol != NULL) { - currencySymbol = getCurrencySymbolNative(env, NULL, locale, internationalCurrencySymbol); - } else { - internationalCurrencySymbol = env->NewStringUTF("XXX"); - } - if (currencySymbol == NULL) { - // This is the UTF-8 encoding of U+00A4 (CURRENCY SIGN). - currencySymbol = env->NewStringUTF("\xc2\xa4"); - } - setStringField(env, localeData, "currencySymbol", currencySymbol); - setStringField(env, localeData, "internationalCurrencySymbol", internationalCurrencySymbol); - - ScopedResourceBundle numberPatterns(ures_getByKey(root.get(), "NumberPatterns", NULL, &status)); - if (U_SUCCESS(status) && ures_getSize(numberPatterns.get()) >= 3) { - setStringField(env, localeData, "numberPattern", numberPatterns.get(), 0); - setStringField(env, localeData, "currencyPattern", numberPatterns.get(), 1); - setStringField(env, localeData, "percentPattern", numberPatterns.get(), 2); - } - - return JNI_TRUE; -} - -static JNINativeMethod gMethods[] = { - {"getAvailableBreakIteratorLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableBreakIteratorLocalesNative}, - {"getAvailableCalendarLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableCalendarLocalesNative}, - {"getAvailableCollatorLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableCollatorLocalesNative}, - {"getAvailableDateFormatLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableDateFormatLocalesNative}, - {"getAvailableLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableLocalesNative}, - {"getAvailableNumberFormatLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableNumberFormatLocalesNative}, - {"getCurrencyCodeNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getCurrencyCodeNative}, - {"getCurrencyFractionDigitsNative", "(Ljava/lang/String;)I", (void*) getCurrencyFractionDigitsNative}, - {"getCurrencySymbolNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getCurrencySymbolNative}, - {"getDisplayCountryNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayCountryNative}, - {"getDisplayLanguageNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayLanguageNative}, - {"getDisplayTimeZoneNative", "(Ljava/lang/String;ZILjava/lang/String;)Ljava/lang/String;", (void*) getDisplayTimeZoneNative}, - {"getDisplayVariantNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayVariantNative}, - {"getISO3CountryNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getISO3CountryNative}, - {"getISO3LanguageNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getISO3LanguageNative}, - {"getISOCountriesNative", "()[Ljava/lang/String;", (void*) getISOCountriesNative}, - {"getISOLanguagesNative", "()[Ljava/lang/String;", (void*) getISOLanguagesNative}, - {"getTimeZonesNative", "([[Ljava/lang/String;Ljava/lang/String;)V", (void*) getTimeZonesNative}, - {"initLocaleDataImpl", "(Ljava/lang/String;Lcom/ibm/icu4jni/util/LocaleData;)Z", (void*) initLocaleDataImpl}, -}; -int register_com_ibm_icu4jni_util_Resources(JNIEnv* env) { - jclass stringclass = env->FindClass("java/lang/String"); - if (stringclass == NULL) { - return -1; - } - string_class = (jclass) env->NewGlobalRef(stringclass); - - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/util/ICU", gMethods, NELEM(gMethods)); -} diff --git a/icu/src/main/native/NativeBreakIterator.cpp b/icu/src/main/native/NativeBreakIterator.cpp deleted file mode 100644 index 0be7630..0000000 --- a/icu/src/main/native/NativeBreakIterator.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#define LOG_TAG "NativeBreakIterator" - -#include "JNIHelp.h" -#include "ErrorCode.h" -#include "ScopedUtfChars.h" -#include "unicode/ubrk.h" -#include "unicode/putil.h" -#include <stdlib.h> - -static jint getIterator(JNIEnv* env, jstring locale, UBreakIteratorType type) { - UErrorCode status = U_ZERO_ERROR; - ScopedUtfChars localeChars(env, locale); - if (!localeChars.c_str()) { - return 0; - } - UBreakIterator* it = ubrk_open(type, localeChars.c_str(), NULL, 0, &status); - icu4jni_error(env, status); - return reinterpret_cast<uintptr_t>(it); -} - -static jint getCharacterInstanceImpl(JNIEnv* env, jclass clazz, jstring locale) { - return getIterator(env, locale, UBRK_CHARACTER); -} - -static jint getLineInstanceImpl(JNIEnv* env, jclass, jstring locale) { - return getIterator(env, locale, UBRK_LINE); -} - -static jint getSentenceInstanceImpl(JNIEnv* env, jclass, jstring locale) { - return getIterator(env, locale, UBRK_SENTENCE); -} - -static jint getWordInstanceImpl(JNIEnv* env, jclass, jstring locale) { - return getIterator(env, locale, UBRK_WORD); -} - -static UBreakIterator* breakIterator(jint address) { - return reinterpret_cast<UBreakIterator*>(static_cast<uintptr_t>(address)); -} - -static void closeBreakIteratorImpl(JNIEnv* env, jclass, jint address) { - ubrk_close(breakIterator(address)); -} - -static jint cloneImpl(JNIEnv* env, jclass, jint address) { - UErrorCode status = U_ZERO_ERROR; - jint bufferSize = U_BRK_SAFECLONE_BUFFERSIZE; - UBreakIterator* it = ubrk_safeClone(breakIterator(address), NULL, &bufferSize, &status); - icu4jni_error(env, status); - return reinterpret_cast<uintptr_t>(it); -} - -static void setTextImpl(JNIEnv* env, jclass, jint address, jstring text) { - UErrorCode status = U_ZERO_ERROR; - const UChar* chars = env->GetStringChars(text, NULL); - ubrk_setText(breakIterator(address), chars, env->GetStringLength(text), &status); - env->ReleaseStringChars(text, chars); - icu4jni_error(env, status); -} - -static jboolean isBoundaryImpl(JNIEnv*, jclass, jint address, jint offset) { - return ubrk_isBoundary(breakIterator(address), offset); -} - -static jint nextImpl(JNIEnv* env, jclass, jint address, jint n) { - UBreakIterator* bi = breakIterator(address); - if (n < 0) { - while (n++ < -1) { - ubrk_previous(bi); - } - return ubrk_previous(bi); - } else if (n == 0) { - return ubrk_current(bi); - } else { - while (n-- > 1) { - ubrk_next(bi); - } - return ubrk_next(bi); - } - return -1; -} - -static jint precedingImpl(JNIEnv*, jclass, jint address, jint offset) { - return ubrk_preceding(breakIterator(address), offset); -} - -static jint firstImpl(JNIEnv*, jclass, jint address) { - return ubrk_first(breakIterator(address)); -} - -static jint followingImpl(JNIEnv*, jclass, jint address, jint offset) { - return ubrk_following(breakIterator(address), offset); -} - -static jint currentImpl(JNIEnv*, jclass, jint address) { - return ubrk_current(breakIterator(address)); -} - -static jint previousImpl(JNIEnv*, jclass, jint address) { - return ubrk_previous(breakIterator(address)); -} - -static jint lastImpl(JNIEnv*, jclass, jint address) { - return ubrk_last(breakIterator(address)); -} - -static JNINativeMethod gMethods[] = { - { "cloneImpl", "(I)I", (void*) cloneImpl }, - { "closeBreakIteratorImpl", "(I)V", (void*) closeBreakIteratorImpl }, - { "currentImpl", "(I)I", (void*) currentImpl }, - { "firstImpl", "(I)I", (void*) firstImpl }, - { "followingImpl", "(II)I", (void*) followingImpl }, - { "getCharacterInstanceImpl", "(Ljava/lang/String;)I", (void*) getCharacterInstanceImpl }, - { "getLineInstanceImpl", "(Ljava/lang/String;)I", (void*) getLineInstanceImpl }, - { "getSentenceInstanceImpl", "(Ljava/lang/String;)I", (void*) getSentenceInstanceImpl }, - { "getWordInstanceImpl", "(Ljava/lang/String;)I", (void*) getWordInstanceImpl }, - { "isBoundaryImpl", "(II)Z", (void*) isBoundaryImpl }, - { "lastImpl", "(I)I", (void*) lastImpl }, - { "nextImpl", "(II)I", (void*) nextImpl }, - { "precedingImpl", "(II)I", (void*) precedingImpl }, - { "previousImpl", "(I)I", (void*) previousImpl }, - { "setTextImpl", "(ILjava/lang/String;)V", (void*) setTextImpl }, -}; -int register_com_ibm_icu4jni_text_NativeBreakIterator(JNIEnv* env) { - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeBreakIterator", - gMethods, NELEM(gMethods)); -} diff --git a/icu/src/main/native/NativeCollation.cpp b/icu/src/main/native/NativeCollation.cpp deleted file mode 100644 index 9a092e8..0000000 --- a/icu/src/main/native/NativeCollation.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/** -******************************************************************************* -* Copyright (C) 1996-2005, International Business Machines Corporation and * -* others. All Rights Reserved. * -******************************************************************************* -* -******************************************************************************* -*/ - -#define LOG_TAG "NativeCollation" - -#include "ErrorCode.h" -#include "JNIHelp.h" -#include "ScopedJavaUnicodeString.h" -#include "ScopedUtfChars.h" -#include "UniquePtr.h" -#include "ucol_imp.h" -#include "unicode/ucol.h" -#include "unicode/ucoleitr.h" - -static UCollator* toCollator(jint address) { - return reinterpret_cast<UCollator*>(static_cast<uintptr_t>(address)); -} - -static UCollationElements* toCollationElements(jint address) { - return reinterpret_cast<UCollationElements*>(static_cast<uintptr_t>(address)); -} - -static void closeCollator(JNIEnv* env, jclass, jint address) { - ucol_close(toCollator(address)); -} - -static void closeElements(JNIEnv* env, jclass, jint address) { - ucol_closeElements(toCollationElements(address)); -} - -static jint compare(JNIEnv* env, jclass, jint address, jstring lhs0, jstring rhs0) { - ScopedJavaUnicodeString lhs(env, lhs0); - ScopedJavaUnicodeString rhs(env, rhs0); - return ucol_strcoll(toCollator(address), - lhs.unicodeString().getBuffer(), lhs.unicodeString().length(), - rhs.unicodeString().getBuffer(), rhs.unicodeString().length()); -} - -static jint getAttribute(JNIEnv* env, jclass, jint address, jint type) { - UErrorCode status = U_ZERO_ERROR; - jint result = ucol_getAttribute(toCollator(address), (UColAttribute) type, &status); - icu4jni_error(env, status); - return result; -} - -static jint getCollationElementIterator(JNIEnv* env, jclass, jint address, jstring source0) { - ScopedJavaUnicodeString source(env, source0); - UErrorCode status = U_ZERO_ERROR; - UCollationElements* result = ucol_openElements(toCollator(address), - source.unicodeString().getBuffer(), source.unicodeString().length(), &status); - icu4jni_error(env, status); - return static_cast<jint>(reinterpret_cast<uintptr_t>(result)); -} - -static jint getMaxExpansion(JNIEnv* env, jclass, jint address, jint order) { - return ucol_getMaxExpansion(toCollationElements(address), order); -} - -static jint getNormalization(JNIEnv* env, jclass, jint address) { - UErrorCode status = U_ZERO_ERROR; - jint result = ucol_getAttribute(toCollator(address), UCOL_NORMALIZATION_MODE, &status); - icu4jni_error(env, status); - return result; -} - -static void setNormalization(JNIEnv* env, jclass, jint address, jint mode) { - UErrorCode status = U_ZERO_ERROR; - ucol_setAttribute(toCollator(address), UCOL_NORMALIZATION_MODE, UColAttributeValue(mode), &status); - icu4jni_error(env, status); -} - -static jint getOffset(JNIEnv* env, jclass, jint address) { - return ucol_getOffset(toCollationElements(address)); -} - -static jstring getRules(JNIEnv* env, jclass, jint address) { - int32_t length = 0; - const UChar* rules = ucol_getRules(toCollator(address), &length); - return env->NewString(rules, length); -} - -static jbyteArray getSortKey(JNIEnv* env, jclass, jint address, jstring source0) { - ScopedJavaUnicodeString source(env, source0); - const UCollator* collator = toCollator(address); - uint8_t byteArray[UCOL_MAX_BUFFER * 2]; - UniquePtr<uint8_t[]> largerByteArray; - uint8_t *usedByteArray = byteArray; - const UChar* chars = source.unicodeString().getBuffer(); - size_t charCount = source.unicodeString().length(); - size_t byteArraySize = ucol_getSortKey(collator, chars, charCount, usedByteArray, sizeof(byteArray) - 1); - if (byteArraySize > sizeof(byteArray) - 1) { - // didn't fit, try again with a larger buffer. - largerByteArray.reset(new uint8_t[byteArraySize + 1]); - usedByteArray = largerByteArray.get(); - byteArraySize = ucol_getSortKey(collator, chars, charCount, usedByteArray, byteArraySize); - } - if (byteArraySize == 0) { - return NULL; - } - jbyteArray result = env->NewByteArray(byteArraySize); - env->SetByteArrayRegion(result, 0, byteArraySize, reinterpret_cast<jbyte*>(usedByteArray)); - return result; -} - -static jint next(JNIEnv* env, jclass, jint address) { - UErrorCode status = U_ZERO_ERROR; - jint result = ucol_next(toCollationElements(address), &status); - icu4jni_error(env, status); - return result; -} - -static jint openCollator(JNIEnv* env, jclass, jstring localeName) { - ScopedUtfChars localeChars(env, localeName); - UErrorCode status = U_ZERO_ERROR; - UCollator* c = ucol_open(localeChars.c_str(), &status); - icu4jni_error(env, status); - return static_cast<jint>(reinterpret_cast<uintptr_t>(c)); -} - -static jint openCollatorFromRules(JNIEnv* env, jclass, jstring rules0, jint mode, jint strength) { - ScopedJavaUnicodeString rules(env, rules0); - UErrorCode status = U_ZERO_ERROR; - UCollator* c = ucol_openRules(rules.unicodeString().getBuffer(), rules.unicodeString().length(), - UColAttributeValue(mode), UCollationStrength(strength), NULL, &status); - icu4jni_error(env, status); - return static_cast<jint>(reinterpret_cast<uintptr_t>(c)); -} - -static jint previous(JNIEnv* env, jclass, jint address) { - UErrorCode status = U_ZERO_ERROR; - jint result = ucol_previous(toCollationElements(address), &status); - icu4jni_error(env, status); - return result; -} - -static void reset(JNIEnv* env, jclass, jint address) { - ucol_reset(toCollationElements(address)); -} - -static jint safeClone(JNIEnv* env, jclass, jint address) { - UErrorCode status = U_ZERO_ERROR; - jint bufferSize = U_COL_SAFECLONE_BUFFERSIZE; - UCollator* c = ucol_safeClone(toCollator(address), NULL, &bufferSize, &status); - icu4jni_error(env, status); - return static_cast<jint>(reinterpret_cast<uintptr_t>(c)); -} - -static void setAttribute(JNIEnv* env, jclass, jint address, jint type, jint value) { - UErrorCode status = U_ZERO_ERROR; - ucol_setAttribute(toCollator(address), (UColAttribute)type, (UColAttributeValue)value, &status); - icu4jni_error(env, status); -} - -static void setOffset(JNIEnv* env, jclass, jint address, jint offset) { - UErrorCode status = U_ZERO_ERROR; - ucol_setOffset(toCollationElements(address), offset, &status); - icu4jni_error(env, status); -} - -static void setText(JNIEnv* env, jclass, jint address, jstring source0) { - ScopedJavaUnicodeString source(env, source0); - UErrorCode status = U_ZERO_ERROR; - ucol_setText(toCollationElements(address), - source.unicodeString().getBuffer(), source.unicodeString().length(), &status); - icu4jni_error(env, status); -} - -static JNINativeMethod gMethods[] = { - { "openCollator", "(Ljava/lang/String;)I", (void*) openCollator }, - { "openCollatorFromRules", "(Ljava/lang/String;II)I", (void*) openCollatorFromRules }, - { "closeCollator", "(I)V", (void*) closeCollator }, - { "compare", "(ILjava/lang/String;Ljava/lang/String;)I", (void*) compare }, - { "getNormalization", "(I)I", (void*) getNormalization }, - { "setNormalization", "(II)V", (void*) setNormalization }, - { "getRules", "(I)Ljava/lang/String;", (void*) getRules }, - { "getSortKey", "(ILjava/lang/String;)[B", (void*) getSortKey }, - { "setAttribute", "(III)V", (void*) setAttribute }, - { "getAttribute", "(II)I", (void*) getAttribute }, - { "safeClone", "(I)I", (void*) safeClone }, - { "getCollationElementIterator", "(ILjava/lang/String;)I", (void*) getCollationElementIterator }, - { "closeElements", "(I)V", (void*) closeElements }, - { "reset", "(I)V", (void*) reset }, - { "next", "(I)I", (void*) next }, - { "previous", "(I)I", (void*) previous }, - { "getMaxExpansion", "(II)I", (void*) getMaxExpansion }, - { "setText", "(ILjava/lang/String;)V", (void*) setText }, - { "getOffset", "(I)I", (void*) getOffset }, - { "setOffset", "(II)V", (void*) setOffset } -}; -int register_com_ibm_icu4jni_text_NativeCollator(JNIEnv* env) { - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeCollation", - gMethods, NELEM(gMethods)); -} diff --git a/icu/src/main/native/NativeConverter.cpp b/icu/src/main/native/NativeConverter.cpp deleted file mode 100644 index 8b3952e..0000000 --- a/icu/src/main/native/NativeConverter.cpp +++ /dev/null @@ -1,1019 +0,0 @@ -/** -******************************************************************************* -* Copyright (C) 1996-2006, International Business Machines Corporation and * -* others. All Rights Reserved. * -******************************************************************************* -* -* -******************************************************************************* -*/ -/* - * @(#) icujniinterface.c 1.2 00/10/11 - * - * (C) Copyright IBM Corp. 2000 - All Rights Reserved - * A JNI wrapper to ICU native converter Interface - * @author: Ram Viswanadha - */ - -#define LOG_TAG "NativeConverter" - -#include "ErrorCode.h" -#include "JNIHelp.h" -#include "ScopedUtfChars.h" -#include "UniquePtr.h" -#include "unicode/ucnv.h" -#include "unicode/ucnv_cb.h" -#include "unicode/uset.h" -#include "unicode/ustring.h" -#include "unicode/utypes.h" -#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 - -/* Prototype of callback for substituting user settable sub chars */ -static void JNI_TO_U_CALLBACK_SUBSTITUTE - (const void *,UConverterToUnicodeArgs *,const char* ,int32_t ,UConverterCallbackReason ,UErrorCode * ); - -static jlong openConverter(JNIEnv* env, jclass, jstring converterName) { - ScopedUtfChars converterNameChars(env, converterName); - if (!converterNameChars.c_str()) { - return 0; - } - UErrorCode errorCode = U_ZERO_ERROR; - UConverter* conv = ucnv_open(converterNameChars.c_str(), &errorCode); - icu4jni_error(env, errorCode); - return (jlong) conv; -} - -static void closeConverter(JNIEnv* env, jclass, jlong handle) { - UConverter* cnv = (UConverter*)(long)handle; - if (cnv) { - // BEGIN android-added - // Free up any contexts created in setCallback[Encode|Decode]() - UConverterToUCallback toAction; - UConverterFromUCallback fromAction; - void* context1 = NULL; - void* context2 = NULL; - // TODO: ICU API bug? - // The documentation clearly states that the caller owns the returned - // pointers: http://icu-project.org/apiref/icu4c/ucnv_8h.html - ucnv_getToUCallBack(cnv, &toAction, const_cast<const void**>(&context1)); - ucnv_getFromUCallBack(cnv, &fromAction, const_cast<const void**>(&context2)); - // END android-added - ucnv_close(cnv); - // BEGIN android-added - if (context1 != NULL) { - free(context1); - } - if (context2 != NULL) { - free(context2); - } - // END android-added - } -} - -/** - * Converts a buffer of Unicode code units to target encoding - * @param env environment handle for JNI - * @param jClass handle for the class - * @param handle address of ICU converter - * @param source buffer of Unicode chars to convert - * @param sourceEnd limit of the source buffer - * @param target buffer to recieve the converted bytes - * @param targetEnd the limit of the target buffer - * @param data buffer to recieve state of the current conversion - * @param flush boolean that specifies end of source input - */ -static jint convertCharToByte(JNIEnv *env, jclass, jlong handle, jcharArray source, jint sourceEnd, jbyteArray target, jint targetEnd, jintArray data, jboolean flush) { - - UErrorCode errorCode =U_ZERO_ERROR; - UConverter* cnv = (UConverter*)handle; - if(cnv) { - jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL); - if(myData) { - jint* sourceOffset = &myData[0]; - jint* targetOffset = &myData[1]; - const jchar* uSource =(jchar*) env->GetPrimitiveArrayCritical(source, NULL); - if(uSource) { - jbyte* uTarget=(jbyte*) env->GetPrimitiveArrayCritical(target,NULL); - if(uTarget) { - const jchar* mySource = uSource+ *sourceOffset; - const UChar* mySourceLimit= uSource+sourceEnd; - char* cTarget = reinterpret_cast<char*>(uTarget+ *targetOffset); - const char* cTargetLimit = reinterpret_cast<const char*>(uTarget+targetEnd); - - ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&mySource, - mySourceLimit,NULL,(UBool) flush, &errorCode); - - *sourceOffset = (jint) (mySource - uSource)-*sourceOffset; - *targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset; - if(U_FAILURE(errorCode)) { - env->ReleasePrimitiveArrayCritical(target,uTarget,0); - env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0); - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return errorCode; - } - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(target,uTarget,0); - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0); - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return errorCode; - } - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - return errorCode; -} - -static jint encode(JNIEnv *env, jclass, jlong handle, jcharArray source, jint sourceEnd, jbyteArray target, jint targetEnd, jintArray data, jboolean flush) { - - UErrorCode ec = UErrorCode(convertCharToByte(env, NULL,handle,source,sourceEnd, target,targetEnd,data,flush)); - UConverter* cnv = (UConverter*)handle; - jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL); - - if(cnv && myData) { - - UErrorCode errorCode = U_ZERO_ERROR; - myData[3] = ucnv_fromUCountPending(cnv, &errorCode); - - if(ec == U_ILLEGAL_CHAR_FOUND || ec == U_INVALID_CHAR_FOUND) { - int8_t count =32; - UChar invalidUChars[32]; - ucnv_getInvalidUChars(cnv,invalidUChars,&count,&errorCode); - - if(U_SUCCESS(errorCode)) { - myData[2] = count; - } - } - } - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return ec; -} - -/** - * Converts a buffer of encoded bytes to Unicode code units - * @param env environment handle for JNI - * @param jClass handle for the class - * @param handle address of ICU converter - * @param source buffer of Unicode chars to convert - * @param sourceEnd limit of the source buffer - * @param target buffer to recieve the converted bytes - * @param targetEnd the limit of the target buffer - * @param data buffer to recieve state of the current conversion - * @param flush boolean that specifies end of source input - */ -static jint convertByteToChar(JNIEnv *env, jclass, jlong handle, jbyteArray source, jint sourceEnd, jcharArray target, jint targetEnd, jintArray data, jboolean flush) { - - UErrorCode errorCode =U_ZERO_ERROR; - UConverter* cnv = (UConverter*)handle; - if(cnv) { - jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL); - if(myData) { - jint* sourceOffset = &myData[0]; - jint* targetOffset = &myData[1]; - - const jbyte* uSource =(jbyte*) env->GetPrimitiveArrayCritical(source, NULL); - if(uSource) { - jchar* uTarget=(jchar*) env->GetPrimitiveArrayCritical(target,NULL); - if(uTarget) { - const jbyte* mySource = uSource+ *sourceOffset; - const char* mySourceLimit = reinterpret_cast<const char*>(uSource+sourceEnd); - UChar* cTarget=uTarget+ *targetOffset; - const UChar* cTargetLimit=uTarget+targetEnd; - - ucnv_toUnicode( cnv , &cTarget, cTargetLimit,(const char**)&mySource, - mySourceLimit,NULL,(UBool) flush, &errorCode); - - *sourceOffset = mySource - uSource - *sourceOffset ; - *targetOffset = cTarget - uTarget - *targetOffset; - if(U_FAILURE(errorCode)) { - env->ReleasePrimitiveArrayCritical(target,uTarget,0); - env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0); - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return errorCode; - } - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(target,uTarget,0); - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0); - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return errorCode; - } - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - return errorCode; -} - -static jint decode(JNIEnv *env, jclass, jlong handle, jbyteArray source, jint sourceEnd, jcharArray target, jint targetEnd, jintArray data, jboolean flush) { - - jint ec = convertByteToChar(env, NULL,handle,source,sourceEnd, target,targetEnd,data,flush); - - jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL); - UConverter* cnv = (UConverter*)handle; - - if(myData && cnv) { - UErrorCode errorCode = U_ZERO_ERROR; - myData[3] = ucnv_toUCountPending(cnv, &errorCode); - - if(ec == U_ILLEGAL_CHAR_FOUND || ec == U_INVALID_CHAR_FOUND ) { - char invalidChars[32] = {'\0'}; - int8_t len = 32; - ucnv_getInvalidChars(cnv,invalidChars,&len,&errorCode); - - if(U_SUCCESS(errorCode)) { - myData[2] = len; - } - } - } - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return ec; -} - -static void resetByteToChar(JNIEnv* env, jclass, jlong handle) { - UConverter* cnv = (UConverter*)handle; - if (cnv) { - ucnv_resetToUnicode(cnv); - } -} - -static void resetCharToByte(JNIEnv* env, jclass, jlong handle) { - UConverter* cnv = (UConverter*)handle; - if (cnv) { - ucnv_resetFromUnicode(cnv); - } -} - -static jint getMaxBytesPerChar(JNIEnv *env, jclass, jlong handle) { - UConverter* cnv = (UConverter*)handle; - return (cnv != NULL) ? ucnv_getMaxCharSize(cnv) : -1; -} - -static jint getMinBytesPerChar(JNIEnv *env, jclass, jlong handle) { - UConverter* cnv = (UConverter*)handle; - return (cnv != NULL) ? ucnv_getMinCharSize(cnv) : -1; -} - -static jfloat getAveBytesPerChar(JNIEnv *env, jclass, jlong handle) { - UConverter* cnv = (UConverter*)handle; - if (cnv) { - jfloat max = (jfloat)ucnv_getMaxCharSize(cnv); - jfloat min = (jfloat)ucnv_getMinCharSize(cnv); - return (jfloat) ( (max+min)/2 ); - } - return -1; -} - -static jint flushByteToChar(JNIEnv *env, jclass,jlong handle, jcharArray target, jint targetEnd, jintArray data) { - - UErrorCode errorCode =U_ZERO_ERROR; - UConverter* cnv = (UConverter*)handle; - if(cnv) { - jbyte source ='\0'; - jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL); - if(myData) { - jint* targetOffset = &myData[1]; - jchar* uTarget=(jchar*) env->GetPrimitiveArrayCritical(target,NULL); - if(uTarget) { - const jbyte* mySource = &source; - const char* mySourceLimit = reinterpret_cast<char*>(&source); - UChar* cTarget=uTarget+ *targetOffset; - const UChar* cTargetLimit=uTarget+targetEnd; - - ucnv_toUnicode( cnv , &cTarget, cTargetLimit,(const char**)&mySource, - mySourceLimit,NULL,TRUE, &errorCode); - - - *targetOffset = (jint) ((jchar*)cTarget - uTarget)- *targetOffset; - if(U_FAILURE(errorCode)) { - env->ReleasePrimitiveArrayCritical(target,uTarget,0); - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return errorCode; - } - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(target,uTarget,0); - - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return errorCode; - } - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - return errorCode; -} - -static jint flushCharToByte (JNIEnv *env, jclass, jlong handle, jbyteArray target, jint targetEnd, jintArray data) { - - UErrorCode errorCode =U_ZERO_ERROR; - UConverter* cnv = (UConverter*)handle; - jchar source = '\0'; - if(cnv) { - jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL); - if(myData) { - jint* targetOffset = &myData[1]; - jbyte* uTarget=(jbyte*) env->GetPrimitiveArrayCritical(target,NULL); - if(uTarget) { - const jchar* mySource = &source; - const UChar* mySourceLimit= &source; - char* cTarget = reinterpret_cast<char*>(uTarget+ *targetOffset); - const char* cTargetLimit = reinterpret_cast<char*>(uTarget+targetEnd); - - ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&mySource, - mySourceLimit,NULL,TRUE, &errorCode); - - - *targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset; - if(U_FAILURE(errorCode)) { - env->ReleasePrimitiveArrayCritical(target,uTarget,0); - - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return errorCode; - } - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(target,uTarget,0); - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0); - return errorCode; - } - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - return errorCode; -} - -static void toChars(const UChar* us, char* cs, int32_t length) { - while (length > 0) { - UChar u = *us++; - *cs++=(char)u; - --length; - } -} -static jint setSubstitutionBytes(JNIEnv *env, jclass, jlong handle, jbyteArray subChars, jint length) { - UConverter* cnv = (UConverter*) handle; - UErrorCode errorCode = U_ZERO_ERROR; - if (cnv) { - jbyte* u_subChars = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(subChars, NULL)); - if (u_subChars) { - char mySubChars[length]; - toChars((UChar*)u_subChars,&mySubChars[0],length); - ucnv_setSubstChars(cnv,mySubChars, (char)length,&errorCode); - if(U_FAILURE(errorCode)) { - env->ReleasePrimitiveArrayCritical(subChars,mySubChars,0); - return errorCode; - } - } else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(subChars,u_subChars,0); - return errorCode; - } - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - return errorCode; -} - - -#define VALUE_STRING_LENGTH 32 - -struct SubCharStruct { - int length; - UChar subChars[256]; - UBool stopOnIllegal; -}; - - -static UErrorCode -setToUCallbackSubs(UConverter* cnv,UChar* subChars, int32_t length,UBool stopOnIllegal ) { - SubCharStruct* substitutionCharS = (SubCharStruct*) malloc(sizeof(SubCharStruct)); - UErrorCode errorCode = U_ZERO_ERROR; - if(substitutionCharS) { - UConverterToUCallback toUOldAction; - void* toUOldContext=NULL; - void* toUNewContext=NULL ; - if(subChars) { - u_strncpy(substitutionCharS->subChars,subChars,length); - }else{ - substitutionCharS->subChars[length++] =0xFFFD; - } - substitutionCharS->subChars[length]=0; - substitutionCharS->length = length; - substitutionCharS->stopOnIllegal = stopOnIllegal; - toUNewContext = substitutionCharS; - - ucnv_setToUCallBack(cnv, - JNI_TO_U_CALLBACK_SUBSTITUTE, - toUNewContext, - &toUOldAction, - (const void**)&toUOldContext, - &errorCode); - - if(toUOldContext) { - SubCharStruct* temp = (SubCharStruct*) toUOldContext; - free(temp); - } - - return errorCode; - } - return U_MEMORY_ALLOCATION_ERROR; -} -static jint setSubstitutionChars(JNIEnv *env, jclass, jlong handle, jcharArray subChars, jint length) { - - UErrorCode errorCode = U_ZERO_ERROR; - UConverter* cnv = (UConverter*) handle; - jchar* u_subChars=NULL; - if(cnv) { - if(subChars) { - int len = env->GetArrayLength(subChars); - u_subChars = reinterpret_cast<jchar*>(env->GetPrimitiveArrayCritical(subChars,NULL)); - if(u_subChars) { - errorCode = setToUCallbackSubs(cnv,u_subChars,len,FALSE); - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - env->ReleasePrimitiveArrayCritical(subChars,u_subChars,0); - return errorCode; - } - } - return U_ILLEGAL_ARGUMENT_ERROR; -} - - -static void JNI_TO_U_CALLBACK_SUBSTITUTE( const void *context, UConverterToUnicodeArgs *toArgs, const char* codeUnits, int32_t length, UConverterCallbackReason reason, UErrorCode * err) { - - if(context) { - SubCharStruct* temp = (SubCharStruct*)context; - if( temp) { - if(temp->stopOnIllegal==FALSE) { - if (reason > UCNV_IRREGULAR) { - return; - } - /* reset the error */ - *err = U_ZERO_ERROR; - ucnv_cbToUWriteUChars(toArgs,temp->subChars ,temp->length , 0, err); - }else{ - if(reason != UCNV_UNASSIGNED) { - /* the caller must have set - * the error code accordingly - */ - return; - }else{ - *err = U_ZERO_ERROR; - ucnv_cbToUWriteUChars(toArgs,temp->subChars ,temp->length , 0, err); - return; - } - } - } - } - return; -} - -static jboolean canEncode(JNIEnv *env, jclass, jlong handle, jint codeUnit) { - - UErrorCode errorCode =U_ZERO_ERROR; - UConverter* cnv = (UConverter*)handle; - if(cnv) { - UChar source[3]; - UChar *mySource=source; - const UChar* sourceLimit = (codeUnit<0x010000) ? &source[1] : &source[2]; - char target[5]; - char *myTarget = target; - const char* targetLimit = &target[4]; - int i=0; - UTF_APPEND_CHAR(&source[0],i,2,codeUnit); - - ucnv_fromUnicode(cnv,&myTarget,targetLimit, - (const UChar**)&mySource, - sourceLimit,NULL, TRUE,&errorCode); - - if(U_SUCCESS(errorCode)) { - return (jboolean)TRUE; - } - } - return (jboolean)FALSE; -} - -/* - * If a charset listed in the IANA Charset Registry is supported by an implementation - * of the Java platform then its canonical name must be the name listed in the registry. - * Many charsets are given more than one name in the registry, in which case the registry - * identifies one of the names as MIME-preferred. If a charset has more than one registry - * name then its canonical name must be the MIME-preferred name and the other names in - * the registry must be valid aliases. If a supported charset is not listed in the IANA - * registry then its canonical name must begin with one of the strings "X-" or "x-". - */ -static jstring getJavaCanonicalName(JNIEnv *env, const char* icuCanonicalName) { - UErrorCode status = U_ZERO_ERROR; - - // Check to see if this is a well-known MIME or IANA name. - const char* cName = NULL; - if ((cName = ucnv_getStandardName(icuCanonicalName, "MIME", &status)) != NULL) { - return env->NewStringUTF(cName); - } else if ((cName = ucnv_getStandardName(icuCanonicalName, "IANA", &status)) != NULL) { - return env->NewStringUTF(cName); - } - - // Check to see if an alias already exists with "x-" prefix, if yes then - // make that the canonical name. - int32_t aliasCount = ucnv_countAliases(icuCanonicalName, &status); - for (int i = 0; i < aliasCount; ++i) { - const char* name = ucnv_getAlias(icuCanonicalName, i, &status); - if (name != NULL && name[0] == 'x' && name[1] == '-') { - return env->NewStringUTF(name); - } - } - - // As a last resort, prepend "x-" to any alias and make that the canonical name. - status = U_ZERO_ERROR; - const char* name = ucnv_getStandardName(icuCanonicalName, "UTR22", &status); - if (name == NULL && strchr(icuCanonicalName, ',') != NULL) { - name = ucnv_getAlias(icuCanonicalName, 1, &status); - } - // If there is no UTR22 canonical name then just return the original name. - if (name == NULL) { - name = icuCanonicalName; - } - UniquePtr<char[]> result(new char[2 + strlen(name) + 1]); - strcpy(&result[0], "x-"); - strcat(&result[0], name); - return env->NewStringUTF(&result[0]); -} - -static jobjectArray getAvailableCharsetNames(JNIEnv *env, jclass) { - int32_t num = ucnv_countAvailable(); - jobjectArray result = env->NewObjectArray(num, env->FindClass("java/lang/String"), NULL); - for (int i = 0; i < num; ++i) { - const char* name = ucnv_getAvailableName(i); - jstring javaCanonicalName = getJavaCanonicalName(env, name); - env->SetObjectArrayElement(result, i, javaCanonicalName); - env->DeleteLocalRef(javaCanonicalName); - } - return result; -} - -static jobjectArray getAliases(JNIEnv* env, const char* icuCanonicalName) { - // Get an upper bound on the number of aliases... - const char* myEncName = icuCanonicalName; - UErrorCode error = U_ZERO_ERROR; - int32_t aliasCount = ucnv_countAliases(myEncName, &error); - if (aliasCount == 0 && myEncName[0] == 'x' && myEncName[1] == '-') { - myEncName = myEncName + 2; - aliasCount = ucnv_countAliases(myEncName, &error); - } - if (!U_SUCCESS(error)) { - return NULL; - } - - // Collect the aliases we want... - const char* aliasArray[aliasCount]; - int actualAliasCount = 0; - for(int i = 0; i < aliasCount; ++i) { - const char* name = ucnv_getAlias(myEncName, (uint16_t) i, &error); - if (!U_SUCCESS(error)) { - return NULL; - } - // TODO: why do we ignore these ones? - if (strchr(name, '+') == 0 && strchr(name, ',') == 0) { - aliasArray[actualAliasCount++]= name; - } - } - - // Convert our C++ char*[] into a Java String[]... - jobjectArray result = env->NewObjectArray(actualAliasCount, env->FindClass("java/lang/String"), NULL); - for (int i = 0; i < actualAliasCount; ++i) { - jstring alias = env->NewStringUTF(aliasArray[i]); - env->SetObjectArrayElement(result, i, alias); - env->DeleteLocalRef(alias); - } - return result; -} - -static const char* getICUCanonicalName(const char* name) { - UErrorCode error = U_ZERO_ERROR; - const char* canonicalName = NULL; - if ((canonicalName = ucnv_getCanonicalName(name, "MIME", &error)) != NULL) { - return canonicalName; - } else if((canonicalName = ucnv_getCanonicalName(name, "IANA", &error)) != NULL) { - return canonicalName; - } else if((canonicalName = ucnv_getCanonicalName(name, "", &error)) != NULL) { - return canonicalName; - } else if((canonicalName = ucnv_getAlias(name, 0, &error)) != NULL) { - /* we have some aliases in the form x-blah .. match those first */ - return canonicalName; - } else if (strstr(name, "x-") == name) { - /* check if the converter can be opened with the name given */ - error = U_ZERO_ERROR; - UConverter* conv = ucnv_open(name + 2, &error); - if (conv != NULL) { - ucnv_close(conv); - return name + 2; - } - } - return NULL; -} - -#define SUBS_ARRAY_CAPACITY 256 -struct EncoderCallbackContext { - int length; - char subChars[SUBS_ARRAY_CAPACITY]; - UConverterFromUCallback onUnmappableInput; - UConverterFromUCallback onMalformedInput; -}; - -static void CHARSET_ENCODER_CALLBACK(const void *context, - UConverterFromUnicodeArgs *fromArgs, - const UChar* codeUnits, - int32_t length, - UChar32 codePoint, - UConverterCallbackReason reason, - UErrorCode * status) { - if(context) { - EncoderCallbackContext* ctx = (EncoderCallbackContext*)context; - - if(ctx) { - UConverterFromUCallback realCB = NULL; - switch(reason) { - case UCNV_UNASSIGNED: - realCB = ctx->onUnmappableInput; - break; - case UCNV_ILLEGAL:/*malformed input*/ - case UCNV_IRREGULAR:/*malformed input*/ - realCB = ctx->onMalformedInput; - break; - /* - case UCNV_RESET: - ucnv_resetToUnicode(args->converter); - break; - case UCNV_CLOSE: - ucnv_close(args->converter); - break; - case UCNV_CLONE: - ucnv_clone(args->clone); - */ - default: - *status = U_ILLEGAL_ARGUMENT_ERROR; - return; - } - if (realCB == NULL) { - *status = U_INTERNAL_PROGRAM_ERROR; - } else { - realCB(context, fromArgs, codeUnits, length, codePoint, reason, status); - } - } - } -} - -static void JNI_FROM_U_CALLBACK_SUBSTITUTE_ENCODER(const void *context, - UConverterFromUnicodeArgs *fromArgs, - const UChar* codeUnits, - int32_t length, - UChar32 codePoint, - UConverterCallbackReason reason, - UErrorCode * err) { - if(context) { - EncoderCallbackContext* temp = (EncoderCallbackContext*)context; - *err = U_ZERO_ERROR; - ucnv_cbFromUWriteBytes(fromArgs,temp->subChars ,temp->length , 0, err); - } - return; -} - -static UConverterFromUCallback getFromUCallback(int32_t mode) { - switch(mode) { - default: /* falls through */ - case com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK: - return UCNV_FROM_U_CALLBACK_STOP; - case com_ibm_icu4jni_converters_NativeConverter_SKIP_CALLBACK: - return UCNV_FROM_U_CALLBACK_SKIP ; - case com_ibm_icu4jni_converters_NativeConverter_SUBSTITUTE_CALLBACK: - return JNI_FROM_U_CALLBACK_SUBSTITUTE_ENCODER; - } -} - -static jint setCallbackEncode(JNIEnv *env, jclass, jlong handle, jint onMalformedInput, jint onUnmappableInput, jbyteArray subChars, jint length) { - - UConverter* conv = (UConverter*)handle; - UErrorCode errorCode =U_ZERO_ERROR; - - if(conv) { - - UConverterFromUCallback fromUOldAction = NULL; - void* fromUOldContext = NULL; - EncoderCallbackContext* fromUNewContext=NULL; - UConverterFromUCallback fromUNewAction=NULL; - jbyte* sub = (jbyte*) env->GetPrimitiveArrayCritical(subChars, NULL); - ucnv_getFromUCallBack(conv, &fromUOldAction, const_cast<const void**>(&fromUOldContext)); - - /* fromUOldContext can only be DecodeCallbackContext since - the converter created is private data for the decoder - and callbacks can only be set via this method! - */ - if(fromUOldContext==NULL) { - fromUNewContext = (EncoderCallbackContext*) malloc(sizeof(EncoderCallbackContext)); - fromUNewAction = CHARSET_ENCODER_CALLBACK; - }else{ - fromUNewContext = (EncoderCallbackContext*) fromUOldContext; - fromUNewAction = fromUOldAction; - fromUOldAction = NULL; - fromUOldContext = NULL; - } - fromUNewContext->onMalformedInput = getFromUCallback(onMalformedInput); - fromUNewContext->onUnmappableInput = getFromUCallback(onUnmappableInput); - // BEGIN android-changed - if(sub!=NULL) { - fromUNewContext->length = length; - const char* src = const_cast<const char*>(reinterpret_cast<char*>(sub)); - strncpy(fromUNewContext->subChars, src, length); - env->ReleasePrimitiveArrayCritical(subChars, sub, 0); - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - // END android-changed - - ucnv_setFromUCallBack(conv, - fromUNewAction, - fromUNewContext, - &fromUOldAction, - (const void**)&fromUOldContext, - &errorCode); - - - return errorCode; - } - return U_ILLEGAL_ARGUMENT_ERROR; -} - -struct DecoderCallbackContext { - int length; - UChar subUChars[256]; - UConverterToUCallback onUnmappableInput; - UConverterToUCallback onMalformedInput; -}; - -static void JNI_TO_U_CALLBACK_SUBSTITUTE_DECODER(const void *context, - UConverterToUnicodeArgs *toArgs, - const char* codeUnits, - int32_t length, - UConverterCallbackReason reason, - UErrorCode * err) { - if(context) { - DecoderCallbackContext* temp = (DecoderCallbackContext*)context; - *err = U_ZERO_ERROR; - ucnv_cbToUWriteUChars(toArgs,temp->subUChars ,temp->length , 0, err); - } - return; -} - -static UConverterToUCallback getToUCallback(int32_t mode) { - switch(mode) { - default: /* falls through */ - case com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK: - return UCNV_TO_U_CALLBACK_STOP; - case com_ibm_icu4jni_converters_NativeConverter_SKIP_CALLBACK: - return UCNV_TO_U_CALLBACK_SKIP ; - case com_ibm_icu4jni_converters_NativeConverter_SUBSTITUTE_CALLBACK: - return JNI_TO_U_CALLBACK_SUBSTITUTE_DECODER; - } -} - -static void CHARSET_DECODER_CALLBACK(const void *context, - UConverterToUnicodeArgs *args, - const char* codeUnits, - int32_t length, - UConverterCallbackReason reason, - UErrorCode *status ) { - - if(context) { - DecoderCallbackContext* ctx = (DecoderCallbackContext*)context; - - if(ctx) { - UConverterToUCallback realCB = NULL; - switch(reason) { - case UCNV_UNASSIGNED: - realCB = ctx->onUnmappableInput; - break; - case UCNV_ILLEGAL:/*malformed input*/ - case UCNV_IRREGULAR:/*malformed input*/ - realCB = ctx->onMalformedInput; - break; - /* - case UCNV_RESET: - ucnv_resetToUnicode(args->converter); - break; - case UCNV_CLOSE: - ucnv_close(args->converter); - break; - case UCNV_CLONE: - ucnv_clone(args->clone); - */ - default: - *status = U_ILLEGAL_ARGUMENT_ERROR; - return; - } - if (realCB == NULL) { - *status = U_INTERNAL_PROGRAM_ERROR; - } else { - realCB(context, args, codeUnits, length, reason, status); - } - } - } -} - -static jint setCallbackDecode(JNIEnv *env, jclass, jlong handle, jint onMalformedInput, jint onUnmappableInput, jcharArray subChars, jint length) { - - UConverter* conv = (UConverter*)handle; - UErrorCode errorCode =U_ZERO_ERROR; - if(conv) { - - UConverterToUCallback toUOldAction ; - void* toUOldContext; - DecoderCallbackContext* toUNewContext = NULL; - UConverterToUCallback toUNewAction = NULL; - jchar* sub = (jchar*) env->GetPrimitiveArrayCritical(subChars, NULL); - - ucnv_getToUCallBack(conv, &toUOldAction, const_cast<const void**>(&toUOldContext)); - - /* toUOldContext can only be DecodeCallbackContext since - the converter created is private data for the decoder - and callbacks can only be set via this method! - */ - if(toUOldContext==NULL) { - toUNewContext = (DecoderCallbackContext*) malloc(sizeof(DecoderCallbackContext)); - toUNewAction = CHARSET_DECODER_CALLBACK; - }else{ - toUNewContext = reinterpret_cast<DecoderCallbackContext*>(toUOldContext); - toUNewAction = toUOldAction; - toUOldAction = NULL; - toUOldContext = NULL; - } - toUNewContext->onMalformedInput = getToUCallback(onMalformedInput); - toUNewContext->onUnmappableInput = getToUCallback(onUnmappableInput); - // BEGIN android-changed - if(sub!=NULL) { - toUNewContext->length = length; - u_strncpy(toUNewContext->subUChars, sub, length); - env->ReleasePrimitiveArrayCritical(subChars, sub, 0); - }else{ - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - } - // END android-changed - ucnv_setToUCallBack(conv, - toUNewAction, - toUNewContext, - &toUOldAction, - (const void**)&toUOldContext, - &errorCode); - - return errorCode; - } - return U_ILLEGAL_ARGUMENT_ERROR; -} - -static jint getMaxCharsPerByte(JNIEnv *env, jclass, jlong handle) { - /* - * currently we know that max number of chars per byte is 2 - */ - return 2; -} - -static jfloat getAveCharsPerByte(JNIEnv *env, jclass, jlong handle) { - return (1 / (jfloat) getMaxBytesPerChar(env, NULL, handle)); -} - -static jbyteArray getSubstitutionBytes(JNIEnv *env, jclass, jlong handle) { - const UConverter * cnv = (const UConverter *) handle; - if (cnv) { - UErrorCode status = U_ZERO_ERROR; - char subBytes[10]; - int8_t len =(char)10; - ucnv_getSubstChars(cnv,subBytes,&len,&status); - if(U_SUCCESS(status)) { - jbyteArray arr = env->NewByteArray(len); - if (arr) { - env->SetByteArrayRegion(arr,0,len,(jbyte*)subBytes); - } - return arr; - } - } - return env->NewByteArray(0); -} - -static jboolean contains(JNIEnv* env, jclass, jlong handle1, jlong handle2) { - UErrorCode status = U_ZERO_ERROR; - const UConverter * cnv1 = (const UConverter *) handle1; - const UConverter * cnv2 = (const UConverter *) handle2; - UBool bRet = 0; - - if(cnv1 != NULL && cnv2 != NULL) { - /* open charset 1 */ - USet* set1 = uset_open(1, 2); - ucnv_getUnicodeSet(cnv1, set1, UCNV_ROUNDTRIP_SET, &status); - - if(U_SUCCESS(status)) { - /* open charset 2 */ - status = U_ZERO_ERROR; - USet* set2 = uset_open(1, 2); - ucnv_getUnicodeSet(cnv2, set2, UCNV_ROUNDTRIP_SET, &status); - - /* contains? */ - if(U_SUCCESS(status)) { - bRet = uset_containsAll(set1, set2); - uset_close(set2); - } - uset_close(set1); - } - } - return bRet; -} - -static jobject charsetForName(JNIEnv* env, jclass, jstring charsetName) { - ScopedUtfChars charsetNameChars(env, charsetName); - if (!charsetNameChars.c_str()) { - return NULL; - } - // Get ICU's canonical name for this charset. - const char* icuCanonicalName = getICUCanonicalName(charsetNameChars.c_str()); - if (icuCanonicalName == NULL) { - return NULL; - } - // Get Java's canonical name for this charset. - jstring javaCanonicalName = getJavaCanonicalName(env, icuCanonicalName); - if (env->ExceptionOccurred()) { - return NULL; - } - - // Check that this charset is supported. - // ICU doesn't offer any "isSupported", so we just open and immediately close. - // We ignore the UErrorCode because ucnv_open returning NULL is all the information we need. - UErrorCode dummy = U_ZERO_ERROR; - UConverter* conv = ucnv_open(icuCanonicalName, &dummy); - if (conv == NULL) { - return NULL; - } - ucnv_close(conv); - - // Get the aliases for this charset. - jobjectArray aliases = getAliases(env, icuCanonicalName); - if (env->ExceptionOccurred()) { - return NULL; - } - - // Construct the CharsetICU object. - jclass charsetClass = env->FindClass("com/ibm/icu4jni/charset/CharsetICU"); - if (env->ExceptionOccurred()) { - return NULL; - } - jmethodID charsetConstructor = env->GetMethodID(charsetClass, "<init>", - "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V"); - if (env->ExceptionOccurred()) { - return NULL; - } - return env->NewObject(charsetClass, charsetConstructor, - javaCanonicalName, env->NewStringUTF(icuCanonicalName), aliases); -} - -static JNINativeMethod gMethods[] = { - { "canEncode", "(JI)Z", (void*) canEncode }, - { "charsetForName", "(Ljava/lang/String;)Ljava/nio/charset/Charset;", (void*) charsetForName }, - { "closeConverter", "(J)V", (void*) closeConverter }, - { "contains", "(JJ)Z", (void*) contains }, - { "decode", "(J[BI[CI[IZ)I", (void*) decode }, - { "encode", "(J[CI[BI[IZ)I", (void*) encode }, - { "flushByteToChar", "(J[CI[I)I", (void*) flushByteToChar }, - { "flushCharToByte", "(J[BI[I)I", (void*) flushCharToByte }, - { "getAvailableCharsetNames", "()[Ljava/lang/String;", (void*) getAvailableCharsetNames }, - { "getAveBytesPerChar", "(J)F", (void*) getAveBytesPerChar }, - { "getAveCharsPerByte", "(J)F", (void*) getAveCharsPerByte }, - { "getMaxBytesPerChar", "(J)I", (void*) getMaxBytesPerChar }, - { "getMaxCharsPerByte", "(J)I", (void*) getMaxCharsPerByte }, - { "getMinBytesPerChar", "(J)I", (void*) getMinBytesPerChar }, - { "getSubstitutionBytes", "(J)[B", (void*) getSubstitutionBytes }, - { "openConverter", "(Ljava/lang/String;)J", (void*) openConverter }, - { "resetByteToChar", "(J)V", (void*) resetByteToChar }, - { "resetCharToByte", "(J)V", (void*) resetCharToByte }, - { "setCallbackDecode", "(JII[CI)I", (void*) setCallbackDecode }, - { "setCallbackEncode", "(JII[BI)I", (void*) setCallbackEncode }, - { "setSubstitutionBytes", "(J[BI)I", (void*) setSubstitutionBytes }, - { "setSubstitutionChars", "(J[CI)I", (void*) setSubstitutionChars }, -}; -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/NativeDecimalFormat.cpp b/icu/src/main/native/NativeDecimalFormat.cpp deleted file mode 100644 index 8f39a39..0000000 --- a/icu/src/main/native/NativeDecimalFormat.cpp +++ /dev/null @@ -1,608 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#define LOG_TAG "NativeDecimalFormat" - -#include "JNIHelp.h" -#include "cutils/log.h" -#include "unicode/unum.h" -#include "unicode/numfmt.h" -#include "unicode/decimfmt.h" -#include "unicode/fmtable.h" -#include "unicode/ustring.h" -#include "digitlst.h" -#include "ErrorCode.h" -#include "ScopedJavaUnicodeString.h" -#include <stdlib.h> -#include <string.h> - -static DecimalFormat* toDecimalFormat(jint addr) { - return reinterpret_cast<DecimalFormat*>(static_cast<uintptr_t>(addr)); -} - -static DecimalFormatSymbols* makeDecimalFormatSymbols(JNIEnv* env, - jstring currencySymbol0, jchar decimalSeparator, jchar digit, - jchar groupingSeparator0, jstring infinity0, - jstring internationalCurrencySymbol0, jchar minusSign, - jchar monetaryDecimalSeparator, jstring nan0, jchar patternSeparator, - jchar percent, jchar perMill, jchar zeroDigit) { - ScopedJavaUnicodeString currencySymbol(env, currencySymbol0); - ScopedJavaUnicodeString infinity(env, infinity0); - ScopedJavaUnicodeString internationalCurrencySymbol(env, internationalCurrencySymbol0); - ScopedJavaUnicodeString nan(env, nan0); - UnicodeString groupingSeparator(groupingSeparator0); - - DecimalFormatSymbols* result = new DecimalFormatSymbols; - result->setSymbol(DecimalFormatSymbols::kCurrencySymbol, currencySymbol.unicodeString()); - result->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, UnicodeString(decimalSeparator)); - result->setSymbol(DecimalFormatSymbols::kDigitSymbol, UnicodeString(digit)); - result->setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, groupingSeparator); - result->setSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol, groupingSeparator); - result->setSymbol(DecimalFormatSymbols::kInfinitySymbol, infinity.unicodeString()); - result->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, internationalCurrencySymbol.unicodeString()); - result->setSymbol(DecimalFormatSymbols::kMinusSignSymbol, UnicodeString(minusSign)); - result->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, UnicodeString(monetaryDecimalSeparator)); - result->setSymbol(DecimalFormatSymbols::kNaNSymbol, nan.unicodeString()); - result->setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, UnicodeString(patternSeparator)); - result->setSymbol(DecimalFormatSymbols::kPercentSymbol, UnicodeString(percent)); - result->setSymbol(DecimalFormatSymbols::kPerMillSymbol, UnicodeString(perMill)); - result->setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, UnicodeString(zeroDigit)); - return result; -} - -static void setDecimalFormatSymbols(JNIEnv* env, jclass, jint addr, - jstring currencySymbol, jchar decimalSeparator, jchar digit, - jchar groupingSeparator, jstring infinity, - jstring internationalCurrencySymbol, jchar minusSign, - jchar monetaryDecimalSeparator, jstring nan, jchar patternSeparator, - jchar percent, jchar perMill, jchar zeroDigit) { - DecimalFormatSymbols* symbols = makeDecimalFormatSymbols(env, - currencySymbol, decimalSeparator, digit, groupingSeparator, - infinity, internationalCurrencySymbol, minusSign, - monetaryDecimalSeparator, nan, patternSeparator, percent, perMill, - zeroDigit); - toDecimalFormat(addr)->adoptDecimalFormatSymbols(symbols); -} - -static jint openDecimalFormatImpl(JNIEnv* env, jclass clazz, jstring pattern0, - jstring currencySymbol, jchar decimalSeparator, jchar digit, - jchar groupingSeparator, jstring infinity, - jstring internationalCurrencySymbol, jchar minusSign, - jchar monetaryDecimalSeparator, jstring nan, jchar patternSeparator, - jchar percent, jchar perMill, jchar zeroDigit) { - if (pattern0 == NULL) { - jniThrowNullPointerException(env, NULL); - return 0; - } - UErrorCode status = U_ZERO_ERROR; - UParseError parseError; - ScopedJavaUnicodeString pattern(env, pattern0); - DecimalFormatSymbols* symbols = makeDecimalFormatSymbols(env, - currencySymbol, decimalSeparator, digit, groupingSeparator, - infinity, internationalCurrencySymbol, minusSign, - monetaryDecimalSeparator, nan, patternSeparator, percent, perMill, - zeroDigit); - DecimalFormat* fmt = new DecimalFormat(pattern.unicodeString(), symbols, parseError, status); - if (fmt == NULL) { - delete symbols; - } - icu4jni_error(env, status); - return static_cast<jint>(reinterpret_cast<uintptr_t>(fmt)); -} - -static void closeDecimalFormatImpl(JNIEnv* env, jclass, jint addr) { - delete toDecimalFormat(addr); -} - -static void setRoundingMode(JNIEnv* env, jclass, jint addr, jint mode, jdouble increment) { - DecimalFormat* fmt = toDecimalFormat(addr); - fmt->setRoundingMode(static_cast<DecimalFormat::ERoundingMode>(mode)); - fmt->setRoundingIncrement(increment); -} - -static void setSymbol(JNIEnv* env, jclass, jint addr, jint symbol, jstring s) { - const UChar* chars = env->GetStringChars(s, NULL); - const int32_t charCount = env->GetStringLength(s); - UErrorCode status = U_ZERO_ERROR; - UNumberFormat* fmt = reinterpret_cast<UNumberFormat*>(static_cast<uintptr_t>(addr)); - unum_setSymbol(fmt, static_cast<UNumberFormatSymbol>(symbol), chars, charCount, &status); - icu4jni_error(env, status); - env->ReleaseStringChars(s, chars); -} - -static void setAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol, - jint value) { - - UNumberFormat *fmt = (UNumberFormat *)(int)addr; - - unum_setAttribute(fmt, (UNumberFormatAttribute) symbol, value); -} - -static jint getAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol) { - - UNumberFormat *fmt = (UNumberFormat *)(int)addr; - - int res = unum_getAttribute(fmt, (UNumberFormatAttribute) symbol); - - return res; -} - -static void setTextAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol, - jstring text) { - - // the errorcode returned by unum_setTextAttribute - UErrorCode status = U_ZERO_ERROR; - - // get the pointer to the number format - UNumberFormat *fmt = (UNumberFormat *)(int)addr; - - const UChar *textChars = env->GetStringChars(text, NULL); - int textLen = env->GetStringLength(text); - - unum_setTextAttribute(fmt, (UNumberFormatTextAttribute) symbol, textChars, - textLen, &status); - - env->ReleaseStringChars(text, textChars); - - icu4jni_error(env, status); -} - -static jstring getTextAttribute(JNIEnv *env, jclass clazz, jint addr, - jint symbol) { - - uint32_t resultlength, reslenneeded; - - // the errorcode returned by unum_getTextAttribute - UErrorCode status = U_ZERO_ERROR; - - // get the pointer to the number format - UNumberFormat *fmt = (UNumberFormat *)(int)addr; - - UChar* result = NULL; - resultlength=0; - - // find out how long the result will be - reslenneeded=unum_getTextAttribute(fmt, (UNumberFormatTextAttribute) symbol, - result, resultlength, &status); - - result = NULL; - if(status==U_BUFFER_OVERFLOW_ERROR) { - status=U_ZERO_ERROR; - resultlength=reslenneeded+1; - result=(UChar*)malloc(sizeof(UChar) * resultlength); - reslenneeded=unum_getTextAttribute(fmt, - (UNumberFormatTextAttribute) symbol, result, resultlength, - &status); - } - if (icu4jni_error(env, status) != FALSE) { - return NULL; - } - - jstring res = env->NewString(result, reslenneeded); - - free(result); - - return res; -} - -static void applyPatternImpl(JNIEnv *env, jclass clazz, jint addr, jboolean localized, jstring pattern0) { - if (pattern0 == NULL) { - jniThrowNullPointerException(env, NULL); - return; - } - ScopedJavaUnicodeString pattern(env, pattern0); - DecimalFormat* fmt = toDecimalFormat(addr); - UErrorCode status = U_ZERO_ERROR; - if (localized) { - fmt->applyLocalizedPattern(pattern.unicodeString(), status); - } else { - fmt->applyPattern(pattern.unicodeString(), status); - } - icu4jni_error(env, status); -} - -static jstring toPatternImpl(JNIEnv *env, jclass, jint addr, jboolean localized) { - DecimalFormat* fmt = toDecimalFormat(addr); - UnicodeString pattern; - if (localized) { - fmt->toLocalizedPattern(pattern); - } else { - fmt->toPattern(pattern); - } - return env->NewString(pattern.getBuffer(), pattern.length()); -} - -template <typename T> -static jstring format(JNIEnv *env, jint addr, jobject field, jstring fieldType, jobject attributes, T val) { - UErrorCode status = U_ZERO_ERROR; - - DecimalFormat::AttributeBuffer attrBuffer; - attrBuffer.buffer = NULL; - DecimalFormat::AttributeBuffer* attrBufferPtr = NULL; - if (attributes != NULL || (fieldType != NULL && field != NULL)) { - attrBufferPtr = &attrBuffer; - // ICU requires that this is dynamically allocated and non-zero size. - // ICU grows it in chunks of 128 bytes, so that's a reasonable initial size. - attrBuffer.bufferSize = 128; - attrBuffer.buffer = new char[attrBuffer.bufferSize]; - attrBuffer.buffer[0] = '\0'; - } - - FieldPosition fp; - fp.setField(FieldPosition::DONT_CARE); - - UnicodeString str; - DecimalFormat* fmt = toDecimalFormat(addr); - fmt->format(val, str, fp, attrBufferPtr); - - if (attrBufferPtr && strlen(attrBuffer.buffer) > 0) { - // check if we want to get all attributes - if (attributes != NULL) { - jstring attrString = env->NewStringUTF(attrBuffer.buffer + 1); // cut off the leading ';' - jclass stringBufferClass = env->FindClass("java/lang/StringBuffer"); - jmethodID appendMethodID = env->GetMethodID(stringBufferClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;"); - env->CallObjectMethod(attributes, appendMethodID, attrString); - } - - // check if we want one special attribute returned in the given FieldPos - if (fieldType != NULL && field != NULL) { - const char* fieldName = env->GetStringUTFChars(fieldType, NULL); - - const char* delimiter = ";"; - char* context = NULL; - char* resattr = strtok_r(attrBuffer.buffer, delimiter, &context); - - while (resattr != NULL && strcmp(resattr, fieldName) != 0) { - resattr = strtok_r(NULL, delimiter, &context); - } - - if (resattr != NULL && strcmp(resattr, fieldName) == 0) { - resattr = strtok_r(NULL, delimiter, &context); - int begin = (int) strtol(resattr, NULL, 10); - resattr = strtok_r(NULL, delimiter, &context); - int end = (int) strtol(resattr, NULL, 10); - - jclass fieldPositionClass = env->FindClass("java/text/FieldPosition"); - jmethodID setBeginIndexMethodID = env->GetMethodID(fieldPositionClass, "setBeginIndex", "(I)V"); - jmethodID setEndIndexMethodID = env->GetMethodID(fieldPositionClass, "setEndIndex", "(I)V"); - env->CallVoidMethod(field, setBeginIndexMethodID, (jint) begin); - env->CallVoidMethod(field, setEndIndexMethodID, (jint) end); - } - env->ReleaseStringUTFChars(fieldType, fieldName); - } - } - - jstring result = env->NewString(str.getBuffer(), str.length()); - delete[] attrBuffer.buffer; - return result; -} - -static jstring formatLong(JNIEnv* env, jclass, jint addr, jlong value, - jobject field, jstring fieldType, jobject attributes) { - int64_t longValue = value; - return format(env, addr, field, fieldType, attributes, longValue); -} - -static jstring formatDouble(JNIEnv* env, jclass, jint addr, jdouble value, - jobject field, jstring fieldType, jobject attributes) { - double doubleValue = value; - return format(env, addr, field, fieldType, attributes, doubleValue); -} - -static jstring formatDigitList(JNIEnv *env, jclass clazz, jint addr, jstring value, - jobject field, jstring fieldType, jobject attributes, jint scale) { - - // const char * valueUTF = env->GetStringUTFChars(value, NULL); - // LOGI("ENTER formatDigitList: %s, scale: %d", valueUTF, scale); - // env->ReleaseStringUTFChars(value, valueUTF); - - if (scale < 0) { - icu4jni_error(env, U_ILLEGAL_ARGUMENT_ERROR); - return NULL; - } - - const char * fieldName = NULL; - if(fieldType != NULL) { - fieldName = env->GetStringUTFChars(fieldType, NULL); - } - - uint32_t reslenneeded; - - // prepare digit list - - const char *valueChars = env->GetStringUTFChars(value, NULL); - - bool isInteger = (scale == 0); - bool isPositive = (*valueChars != '-'); - - // skip the '-' if the number is negative - const char *digits = (isPositive ? valueChars : valueChars + 1); - int length = strlen(digits); - - DecimalFormat* fmt = toDecimalFormat(addr); - - // The length of our digit list buffer must be the actual string length + 3, - // because ICU will append some additional characters at the head and at the - // tail of the string, in order to keep strtod() happy: - // - // - The sign "+" or "-" is appended at the head - // - The exponent "e" and the "\0" terminator is appended at the tail - // - // In retrospect, the changes to ICU's DigitList that were necessary for - // big numbers look a bit hacky. It would make sense to rework all this - // once ICU 4.x has been integrated into Android. Ideally, big number - // support would make it into ICU itself, so we don't need our private - // fix anymore. - DigitList digitList(length + 3); - digitList.fCount = length; - strcpy(digitList.fDigits, digits); - env->ReleaseStringUTFChars(value, valueChars); - - digitList.fDecimalAt = digitList.fCount - scale; - digitList.fIsPositive = isPositive; - digitList.fRoundingMode = fmt->getRoundingMode(); - digitList.round(fmt->getMaximumFractionDigits() + digitList.fDecimalAt); - - UChar *result = NULL; - - FieldPosition fp; - fp.setField(FieldPosition::DONT_CARE); - fp.setBeginIndex(0); - fp.setEndIndex(0); - - UErrorCode status = U_ZERO_ERROR; - - DecimalFormat::AttributeBuffer *attrBuffer = NULL; - attrBuffer = (DecimalFormat::AttributeBuffer *) calloc(sizeof(DecimalFormat::AttributeBuffer), 1); - attrBuffer->bufferSize = 128; - attrBuffer->buffer = (char *) calloc(129 * sizeof(char), 1); - - UnicodeString res; - - fmt->subformat(res, fp, attrBuffer, digitList, isInteger); - - reslenneeded = res.extract(NULL, 0, status); - - if(status==U_BUFFER_OVERFLOW_ERROR) { - status=U_ZERO_ERROR; - - result = (UChar*)malloc(sizeof(UChar) * (reslenneeded + 1)); - - res.extract(result, reslenneeded + 1, status); - - if (icu4jni_error(env, status) != FALSE) { - if(fieldType != NULL) { - env->ReleaseStringUTFChars(fieldType, fieldName); - } - free(result); - free(attrBuffer->buffer); - free(attrBuffer); - return NULL; - } - - } else { - if(fieldType != NULL) { - env->ReleaseStringUTFChars(fieldType, fieldName); - } - free(attrBuffer->buffer); - free(attrBuffer); - return NULL; - } - - int attrLength = (strlen(attrBuffer->buffer) + 1 ); - - if(attrLength > 1) { - - // check if we want to get all attributes - if(attributes != NULL) { - // prepare the classes and method ids - const char * stringBufferClassName = "java/lang/StringBuffer"; - jclass stringBufferClass = env->FindClass(stringBufferClassName); - jmethodID appendMethodID = env->GetMethodID(stringBufferClass, - "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;"); - - jstring attrString = env->NewStringUTF(attrBuffer->buffer + 1); // cut off the leading ';' - env->CallObjectMethod(attributes, appendMethodID, attrString); - } - - // check if we want one special attribute returned in the given FieldPos - if(fieldName != NULL && field != NULL) { - const char *delimiter = ";"; - int begin; - int end; - char * resattr; - resattr = strtok(attrBuffer->buffer, delimiter); - - while(resattr != NULL && strcmp(resattr, fieldName) != 0) { - resattr = strtok(NULL, delimiter); - } - - if(resattr != NULL && strcmp(resattr, fieldName) == 0) { - - // prepare the classes and method ids - const char * fieldPositionClassName = - "java/text/FieldPosition"; - jclass fieldPositionClass = env->FindClass( - fieldPositionClassName); - jmethodID setBeginIndexMethodID = env->GetMethodID( - fieldPositionClass, "setBeginIndex", "(I)V"); - jmethodID setEndIndexMethodID = env->GetMethodID( - fieldPositionClass, "setEndIndex", "(I)V"); - - - resattr = strtok(NULL, delimiter); - begin = (int) strtol(resattr, NULL, 10); - resattr = strtok(NULL, delimiter); - end = (int) strtol(resattr, NULL, 10); - - env->CallVoidMethod(field, setBeginIndexMethodID, (jint) begin); - env->CallVoidMethod(field, setEndIndexMethodID, (jint) end); - } - } - } - - if(fieldType != NULL) { - env->ReleaseStringUTFChars(fieldType, fieldName); - } - - jstring resulting = env->NewString(result, reslenneeded); - - free(attrBuffer->buffer); - free(attrBuffer); - free(result); - // const char * resultUTF = env->GetStringUTFChars(resulting, NULL); - // LOGI("RETURN formatDigitList: %s", resultUTF); - // env->ReleaseStringUTFChars(resulting, resultUTF); - - return resulting; -} - -static jobject parse(JNIEnv *env, jclass clazz, jint addr, jstring text, - jobject position) { - // TODO: cache these? - jclass parsePositionClass = env->FindClass("java/text/ParsePosition"); - jclass longClass = env->FindClass("java/lang/Long"); - jclass doubleClass = env->FindClass("java/lang/Double"); - jclass bigDecimalClass = env->FindClass("java/math/BigDecimal"); - jclass bigIntegerClass = env->FindClass("java/math/BigInteger"); - - jmethodID getIndexMethodID = env->GetMethodID(parsePositionClass, - "getIndex", "()I"); - jmethodID setIndexMethodID = env->GetMethodID(parsePositionClass, - "setIndex", "(I)V"); - jmethodID setErrorIndexMethodID = env->GetMethodID(parsePositionClass, - "setErrorIndex", "(I)V"); - - jmethodID longInitMethodID = env->GetMethodID(longClass, "<init>", "(J)V"); - jmethodID dblInitMethodID = env->GetMethodID(doubleClass, "<init>", "(D)V"); - jmethodID bigDecimalInitMethodID = env->GetMethodID(bigDecimalClass, "<init>", "(Ljava/math/BigInteger;I)V"); - jmethodID bigIntegerInitMethodID = env->GetMethodID(bigIntegerClass, "<init>", "(Ljava/lang/String;)V"); - jmethodID doubleValueMethodID = env->GetMethodID(bigDecimalClass, "doubleValue", "()D"); - - // make sure the ParsePosition is valid. Actually icu4c would parse a number - // correctly even if the parsePosition is set to -1, but since the RI fails - // for that case we have to fail too - int parsePos = env->CallIntMethod(position, getIndexMethodID, NULL); - const int strlength = env->GetStringLength(text); - if(parsePos < 0 || parsePos > strlength) { - return NULL; - } - - ParsePosition pp; - pp.setIndex(parsePos); - - DigitList digits; - - UNumberFormat *fmt = (UNumberFormat *)(int)addr; - Formattable res; - bool resultAssigned; - jchar *str = (UChar *)env->GetStringChars(text, NULL); - const UnicodeString src((UChar*)str, strlength, strlength); - ((const DecimalFormat*)fmt)->parse(src, resultAssigned, res, pp, FALSE, digits); - env->ReleaseStringChars(text, str); - - if(pp.getErrorIndex() == -1) { - parsePos = pp.getIndex(); - } else { - env->CallVoidMethod(position, setErrorIndexMethodID, - (jint) pp.getErrorIndex()); - return NULL; - } - - Formattable::Type numType = res.getType(); - UErrorCode fmtStatus; - - double resultDouble; - long resultLong; - int64_t resultInt64; - jstring resultStr; - jobject resultObject1, resultObject2; - - if (resultAssigned) - { - switch(numType) { - case Formattable::kDouble: - resultDouble = res.getDouble(); - env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos); - return env->NewObject(doubleClass, dblInitMethodID, - (jdouble) resultDouble); - case Formattable::kLong: - resultLong = res.getLong(); - env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos); - return env->NewObject(longClass, longInitMethodID, - (jlong) resultLong); - case Formattable::kInt64: - resultInt64 = res.getInt64(); - env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos); - return env->NewObject(longClass, longInitMethodID, - (jlong) resultInt64); - default: - return NULL; - } - } - else - { - int scale = digits.fCount - digits.fDecimalAt; - // ATTENTION: Abuse of Implementation Knowlegde! - digits.fDigits[digits.fCount] = 0; - if (digits.fIsPositive) { - resultStr = env->NewStringUTF(digits.fDigits); - } else { - if (digits.fCount == 0) { - env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos); - return env->NewObject(doubleClass, dblInitMethodID, (jdouble)-0); - } else { - // ATTENTION: Abuse of Implementation Knowlegde! - *(digits.fDigits - 1) = '-'; - resultStr = env->NewStringUTF(digits.fDigits - 1); - } - } - - env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos); - - resultObject1 = env->NewObject(bigIntegerClass, bigIntegerInitMethodID, resultStr); - resultObject2 = env->NewObject(bigDecimalClass, bigDecimalInitMethodID, resultObject1, scale); - return resultObject2; - } -} - -static jint cloneDecimalFormatImpl(JNIEnv *env, jclass, jint addr) { - DecimalFormat* fmt = toDecimalFormat(addr); - return static_cast<jint>(reinterpret_cast<uintptr_t>(fmt->clone())); -} - -static JNINativeMethod gMethods[] = { - {"applyPatternImpl", "(IZLjava/lang/String;)V", (void*) applyPatternImpl}, - {"cloneDecimalFormatImpl", "(I)I", (void*) cloneDecimalFormatImpl}, - {"closeDecimalFormatImpl", "(I)V", (void*) closeDecimalFormatImpl}, - {"format", "(IDLjava/text/FieldPosition;Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/String;", (void*) formatDouble}, - {"format", "(IJLjava/text/FieldPosition;Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/String;", (void*) formatLong}, - {"format", "(ILjava/lang/String;Ljava/text/FieldPosition;Ljava/lang/String;Ljava/lang/StringBuffer;I)Ljava/lang/String;", (void*) formatDigitList}, - {"getAttribute", "(II)I", (void*) getAttribute}, - {"getTextAttribute", "(II)Ljava/lang/String;", (void*) getTextAttribute}, - {"openDecimalFormatImpl", "(Ljava/lang/String;Ljava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)I", (void*) openDecimalFormatImpl}, - {"parse", "(ILjava/lang/String;Ljava/text/ParsePosition;)Ljava/lang/Number;", (void*) parse}, - {"setAttribute", "(III)V", (void*) setAttribute}, - {"setDecimalFormatSymbols", "(ILjava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)V", (void*) setDecimalFormatSymbols}, - {"setSymbol", "(IILjava/lang/String;)V", (void*) setSymbol}, - {"setRoundingMode", "(IID)V", (void*) setRoundingMode}, - {"setTextAttribute", "(IILjava/lang/String;)V", (void*) setTextAttribute}, - {"toPatternImpl", "(IZ)Ljava/lang/String;", (void*) toPatternImpl}, -}; -int register_com_ibm_icu4jni_text_NativeDecimalFormat(JNIEnv* env) { - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeDecimalFormat", gMethods, - NELEM(gMethods)); -} diff --git a/icu/src/main/native/NativeIDN.cpp b/icu/src/main/native/NativeIDN.cpp deleted file mode 100644 index e8052fc..0000000 --- a/icu/src/main/native/NativeIDN.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#define LOG_TAG "NativeIDN" - -#include "ErrorCode.h" -#include "JNIHelp.h" -#include "ScopedJavaUnicodeString.h" -#include "unicode/uidna.h" - -static bool isLabelSeparator(const UChar ch) { - switch (ch) { - case 0x3002: // ideographic full stop - case 0xff0e: // fullwidth full stop - case 0xff61: // halfwidth ideographic full stop - return true; - default: - return false; - } -} - -static jstring convertImpl(JNIEnv* env, jclass, jstring s, jint flags, jboolean toAscii) { - ScopedJavaUnicodeString sus(env, s); - const UChar* src = sus.unicodeString().getBuffer(); - const size_t srcLength = sus.unicodeString().length(); - UChar dst[256]; - UErrorCode status = U_ZERO_ERROR; - size_t resultLength = toAscii - ? uidna_IDNToASCII(src, srcLength, &dst[0], sizeof(dst), flags, NULL, &status) - : uidna_IDNToUnicode(src, srcLength, &dst[0], sizeof(dst), flags, NULL, &status); - if (U_FAILURE(status)) { - jniThrowException(env, "java/lang/IllegalArgumentException", u_errorName(status)); - return NULL; - } - if (!toAscii) { - // ICU only translates separators to ASCII for toASCII. - // Java expects the translation for toUnicode too. - // We may as well do this here, while the string is still mutable. - for (size_t i = 0; i < resultLength; ++i) { - if (isLabelSeparator(dst[i])) { - dst[i] = '.'; - } - } - } - return env->NewString(&dst[0], resultLength); -} - -static JNINativeMethod gMethods[] = { - {"convertImpl", "(Ljava/lang/String;IZ)Ljava/lang/String;", (void*) convertImpl}, -}; -int register_com_ibm_icu4jni_text_NativeIDN(JNIEnv* env) { - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeIDN", gMethods, NELEM(gMethods)); -} diff --git a/icu/src/main/native/NativeNormalizer.cpp b/icu/src/main/native/NativeNormalizer.cpp deleted file mode 100644 index 257cf9b..0000000 --- a/icu/src/main/native/NativeNormalizer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#define LOG_TAG "NativeNormalizer" - -#include "ErrorCode.h" -#include "JNIHelp.h" -#include "ScopedJavaUnicodeString.h" -#include "unicode/normlzr.h" - -static jstring normalizeImpl(JNIEnv* env, jclass, jstring s, jint intMode) { - ScopedJavaUnicodeString src(env, s); - UNormalizationMode mode = static_cast<UNormalizationMode>(intMode); - UErrorCode errorCode = U_ZERO_ERROR; - UnicodeString dst; - Normalizer::normalize(src.unicodeString(), mode, 0, dst, errorCode); - icu4jni_error(env, errorCode); - return dst.isBogus() ? NULL : env->NewString(dst.getBuffer(), dst.length()); -} - -static jboolean isNormalizedImpl(JNIEnv* env, jclass, jstring s, jint intMode) { - ScopedJavaUnicodeString src(env, s); - UNormalizationMode mode = static_cast<UNormalizationMode>(intMode); - UErrorCode errorCode = U_ZERO_ERROR; - UBool result = Normalizer::isNormalized(src.unicodeString(), mode, errorCode); - icu4jni_error(env, errorCode); - return result; -} - -static JNINativeMethod gMethods[] = { - {"normalizeImpl", "(Ljava/lang/String;I)Ljava/lang/String;", (void*) normalizeImpl}, - {"isNormalizedImpl", "(Ljava/lang/String;I)Z", (void*) isNormalizedImpl}, -}; -int register_com_ibm_icu4jni_text_NativeNormalizer(JNIEnv* env) { - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeNormalizer", - gMethods, NELEM(gMethods)); -} diff --git a/icu/src/main/native/NativeRegEx.cpp b/icu/src/main/native/NativeRegEx.cpp deleted file mode 100644 index 511f1e4..0000000 --- a/icu/src/main/native/NativeRegEx.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#define LOG_TAG "NativeRegEx" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "unicode/uregex.h" -#include "unicode/utypes.h" -#include "unicode/parseerr.h" - -#include <jni.h> -#include <JNIHelp.h> - -static jchar EMPTY_STRING = 0; - -/** - * A data structure that ties together an ICU regular expression and the - * character data it refers to (but does not have a copy of), so we can - * manage memory properly. - */ -struct RegExData { - // A pointer to the ICU regular expression - URegularExpression* regex; - // A pointer to (a copy of) the input text that *we* manage - jchar* text; -}; - -static void throwPatternSyntaxException(JNIEnv* env, UErrorCode status, - jstring pattern, UParseError error) -{ - jclass clazz = env->FindClass("java/util/regex/PatternSyntaxException"); - jmethodID method = env->GetMethodID(clazz, "<init>", - "(Ljava/lang/String;Ljava/lang/String;I)V"); - - jstring message = env->NewStringUTF(u_errorName(status)); - jthrowable except = (jthrowable)(env->NewObject(clazz, method, message, - pattern, error.offset)); - env->Throw(except); -} - -static void throwRuntimeException(JNIEnv* env, UErrorCode status) { - jniThrowRuntimeException(env, u_errorName(status)); -} - -static void _close(JNIEnv* env, jclass clazz, RegExData* data) -{ - if (data->regex != NULL) { - uregex_close(data->regex); - } - - if (data->text != &EMPTY_STRING) { - delete[] data->text; - } - - free(data); -} - -static RegExData* open(JNIEnv* env, jclass clazz, jstring pattern, jint flags) -{ - flags = flags | UREGEX_ERROR_ON_UNKNOWN_ESCAPES; - - RegExData* data = (RegExData*)calloc(sizeof(RegExData), 1); - - UErrorCode status = U_ZERO_ERROR; - UParseError error; - error.offset = -1; - - jchar const * patternRaw; - int patternLen = env->GetStringLength(pattern); - if (patternLen == 0) { - data->regex = uregex_open(&EMPTY_STRING, -1, flags, &error, &status); - } else { - jchar const * patternRaw = env->GetStringChars(pattern, NULL); - data->regex = uregex_open(patternRaw, patternLen, flags, &error, - &status); - env->ReleaseStringChars(pattern, patternRaw); - } - - if (!U_SUCCESS(status)) { - _close(env, clazz, data); - throwPatternSyntaxException(env, status, pattern, error); - data = NULL; - } - - return data; -} - -static RegExData* _clone(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - - URegularExpression* clonedRegex = uregex_clone(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - - RegExData* result = (RegExData*)calloc(sizeof(RegExData), 1); - result->regex = clonedRegex; - - return result; -} - -static void setText(JNIEnv* env, jclass clazz, RegExData* data, jstring text) -{ - UErrorCode status = U_ZERO_ERROR; - - uregex_setText(data->regex, &EMPTY_STRING, 0, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - return; - } - - if (data->text != &EMPTY_STRING) { - delete[] data->text; - data->text = NULL; - } - - int textLen = env->GetStringLength(text); - if (textLen == 0) { - data->text = &EMPTY_STRING; - } else { - data->text = new jchar[textLen + 1]; - env->GetStringRegion(text, 0, textLen, data->text); - data->text[textLen] = 0; - } - - uregex_setText(data->regex, data->text, textLen, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } -} - -static jboolean matches(JNIEnv* env, jclass clazz, RegExData* data, - jint startIndex) -{ - UErrorCode status = U_ZERO_ERROR; - - jboolean result = uregex_matches(data->regex, startIndex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - - return result; -} - -static jboolean lookingAt(JNIEnv* env, jclass clazz, RegExData* data, - jint startIndex) -{ - UErrorCode status = U_ZERO_ERROR; - - jboolean result = uregex_lookingAt(data->regex, startIndex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - - return result; -} - -static jboolean find(JNIEnv* env, jclass clazz, RegExData* data, - jint startIndex) -{ - UErrorCode status = U_ZERO_ERROR; - - jboolean result = uregex_find(data->regex, startIndex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - - return result; -} - -static jboolean findNext(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - - jboolean result = uregex_findNext(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - - return result; -} - -static jint groupCount(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - - jint result = uregex_groupCount(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - - return result; -} - -static void startEnd(JNIEnv* env, jclass clazz, RegExData* data, - jintArray offsets) -{ - UErrorCode status = U_ZERO_ERROR; - - jint * offsetsRaw = env->GetIntArrayElements(offsets, NULL); - - int groupCount = uregex_groupCount(data->regex, &status); - for (int i = 0; i <= groupCount && U_SUCCESS(status); i++) { - offsetsRaw[2 * i + 0] = uregex_start(data->regex, i, &status); - offsetsRaw[2 * i + 1] = uregex_end(data->regex, i, &status); - } - - env->ReleaseIntArrayElements(offsets, offsetsRaw, 0); - - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } -} - -static void setRegion(JNIEnv* env, jclass clazz, RegExData* data, jint start, - jint end) -{ - UErrorCode status = U_ZERO_ERROR; - uregex_setRegion(data->regex, start, end, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } -} - -static jint regionStart(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - int result = uregex_regionStart(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - return result; -} - -static jint regionEnd(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - int result = uregex_regionEnd(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - return result; -} - -static void useTransparentBounds(JNIEnv* env, jclass clazz, RegExData* data, - jboolean value) -{ - UErrorCode status = U_ZERO_ERROR; - uregex_useTransparentBounds(data->regex, value, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } -} - -static jboolean hasTransparentBounds(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - jboolean result = uregex_hasTransparentBounds(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - return result; -} - -static void useAnchoringBounds(JNIEnv* env, jclass clazz, RegExData* data, - jboolean value) -{ - UErrorCode status = U_ZERO_ERROR; - uregex_useAnchoringBounds(data->regex, value, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } -} - -static jboolean hasAnchoringBounds(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - jboolean result = uregex_hasAnchoringBounds(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - return result; -} - -static jboolean hitEnd(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - jboolean result = uregex_hitEnd(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - return result; -} - -static jboolean requireEnd(JNIEnv* env, jclass clazz, RegExData* data) -{ - UErrorCode status = U_ZERO_ERROR; - jboolean result = uregex_requireEnd(data->regex, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } - return result; -} - -static void reset(JNIEnv* env, jclass clazz, RegExData* data, jint position) -{ - UErrorCode status = U_ZERO_ERROR; - uregex_reset(data->regex, position, &status); - if (!U_SUCCESS(status)) { - throwRuntimeException(env, status); - } -} - -static JNINativeMethod gMethods[] = { - { "open", "(Ljava/lang/String;I)I", (void*)open }, - { "clone", "(I)I", (void*)_clone }, - { "close", "(I)V", (void*)_close }, - { "setText", "(ILjava/lang/String;)V", (void*)setText }, - { "matches", "(II)Z", (void*)matches }, - { "lookingAt", "(II)Z", (void*)lookingAt }, - { "find", "(II)Z", (void*)find }, - { "findNext", "(I)Z", (void*)findNext }, - { "groupCount", "(I)I", (void*)groupCount }, - { "startEnd", "(I[I)V", (void*)startEnd }, - { "setRegion", "(III)V", (void*)setRegion }, - { "regionStart", "(I)I", (void*)regionStart }, - { "regionEnd", "(I)I", (void*)regionEnd }, - { "useTransparentBounds", "(IZ)V", (void*)useTransparentBounds }, - { "hasTransparentBounds", "(I)Z", (void*)hasTransparentBounds }, - { "useAnchoringBounds", "(IZ)V", (void*)useAnchoringBounds }, - { "hasAnchoringBounds", "(I)Z", (void*)hasAnchoringBounds }, - { "hitEnd", "(I)Z", (void*)hitEnd }, - { "requireEnd", "(I)Z", (void*)requireEnd }, - { "reset", "(II)V", (void*)reset }, -}; -int register_com_ibm_icu4jni_regex_NativeRegEx(JNIEnv* env) { - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/regex/NativeRegEx", - gMethods, NELEM(gMethods)); -} diff --git a/icu/src/main/native/ScopedJavaUnicodeString.h b/icu/src/main/native/ScopedJavaUnicodeString.h deleted file mode 100644 index b108a6b..0000000 --- a/icu/src/main/native/ScopedJavaUnicodeString.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#ifndef SCOPED_JAVA_UNICODE_STRING_H_included -#define SCOPED_JAVA_UNICODE_STRING_H_included - -#include "JNIHelp.h" -#include "unicode/unistr.h" - -// A smart pointer that provides access to an ICU UnicodeString given a JNI -// jstring. We give ICU a direct pointer to the characters on the Java heap. -// It's clever enough to copy-on-write if necessary. -class ScopedJavaUnicodeString { -public: - ScopedJavaUnicodeString(JNIEnv* env, jstring s) : mEnv(env), mString(s) { - mChars = env->GetStringChars(mString, NULL); - const int32_t charCount = env->GetStringLength(mString); - mUnicodeString.setTo(false, mChars, charCount); - } - - ~ScopedJavaUnicodeString() { - mEnv->ReleaseStringChars(mString, mChars); - } - - const UnicodeString& unicodeString() const { - return mUnicodeString; - } - - UnicodeString& unicodeString() { - return mUnicodeString; - } - -private: - JNIEnv* mEnv; - jstring mString; - const UChar* mChars; - UnicodeString mUnicodeString; - - // Disallow copy and assignment. - ScopedJavaUnicodeString(const ScopedJavaUnicodeString&); - void operator=(const ScopedJavaUnicodeString&); -}; - -#endif // SCOPED_JAVA_UNICODE_STRING_H_included diff --git a/icu/src/main/native/UCharacter.cpp b/icu/src/main/native/UCharacter.cpp deleted file mode 100644 index abad16a..0000000 --- a/icu/src/main/native/UCharacter.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#define LOG_TAG "UCharacter" - -#include "JNIHelp.h" -#include "ScopedJavaUnicodeString.h" -#include "ScopedUtfChars.h" -#include "unicode/locid.h" -#include "unicode/uchar.h" -#include <math.h> -#include <stdlib.h> - -static jint digitImpl(JNIEnv*, jclass, jint codePoint, jint radix) { - return u_digit(codePoint, radix); -} - -static jint getTypeImpl(JNIEnv*, jclass, jint codePoint) { - return u_charType(codePoint); -} - -static jbyte getDirectionalityImpl(JNIEnv*, jclass, jint codePoint) { - return u_charDirection(codePoint); -} - -static jboolean isMirroredImpl(JNIEnv*, jclass, jint codePoint) { - return u_isMirrored(codePoint); -} - -static jint getNumericValueImpl(JNIEnv*, jclass, jint codePoint){ - // The letters A-Z in their uppercase ('\u0041' through '\u005A'), - // lowercase ('\u0061' through '\u007A'), - // and full width variant ('\uFF21' through '\uFF3A' - // and '\uFF41' through '\uFF5A') forms - // have numeric values from 10 through 35. This is independent of the - // Unicode specification, which does not assign numeric values to these - // char values. - if (codePoint >= 0x41 && codePoint <= 0x5A) { - return codePoint - 0x37; - } - if (codePoint >= 0x61 && codePoint <= 0x7A) { - return codePoint - 0x57; - } - if (codePoint >= 0xFF21 && codePoint <= 0xFF3A) { - return codePoint - 0xFF17; - } - if (codePoint >= 0xFF41 && codePoint <= 0xFF5A) { - return codePoint - 0xFF37; - } - - double result = u_getNumericValue(codePoint); - - if (result == U_NO_NUMERIC_VALUE) { - return -1; - } else if (result < 0 || floor(result + 0.5) != result) { - return -2; - } - - return result; -} - -static jboolean isDefinedImpl(JNIEnv*, jclass, jint codePoint) { - return u_isdefined(codePoint); -} - -static jboolean isDigitImpl(JNIEnv*, jclass, jint codePoint) { - return u_isdigit(codePoint); -} - -static jboolean isIdentifierIgnorableImpl(JNIEnv*, jclass, jint codePoint) { - // Java also returns TRUE for U+0085 Next Line (it omits U+0085 from whitespace ISO controls) - if(codePoint == 0x0085) { - return JNI_TRUE; - } - return u_isIDIgnorable(codePoint); -} - -static jboolean isLetterImpl(JNIEnv*, jclass, jint codePoint) { - return u_isalpha(codePoint); -} - -static jboolean isLetterOrDigitImpl(JNIEnv*, jclass, jint codePoint) { - return u_isalnum(codePoint); -} - -static jboolean isSpaceCharImpl(JNIEnv*, jclass, jint codePoint) { - return u_isJavaSpaceChar(codePoint); -} - -static jboolean isTitleCaseImpl(JNIEnv*, jclass, jint codePoint) { - return u_istitle(codePoint); -} - -static jboolean isUnicodeIdentifierPartImpl(JNIEnv*, jclass, jint codePoint) { - return u_isIDPart(codePoint); -} - -static jboolean isUnicodeIdentifierStartImpl(JNIEnv*, jclass, jint codePoint) { - return u_isIDStart(codePoint); -} - -static jboolean isWhitespaceImpl(JNIEnv*, jclass, jint codePoint) { - // Java omits U+0085 - if(codePoint == 0x0085) { - return JNI_FALSE; - } - return u_isWhitespace(codePoint); -} - -static jint toLowerCaseImpl(JNIEnv*, jclass, jint codePoint) { - return u_tolower(codePoint); -} - -static jint toTitleCaseImpl(JNIEnv*, jclass, jint codePoint) { - return u_totitle(codePoint); -} - -static jint toUpperCaseImpl(JNIEnv*, jclass, jint codePoint) { - return u_toupper(codePoint); -} - -static jstring toLowerCaseStringImpl(JNIEnv* env, jclass, jstring javaString, jstring localeName) { - ScopedJavaUnicodeString scopedString(env, javaString); - UnicodeString& s(scopedString.unicodeString()); - UnicodeString original(s); - s.toLower(Locale::createFromName(ScopedUtfChars(env, localeName).c_str())); - return s == original ? javaString : env->NewString(s.getBuffer(), s.length()); -} - -static jstring toUpperCaseStringImpl(JNIEnv* env, jclass, jstring javaString, jstring localeName) { - ScopedJavaUnicodeString scopedString(env, javaString); - UnicodeString& s(scopedString.unicodeString()); - UnicodeString original(s); - s.toUpper(Locale::createFromName(ScopedUtfChars(env, localeName).c_str())); - return s == original ? javaString : env->NewString(s.getBuffer(), s.length()); -} - -static jboolean isUpperCaseImpl(JNIEnv*, jclass, jint codePoint) { - return u_isupper(codePoint); -} - -static jboolean isLowerCaseImpl(JNIEnv*, jclass, jint codePoint) { - return u_islower(codePoint); -} - -static int forNameImpl(JNIEnv* env, jclass, jstring blockName) { - if (blockName == NULL) { - jniThrowNullPointerException(env, NULL); - return -1; - } - const char* bName = env->GetStringUTFChars(blockName, NULL); - int result = u_getPropertyValueEnum(UCHAR_BLOCK, bName); - env->ReleaseStringUTFChars(blockName, bName); - return result; -} - -static int ofImpl(JNIEnv*, jclass, jint codePoint) { - return ublock_getCode(codePoint); -} - -static JNINativeMethod gMethods[] = { - { "digit", "(II)I", (void*) digitImpl }, - { "forName", "(Ljava/lang/String;)I", (void*) forNameImpl }, - { "getDirectionality", "(I)B", (void*) getDirectionalityImpl }, - { "getNumericValue", "(I)I", (void*) getNumericValueImpl }, - { "getType", "(I)I", (void*) getTypeImpl }, - { "isDefined", "(I)Z", (void*) isDefinedImpl }, - { "isDigit", "(I)Z", (void*) isDigitImpl }, - { "isIdentifierIgnorable", "(I)Z", (void*) isIdentifierIgnorableImpl }, - { "isLetter", "(I)Z", (void*) isLetterImpl }, - { "isLetterOrDigit", "(I)Z", (void*) isLetterOrDigitImpl }, - { "isLowerCase", "(I)Z", (void*) isLowerCaseImpl }, - { "isMirrored", "(I)Z", (void*) isMirroredImpl }, - { "isSpaceChar", "(I)Z", (void*) isSpaceCharImpl }, - { "isTitleCase", "(I)Z", (void*) isTitleCaseImpl }, - { "isUnicodeIdentifierPart", "(I)Z", (void*) isUnicodeIdentifierPartImpl }, - { "isUnicodeIdentifierStart", "(I)Z", (void*) isUnicodeIdentifierStartImpl }, - { "isUpperCase", "(I)Z", (void*) isUpperCaseImpl }, - { "isWhitespace", "(I)Z", (void*) isWhitespaceImpl }, - { "of", "(I)I", (void*) ofImpl }, - { "toLowerCase", "(I)I", (void*) toLowerCaseImpl }, - { "toTitleCase", "(I)I", (void*) toTitleCaseImpl }, - { "toUpperCase", "(I)I", (void*) toUpperCaseImpl }, - { "toLowerCase", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) toLowerCaseStringImpl }, - { "toUpperCase", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) toUpperCaseStringImpl }, -}; -int register_com_ibm_icu4jni_lang_UCharacter(JNIEnv* env) { - return jniRegisterNativeMethods(env, "com/ibm/icu4jni/lang/UCharacter", - gMethods, NELEM(gMethods)); -} diff --git a/icu/src/main/native/sub.mk b/icu/src/main/native/sub.mk deleted file mode 100644 index 599c102..0000000 --- a/icu/src/main/native/sub.mk +++ /dev/null @@ -1,31 +0,0 @@ -# This file is included by the top-level libcore Android.mk. -# It's not a normal makefile, so we don't include CLEAR_VARS -# or BUILD_*_LIBRARY. - -LOCAL_SRC_FILES := \ - BidiWrapper.cpp \ - ErrorCode.cpp \ - ICU.cpp \ - NativeBreakIterator.cpp \ - NativeCollation.cpp \ - NativeConverter.cpp \ - NativeDecimalFormat.cpp \ - NativeIDN.cpp \ - NativeNormalizer.cpp \ - NativeRegEx.cpp \ - UCharacter.cpp - -LOCAL_C_INCLUDES += \ - external/icu4c/common \ - external/icu4c/i18n - -# Any shared/static libs that are listed here must also -# be listed in libs/nativehelper/Android.mk. -# TODO: fix this requirement - -LOCAL_SHARED_LIBRARIES += \ - libicudata \ - libicuuc \ - libicui18n - -LOCAL_STATIC_LIBRARIES += |