summaryrefslogtreecommitdiffstats
path: root/icu/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'icu/src/main')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java32
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/Collator.java36
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/RuleBasedBreakIterator.java7
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java258
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java13
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/Resources.java29
-rw-r--r--icu/src/main/native/RuleBasedNumberFormat.cpp336
-rw-r--r--icu/src/main/native/sub.mk1
8 files changed, 47 insertions, 665 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java b/icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java
index 5ef1161..aa925aa 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java
@@ -16,6 +16,7 @@
package com.ibm.icu4jni.text;
+import com.ibm.icu4jni.util.Resources;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Locale;
@@ -30,36 +31,7 @@ public abstract class BreakIterator implements Cloneable
protected int type = 0;
public static Locale[] getAvailableLocales() {
-
- String[] locales = NativeBreakIterator.getAvailableLocalesImpl();
-
- Locale[] result = new Locale[locales.length];
-
- String locale;
-
- int index, index2;
-
- for(int i = 0; i < locales.length; i++) {
- locale = locales[i];
-
- index = locale.indexOf('_');
- index2 = locale.lastIndexOf('_');
-
- if(index == -1) {
- result[i] = new Locale(locales[i]);
- } else if(index > 0 && index == index2) {
- result[i] = new Locale(
- locale.substring(0,index),
- locale.substring(index+1));
- } else if(index > 0 && index2 > index) {
- result[i] = new Locale(
- locale.substring(0,index),
- locale.substring(index+1,index2),
- locale.substring(index2+1));
- }
- }
-
- return result;
+ return Resources.localesFromStrings(NativeBreakIterator.getAvailableLocalesImpl());
}
public static BreakIterator getCharacterInstance() {
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
index 4a7e1bf..0963b81 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
@@ -10,8 +10,9 @@
package com.ibm.icu4jni.text;
-import java.util.Locale;
import com.ibm.icu4jni.text.RuleBasedCollator;
+import com.ibm.icu4jni.util.Resources;
+import java.util.Locale;
/**
* Abstract class handling locale specific collation via JNI and ICU.
@@ -394,38 +395,7 @@ public abstract class Collator implements Cloneable
*/
public abstract int hashCode();
- // BEGIN android-added
public static Locale[] getAvailableLocales() {
-
- String[] locales = NativeCollation.getAvailableLocalesImpl();
-
- Locale[] result = new Locale[locales.length];
-
- String locale;
-
- int index, index2;
-
- for(int i = 0; i < locales.length; i++) {
- locale = locales[i];
-
- index = locale.indexOf('_');
- index2 = locale.lastIndexOf('_');
-
- if(index == -1) {
- result[i] = new Locale(locales[i]);
- } else if(index == 2 && index == index2) {
- result[i] = new Locale(
- locale.substring(0,2),
- locale.substring(3,5));
- } else if(index == 2 && index2 > index) {
- result[i] = new Locale(
- locale.substring(0,index),
- locale.substring(index + 1,index2),
- locale.substring(index2 + 1));
- }
- }
-
- return result;
+ return Resources.localesFromStrings(NativeCollation.getAvailableLocalesImpl());
}
- // END android-added
}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedBreakIterator.java b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedBreakIterator.java
index 4d38f2b..e532ac4 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedBreakIterator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedBreakIterator.java
@@ -58,7 +58,12 @@ public class RuleBasedBreakIterator extends BreakIterator {
return result && iter.equals(this.charIter);
}
-
+
+ @Override
+ public int hashCode() {
+ return 42; // No-one uses RuleBasedBreakIterator as a hash key.
+ }
+
@Override
public int current() {
return NativeBreakIterator.currentImpl(this.addr);
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java
deleted file mode 100644
index 3c865d8..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java
+++ /dev/null
@@ -1,258 +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.
- */
-
-package com.ibm.icu4jni.text;
-
-import java.text.FieldPosition;
-import java.text.Format;
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.Locale;
-
-public class RuleBasedNumberFormat extends NumberFormat {
-
- /**
- * Enum of predefined RBNF types.
- */
- public enum RBNFType {
- /**
- * This creates a spellout instance of RBNF.
- * It formats numbers into textual representation:
- * 15 -> 'fifteen' or 15.15 -> 'fifteen point one five'
- * and it can parse words into numbers: 'twenty' -> 20
- */
- SPELLOUT(0),
- /**
- * This creates an ordinal instance of RBNF.
- * It formats numbers into an ordinal text representation:
- * 15 -> '15th' and by parsing it also works in the other direction.
- */
- ORDINAL(1),
- /**
- * This creates instance of RBNF that allows to format numbers into time
- * values: 15 -> '15 sec.' and by parsing it also works in the other
- * direction.
- */
- DURATION(2);
-
- int type;
-
- RBNFType(int t) {
- type = t;
- }
-
- int getType() {
- return type;
- }
- }
-
- @Override
- protected void finalize(){
- close();
- }
-
- private int addr = 0;
-
- /**
- * Open a new rule based number format of selected type for the
- * default location
- *
- * @param type the type of rule based number format
- */
- public void open(RBNFType type) {
- this.addr = openRBNFImpl(type.getType(),
- Locale.getDefault().toString());
- }
-
- /**
- * Open a new rule based number format of selected type for the
- * given location
- *
- * @param type the type of rule based number format
- * @param locale the locale to use for this rule based number format
- */
- public void open(RBNFType type, Locale locale) {
- String loc = locale.toString();
- if (loc == null) {
- throw new NullPointerException();
- }
- this.addr = openRBNFImpl(type.getType(), loc);
- }
-
- private static native int openRBNFImpl(int type, String loc);
-
- /**
- * Open a new rule based number format for the
- * default location. The rule passed to the method has to be of the form
- * described in the ibm icu documentation for RuleBasedNumberFormat.
- *
- * @param rule the rule for the rule based number format
- */
- public void open(String rule) {
- if (rule == null) {
- throw new NullPointerException();
- }
- this.addr = openRBNFImpl(rule, Locale.getDefault().toString());
- }
-
- /**
- * Open a new rule based number format for the
- * given location. The rule passed to the method has to be of the form
- * described in the ibm icu documentation for RuleBasedNumberFormat.
- *
- * @param rule the rule for the rule based number format
- * @param locale the locale to use for this rule based number format
- */
- public void open(String rule, Locale locale) {
- String loc = locale.toString();
- if (loc == null || rule == null) {
- throw new NullPointerException();
- }
- this.addr = openRBNFImpl(rule, locale.toString());
- }
-
- private static native int openRBNFImpl(String rule, String loc);
-
- /**
- * close a RuleBasedNumberFormat
- */
- public void close() {
- if(this.addr != 0) {
- closeRBNFImpl(this.addr);
- this.addr = 0;
- }
- }
-
- private static native void closeRBNFImpl(int addr);
-
- @Override
- public StringBuffer format(long value, StringBuffer buffer, FieldPosition field) {
-
- if(buffer == null) {
- throw new NullPointerException();
- }
-
- String fieldType = null;
-
- if(field != null) {
- fieldType = getFieldType(field.getFieldAttribute());
- }
-
- String result = formatRBNFImpl(this.addr, value, field,
- fieldType, null);
-
- buffer.append(result.toCharArray(), 0, result.length());
-
- return buffer;
- }
-
- private static native String formatRBNFImpl(int addr, long value,
- FieldPosition field, String fieldType, StringBuffer buffer);
-
- @Override
- public StringBuffer format(double value, StringBuffer buffer, FieldPosition field) {
-
- if(buffer == null) {
- throw new NullPointerException();
- }
-
- String fieldType = null;
-
- if(field != null) {
- fieldType = getFieldType(field.getFieldAttribute());
- }
-
- String result = formatRBNFImpl(this.addr, value, field,
- fieldType, null);
-
- buffer.append(result.toCharArray(), 0, result.length());
-
- return buffer;
- }
-
- private static native String formatRBNFImpl(int addr, double value,
- FieldPosition field, String fieldType, StringBuffer buffer);
-
- @Override
- public Number parse(String string, ParsePosition position) {
- if (string == null || position == null) {
- throw new NullPointerException();
- }
- return parseRBNFImpl(this.addr, string, position, false);
- }
-
- /**
- * This method has the same functionality
- * as {@link #parse(String, ParsePosition)}
- * But it uses lenient parsing. This means it also accepts strings that
- * differ from the correct writing (e.g. case or umlaut differences).
- *
- * @param string the string to parse
- * @param position the ParsePosition, updated on return with the index
- * following the parsed text, or on error the index is unchanged and
- * the error index is set to the index where the error occurred
- * @return the Number resulting from the parse, or null if there is an error
- */
- public Number parseLenient(String string, ParsePosition position) {
- if (string == null || position == null) {
- throw new NullPointerException();
- }
- return parseRBNFImpl(this.addr, string, position, true);
- }
-
- static native Number parseRBNFImpl(int addr, String string, ParsePosition position, boolean lenient);
-
-
- static private String getFieldType(Format.Field field) {
- if(field == null) {
- return null;
- }
- if(field.equals(NumberFormat.Field.SIGN)) {
- return "sign";
- }
- if(field.equals(NumberFormat.Field.INTEGER)) {
- return "integer";
- }
- if(field.equals(NumberFormat.Field.FRACTION)) {
- return "fraction";
- }
- if(field.equals(NumberFormat.Field.EXPONENT)) {
- return "exponent";
- }
- if(field.equals(NumberFormat.Field.EXPONENT_SIGN)) {
- return "exponent_sign";
- }
- if(field.equals(NumberFormat.Field.EXPONENT_SYMBOL)) {
- return "exponent_symbol";
- }
- if(field.equals(NumberFormat.Field.CURRENCY)) {
- return "currency";
- }
- if(field.equals(NumberFormat.Field.GROUPING_SEPARATOR)) {
- return "grouping_separator";
- }
- if(field.equals(NumberFormat.Field.DECIMAL_SEPARATOR)) {
- return "decimal_separator";
- }
- if(field.equals(NumberFormat.Field.PERCENT)) {
- return "percent";
- }
- if(field.equals(NumberFormat.Field.PERMILLE)) {
- return "permille";
- }
- return null;
- }
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java b/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java
index 24d3323..87f9bc2 100644
--- a/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java
+++ b/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java
@@ -17,6 +17,7 @@
package com.ibm.icu4jni.util;
import java.text.DateFormat;
+import java.util.Arrays;
/**
* Passes locale-specific from ICU native code to Java.
@@ -66,12 +67,12 @@ public class LocaleData {
return "LocaleData[" +
"firstDayOfWeek=" + firstDayOfWeek + "," +
"minimalDaysInFirstWeek=" + minimalDaysInFirstWeek + "," +
- "amPm=" + amPm + "," +
- "eras=" + eras + "," +
- "longMonthNames=" + longMonthNames + "," +
- "shortMonthNames=" + shortMonthNames + "," +
- "longWeekdayNames=" + longWeekdayNames + "," +
- "shortWeekdayNames=" + shortWeekdayNames + "," +
+ "amPm=" + Arrays.toString(amPm) + "," +
+ "eras=" + Arrays.toString(eras) + "," +
+ "longMonthNames=" + Arrays.toString(longMonthNames) + "," +
+ "shortMonthNames=" + Arrays.toString(shortMonthNames) + "," +
+ "longWeekdayNames=" + Arrays.toString(longWeekdayNames) + "," +
+ "shortWeekdayNames=" + Arrays.toString(shortWeekdayNames) + "," +
"fullTimeFormat=" + fullTimeFormat + "," +
"longTimeFormat=" + longTimeFormat + "," +
"mediumTimeFormat=" + mediumTimeFormat + "," +
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
index cbad9a5..66bfdfb 100644
--- a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
+++ b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
@@ -285,6 +285,35 @@ public class Resources {
return result;
}
+ /**
+ * Returns the appropriate {@code Locale} given a {@code String} of the form returned
+ * by {@code toString}. This is very lenient, and doesn't care what's between the underscores:
+ * this method can parse strings that {@code Locale.toString} won't produce.
+ * Used to remove duplication.
+ */
+ public static Locale localeFromString(String localeName) {
+ int first = localeName.indexOf('_');
+ int second = localeName.indexOf('_', first + 1);
+ if (first == -1) {
+ // Language only ("ja").
+ return new Locale(localeName);
+ } else if (second == -1) {
+ // Language and country ("ja_JP").
+ return new Locale(localeName.substring(0, first), localeName.substring(first + 1));
+ } else {
+ // Language and country and variant ("ja_JP_TRADITIONAL").
+ return new Locale(localeName.substring(0, first), localeName.substring(first + 1, second), localeName.substring(second + 1));
+ }
+ }
+
+ public static Locale[] localesFromStrings(String[] localeNames) {
+ Locale[] result = new Locale[localeNames.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = localeFromString(localeNames[i]);
+ }
+ return result;
+ }
+
// --- Native methods accessing ICU's database ----------------------------
public static native String getDisplayCountryNative(String countryCode, String locale);
diff --git a/icu/src/main/native/RuleBasedNumberFormat.cpp b/icu/src/main/native/RuleBasedNumberFormat.cpp
deleted file mode 100644
index c7486e1..0000000
--- a/icu/src/main/native/RuleBasedNumberFormat.cpp
+++ /dev/null
@@ -1,336 +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.
- */
-
-#include "JNIHelp.h"
-#include "AndroidSystemNatives.h"
-#include "unicode/numfmt.h"
-#include "unicode/rbnf.h"
-#include "unicode/fmtable.h"
-#include "unicode/ustring.h"
-#include "unicode/locid.h"
-#include "ErrorCode.h"
-#include <stdlib.h>
-#include <string.h>
-
-static jint openRBNFImpl1(JNIEnv* env, jclass clazz,
- jint type, jstring locale) {
-
- // LOGI("ENTER openRBNFImpl1");
-
- // the errorcode returned by unum_open
- UErrorCode status = U_ZERO_ERROR;
-
- // prepare the locale string for the call to unum_open
- const char *localeChars = env->GetStringUTFChars(locale, NULL);
-
- URBNFRuleSetTag style;
- if(type == 0) {
- style = URBNF_SPELLOUT;
- } else if(type == 1) {
- style = URBNF_ORDINAL;
- } else if(type == 2) {
- style = URBNF_DURATION;
- } else if(type == 3) {
- style = URBNF_COUNT;
- } else {
- icu4jni_error(env, U_ILLEGAL_ARGUMENT_ERROR);
- }
-
- Locale loc = Locale::createFromName(localeChars);
-
- // open a default type number format
- RuleBasedNumberFormat *fmt = new RuleBasedNumberFormat(style, loc, status);
-
- // release the allocated strings
- env->ReleaseStringUTFChars(locale, localeChars);
-
- // check for an error
- if (icu4jni_error(env, status) != FALSE) {
- return 0;
- }
-
- // return the handle to the number format
- return (long) fmt;
-
-}
-
-static jint openRBNFImpl2(JNIEnv* env, jclass clazz,
- jstring rule, jstring locale) {
-
- // LOGI("ENTER openRBNFImpl2");
-
- // the errorcode returned by unum_open
- UErrorCode status = U_ZERO_ERROR;
-
- // prepare the pattern string for the call to unum_open
- const UChar *ruleChars = env->GetStringChars(rule, NULL);
- int ruleLen = env->GetStringLength(rule);
-
- // prepare the locale string for the call to unum_open
- const char *localeChars = env->GetStringUTFChars(locale, NULL);
-
- // open a rule based number format
- UNumberFormat *fmt = unum_open(UNUM_PATTERN_RULEBASED, ruleChars, ruleLen,
- localeChars, NULL, &status);
-
- // release the allocated strings
- env->ReleaseStringChars(rule, ruleChars);
- env->ReleaseStringUTFChars(locale, localeChars);
-
- // check for an error
- if (icu4jni_error(env, status) != FALSE) {
- return 0;
- }
-
- // return the handle to the number format
- return (long) fmt;
-
-}
-
-static void closeRBNFImpl(JNIEnv *env, jclass clazz, jint addr) {
-
- // LOGI("ENTER closeRBNFImpl");
-
- // get the pointer to the number format
- RuleBasedNumberFormat *fmt = (RuleBasedNumberFormat *)(int)addr;
-
- // close this number format
- delete fmt;
-}
-
-static jstring formatLongRBNFImpl(JNIEnv *env, jclass clazz, jint addr, jlong value,
- jobject field, jstring fieldType, jobject attributes) {
-
- // LOGI("ENTER formatLongRBNFImpl");
-
- const char * fieldPositionClassName = "java/text/FieldPosition";
- const char * stringBufferClassName = "java/lang/StringBuffer";
- jclass fieldPositionClass = env->FindClass(fieldPositionClassName);
- jclass stringBufferClass = env->FindClass(stringBufferClassName);
- jmethodID setBeginIndexMethodID = env->GetMethodID(fieldPositionClass,
- "setBeginIndex", "(I)V");
- jmethodID setEndIndexMethodID = env->GetMethodID(fieldPositionClass,
- "setEndIndex", "(I)V");
- jmethodID appendMethodID = env->GetMethodID(stringBufferClass,
- "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
-
- const char * fieldName = NULL;
-
- if(fieldType != NULL) {
- fieldName = env->GetStringUTFChars(fieldType, NULL);
- }
-
- uint32_t reslenneeded;
- int64_t val = value;
- UChar *result = NULL;
-
- FieldPosition fp;
- fp.setField(FieldPosition::DONT_CARE);
-
- UErrorCode status = U_ZERO_ERROR;
-
- RuleBasedNumberFormat *fmt = (RuleBasedNumberFormat *)(int)addr;
-
- UnicodeString res;
-
- fmt->format(val, res, fp);
-
- 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) {
- free(result);
- return NULL;
- }
-
- if(fieldType != NULL) {
- env->ReleaseStringUTFChars(fieldType, fieldName);
- }
-
- jstring resulting = env->NewString(result, reslenneeded);
-
- free(result);
-
- return resulting;
-}
-
-static jstring formatDoubleRBNFImpl(JNIEnv *env, jclass clazz, jint addr, jdouble value,
- jobject field, jstring fieldType, jobject attributes) {
-
- // LOGI("ENTER formatDoubleRBNFImpl");
-
- const char * fieldPositionClassName = "java/text/FieldPosition";
- const char * stringBufferClassName = "java/lang/StringBuffer";
- jclass fieldPositionClass = env->FindClass(fieldPositionClassName);
- jclass stringBufferClass = env->FindClass(stringBufferClassName);
- jmethodID setBeginIndexMethodID = env->GetMethodID(fieldPositionClass,
- "setBeginIndex", "(I)V");
- jmethodID setEndIndexMethodID = env->GetMethodID(fieldPositionClass,
- "setEndIndex", "(I)V");
- jmethodID appendMethodID = env->GetMethodID(stringBufferClass,
- "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
-
- const char * fieldName = NULL;
-
- if(fieldType != NULL) {
- fieldName = env->GetStringUTFChars(fieldType, NULL);
- }
-
- uint32_t reslenneeded;
- double val = value;
- UChar *result = NULL;
-
- FieldPosition fp;
- fp.setField(FieldPosition::DONT_CARE);
-
- UErrorCode status = U_ZERO_ERROR;
-
- RuleBasedNumberFormat *fmt = (RuleBasedNumberFormat *)(int)addr;
-
- UnicodeString res;
-
- fmt->format(val, res, fp);
-
- 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) {
- free(result);
- return NULL;
- }
-
- if(fieldType != NULL) {
- env->ReleaseStringUTFChars(fieldType, fieldName);
- }
-
- jstring resulting = env->NewString(result, reslenneeded);
-
- free(result);
-
- return resulting;
-}
-
-static jobject parseRBNFImpl(JNIEnv *env, jclass clazz, jint addr, jstring text,
- jobject position, jboolean lenient) {
-
- // LOGI("ENTER parseRBNFImpl");
-
- // TODO: cache these?
- jclass parsePositionClass = env->FindClass("java/text/ParsePosition");
- jclass longClass = env->FindClass("java/lang/Long");
- jclass doubleClass = env->FindClass("java/lang/Double");
-
- 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");
-
- // 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;
- }
-
- Formattable res;
-
- jchar *str = (UChar *)env->GetStringChars(text, NULL);
-
- const UnicodeString src((UChar*)str, strlength, strlength);
- ParsePosition pp;
-
- pp.setIndex(parsePos);
-
- UNumberFormat *fmt = (UNumberFormat *)(int)addr;
- if(lenient) {
- unum_setAttribute(fmt, UNUM_LENIENT_PARSE, JNI_TRUE);
- }
-
- ((const NumberFormat*)fmt)->parse(src, res, pp);
-
- if(lenient) {
- unum_setAttribute(fmt, UNUM_LENIENT_PARSE, JNI_FALSE);
- }
-
- 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();
- if (numType == Formattable::kDouble) {
- double resultDouble = res.getDouble();
- env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
- return env->NewObject(doubleClass, dblInitMethodID,
- (jdouble) resultDouble);
- } else if (numType == Formattable::kLong) {
- long resultLong = res.getLong();
- env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
- return env->NewObject(longClass, longInitMethodID, (jlong) resultLong);
- } else if (numType == Formattable::kInt64) {
- int64_t resultInt64 = res.getInt64();
- env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
- return env->NewObject(longClass, longInitMethodID, (jlong) resultInt64);
- } else {
- return NULL;
- }
-}
-
-static JNINativeMethod gMethods[] = {
- /* name, signature, funcPtr */
- {"openRBNFImpl", "(ILjava/lang/String;)I", (void*) openRBNFImpl1},
- {"openRBNFImpl", "(Ljava/lang/String;Ljava/lang/String;)I",
- (void*) openRBNFImpl2},
- {"closeRBNFImpl", "(I)V", (void*) closeRBNFImpl},
- {"formatRBNFImpl",
- "(IJLjava/text/FieldPosition;Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/String;",
- (void*) formatLongRBNFImpl},
- {"formatRBNFImpl",
- "(IDLjava/text/FieldPosition;Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/String;",
- (void*) formatDoubleRBNFImpl},
- {"parseRBNFImpl",
- "(ILjava/lang/String;Ljava/text/ParsePosition;Z)Ljava/lang/Number;",
- (void*) parseRBNFImpl},
-};
-int register_com_ibm_icu4jni_text_NativeRBNF(JNIEnv* env) {
- return jniRegisterNativeMethods(env,
- "com/ibm/icu4jni/text/RuleBasedNumberFormat", gMethods,
- NELEM(gMethods));
-}
diff --git a/icu/src/main/native/sub.mk b/icu/src/main/native/sub.mk
index 41260cf..b101531 100644
--- a/icu/src/main/native/sub.mk
+++ b/icu/src/main/native/sub.mk
@@ -11,7 +11,6 @@ LOCAL_SRC_FILES := \
NativeDecimalFormat.cpp \
NativeNormalizer.cpp \
NativeRegEx.cpp \
- RuleBasedNumberFormat.cpp \
Resources.cpp \
UCharacter.cpp