summaryrefslogtreecommitdiffstats
path: root/icu/src/main
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-02-03 11:14:01 -0800
committerElliott Hughes <enh@google.com>2010-02-03 11:14:01 -0800
commit4d4ca58e669c83e2c4e0a0d49d3d854f6883dc84 (patch)
treebae3cdd010974d0fc8e8a012cbd5f85683867065 /icu/src/main
parent64f2ba48fb9306ab1d97f5f83053ee7f48223de8 (diff)
downloadlibcore-4d4ca58e669c83e2c4e0a0d49d3d854f6883dc84.zip
libcore-4d4ca58e669c83e2c4e0a0d49d3d854f6883dc84.tar.gz
libcore-4d4ca58e669c83e2c4e0a0d49d3d854f6883dc84.tar.bz2
Remove RuleBasedNumberFormat from our icu4jni fork, since we don't need it.
This is ICU API not used by Java, so there's no point pretending to maintain it. Bug: http://b/2377457
Diffstat (limited to 'icu/src/main')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java258
-rw-r--r--icu/src/main/native/RuleBasedNumberFormat.cpp336
-rw-r--r--icu/src/main/native/sub.mk1
3 files changed, 0 insertions, 595 deletions
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/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 fd5f20c..3c13ea0 100644
--- a/icu/src/main/native/sub.mk
+++ b/icu/src/main/native/sub.mk
@@ -10,7 +10,6 @@ LOCAL_SRC_FILES := \
NativeConverter.cpp \
NativeDecimalFormat.cpp \
NativeRegEx.cpp \
- RuleBasedNumberFormat.cpp \
Resources.cpp \
UCharacter.cpp