summaryrefslogtreecommitdiffstats
path: root/icu/src/main/native
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-01-22 18:22:53 -0800
committerElliott Hughes <enh@google.com>2010-01-22 18:28:47 -0800
commit1698d148fba5718d68de04df1b726940c50fd015 (patch)
treeaaea1c31ef4b6413ce2f0c3ed26e261abf8eb605 /icu/src/main/native
parent29d8606c7d5f8e1b6957ef4bced99251ec1dffff (diff)
downloadlibcore-1698d148fba5718d68de04df1b726940c50fd015.zip
libcore-1698d148fba5718d68de04df1b726940c50fd015.tar.gz
libcore-1698d148fba5718d68de04df1b726940c50fd015.tar.bz2
Switch our ICU JNI over to C++ and tidy up a little.
The big ugly files (implementing NativeCollation and NativeConverter), I've just done the minimum necessary for them to compile under a C++ compiler. For the small ones, I've been through them more thoroughly, removing duplication and the like. I only came across one bug; a failure path in BidiWrapper that would have leaked.
Diffstat (limited to 'icu/src/main/native')
-rw-r--r--icu/src/main/native/BidiWrapper.cpp161
-rw-r--r--icu/src/main/native/BidiWrapperInterface.c223
-rw-r--r--icu/src/main/native/BidiWrapperInterface.h132
-rw-r--r--icu/src/main/native/BreakIteratorInterface.c264
-rw-r--r--icu/src/main/native/CollationInterface.h214
-rw-r--r--icu/src/main/native/ErrorCode.cpp (renamed from icu/src/main/native/ErrorCode.c)0
-rw-r--r--icu/src/main/native/NativeBreakIterator.cpp155
-rw-r--r--icu/src/main/native/NativeCollation.cpp (renamed from icu/src/main/native/CollationInterface.c)117
-rw-r--r--icu/src/main/native/NativeConverter.cpp (renamed from icu/src/main/native/ConverterInterface.c)293
-rw-r--r--icu/src/main/native/NativeDecimalFormat.cpp (renamed from icu/src/main/native/DecimalFormatInterface.cpp)3
-rw-r--r--icu/src/main/native/NativeRegEx.cpp (renamed from icu/src/main/native/RegExInterface.cpp)28
-rw-r--r--icu/src/main/native/Resources.cpp (renamed from icu/src/main/native/ResourceInterface.cpp)4
-rw-r--r--icu/src/main/native/RuleBasedNumberFormat.cpp (renamed from icu/src/main/native/RBNFInterface.cpp)0
-rw-r--r--icu/src/main/native/UCharacter.cpp (renamed from icu/src/main/native/CharacterInterface.c)62
-rw-r--r--icu/src/main/native/sub.mk20
15 files changed, 565 insertions, 1111 deletions
diff --git a/icu/src/main/native/BidiWrapper.cpp b/icu/src/main/native/BidiWrapper.cpp
new file mode 100644
index 0000000..6bc650a
--- /dev/null
+++ b/icu/src/main/native/BidiWrapper.cpp
@@ -0,0 +1,161 @@
+/*
+ * 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.
+ */
+#include "AndroidSystemNatives.h"
+#include <JNIHelp.h>
+#include "ErrorCode.h"
+#include "unicode/ubidi.h"
+#include <stdlib.h>
+#include <string.h>
+
+struct BiDiData {
+ BiDiData(UBiDi* biDi) : mBiDi(biDi), embeddingLevels(NULL) {
+ }
+ ~BiDiData() {
+ ubidi_close(mBiDi);
+ delete[] embeddingLevels;
+ }
+ UBiDi* mBiDi;
+ jbyte* embeddingLevels;
+};
+
+static BiDiData* biDiData(jlong ptr) {
+ return reinterpret_cast<BiDiData*>(static_cast<uintptr_t>(ptr));
+}
+
+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);
+ jbyte* oldEmbeddingLevels = data->embeddingLevels;
+ // Copy the new embedding levels from the Java heap to the native heap.
+ if (newEmbeddingLevels != NULL) {
+ data->embeddingLevels = new jbyte[length];
+ env->GetByteArrayRegion(newEmbeddingLevels, 0, length, data->embeddingLevels);
+ } else {
+ data->embeddingLevels = NULL;
+ }
+ UErrorCode err = U_ZERO_ERROR;
+ jchar* _text = env->GetCharArrayElements(text, NULL);
+ ubidi_setPara(data->mBiDi, _text, length, paraLevel, (UBiDiLevel*) data->embeddingLevels, &err);
+ env->ReleaseCharArrayElements(text, _text, 0);
+ delete[] oldEmbeddingLevels;
+ 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)) {
+ return 0;
+ }
+ BiDiData* lineData = new BiDiData(sized);
+ BiDiData* data = biDiData(ptr);
+ ubidi_setLine(data->mBiDi, start, limit, lineData->mBiDi, &err);
+ icu4jni_error(env, err);
+ return reinterpret_cast<uintptr_t>(lineData);
+}
+
+static jint BidiWrapper_ubidi_getDirection(JNIEnv * env, jclass clazz, jlong ptr) {
+ return ubidi_getDirection(biDiData(ptr)->mBiDi);
+}
+
+static jint BidiWrapper_ubidi_getLength(JNIEnv* env, jclass, jlong ptr) {
+ return ubidi_getLength(biDiData(ptr)->mBiDi);
+}
+
+static jbyte BidiWrapper_ubidi_getParaLevel(JNIEnv* env, jclass, jlong ptr) {
+ return ubidi_getParaLevel(biDiData(ptr)->mBiDi);
+}
+
+static jbyteArray BidiWrapper_ubidi_getLevels(JNIEnv* env, jclass, jlong ptr) {
+ BiDiData* data = biDiData(ptr);
+ UErrorCode err = U_ZERO_ERROR;
+ const UBiDiLevel* levels = ubidi_getLevels(data->mBiDi, &err);
+ if (icu4jni_error(env, err)) {
+ return NULL;
+ }
+ int len = ubidi_getLength(data->mBiDi);
+ 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) {
+ BiDiData* data = biDiData(ptr);
+ UErrorCode err = U_ZERO_ERROR;
+ int count = ubidi_countRuns(data->mBiDi, &err);
+ icu4jni_error(env, err);
+ return count;
+}
+
+static jobjectArray BidiWrapper_ubidi_getRuns(JNIEnv* env, jclass, jlong ptr) {
+ BiDiData* data = biDiData(ptr);
+ UErrorCode err = U_ZERO_ERROR;
+ int runCount = ubidi_countRuns(data->mBiDi, &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(data->mBiDi, 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) {
+ 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);
+ jintArray result = env->NewIntArray(length);
+ env->SetIntArrayRegion(result, 0, length, local_indexMap);
+ delete[] local_indexMap;
+ 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/BidiWrapperInterface.c b/icu/src/main/native/BidiWrapperInterface.c
deleted file mode 100644
index 19ac520..0000000
--- a/icu/src/main/native/BidiWrapperInterface.c
+++ /dev/null
@@ -1,223 +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.
- */
-
-#include "BidiWrapperInterface.h"
-#include "ErrorCode.h"
-#include "unicode/ubidi.h"
-#include <stdlib.h>
-#include <string.h>
-
-typedef struct {
- UBiDi *pBiDi;
- void *embeddingLevels;
-} BiDiData;
-
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1open
- (JNIEnv * env, jclass clazz)
-{
- BiDiData *data = (BiDiData *)malloc(sizeof(BiDiData));
- (*data).pBiDi = ubidi_open ();
- (*data).embeddingLevels = NULL;
- return (jlong) (data);
-}
-
-JNIEXPORT void JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1close
- (JNIEnv * env, jclass clazz, jlong pBiDi)
-{
- BiDiData *data = (BiDiData *)pBiDi;
-
- ubidi_close ((*data).pBiDi);
-
- free((*data).embeddingLevels);
- free(data);
-}
-
-JNIEXPORT void JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1setPara
- (JNIEnv * env, jclass clazz, jlong pBiDi, jcharArray text, jint length,
- jbyte paraLevel, jbyteArray newEmbeddingLevels)
-{
- BiDiData *data = (BiDiData *)pBiDi;
- void *oldEmbeddingLevels = (*data).embeddingLevels;
-
- // Copy the new embedding levels from the Java heap to the native heap.
- if (newEmbeddingLevels != NULL) {
- (*data).embeddingLevels = malloc(length);
- (*env)->GetByteArrayRegion(env, newEmbeddingLevels, 0, length,
- (*data).embeddingLevels);
- } else {
- (*data).embeddingLevels = NULL;
- }
-
- UErrorCode err = 0;
- jchar* _text = (*env)->GetCharArrayElements(env, text, NULL);
- ubidi_setPara ((*data).pBiDi, _text, length, paraLevel,
- ((*data).embeddingLevels), &err);
- (*env)->ReleaseCharArrayElements (env, text, _text, 0);
- free(oldEmbeddingLevels);
-
- icu4jni_error(env, err);
-}
-
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1setLine
- (JNIEnv * env, jclass clazz, jlong pBiDi, jint start, jint limit)
-{
- UErrorCode err = 0;
- BiDiData *data = (BiDiData *)pBiDi;
- BiDiData *lineData = (BiDiData *) malloc(sizeof(BiDiData));
- (*lineData).embeddingLevels = NULL;
-
- (*lineData).pBiDi = ubidi_openSized (limit - start, 0, &err);
- if (icu4jni_error(env, err)) {
- return 0;
- }
-
- ubidi_setLine ((*data).pBiDi, start, limit, (*lineData).pBiDi, &err);
- icu4jni_error(env, err);
- return (jlong) lineData;
-}
-
-JNIEXPORT jint JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getDirection
- (JNIEnv * env, jclass clazz, jlong pBiDi)
-{
- BiDiData *data = (BiDiData *)pBiDi;
- return ubidi_getDirection ((*data).pBiDi);
-}
-
-JNIEXPORT jint JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getLength
- (JNIEnv * env, jclass clazz, jlong pBiDi)
-{
- BiDiData *data = (BiDiData *)pBiDi;
- return ubidi_getLength ((*data).pBiDi);
-}
-
-JNIEXPORT jbyte JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getParaLevel
- (JNIEnv * env, jclass clazz, jlong pBiDi)
-{
- BiDiData *data = (BiDiData *)pBiDi;
- return ubidi_getParaLevel ((*data).pBiDi);
-}
-
-JNIEXPORT jbyteArray JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getLevels
- (JNIEnv * env, jclass clazz, jlong pBiDi)
-{
- BiDiData *data = (BiDiData *)pBiDi;
-
- UErrorCode err = 0;
- const UBiDiLevel* levels = ubidi_getLevels((*data).pBiDi, &err);
- if (icu4jni_error(env, err)) {
- return NULL;
- }
-
- int len = ubidi_getLength((*data).pBiDi);
- jbyteArray result = (*env)->NewByteArray(env, len);
- (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*) levels);
-
- return result;
-}
-
-JNIEXPORT jint JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1countRuns
- (JNIEnv * env, jclass clazz, jlong pBiDi)
-{
- BiDiData *data = (BiDiData *)pBiDi;
-
- UErrorCode err = 0;
- int count = ubidi_countRuns ((*data).pBiDi, &err);
- icu4jni_error(env, err);
- return count;
-}
-
-JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getRuns
- (JNIEnv * env, jclass clz, jlong pBiDi)
-{
- BiDiData* data = (BiDiData*) pBiDi;
-
- UErrorCode err = 0;
- int runCount = ubidi_countRuns((*data).pBiDi, &err);
- if (icu4jni_error(env, err)) {
- return 0;
- }
-
- jclass bidiRunClass = (*env)->FindClass(env, "org/apache/harmony/text/BidiRun");
- jmethodID bidiRunConstructor = (*env)->GetMethodID(env, bidiRunClass, "<init>", "(III)V");
- jobjectArray runs = (*env)->NewObjectArray(env, runCount, bidiRunClass, NULL);
- UBiDiLevel level = 0;
- int start = 0;
- int limit = 0;
- int i = 0; // TODO: switch this file to C++!
- for (i = 0; i < runCount; ++i) {
- ubidi_getLogicalRun((*data).pBiDi, start, &limit, &level);
- jobject run = (*env)->NewObject(env, bidiRunClass, bidiRunConstructor, start, limit, level);
- (*env)->SetObjectArrayElement(env, runs, i, run);
- start = limit;
- }
- return runs;
-}
-
-JNIEXPORT jintArray JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1reorderVisual
- (JNIEnv * env, jclass clazz, jbyteArray levels, jint length)
-{
- UBiDiLevel *local_levels = 0;
- int *local_indexMap = 0;
- jintArray result = 0;
-
- local_indexMap = (int *) malloc(sizeof (int) * length);
- local_levels = (*env)->GetByteArrayElements (env, levels, NULL);
-
- ubidi_reorderVisual (local_levels, length, local_indexMap);
-
- result = (*env)->NewIntArray (env, length);
- (*env)->SetIntArrayRegion (env, result, 0, length, (jint *) local_indexMap);
-
- free(local_indexMap);
- (*env)->ReleaseByteArrayElements (env, levels, local_levels, 0);
-
- return result;
-}
-
-/*
- * JNI registration
- */
-static JNINativeMethod gMethods[] = {
- /* NAME , SIGNATURE , FUNCPTR */
- { "ubidi_open" , "()J" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1open },
- { "ubidi_close" , "(J)V" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1close },
- { "ubidi_setPara" , "(J[CIB[B)V" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1setPara },
- { "ubidi_setLine" , "(JII)J" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1setLine },
- { "ubidi_getDirection" , "(J)I" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1getDirection },
- { "ubidi_getLength" , "(J)I" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1getLength },
- { "ubidi_getParaLevel" , "(J)B" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1getParaLevel },
- { "ubidi_getLevels" , "(J)[B" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1getLevels },
- { "ubidi_countRuns" , "(J)I" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1countRuns },
- { "ubidi_getRuns" , "(J)[Lorg/apache/harmony/text/BidiRun;",
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1getRuns },
- { "ubidi_reorderVisual", "([BI)[I" ,
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1reorderVisual },
-};
-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/BidiWrapperInterface.h b/icu/src/main/native/BidiWrapperInterface.h
deleted file mode 100644
index c73597e..0000000
--- a/icu/src/main/native/BidiWrapperInterface.h
+++ /dev/null
@@ -1,132 +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.
- */
-
-#include <JNIHelp.h>
-/* Header for class org_apache_harmony_text_BidiWrapper */
-
-#if !defined(_Included_org_apache_harmony_text_BidiWrapper)
-#define _Included_org_apache_harmony_text_BidiWrapper
-#if defined(__cplusplus)
-extern "C"
-{
-#endif
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_DEFAULT_LTR
-#define org_apache_harmony_text_BidiWrapper_UBIDI_DEFAULT_LTR 254L
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_DEFAULT_RTL
-#define org_apache_harmony_text_BidiWrapper_UBIDI_DEFAULT_RTL 255L
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_MAX_EXPLICIT_LEVEL
-#define org_apache_harmony_text_BidiWrapper_UBIDI_MAX_EXPLICIT_LEVEL 61L
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_LEVEL_OVERRIDE
-#define org_apache_harmony_text_BidiWrapper_UBIDI_LEVEL_OVERRIDE 128L
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_KEEP_BASE_COMBINING
-#define org_apache_harmony_text_BidiWrapper_UBIDI_KEEP_BASE_COMBINING 1L
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_DO_MIRRORING
-#define org_apache_harmony_text_BidiWrapper_UBIDI_DO_MIRRORING 2L
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_INSERT_LRM_FOR_NUMERIC
-#define org_apache_harmony_text_BidiWrapper_UBIDI_INSERT_LRM_FOR_NUMERIC 4L
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_REMOVE_BIDI_CONTROLS
-#define org_apache_harmony_text_BidiWrapper_UBIDI_REMOVE_BIDI_CONTROLS 8L
-#undef org_apache_harmony_text_BidiWrapper_UBIDI_OUTPUT_REVERSE
-#define org_apache_harmony_text_BidiWrapper_UBIDI_OUTPUT_REVERSE 16L
-#undef org_apache_harmony_text_BidiWrapper_UBiDiDirection_UBIDI_LTR
-#define org_apache_harmony_text_BidiWrapper_UBiDiDirection_UBIDI_LTR 0L
-#undef org_apache_harmony_text_BidiWrapper_UBiDiDirection_UBIDI_RTL
-#define org_apache_harmony_text_BidiWrapper_UBiDiDirection_UBIDI_RTL 1L
-#undef org_apache_harmony_text_BidiWrapper_UBiDiDirection_UBIDI_MIXED
-#define org_apache_harmony_text_BidiWrapper_UBiDiDirection_UBIDI_MIXED 2L
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_open
- * Signature: ()J
- */
- JNIEXPORT jlong JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1open
- (JNIEnv *, jclass);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_close
- * Signature: (J)V
- */
- JNIEXPORT void JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1close
- (JNIEnv *, jclass, jlong);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_setPara
- * Signature: (J[CIB[B)V
- */
- JNIEXPORT void JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1setPara
- (JNIEnv *, jclass, jlong, jcharArray, jint, jbyte, jbyteArray);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_setLine
- * Signature: (JII)J
- */
- JNIEXPORT jlong JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1setLine
- (JNIEnv *, jclass, jlong, jint, jint);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_getDirection
- * Signature: (J)I
- */
- JNIEXPORT jint JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getDirection
- (JNIEnv *, jclass, jlong);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_getLength
- * Signature: (J)I
- */
- JNIEXPORT jint JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getLength
- (JNIEnv *, jclass, jlong);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_getParaLevel
- * Signature: (J)B
- */
- JNIEXPORT jbyte JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getParaLevel
- (JNIEnv *, jclass, jlong);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_getLevels
- * Signature: (J)[B
- */
- JNIEXPORT jbyteArray JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getLevels
- (JNIEnv *, jclass, jlong);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_countRuns
- * Signature: (J)I
- */
- JNIEXPORT jint JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1countRuns
- (JNIEnv *, jclass, jlong);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_getRuns
- * Signature: (J)[Lorg/apache/harmony/text/BidiRun;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_text_BidiWrapper_ubidi_1getRuns
- (JNIEnv *, jclass, jlong);
-/*
- * Class: org_apache_harmony_text_BidiWrapper
- * Method: ubidi_reorderVisual
- * Signature: ([BI)[I
- */
- JNIEXPORT jintArray JNICALL
- Java_org_apache_harmony_text_BidiWrapper_ubidi_1reorderVisual (JNIEnv *, jclass,
- jbyteArray, jint);
-#if defined(__cplusplus)
-}
-#endif
-#endif
diff --git a/icu/src/main/native/BreakIteratorInterface.c b/icu/src/main/native/BreakIteratorInterface.c
deleted file mode 100644
index d4bf0c1..0000000
--- a/icu/src/main/native/BreakIteratorInterface.c
+++ /dev/null
@@ -1,264 +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.
- */
-
-#include "JNIHelp.h"
-#include "AndroidSystemNatives.h"
-#include "ErrorCode.h"
-#include "unicode/ubrk.h"
-#include "unicode/putil.h"
-#include <stdlib.h>
-
-static jobjectArray getAvailableLocalesImpl(JNIEnv *env, jclass clazz) {
- jclass stringClass = (*env)->FindClass(env, "java/lang/String");
- if (stringClass == NULL) {
- return NULL;
- }
- size_t count = ubrk_countAvailable();
- jobjectArray result = (*env)->NewObjectArray(env, count, stringClass, NULL);
- size_t i = 0;
- for (; i < count; ++i) {
- jstring s = (*env)->NewStringUTF(env, ubrk_getAvailable(i));
- (*env)->SetObjectArrayElement(env, result, i, s);
- (*env)->DeleteLocalRef(env, s);
- }
- return result;
-}
-
-static jint getCharacterInstanceImpl(JNIEnv *env, jclass clazz, jstring locale) {
-
- UErrorCode status = U_ZERO_ERROR;
-
- const char *localeChars = (*env)->GetStringUTFChars(env, locale, 0);
-
- UBreakIterator *iter = ubrk_open(UBRK_CHARACTER, localeChars, NULL, 0, &status);
-
- (*env)->ReleaseStringUTFChars(env, locale, localeChars);
-
- if ( icu4jni_error(env, status) != FALSE) {
- return 0;
- }
-
- return (long) iter;
-}
-
-static jint getLineInstanceImpl(JNIEnv *env, jclass clazz, jstring locale) {
-
- UErrorCode status = U_ZERO_ERROR;
-
- const char *localeChars = (*env)->GetStringUTFChars(env, locale, 0);
-
- enum UBreakIteratorType type = UBRK_LINE;
-
- UBreakIterator *iter = ubrk_open(type, localeChars, NULL, 0, &status);
-
- (*env)->ReleaseStringUTFChars(env, locale, localeChars);
-
- if ( icu4jni_error(env, status) != FALSE) {
- return 0;
- }
-
- return (long) iter;
-}
-
-static jint getSentenceInstanceImpl(JNIEnv *env, jclass clazz, jstring locale) {
-
- UErrorCode status = U_ZERO_ERROR;
-
- const char *localeChars = (*env)->GetStringUTFChars(env, locale, 0);
-
- enum UBreakIteratorType type = UBRK_SENTENCE;
-
- UBreakIterator *iter = ubrk_open(type, localeChars, NULL, 0, &status);
-
- (*env)->ReleaseStringUTFChars(env, locale, localeChars);
-
- if ( icu4jni_error(env, status) != FALSE) {
- return 0;
- }
-
- return (long) iter;
-}
-
-static jint getWordInstanceImpl(JNIEnv *env, jclass clazz, jstring locale) {
-
- UErrorCode status = U_ZERO_ERROR;
-
- const char *localeChars = (*env)->GetStringUTFChars(env, locale, 0);
-
- enum UBreakIteratorType type = UBRK_WORD;
-
- UBreakIterator *iter = ubrk_open(type, localeChars, NULL, 0, &status);
-
- (*env)->ReleaseStringUTFChars(env, locale, localeChars);
-
- if ( icu4jni_error(env, status) != FALSE) {
- return 0;
- }
-
- return (long) iter;
-}
-
-static void closeBreakIteratorImpl(JNIEnv *env, jclass clazz, jint address) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- ubrk_close(bi);
-}
-
-static jint cloneImpl(JNIEnv *env, jclass clazz, jint address) {
-
- UErrorCode status = U_ZERO_ERROR;
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- jint buffersize = U_BRK_SAFECLONE_BUFFERSIZE;
-
- UBreakIterator *iter = ubrk_safeClone(bi, NULL, &buffersize, &status);
-
- if (icu4jni_error(env, status) != FALSE) {
- return 0;
- }
-
- return (long) iter;
-}
-
-static void setTextImpl(JNIEnv *env, jclass clazz, jint address, jstring text) {
-
- UErrorCode status = U_ZERO_ERROR;
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- const UChar *strUChars = (*env)->GetStringChars(env, text, NULL);
- int strLen = (*env)->GetStringLength(env, text);
-
- ubrk_setText(bi, strUChars, strLen, &status);
-
- (*env)->ReleaseStringChars(env, text, strUChars);
-
- icu4jni_error(env, status);
-}
-
-static jboolean isBoundaryImpl(JNIEnv *env, jclass clazz, jint address, jint offset) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- return ubrk_isBoundary(bi, offset);
-}
-
-static jint nextImpl(JNIEnv *env, jclass clazz, jint address, jint n) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)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 *env, jclass clazz, jint address, jint offset) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- return ubrk_preceding(bi, offset);
-}
-
-static jint firstImpl(JNIEnv *env, jclass clazz, jint address) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- return ubrk_first(bi);
-}
-
-static jint followingImpl(JNIEnv *env, jclass clazz, jint address, jint offset) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- return ubrk_following(bi, offset);
-}
-
-static jint currentImpl(JNIEnv *env, jclass clazz, jint address) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- return ubrk_current(bi);
-}
-
-static jint previousImpl(JNIEnv *env, jclass clazz, jint address) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- return ubrk_previous(bi);
-}
-
-static jint lastImpl(JNIEnv *env, jclass clazz, jint address) {
-
- UBreakIterator *bi = (UBreakIterator *)(long)address;
-
- return ubrk_last(bi);
-}
-
-/*
- * JNI registration
- */
-static JNINativeMethod gMethods[] = {
- /* name, signature, funcPtr */
- { "getAvailableLocalesImpl", "()[Ljava/lang/String;", (void*) getAvailableLocalesImpl },
- { "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 },
- { "closeBreakIteratorImpl", "(I)V",
- (void*) closeBreakIteratorImpl },
- { "cloneImpl", "(I)I",
- (void*) cloneImpl },
- { "setTextImpl", "(ILjava/lang/String;)V",
- (void*) setTextImpl },
- { "isBoundaryImpl", "(II)Z",
- (void*) isBoundaryImpl },
- { "nextImpl", "(II)I",
- (void*) nextImpl },
- { "precedingImpl", "(II)I",
- (void*) precedingImpl },
- { "firstImpl", "(I)I",
- (void*) firstImpl },
- { "lastImpl", "(I)I",
- (void*) lastImpl },
- { "currentImpl", "(I)I",
- (void*) currentImpl },
- { "followingImpl", "(II)I",
- (void*) followingImpl },
- { "previousImpl", "(I)I",
- (void*) previousImpl },
-};
-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/CollationInterface.h b/icu/src/main/native/CollationInterface.h
deleted file mode 100644
index bdb4b67..0000000
--- a/icu/src/main/native/CollationInterface.h
+++ /dev/null
@@ -1,214 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class CollationInterface */
-
-#ifndef _Included_com_ibm_icu4jni_text_NativeCollation
-#define _Included_com_ibm_icu4jni_text_NativeCollation
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: closeCollator
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_text_NativeCollation_closeCollator
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: closeElements
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_text_NativeCollation_closeElements
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: compare
- * Signature: (JLjava/lang/String;Ljava/lang/String;)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_compare
- (JNIEnv *, jclass, jlong, jstring, jstring);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: getAttribute
- * Signature: (JI)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_getAttribute
- (JNIEnv *, jclass, jlong, jint);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: getCollationElementIterator
- * Signature: (JLjava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_com_ibm_icu4jni_text_NativeCollation_getCollationElementIterator
- (JNIEnv *, jclass, jlong, jstring);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: getMaxExpansion
- * Signature: (JI)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_getMaxExpansion
- (JNIEnv *, jclass, jlong, jint);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: getNormalization
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_getNormalization
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: getOffset
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_getOffset
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: getRules
- * Signature: (J)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_com_ibm_icu4jni_text_NativeCollation_getRules
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: getSortKey
- * Signature: (JLjava/lang/String;)[B
- */
-JNIEXPORT jbyteArray JNICALL Java_com_ibm_icu4jni_text_NativeCollation_getSortKey
- (JNIEnv *, jclass, jlong, jstring);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: hashCode
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_hashCode
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: next
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_next
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: openCollator
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_com_ibm_icu4jni_text_NativeCollation_openCollator__
- (JNIEnv *, jclass);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: openCollator
- * Signature: (Ljava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_com_ibm_icu4jni_text_NativeCollation_openCollator__Ljava_lang_String_2
- (JNIEnv *, jclass, jstring);
-
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: openCollatorFromRules
- * Signature: (Ljava/lang/String;II)J
- */
-JNIEXPORT jlong JNICALL Java_com_ibm_icu4jni_text_NativeCollation_openCollatorFromRules
- (JNIEnv *, jclass, jstring, jint, jint);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: previous
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_previous
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: primaryOrder
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_primaryOrder
- (JNIEnv *, jclass, jint);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: reset
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_text_NativeCollation_reset
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: safeClone
- * Signature: (J)J
- */
-JNIEXPORT jlong JNICALL Java_com_ibm_icu4jni_text_NativeCollation_safeClone
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: secondaryOrder
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_secondaryOrder
- (JNIEnv *, jclass, jint);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: setAttribute
- * Signature: (JII)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_text_NativeCollation_setAttribute
- (JNIEnv *, jclass, jlong, jint, jint);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: setOffset
- * Signature: (JI)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_text_NativeCollation_setOffset
- (JNIEnv *, jclass, jlong, jint);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: setText
- * Signature: (JLjava/lang/String;)V
- */
-JNIEXPORT void JNICALL Java_com_ibm_icu4jni_text_NativeCollation_setText
- (JNIEnv *, jclass, jlong, jstring);
-
-/*
- * Class: com_ibm_icu4jni_text_NativeCollation
- * Method: tertiaryOrder
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL Java_com_ibm_icu4jni_text_NativeCollation_tertiaryOrder
- (JNIEnv *, jclass, jint);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/icu/src/main/native/ErrorCode.c b/icu/src/main/native/ErrorCode.cpp
index 94c4239..94c4239 100644
--- a/icu/src/main/native/ErrorCode.c
+++ b/icu/src/main/native/ErrorCode.cpp
diff --git a/icu/src/main/native/NativeBreakIterator.cpp b/icu/src/main/native/NativeBreakIterator.cpp
new file mode 100644
index 0000000..600f501
--- /dev/null
+++ b/icu/src/main/native/NativeBreakIterator.cpp
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+
+#include "JNIHelp.h"
+#include "AndroidSystemNatives.h"
+#include "ErrorCode.h"
+#include "unicode/ubrk.h"
+#include "unicode/putil.h"
+#include <stdlib.h>
+
+static jobjectArray getAvailableLocalesImpl(JNIEnv* env, jclass) {
+ jclass stringClass = env->FindClass("java/lang/String");
+ if (stringClass == NULL) {
+ return NULL;
+ }
+ size_t count = ubrk_countAvailable();
+ jobjectArray result = env->NewObjectArray(count, stringClass, NULL);
+ for (size_t i = 0; i < count; ++i) {
+ jstring s = env->NewStringUTF(ubrk_getAvailable(i));
+ env->SetObjectArrayElement(result, i, s);
+ env->DeleteLocalRef(s);
+ }
+ return result;
+}
+
+static jint getIterator(JNIEnv* env, jstring locale, UBreakIteratorType type) {
+ UErrorCode status = U_ZERO_ERROR;
+ const char* localeChars = env->GetStringUTFChars(locale, NULL);
+ UBreakIterator* it = ubrk_open(type, localeChars, NULL, 0, &status);
+ env->ReleaseStringUTFChars(locale, localeChars);
+ 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 },
+ { "getAvailableLocalesImpl", "()[Ljava/lang/String;", (void*) getAvailableLocalesImpl },
+ { "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/CollationInterface.c b/icu/src/main/native/NativeCollation.cpp
index 14cda90..52c1c7c 100644
--- a/icu/src/main/native/CollationInterface.c
+++ b/icu/src/main/native/NativeCollation.cpp
@@ -62,15 +62,15 @@ static jint compare(JNIEnv *env, jclass obj, jint address,
const UCollator *collator = (const UCollator *)(int)address;
jint result = -2;
if(collator){
- jsize srclength = (*env)->GetStringLength(env, source);
- const UChar *srcstr = (const UChar *)(*env)->GetStringCritical(env,source,0);
- if(srcstr){
- jsize tgtlength = (*env)->GetStringLength(env, target);
- const UChar *tgtstr = (const UChar *)(*env)->GetStringCritical(env,target,0);
+ jsize srcLength = env->GetStringLength(source);
+ const UChar *chars = (const UChar *) env->GetStringCritical(source,0);
+ if(chars){
+ jsize tgtlength = env->GetStringLength(target);
+ const UChar *tgtstr = (const UChar *) env->GetStringCritical(target,0);
if(tgtstr){
- result = ucol_strcoll(collator, srcstr, srclength, tgtstr, tgtlength);
- (*env)->ReleaseStringCritical(env, source, srcstr);
- (*env)->ReleaseStringCritical(env, target, tgtstr);
+ result = ucol_strcoll(collator, chars, srcLength, tgtstr, tgtlength);
+ env->ReleaseStringCritical(source, chars);
+ env->ReleaseStringCritical(target, tgtstr);
return result;
}else{
icu4jni_error(env,U_ILLEGAL_ARGUMENT_ERROR);
@@ -127,12 +127,12 @@ static jint getCollationElementIterator(JNIEnv *env,
UCollator *collator = (UCollator *)(int)address;
jint result=0;
if(collator){
- jsize srclength = (*env)->GetStringLength(env, source);
- const UChar *srcstr = (const UChar *)(*env)->GetStringCritical(env,source,0);
- if(srcstr){
- result = (jint)(ucol_openElements(collator, srcstr, srclength, &status));
+ jsize srcLength = env->GetStringLength(source);
+ const UChar *chars = (const UChar *) env->GetStringCritical(source,0);
+ if(chars){
+ result = (jint)(ucol_openElements(collator, chars, srcLength, &status));
- (*env)->ReleaseStringCritical(env, source, srcstr);
+ env->ReleaseStringCritical(source, chars);
icu4jni_error(env, status);
}else{
icu4jni_error(env, U_ILLEGAL_ARGUMENT_ERROR);
@@ -187,12 +187,10 @@ static jint getNormalization(JNIEnv *env, jclass obj,
* @param address of C collator
* @param mode the normalization mode
*/
-static void setNormalization(JNIEnv *env, jclass obj, jint address,
- jint mode) {
-
- const UCollator* collator = (const UCollator*) address;
+static void setNormalization(JNIEnv *env, jclass, jint address, jint mode) {
+ UCollator* collator = reinterpret_cast<UCollator*>(static_cast<uintptr_t>(address));
UErrorCode status = U_ZERO_ERROR;
- ucol_setAttribute(collator, UCOL_NORMALIZATION_MODE, mode, &status);
+ ucol_setAttribute(collator, UCOL_NORMALIZATION_MODE, UColAttributeValue(mode), &status);
icu4jni_error(env, status);
}
@@ -226,7 +224,7 @@ static jstring getRules(JNIEnv *env, jclass obj,
const UCollator *collator = (const UCollator *)(int)address;
int32_t length=0;
const UChar *rules = ucol_getRules(collator, &length);
- return (*env)->NewString(env, rules, length);
+ return env->NewString(rules, length);
}
/**
@@ -242,45 +240,45 @@ static jbyteArray getSortKey(JNIEnv *env, jclass obj,
jint address, jstring source) {
const UCollator *collator = (const UCollator *)(int)address;
- jbyteArray result;
+ jbyteArray result = NULL;
if(collator && source){
// BEGIN android-added
if(!source) {
return NULL;
}
// END android-added
- jsize srclength = (*env)->GetStringLength(env, source);
- const UChar *srcstr = (const UChar *)(*env)->GetStringCritical(env,source, 0);
- if(srcstr){
+ jsize srcLength = env->GetStringLength(source);
+ const UChar *chars = (const UChar *) env->GetStringCritical(source, 0);
+ if (chars){
// BEGIN android-changed
- uint8_t bytearray[UCOL_MAX_BUFFER * 2];
- uint8_t *largerbytearray = NULL;
- uint8_t *usedbytearray = bytearray;
+ uint8_t byteArray[UCOL_MAX_BUFFER * 2];
+ uint8_t *largerByteArray = NULL;
+ uint8_t *usedByteArray = byteArray;
- jint bytearraysize = ucol_getSortKey(collator, srcstr, srclength, bytearray,
- sizeof(bytearray) - 1);
+ size_t byteArraySize = ucol_getSortKey(collator, chars, srcLength, byteArray,
+ sizeof(byteArray) - 1);
- if (bytearraysize > sizeof(bytearray) - 1) {
- // didn't fit, try again with a larger buffer.
- largerbytearray = malloc(bytearraysize + 1);
- usedbytearray = largerbytearray;
- bytearraysize = ucol_getSortKey(collator, srcstr, srclength, largerbytearray,
- bytearraysize);
+ if (byteArraySize > sizeof(byteArray) - 1) {
+ // didn't fit, try again with a larger buffer.
+ largerByteArray = new uint8_t[byteArraySize + 1];
+ usedByteArray = largerByteArray;
+ byteArraySize = ucol_getSortKey(collator, chars, srcLength, largerByteArray,
+ byteArraySize);
}
- (*env)->ReleaseStringCritical(env, source, srcstr);
+ env->ReleaseStringCritical(source, chars);
- if (bytearraysize == 0) {
- free(largerbytearray);
- return NULL;
+ if (byteArraySize == 0) {
+ delete[] largerByteArray;
+ return NULL;
}
/* no problem converting uint8_t to int8_t, gives back the correct value
* tried and tested
*/
- result = (*env)->NewByteArray(env, bytearraysize);
- (*env)->SetByteArrayRegion(env, result, 0, bytearraysize, usedbytearray);
- free(largerbytearray);
+ result = env->NewByteArray(byteArraySize);
+ env->SetByteArrayRegion(result, 0, byteArraySize, reinterpret_cast<jbyte*>(usedByteArray));
+ delete[] largerByteArray;
// END android-changed
}else{
icu4jni_error(env,U_ILLEGAL_ARGUMENT_ERROR);
@@ -339,9 +337,9 @@ static jint next(JNIEnv *env, jclass obj, jint address) {
*/
static jint openCollator__(JNIEnv *env, jclass obj) {
UErrorCode status = U_ZERO_ERROR;
- jint result = ucol_open(NULL, &status);
+ UCollator* result = ucol_open(NULL, &status);
icu4jni_error(env, status);
- return result;
+ return reinterpret_cast<uintptr_t>(result);
}
@@ -360,17 +358,17 @@ static jint openCollator__Ljava_lang_String_2(JNIEnv *env,
jclass obj, jstring locale) {
/* this will be null terminated */
- const char* localeStr = (*env)->GetStringUTFChars(env, locale, NULL);
+ const char* localeStr = env->GetStringUTFChars(locale, NULL);
if (localeStr == NULL) {
icu4jni_error(env, U_ILLEGAL_ARGUMENT_ERROR);
return 0;
}
UErrorCode status = U_ZERO_ERROR;
- jint result = ucol_open(localeStr, &status);
- (*env)->ReleaseStringUTFChars(env, locale, localeStr);
+ UCollator* result = ucol_open(localeStr, &status);
+ env->ReleaseStringUTFChars(locale, localeStr);
icu4jni_error(env, status);
- return result;
+ return reinterpret_cast<uintptr_t>(result);
}
/**
@@ -389,8 +387,8 @@ static jint openCollator__Ljava_lang_String_2(JNIEnv *env,
static jint openCollatorFromRules(JNIEnv *env, jclass obj,
jstring rules, jint normalizationmode, jint strength) {
- jsize ruleslength = (*env)->GetStringLength(env, rules);
- const UChar *rulestr = (const UChar *)(*env)->GetStringCritical(env,rules, 0);
+ jsize ruleslength = env->GetStringLength(rules);
+ const UChar *rulestr = (const UChar *) env->GetStringCritical(rules, 0);
UErrorCode status = U_ZERO_ERROR;
jint result = 0;
if(rulestr){
@@ -398,7 +396,7 @@ static jint openCollatorFromRules(JNIEnv *env, jclass obj,
(UColAttributeValue)normalizationmode,
(UCollationStrength)strength, NULL, &status);
- (*env)->ReleaseStringCritical(env, rules, rulestr);
+ env->ReleaseStringCritical(rules, rulestr);
icu4jni_error(env, status);
}else{
icu4jni_error(env,U_ILLEGAL_ARGUMENT_ERROR);
@@ -516,27 +514,26 @@ static void setText(JNIEnv *env, jclass obj, jint address,
UCollationElements *iterator = (UCollationElements *)(int)address;
UErrorCode status = U_ZERO_ERROR;
- int strlength = (*env)->GetStringLength(env, source);
- const UChar *str = (const UChar *)(*env)->GetStringCritical(env, source, 0);
+ int strlength = env->GetStringLength(source);
+ const UChar *str = (const UChar *) env->GetStringCritical(source, 0);
ucol_setText(iterator, str, strlength, &status);
- (*env)->ReleaseStringCritical(env, source, str);
+ env->ReleaseStringCritical(source, str);
icu4jni_error(env, status);
}
static jobjectArray getAvailableLocalesImpl(JNIEnv *env, jclass clazz) {
- jclass stringClass = (*env)->FindClass(env, "java/lang/String");
+ jclass stringClass = env->FindClass("java/lang/String");
if (stringClass == NULL) {
return NULL;
}
size_t count = ucol_countAvailable();
- jobjectArray result = (*env)->NewObjectArray(env, count, stringClass, NULL);
- size_t i = 0;
- for (; i < count; ++i) {
- jstring s = (*env)->NewStringUTF(env, ucol_getAvailable(i));
- (*env)->SetObjectArrayElement(env, result, i, s);
- (*env)->DeleteLocalRef(env, s);
+ jobjectArray result = env->NewObjectArray(count, stringClass, NULL);
+ for (size_t i = 0; i < count; ++i) {
+ jstring s = env->NewStringUTF(ucol_getAvailable(i));
+ env->SetObjectArrayElement(result, i, s);
+ env->DeleteLocalRef(s);
}
return result;
}
diff --git a/icu/src/main/native/ConverterInterface.c b/icu/src/main/native/NativeConverter.cpp
index d7a159b..f704e8f 100644
--- a/icu/src/main/native/ConverterInterface.c
+++ b/icu/src/main/native/NativeConverter.cpp
@@ -36,7 +36,7 @@
// END android-removed
/* Prototype of callback for substituting user settable sub chars */
-void JNI_TO_U_CALLBACK_SUBSTITUTE
+static void JNI_TO_U_CALLBACK_SUBSTITUTE
(const void *,UConverterToUnicodeArgs *,const char* ,int32_t ,UConverterCallbackReason ,UErrorCode * );
/**
@@ -51,13 +51,13 @@ static jlong openConverter (JNIEnv *env, jclass jClass, jstring converterName) {
UConverter* conv=NULL;
UErrorCode errorCode = U_ZERO_ERROR;
- const char* cnvName= (const char*) (*env)->GetStringUTFChars(env, converterName,NULL);
+ const char* cnvName= (const char*) env->GetStringUTFChars(converterName,NULL);
if(cnvName) {
- int count = (*env)->GetStringUTFLength(env,converterName);
+ int count = env->GetStringUTFLength(converterName);
conv = ucnv_open(cnvName,&errorCode);
}
- (*env)->ReleaseStringUTFChars(env, converterName,cnvName);
+ env->ReleaseStringUTFChars(converterName,cnvName);
if (icu4jni_error(env, errorCode) != FALSE) {
return 0;
@@ -80,10 +80,13 @@ static void closeConverter (JNIEnv *env, jclass jClass, jlong handle) {
// Free up any contexts created in setCallback[Encode|Decode]()
UConverterToUCallback toAction;
UConverterFromUCallback fromAction;
- void * context1 = NULL;
- void * context2 = NULL;
- ucnv_getToUCallBack(cnv, &toAction, &context1);
- ucnv_getFromUCallBack(cnv, &fromAction, &context2);
+ 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
@@ -196,23 +199,22 @@ static jint setSubstitutionModeByteToChar (JNIEnv *env, jclass jClass, jlong han
* @param flush boolean that specifies end of source input
*/
static jint convertCharToByte(JNIEnv *env, jclass 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(env,data,NULL);
+ jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
if(myData) {
jint* sourceOffset = &myData[0];
jint* targetOffset = &myData[1];
- const jchar* uSource =(jchar*) (*env)->GetPrimitiveArrayCritical(env,source, NULL);
+ const jchar* uSource =(jchar*) env->GetPrimitiveArrayCritical(source, NULL);
if(uSource) {
- jbyte* uTarget=(jbyte*) (*env)->GetPrimitiveArrayCritical(env,target,NULL);
+ jbyte* uTarget=(jbyte*) env->GetPrimitiveArrayCritical(target,NULL);
if(uTarget) {
const jchar* mySource = uSource+ *sourceOffset;
const UChar* mySourceLimit= uSource+sourceEnd;
- char* cTarget=uTarget+ *targetOffset;
- const char* cTargetLimit=uTarget+targetEnd;
+ 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);
@@ -220,23 +222,23 @@ static jint convertCharToByte(JNIEnv *env, jclass jClass, jlong handle, jcharAr
*sourceOffset = (jint) (mySource - uSource)-*sourceOffset;
*targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset;
if(U_FAILURE(errorCode)) {
- (*env)->ReleasePrimitiveArrayCritical(env,target,uTarget,0);
- (*env)->ReleasePrimitiveArrayCritical(env,source,(jchar*)uSource,0);
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ 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(env,target,uTarget,0);
+ env->ReleasePrimitiveArrayCritical(target,uTarget,0);
}else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,source,(jchar*)uSource,0);
+ env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
}else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return errorCode;
}
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
@@ -245,9 +247,9 @@ static jint convertCharToByte(JNIEnv *env, jclass jClass, jlong handle, jcharAr
static jint encode(JNIEnv *env, jclass jClass, jlong handle, jcharArray source, jint sourceEnd, jbyteArray target, jint targetEnd, jintArray data, jboolean flush) {
- UErrorCode ec = convertCharToByte(env,jClass,handle,source,sourceEnd, target,targetEnd,data,flush);
+ UErrorCode ec = UErrorCode(convertCharToByte(env, jClass,handle,source,sourceEnd, target,targetEnd,data,flush));
UConverter* cnv = (UConverter*)handle;
- jint* myData = (jint*) (*env)->GetPrimitiveArrayCritical(env,data,NULL);
+ jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
if(cnv && myData) {
@@ -264,7 +266,7 @@ static jint encode(JNIEnv *env, jclass jClass, jlong handle, jcharArray source,
}
}
}
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return ec;
}
@@ -285,17 +287,17 @@ static jint convertByteToChar(JNIEnv *env, jclass jClass, jlong handle, jbyteArr
UErrorCode errorCode =U_ZERO_ERROR;
UConverter* cnv = (UConverter*)handle;
if(cnv) {
- jint* myData = (jint*) (*env)->GetPrimitiveArrayCritical(env,data,NULL);
+ jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
if(myData) {
jint* sourceOffset = &myData[0];
jint* targetOffset = &myData[1];
- const jbyte* uSource =(jbyte*) (*env)->GetPrimitiveArrayCritical(env,source, NULL);
+ const jbyte* uSource =(jbyte*) env->GetPrimitiveArrayCritical(source, NULL);
if(uSource) {
- jchar* uTarget=(jchar*) (*env)->GetPrimitiveArrayCritical(env,target,NULL);
+ jchar* uTarget=(jchar*) env->GetPrimitiveArrayCritical(target,NULL);
if(uTarget) {
const jbyte* mySource = uSource+ *sourceOffset;
- const char* mySourceLimit= uSource+sourceEnd;
+ const char* mySourceLimit = reinterpret_cast<const char*>(uSource+sourceEnd);
UChar* cTarget=uTarget+ *targetOffset;
const UChar* cTargetLimit=uTarget+targetEnd;
@@ -305,23 +307,23 @@ static jint convertByteToChar(JNIEnv *env, jclass jClass, jlong handle, jbyteArr
*sourceOffset = mySource - uSource - *sourceOffset ;
*targetOffset = cTarget - uTarget - *targetOffset;
if(U_FAILURE(errorCode)) {
- (*env)->ReleasePrimitiveArrayCritical(env,target,uTarget,0);
- (*env)->ReleasePrimitiveArrayCritical(env,source,(jchar*)uSource,0);
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ 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(env,target,uTarget,0);
+ env->ReleasePrimitiveArrayCritical(target,uTarget,0);
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,source,(jchar*)uSource,0);
+ env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return errorCode;
}
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
@@ -332,7 +334,7 @@ static jint decode(JNIEnv *env, jclass jClass, jlong handle, jbyteArray source,
jint ec = convertByteToChar(env, jClass,handle,source,sourceEnd, target,targetEnd,data,flush);
- jint* myData = (jint*) (*env)->GetPrimitiveArrayCritical(env,data,NULL);
+ jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
UConverter* cnv = (UConverter*)handle;
if(myData && cnv) {
@@ -349,7 +351,7 @@ static jint decode(JNIEnv *env, jclass jClass, jlong handle, jbyteArray source,
}
}
}
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return ec;
}
static void resetByteToChar(JNIEnv *env, jclass jClass, jlong handle) {
@@ -376,11 +378,11 @@ static jint countInvalidBytes (JNIEnv *env, jclass jClass, jlong handle, jintArr
if(cnv) {
char invalidChars[32];
- jint* len = (jint*) (*env)->GetPrimitiveArrayCritical(env,length, NULL);
+ jint* len = (jint*) env->GetPrimitiveArrayCritical(length, NULL);
if(len) {
ucnv_getInvalidChars(cnv,invalidChars,(int8_t*)len,&errorCode);
}
- (*env)->ReleasePrimitiveArrayCritical(env,length,(jint*)len,0);
+ env->ReleasePrimitiveArrayCritical(length,(jint*)len,0);
return errorCode;
}
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
@@ -395,11 +397,11 @@ static jint countInvalidChars(JNIEnv *env, jclass jClass, jlong handle, jintArra
UConverter* cnv = (UConverter*)handle;
UChar invalidUChars[32];
if(cnv) {
- jint* len = (jint*) (*env)->GetPrimitiveArrayCritical(env,length, NULL);
+ jint* len = (jint*) env->GetPrimitiveArrayCritical(length, NULL);
if(len) {
ucnv_getInvalidUChars(cnv,invalidUChars,(int8_t*)len,&errorCode);
}
- (*env)->ReleasePrimitiveArrayCritical(env,length,(jint*)len,0);
+ env->ReleasePrimitiveArrayCritical(length,(jint*)len,0);
return errorCode;
}
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
@@ -440,13 +442,13 @@ static jint flushByteToChar(JNIEnv *env, jclass jClass,jlong handle, jcharArray
UConverter* cnv = (UConverter*)handle;
if(cnv) {
jbyte source ='\0';
- jint* myData = (jint*) (*env)->GetPrimitiveArrayCritical(env,data,NULL);
+ jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
if(myData) {
jint* targetOffset = &myData[1];
- jchar* uTarget=(jchar*) (*env)->GetPrimitiveArrayCritical(env,target,NULL);
+ jchar* uTarget=(jchar*) env->GetPrimitiveArrayCritical(target,NULL);
if(uTarget) {
- const jbyte* mySource =&source;
- const char* mySourceLimit=&source;
+ const jbyte* mySource = &source;
+ const char* mySourceLimit = reinterpret_cast<char*>(&source);
UChar* cTarget=uTarget+ *targetOffset;
const UChar* cTargetLimit=uTarget+targetEnd;
@@ -456,19 +458,19 @@ static jint flushByteToChar(JNIEnv *env, jclass jClass,jlong handle, jcharArray
*targetOffset = (jint) ((jchar*)cTarget - uTarget)- *targetOffset;
if(U_FAILURE(errorCode)) {
- (*env)->ReleasePrimitiveArrayCritical(env,target,uTarget,0);
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ env->ReleasePrimitiveArrayCritical(target,uTarget,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return errorCode;
}
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,target,uTarget,0);
+ env->ReleasePrimitiveArrayCritical(target,uTarget,0);
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return errorCode;
}
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
@@ -481,15 +483,15 @@ static jint flushCharToByte (JNIEnv *env, jclass jClass, jlong handle, jbyteArra
UConverter* cnv = (UConverter*)handle;
jchar source = '\0';
if(cnv) {
- jint* myData = (jint*) (*env)->GetPrimitiveArrayCritical(env,data,NULL);
+ jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
if(myData) {
jint* targetOffset = &myData[1];
- jbyte* uTarget=(jbyte*) (*env)->GetPrimitiveArrayCritical(env,target,NULL);
+ jbyte* uTarget=(jbyte*) env->GetPrimitiveArrayCritical(target,NULL);
if(uTarget) {
const jchar* mySource = &source;
const UChar* mySourceLimit= &source;
- char* cTarget=uTarget+ *targetOffset;
- const char* cTargetLimit=uTarget+targetEnd;
+ 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);
@@ -497,26 +499,26 @@ static jint flushCharToByte (JNIEnv *env, jclass jClass, jlong handle, jbyteArra
*targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset;
if(U_FAILURE(errorCode)) {
- (*env)->ReleasePrimitiveArrayCritical(env,target,uTarget,0);
+ env->ReleasePrimitiveArrayCritical(target,uTarget,0);
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return errorCode;
}
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,target,uTarget,0);
+ env->ReleasePrimitiveArrayCritical(target,uTarget,0);
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,data,(jint*)myData,0);
+ env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
return errorCode;
}
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
return errorCode;
}
-void toChars(const UChar* us, char* cs, int32_t length) {
+static void toChars(const UChar* us, char* cs, int32_t length) {
UChar u;
while(length>0) {
u=*us++;
@@ -529,21 +531,21 @@ static jint setSubstitutionBytes(JNIEnv *env, jclass jClass, jlong handle, jbyte
UConverter* cnv = (UConverter*) handle;
UErrorCode errorCode = U_ZERO_ERROR;
if(cnv) {
- jbyte* u_subChars = (*env)->GetPrimitiveArrayCritical(env,subChars,NULL);
+ jbyte* u_subChars = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(subChars, NULL));
if(u_subChars) {
- char* mySubChars= (char*)malloc(sizeof(char)*length);
+ char* mySubChars = new char[length];
toChars((UChar*)u_subChars,&mySubChars[0],length);
ucnv_setSubstChars(cnv,mySubChars, (char)length,&errorCode);
if(U_FAILURE(errorCode)) {
- (*env)->ReleasePrimitiveArrayCritical(env,subChars,mySubChars,0);
+ env->ReleasePrimitiveArrayCritical(subChars,mySubChars,0);
return errorCode;
}
- free(mySubChars);
+ delete[] mySubChars;
}
else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
- (*env)->ReleasePrimitiveArrayCritical(env,subChars,u_subChars,0);
+ env->ReleasePrimitiveArrayCritical(subChars,u_subChars,0);
return errorCode;
}
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
@@ -553,11 +555,11 @@ static jint setSubstitutionBytes(JNIEnv *env, jclass jClass, jlong handle, jbyte
#define VALUE_STRING_LENGTH 32
-typedef struct{
+struct SubCharStruct {
int length;
UChar subChars[256];
UBool stopOnIllegal;
-}SubCharStruct;
+};
static UErrorCode
@@ -601,14 +603,14 @@ static jint setSubstitutionChars(JNIEnv *env, jclass jClass, jlong handle, jchar
jchar* u_subChars=NULL;
if(cnv) {
if(subChars) {
- int len = (*env)->GetArrayLength(env,subChars);
- u_subChars = (*env)->GetPrimitiveArrayCritical(env,subChars,NULL);
+ 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(env,subChars,u_subChars,0);
+ env->ReleasePrimitiveArrayCritical(subChars,u_subChars,0);
return errorCode;
}
}
@@ -616,7 +618,7 @@ static jint setSubstitutionChars(JNIEnv *env, jclass jClass, jlong handle, jchar
}
-void JNI_TO_U_CALLBACK_SUBSTITUTE( const void *context, UConverterToUnicodeArgs *toArgs, const char* codeUnits, int32_t length, UConverterCallbackReason reason, UErrorCode * err) {
+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;
@@ -676,33 +678,32 @@ static jboolean canDecode(JNIEnv *env, jclass jClass, jlong handle, jbyteArray s
UErrorCode errorCode =U_ZERO_ERROR;
UConverter* cnv = (UConverter*)handle;
if(cnv) {
- jint len = (*env)->GetArrayLength(env,source);
- jbyte* cSource =(jbyte*) (*env)->GetPrimitiveArrayCritical(env,source, NULL);
+ jint len = env->GetArrayLength(source);
+ jbyte* cSource =(jbyte*) env->GetPrimitiveArrayCritical(source, NULL);
if(cSource) {
- const jbyte* cSourceLimit = cSource+len;
+ const char* cSourceLimit = reinterpret_cast<const char*>(cSource+len);
/* Assume that we need at most twice the length of source */
UChar* target = (UChar*) malloc(sizeof(UChar)* (len<<1));
UChar* targetLimit = target + (len<<1);
if(target) {
- ucnv_toUnicode(cnv,&target,targetLimit,
- (const char**)&cSource,
- cSourceLimit,NULL, TRUE,&errorCode);
+ ucnv_toUnicode(cnv,&target,targetLimit, (const char**)&cSource,
+ cSourceLimit,NULL, TRUE,&errorCode);
if(U_SUCCESS(errorCode)) {
free(target);
- (*env)->ReleasePrimitiveArrayCritical(env,source,cSource,0);
+ env->ReleasePrimitiveArrayCritical(source,cSource,0);
return (jboolean)TRUE;
}
}
free(target);
}
- (*env)->ReleasePrimitiveArrayCritical(env,source,cSource,0);
+ env->ReleasePrimitiveArrayCritical(source,cSource,0);
}
return (jboolean)FALSE;
}
-int32_t copyString(char* dest, int32_t destCapacity, int32_t startIndex,
+static int32_t copyString(char* dest, int32_t destCapacity, int32_t startIndex,
const char* src, UErrorCode* status) {
int32_t srcLen = 0, i=0;
if(U_FAILURE(*status)) {
@@ -725,7 +726,7 @@ int32_t copyString(char* dest, int32_t destCapacity, int32_t startIndex,
return startIndex;
}
-int32_t getJavaCanonicalName1(const char* icuCanonicalName,
+static int32_t getJavaCanonicalName1(const char* icuCanonicalName,
char* canonicalName, int32_t capacity,
UErrorCode* status) {
/*
@@ -791,9 +792,8 @@ static jobjectArray getAvailable(JNIEnv *env, jclass jClass) {
UErrorCode error = U_ZERO_ERROR;
const char* name =NULL;
char canonicalName[256]={0};
- ret= (jobjectArray)(*env)->NewObjectArray( env,num,
- (*env)->FindClass(env,"java/lang/String"),
- (*env)->NewStringUTF(env,""));
+ ret= env->NewObjectArray(num, env->FindClass("java/lang/String"),
+ env->NewStringUTF(""));
for(i=0;i<num;i++) {
name = ucnv_getAvailableName(i);
@@ -806,9 +806,9 @@ static jobjectArray getAvailable(JNIEnv *env, jclass jClass) {
printf("canonical name for %s\n", canonicalName);
#endif
// BEGIN android-changed
- jstring canonName = (*env)->NewStringUTF(env,canonicalName);
- (*env)->SetObjectArrayElement(env,ret,i,canonName);
- (*env)->DeleteLocalRef(env, canonName);
+ jstring canonName = env->NewStringUTF(canonicalName);
+ env->SetObjectArrayElement(ret,i,canonName);
+ env->DeleteLocalRef(canonName);
// END android-changed
/*printf("canonical name : %s at %i\n", name,i); */
canonicalName[0]='\0';/* nul terminate */
@@ -820,13 +820,13 @@ static jint countAliases(JNIEnv *env, jclass jClass,jstring enc) {
UErrorCode error = U_ZERO_ERROR;
jint num =0;
- const char* encName = (*env)->GetStringUTFChars(env,enc,NULL);
+ const char* encName = env->GetStringUTFChars(enc,NULL);
if(encName) {
num = ucnv_countAliases(encName,&error);
}
- (*env)->ReleaseStringUTFChars(env,enc,encName);
+ env->ReleaseStringUTFChars(enc,encName);
return num;
}
@@ -837,7 +837,7 @@ static jobjectArray getAliases(JNIEnv *env, jclass jClass, jstring enc) {
jobjectArray ret=NULL;
int32_t aliasNum = 0;
UErrorCode error = U_ZERO_ERROR;
- const char* encName = (*env)->GetStringUTFChars(env,enc,NULL);
+ const char* encName = env->GetStringUTFChars(enc,NULL);
int i=0;
int j=0;
const char* aliasArray[50];
@@ -880,19 +880,18 @@ static jobjectArray getAliases(JNIEnv *env, jclass jClass, jstring enc) {
// }
// END android-removed
- ret = (jobjectArray)(*env)->NewObjectArray(env,j,
- (*env)->FindClass(env,"java/lang/String"),
- (*env)->NewStringUTF(env,""));
+ ret = (jobjectArray)env->NewObjectArray(j,
+ env->FindClass("java/lang/String"), env->NewStringUTF(""));
for(;--j>=0;) {
// BEGIN android-changed
- jstring alias = (*env)->NewStringUTF(env, aliasArray[j]);
- (*env)->SetObjectArrayElement(env, ret, j, alias);
- (*env)->DeleteLocalRef(env, alias);
+ jstring alias = env->NewStringUTF(aliasArray[j]);
+ env->SetObjectArrayElement(ret, j, alias);
+ env->DeleteLocalRef(alias);
// END android-changed
}
}
}
- (*env)->ReleaseStringUTFChars(env,enc,encName);
+ env->ReleaseStringUTFChars(enc,encName);
return (ret);
}
@@ -900,7 +899,7 @@ static jobjectArray getAliases(JNIEnv *env, jclass jClass, jstring enc) {
static jstring getCanonicalName(JNIEnv *env, jclass jClass,jstring enc) {
UErrorCode error = U_ZERO_ERROR;
- const char* encName = (*env)->GetStringUTFChars(env,enc,NULL);
+ const char* encName = env->GetStringUTFChars(enc,NULL);
const char* canonicalName = "";
// BEGIN android-changed
jstring ret = NULL;
@@ -909,8 +908,8 @@ static jstring getCanonicalName(JNIEnv *env, jclass jClass,jstring enc) {
if(canonicalName !=NULL && strstr(canonicalName,",")!=0) {
canonicalName = ucnv_getAlias(canonicalName,1,&error);
}
- ret = ((*env)->NewStringUTF(env, canonicalName));
- (*env)->ReleaseStringUTFChars(env,enc,encName);
+ ret = (env->NewStringUTF(canonicalName));
+ env->ReleaseStringUTFChars(enc,encName);
}
// END android-changed
return ret;
@@ -919,42 +918,42 @@ static jstring getCanonicalName(JNIEnv *env, jclass jClass,jstring enc) {
static jstring getICUCanonicalName(JNIEnv *env, jclass jClass, jstring enc) {
UErrorCode error = U_ZERO_ERROR;
- const char* encName = (*env)->GetStringUTFChars(env,enc,NULL);
+ const char* encName = env->GetStringUTFChars(enc,NULL);
const char* canonicalName = NULL;
jstring ret = NULL;
if(encName) {
// BEGIN android-removed
// if(strcmp(encName,"UTF-16")==0) {
- // ret = ((*env)->NewStringUTF(env,UTF_16BE));
+ // ret = (env->NewStringUTF(UTF_16BE));
// }else
// END android-removed
if((canonicalName = ucnv_getCanonicalName(encName, "MIME", &error))!=NULL) {
- ret = ((*env)->NewStringUTF(env, canonicalName));
+ ret = (env->NewStringUTF(canonicalName));
}else if((canonicalName = ucnv_getCanonicalName(encName, "IANA", &error))!=NULL) {
- ret = ((*env)->NewStringUTF(env, canonicalName));
+ ret = (env->NewStringUTF(canonicalName));
}else if((canonicalName = ucnv_getCanonicalName(encName, "", &error))!=NULL) {
- ret = ((*env)->NewStringUTF(env, canonicalName));
+ ret = (env->NewStringUTF(canonicalName));
}else if((canonicalName = ucnv_getAlias(encName, 0, &error)) != NULL) {
/* we have some aliases in the form x-blah .. match those first */
- ret = ((*env)->NewStringUTF(env, canonicalName));
+ ret = (env->NewStringUTF(canonicalName));
}else if( ret ==NULL && strstr(encName, "x-") == encName) {
/* check if the converter can be opened with the encName given */
UConverter* conv = NULL;
error = U_ZERO_ERROR;
conv = ucnv_open(encName+2, &error);
if(conv!=NULL) {
- ret = ((*env)->NewStringUTF(env, encName+2));
+ ret = (env->NewStringUTF(encName+2));
}else{
/* unsupported encoding */
- ret = ((*env)->NewStringUTF(env, ""));
+ ret = (env->NewStringUTF(""));
}
ucnv_close(conv);
}else{
/* unsupported encoding */
- ret = ((*env)->NewStringUTF(env, ""));
+ ret = (env->NewStringUTF(""));
}
}
- (*env)->ReleaseStringUTFChars(env,enc,encName);
+ env->ReleaseStringUTFChars(enc,encName);
return ret;
}
@@ -969,26 +968,26 @@ static jstring getJavaCanonicalName2(JNIEnv *env, jclass jClass, jstring icuCano
registry then its canonical name must begin with one of the strings "X-" or "x-".
*/
UErrorCode error = U_ZERO_ERROR;
- const char* icuCanonicalName = (*env)->GetStringUTFChars(env,icuCanonName,NULL);
+ const char* icuCanonicalName = env->GetStringUTFChars(icuCanonName,NULL);
char cName[UCNV_MAX_CONVERTER_NAME_LENGTH] = {0};
jstring ret;
if(icuCanonicalName && icuCanonicalName[0] != 0) {
getJavaCanonicalName1(icuCanonicalName, cName, UCNV_MAX_CONVERTER_NAME_LENGTH, &error);
}
- ret = ((*env)->NewStringUTF(env, cName));
- (*env)->ReleaseStringUTFChars(env,icuCanonName,icuCanonicalName);
+ ret = (env->NewStringUTF(cName));
+ env->ReleaseStringUTFChars(icuCanonName,icuCanonicalName);
return ret;
}
#define SUBS_ARRAY_CAPACITY 256
-typedef struct{
+struct EncoderCallbackContext {
int length;
char subChars[SUBS_ARRAY_CAPACITY];
UConverterFromUCallback onUnmappableInput;
UConverterFromUCallback onMalformedInput;
-}EncoderCallbackContext;
+};
-void CHARSET_ENCODER_CALLBACK(const void *context,
+static void CHARSET_ENCODER_CALLBACK(const void *context,
UConverterFromUnicodeArgs *fromArgs,
const UChar* codeUnits,
int32_t length,
@@ -1030,7 +1029,7 @@ void CHARSET_ENCODER_CALLBACK(const void *context,
}
}
-void JNI_FROM_U_CALLBACK_SUBSTITUTE_ENCODER(const void *context,
+static void JNI_FROM_U_CALLBACK_SUBSTITUTE_ENCODER(const void *context,
UConverterFromUnicodeArgs *fromArgs,
const UChar* codeUnits,
int32_t length,
@@ -1045,7 +1044,7 @@ void JNI_FROM_U_CALLBACK_SUBSTITUTE_ENCODER(const void *context,
return;
}
-UConverterFromUCallback getFromUCallback(int32_t mode) {
+static UConverterFromUCallback getFromUCallback(int32_t mode) {
switch(mode) {
default: /* falls through */
case com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK:
@@ -1068,8 +1067,8 @@ static jint setCallbackEncode(JNIEnv *env, jclass jClass, jlong handle, jint onM
void* fromUOldContext = NULL;
EncoderCallbackContext* fromUNewContext=NULL;
UConverterFromUCallback fromUNewAction=NULL;
- jbyte* sub = (jbyte*) (*env)->GetPrimitiveArrayCritical(env,subChars, NULL);
- ucnv_getFromUCallBack(conv, &fromUOldAction, &fromUOldContext);
+ 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
@@ -1079,7 +1078,7 @@ static jint setCallbackEncode(JNIEnv *env, jclass jClass, jlong handle, jint onM
fromUNewContext = (EncoderCallbackContext*) malloc(sizeof(EncoderCallbackContext));
fromUNewAction = CHARSET_ENCODER_CALLBACK;
}else{
- fromUNewContext = fromUOldContext;
+ fromUNewContext = (EncoderCallbackContext*) fromUOldContext;
fromUNewAction = fromUOldAction;
fromUOldAction = NULL;
fromUOldContext = NULL;
@@ -1089,8 +1088,9 @@ static jint setCallbackEncode(JNIEnv *env, jclass jClass, jlong handle, jint onM
// BEGIN android-changed
if(sub!=NULL) {
fromUNewContext->length = length;
- strncpy(fromUNewContext->subChars, sub, length);
- (*env)->ReleasePrimitiveArrayCritical(env,subChars, sub, 0);
+ 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;
}
@@ -1109,14 +1109,14 @@ static jint setCallbackEncode(JNIEnv *env, jclass jClass, jlong handle, jint onM
return U_ILLEGAL_ARGUMENT_ERROR;
}
-typedef struct{
+struct DecoderCallbackContext {
int length;
UChar subUChars[256];
UConverterToUCallback onUnmappableInput;
UConverterToUCallback onMalformedInput;
-}DecoderCallbackContext;
+};
-void JNI_TO_U_CALLBACK_SUBSTITUTE_DECODER(const void *context,
+static void JNI_TO_U_CALLBACK_SUBSTITUTE_DECODER(const void *context,
UConverterToUnicodeArgs *toArgs,
const char* codeUnits,
int32_t length,
@@ -1130,7 +1130,7 @@ void JNI_TO_U_CALLBACK_SUBSTITUTE_DECODER(const void *context,
return;
}
-UConverterToUCallback getToUCallback(int32_t mode) {
+static UConverterToUCallback getToUCallback(int32_t mode) {
switch(mode) {
default: /* falls through */
case com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK:
@@ -1142,7 +1142,7 @@ UConverterToUCallback getToUCallback(int32_t mode) {
}
}
-void CHARSET_DECODER_CALLBACK(const void *context,
+static void CHARSET_DECODER_CALLBACK(const void *context,
UConverterToUnicodeArgs *args,
const char* codeUnits,
int32_t length,
@@ -1194,9 +1194,9 @@ static jint setCallbackDecode(JNIEnv *env, jclass jClass, jlong handle, jint onM
void* toUOldContext;
DecoderCallbackContext* toUNewContext = NULL;
UConverterToUCallback toUNewAction = NULL;
- jchar* sub = (jchar*) (*env)->GetPrimitiveArrayCritical(env,subChars, NULL);
+ jchar* sub = (jchar*) env->GetPrimitiveArrayCritical(subChars, NULL);
- ucnv_getToUCallBack(conv, &toUOldAction, &toUOldContext);
+ ucnv_getToUCallBack(conv, &toUOldAction, const_cast<const void**>(&toUOldContext));
/* toUOldContext can only be DecodeCallbackContext since
the converter created is private data for the decoder
@@ -1206,7 +1206,7 @@ static jint setCallbackDecode(JNIEnv *env, jclass jClass, jlong handle, jint onM
toUNewContext = (DecoderCallbackContext*) malloc(sizeof(DecoderCallbackContext));
toUNewAction = CHARSET_DECODER_CALLBACK;
}else{
- toUNewContext = toUOldContext;
+ toUNewContext = reinterpret_cast<DecoderCallbackContext*>(toUOldContext);
toUNewAction = toUOldAction;
toUOldAction = NULL;
toUOldContext = NULL;
@@ -1217,7 +1217,7 @@ static jint setCallbackDecode(JNIEnv *env, jclass jClass, jlong handle, jint onM
if(sub!=NULL) {
toUNewContext->length = length;
u_strncpy(toUNewContext->subUChars, sub, length);
- (*env)->ReleasePrimitiveArrayCritical(env,subChars, sub, 0);
+ env->ReleasePrimitiveArrayCritical(subChars, sub, 0);
}else{
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
}
@@ -1234,25 +1234,16 @@ static jint setCallbackDecode(JNIEnv *env, jclass jClass, jlong handle, jint onM
return U_ILLEGAL_ARGUMENT_ERROR;
}
-static jlong safeClone(JNIEnv *env, jclass jClass, jlong src) {
-
- UErrorCode status = U_ZERO_ERROR;
-
- jint buffersize = U_CNV_SAFECLONE_BUFFERSIZE;
-
- UConverter* conv=NULL;
- UErrorCode errorCode = U_ZERO_ERROR;
- UConverter* source = (UConverter*) src;
-
- if(source) {
- conv = ucnv_safeClone(source, NULL, &buffersize, &errorCode);
- }
-
- if (icu4jni_error(env, errorCode) != FALSE) {
+static jlong safeClone(JNIEnv *env, jclass, jlong address) {
+ UConverter* source = reinterpret_cast<UConverter*>(static_cast<uintptr_t>(address));
+ if (!source) {
return NULL;
}
-
- return conv;
+ UErrorCode status = U_ZERO_ERROR;
+ jint bufferSize = U_CNV_SAFECLONE_BUFFERSIZE;
+ UConverter* conv = ucnv_safeClone(source, NULL, &bufferSize, &status);
+ icu4jni_error(env, status);
+ return reinterpret_cast<uintptr_t>(conv);
}
static jint getMaxCharsPerByte(JNIEnv *env, jclass jClass, jlong handle) {
@@ -1268,7 +1259,7 @@ static jfloat getAveCharsPerByte(JNIEnv *env, jclass jClass, jlong handle) {
return ret;
}
-void toUChars(const char* cs, UChar* us, int32_t length) {
+static void toUChars(const char* cs, UChar* us, int32_t length) {
char c;
while(length>0) {
c=*cs++;
@@ -1287,14 +1278,14 @@ static jbyteArray getSubstitutionBytes(JNIEnv *env, jclass jClass, jlong handle)
if(cnv) {
ucnv_getSubstChars(cnv,subBytes,&len,&status);
if(U_SUCCESS(status)) {
- arr = ((*env)->NewByteArray(env, len));
+ arr = (env->NewByteArray(len));
if(arr) {
- (*env)->SetByteArrayRegion(env,arr,0,len,(jbyte*)subBytes);
+ env->SetByteArrayRegion(arr,0,len,(jbyte*)subBytes);
}
return arr;
}
}
- return ((*env)->NewByteArray(env, 0));
+ return (env->NewByteArray(0));
}
static jboolean contains( JNIEnv *env, jclass jClass, jlong handle1, jlong handle2) {
diff --git a/icu/src/main/native/DecimalFormatInterface.cpp b/icu/src/main/native/NativeDecimalFormat.cpp
index caae492..cde2001 100644
--- a/icu/src/main/native/DecimalFormatInterface.cpp
+++ b/icu/src/main/native/NativeDecimalFormat.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#define LOG_TAG "DecimalFormatInterface"
#include "JNIHelp.h"
#include "AndroidSystemNatives.h"
#include "unicode/unum.h"
@@ -26,6 +25,8 @@
#include "ErrorCode.h"
#include <stdlib.h>
#include <string.h>
+
+#define LOG_TAG "NativeDecimalFormat"
#include "cutils/log.h"
static jint openDecimalFormatImpl(JNIEnv *env, jclass clazz, jstring locale,
diff --git a/icu/src/main/native/RegExInterface.cpp b/icu/src/main/native/NativeRegEx.cpp
index 0ca3d06..387d7e4 100644
--- a/icu/src/main/native/RegExInterface.cpp
+++ b/icu/src/main/native/NativeRegEx.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "AndroidSystemNatives.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -327,11 +329,7 @@ static void reset(JNIEnv* env, jclass clazz, RegExData* data, jint position)
}
}
-/*
- * JNI registration.
- */
-static JNINativeMethod sMethods[] = {
- /* name, signature, funcPtr */
+static JNINativeMethod gMethods[] = {
{ "open", "(Ljava/lang/String;I)I", (void*)open },
{ "clone", "(I)I", (void*)_clone },
{ "close", "(I)V", (void*)_close },
@@ -351,21 +349,9 @@ static JNINativeMethod sMethods[] = {
{ "hasAnchoringBounds", "(I)Z", (void*)hasAnchoringBounds },
{ "hitEnd", "(I)Z", (void*)hitEnd },
{ "requireEnd", "(I)Z", (void*)requireEnd },
- { "reset", "(II)V", (void*)reset }
+ { "reset", "(II)V", (void*)reset },
};
-
-extern "C" int register_com_ibm_icu4jni_regex_NativeRegEx(JNIEnv* env)
-{
- jclass clazz;
-
- clazz = env->FindClass("com/ibm/icu4jni/regex/NativeRegEx");
- if (clazz == NULL) {
- return -1;
- }
-
- if (env->RegisterNatives(clazz, sMethods, NELEM(sMethods)) < 0) {
- return -1;
- }
-
- return 0;
+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/ResourceInterface.cpp b/icu/src/main/native/Resources.cpp
index 68ecf95..0df2859 100644
--- a/icu/src/main/native/ResourceInterface.cpp
+++ b/icu/src/main/native/Resources.cpp
@@ -32,12 +32,14 @@
#include "unicode/ustring.h"
#include "unicode/timezone.h"
#include "ErrorCode.h"
-#include <cutils/log.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
+#define LOG_TAG "Resources"
+#include "cutils/log.h"
+
static jclass string_class;
class ScopedResourceBundle {
diff --git a/icu/src/main/native/RBNFInterface.cpp b/icu/src/main/native/RuleBasedNumberFormat.cpp
index c7486e1..c7486e1 100644
--- a/icu/src/main/native/RBNFInterface.cpp
+++ b/icu/src/main/native/RuleBasedNumberFormat.cpp
diff --git a/icu/src/main/native/CharacterInterface.c b/icu/src/main/native/UCharacter.cpp
index 26e6826..c13b6d3 100644
--- a/icu/src/main/native/CharacterInterface.c
+++ b/icu/src/main/native/UCharacter.cpp
@@ -17,25 +17,26 @@
#include "JNIHelp.h"
#include "AndroidSystemNatives.h"
#include "unicode/uchar.h"
+#include <math.h>
#include <stdlib.h>
-static jint digitImpl(JNIEnv *env, jclass clazz, jint codePoint, jint radix) {
+static jint digitImpl(JNIEnv*, jclass, jint codePoint, jint radix) {
return u_digit(codePoint, radix);
}
-static jint getTypeImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jint getTypeImpl(JNIEnv*, jclass, jint codePoint) {
return u_charType(codePoint);
}
-static jbyte getDirectionalityImpl(JNIEnv *env, jclass clazz, jint codePoint) {
- return u_charDirection (codePoint);
+static jbyte getDirectionalityImpl(JNIEnv*, jclass, jint codePoint) {
+ return u_charDirection(codePoint);
}
-static jboolean isMirroredImpl(JNIEnv *env, jclass clazz, jint codePoint) {
- return u_isMirrored (codePoint);
+static jboolean isMirroredImpl(JNIEnv*, jclass, jint codePoint) {
+ return u_isMirrored(codePoint);
}
-static jint getNumericValueImpl(JNIEnv *env, jclass clazz, jint 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'
@@ -67,93 +68,86 @@ static jint getNumericValueImpl(JNIEnv *env, jclass clazz, jint codePoint){
return result;
}
-static jboolean isDefinedImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jboolean isDefinedImpl(JNIEnv*, jclass, jint codePoint) {
return u_isdefined(codePoint);
}
-static jboolean isDigitImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jboolean isDigitImpl(JNIEnv*, jclass, jint codePoint) {
return u_isdigit(codePoint);
}
-static jboolean isIdentifierIgnorableImpl(JNIEnv *env, jclass clazz,
- jint 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 *env, jclass clazz, jint codePoint) {
+static jboolean isLetterImpl(JNIEnv*, jclass, jint codePoint) {
return u_isalpha(codePoint);
}
-static jboolean isLetterOrDigitImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jboolean isLetterOrDigitImpl(JNIEnv*, jclass, jint codePoint) {
return u_isalnum(codePoint);
}
-static jboolean isSpaceCharImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jboolean isSpaceCharImpl(JNIEnv*, jclass, jint codePoint) {
return u_isJavaSpaceChar(codePoint);
}
-static jboolean isTitleCaseImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jboolean isTitleCaseImpl(JNIEnv*, jclass, jint codePoint) {
return u_istitle(codePoint);
}
-static jboolean isUnicodeIdentifierPartImpl(JNIEnv *env, jclass clazz,
- jint codePoint) {
+static jboolean isUnicodeIdentifierPartImpl(JNIEnv*, jclass, jint codePoint) {
return u_isIDPart(codePoint);
}
-static jboolean isUnicodeIdentifierStartImpl(JNIEnv *env, jclass clazz,
- jint codePoint) {
+static jboolean isUnicodeIdentifierStartImpl(JNIEnv*, jclass, jint codePoint) {
return u_isIDStart(codePoint);
}
-static jboolean isWhitespaceImpl(JNIEnv *env, jclass clazz, jint 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 *env, jclass clazz, jint codePoint) {
+static jint toLowerCaseImpl(JNIEnv*, jclass, jint codePoint) {
return u_tolower(codePoint);
}
-static jint toTitleCaseImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jint toTitleCaseImpl(JNIEnv*, jclass, jint codePoint) {
return u_totitle(codePoint);
}
-static jint toUpperCaseImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jint toUpperCaseImpl(JNIEnv*, jclass, jint codePoint) {
return u_toupper(codePoint);
}
-static jboolean isUpperCaseImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jboolean isUpperCaseImpl(JNIEnv*, jclass, jint codePoint) {
return u_isupper(codePoint);
}
-static jboolean isLowerCaseImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static jboolean isLowerCaseImpl(JNIEnv*, jclass, jint codePoint) {
return u_islower(codePoint);
}
-static int forNameImpl(JNIEnv *env, jclass clazz, jstring blockName) {
+static int forNameImpl(JNIEnv* env, jclass, jstring blockName) {
if (blockName == NULL) {
jniThrowException(env, "java/lang/NullPointerException", NULL);
return -1;
}
- const char* bName = (*env)->GetStringUTFChars(env, blockName, NULL);
+ const char* bName = env->GetStringUTFChars(blockName, NULL);
int result = u_getPropertyValueEnum(UCHAR_BLOCK, bName);
- (*env)->ReleaseStringUTFChars(env, blockName, bName);
+ env->ReleaseStringUTFChars(blockName, bName);
return result;
}
-static int ofImpl(JNIEnv *env, jclass clazz, jint codePoint) {
+static int ofImpl(JNIEnv*, jclass, jint codePoint) {
return ublock_getCode(codePoint);
}
@@ -186,7 +180,7 @@ static JNINativeMethod gMethods[] = {
{ "toUpperCase", "(I)I", (void*) toUpperCaseImpl },
};
-int register_com_ibm_icu4jni_lang_UCharacter(JNIEnv *env) {
+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
index 2f160f5..fd5f20c 100644
--- a/icu/src/main/native/sub.mk
+++ b/icu/src/main/native/sub.mk
@@ -3,16 +3,16 @@
# or BUILD_*_LIBRARY.
LOCAL_SRC_FILES := \
- BidiWrapperInterface.c \
- BreakIteratorInterface.c \
- DecimalFormatInterface.cpp \
- CharacterInterface.c \
- ConverterInterface.c \
- CollationInterface.c \
- RegExInterface.cpp \
- ResourceInterface.cpp \
- RBNFInterface.cpp \
- ErrorCode.c
+ BidiWrapper.cpp \
+ ErrorCode.cpp \
+ NativeBreakIterator.cpp \
+ NativeCollation.cpp \
+ NativeConverter.cpp \
+ NativeDecimalFormat.cpp \
+ NativeRegEx.cpp \
+ RuleBasedNumberFormat.cpp \
+ Resources.cpp \
+ UCharacter.cpp
LOCAL_C_INCLUDES += \
external/icu4c/common \