From dd828f42a5c83b4270d4fbf6fce2da1878f1e84a Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Wed, 17 Dec 2008 18:03:55 -0800 Subject: Code drop from //branches/cupcake/...@124589 --- .../com/ibm/icu4jni/charset/CharsetDecoderICU.java | 6 +- .../com/ibm/icu4jni/charset/CharsetEncoderICU.java | 4 +- .../java/com/ibm/icu4jni/charset/CharsetICU.java | 7 +- .../ibm/icu4jni/charset/CharsetProviderICU.java | 4 +- .../com/ibm/icu4jni/charset/NativeConverter.java | 422 +++++++++++++++++++++ .../ibm/icu4jni/converters/NativeConverter.java | 422 --------------------- .../main/java/com/ibm/icu4jni/lang/UCharacter.java | 3 + .../main/java/com/ibm/icu4jni/text/Collator.java | 12 +- .../java/com/ibm/icu4jni/text/DecimalFormat.java | 85 +++-- .../com/ibm/icu4jni/text/NativeBreakIterator.java | 2 +- .../java/com/ibm/icu4jni/text/NativeCollation.java | 2 +- .../com/ibm/icu4jni/text/NativeDecimalFormat.java | 2 +- .../com/ibm/icu4jni/text/RuleBasedCollator.java | 24 +- .../ibm/icu4jni/text/RuleBasedNumberFormat.java | 20 +- icu/src/main/native/ConverterInterface.c | 17 +- icu/src/main/native/DecimalFormatInterface.cpp | 19 +- icu/src/main/native/RBNFInterface.cpp | 2 +- icu/src/main/native/ResourceInterface.cpp | 1 + 18 files changed, 557 insertions(+), 497 deletions(-) create mode 100644 icu/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java delete mode 100644 icu/src/main/java/com/ibm/icu4jni/converters/NativeConverter.java (limited to 'icu/src') diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java index 9d5387e..e33e1b2 100644 --- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java +++ b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java @@ -15,7 +15,9 @@ package com.ibm.icu4jni.charset; import com.ibm.icu4jni.common.ErrorCode; -import com.ibm.icu4jni.converters.NativeConverter; +// BEGIN android-removed +// import com.ibm.icu4jni.converters.NativeConverter; +// ENd android-removed import java.nio.CharBuffer; @@ -253,7 +255,7 @@ public final class CharsetDecoderICU extends CharsetDecoder{ }else if(ec==ErrorCode.U_INVALID_CHAR_FOUND){ return CoderResult.unmappableForLength(data[INVALID_BYTES]); }else if(ec==ErrorCode.U_ILLEGAL_CHAR_FOUND){ - return CoderResult.malformedForLength(data[INVALID_BYTES]); + return CoderResult.unmappableForLength(data[INVALID_BYTES]); } /* decoding action succeded */ return CoderResult.UNDERFLOW; diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java index cdc98a7..0fdb2c5 100644 --- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java +++ b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java @@ -22,7 +22,9 @@ import java.nio.charset.CoderResult; import java.nio.charset.CodingErrorAction; import com.ibm.icu4jni.common.ErrorCode; -import com.ibm.icu4jni.converters.NativeConverter; +// BEGIN android-removed +// import com.ibm.icu4jni.converters.NativeConverter; +// END android-removed public final class CharsetEncoderICU extends CharsetEncoder { diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java index cc0e04a..df6f7dc 100644 --- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java +++ b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java @@ -15,9 +15,10 @@ import java.nio.charset.CharsetEncoder; import java.util.HashMap; import java.util.Map; -import com.ibm.icu4jni.common.ErrorCode; -import com.ibm.icu4jni.converters.NativeConverter; - +// BEGIN android-removed +// import com.ibm.icu4jni.common.ErrorCode; +// import com.ibm.icu4jni.converters.NativeConverter; +// END android-removed public final class CharsetICU extends Charset{ diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetProviderICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetProviderICU.java index 42d9f99..6f63479 100644 --- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetProviderICU.java +++ b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetProviderICU.java @@ -13,7 +13,9 @@ import java.nio.charset.Charset; import java.nio.charset.spi.CharsetProvider; import java.util.*; import java.util.Iterator; -import com.ibm.icu4jni.converters.NativeConverter; +// BEGIN android-removed +// import com.ibm.icu4jni.converters.NativeConverter; +// END android-removed public final class CharsetProviderICU extends CharsetProvider{ diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java b/icu/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java new file mode 100644 index 0000000..2bfb050 --- /dev/null +++ b/icu/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java @@ -0,0 +1,422 @@ +/** +******************************************************************************* +* Copyright (C) 1996-2006, International Business Machines Corporation and * +* others. All Rights Reserved. * +******************************************************************************* +* +******************************************************************************* +*/ + +package com.ibm.icu4jni.charset; + +/** + * Class for accessing the underlying JNI methods + * @internal ICU 2.4 + */ +final class NativeConverter{ + + //Native methods + + /** + * Converts an array of bytes containing characters in an external + * encoding into an array of Unicode characters. This method allows + * a buffer by buffer conversion of a data stream. The state of the + * conversion is saved between calls to convert. Among other things, + * this means multibyte input sequences can be split between calls. + * If a call to convert results in an Error, the conversion may be + * continued by calling convert again with suitably modified parameters. + * All conversions should be finished with a call to the flush method. + * + * @param converterHandle Address of converter object created by C code + * @param input byte array containing text to be converted. + * @param inEnd stop conversion at this offset in input array (exclusive). + * @param output character array to receive conversion result. + * @param outEnd stop writing to output array at this offset (exclusive). + * @param data integer array containing the following data + * data[0] = inputOffset + * data[1] = outputOffset + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + + public static final native int convertByteToChar( long converterHandle, + byte[] input, int inEnd, + char[] output, int outEnd, + int[] data, + boolean flush); + /** + * Converts an array of bytes containing characters in an external + * encoding into an array of Unicode characters. This method allows + * a buffer by buffer conversion of a data stream. The state of the + * conversion is saved between calls to convert. Among other things, + * this means multibyte input sequences can be split between calls. + * If a call to convert results in an Error, the conversion may be + * continued by calling convert again with suitably modified parameters. + * All conversions should be finished with a call to the flush method. + * + * @param converterHandle Address of converter object created by C code + * @param input byte array containing text to be converted. + * @param inEnd stop conversion at this offset in input array (exclusive). + * @param output character array to receive conversion result. + * @param outEnd stop writing to output array at this offset (exclusive). + * @param data integer array containing the following data + * data[0] = inputOffset + * data[1] = outputOffset + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int decode( long converterHandle, + byte[] input, int inEnd, + char[] output, int outEnd, + int[] data, + boolean flush); + /** + * Converts an array of Unicode chars containing characters in an + * external encoding into an array of bytes. This method allows + * a buffer by buffer conversion of a data stream. The state of the + * conversion is saved between calls to convert. Among other things, + * this means multibyte input sequences can be split between calls. + * If a call to convert results in an Error, the conversion may be + * continued by calling convert again with suitably modified parameters. + * All conversions should be finished with a call to the flush method. + * + * @param converterHandle Address of converter object created by C code + * @param input char array containing text to be converted. + * @param inEnd stop conversion at this offset in input array (exclusive). + * @param output byte array to receive conversion result. + * @param outEnd stop writing to output array at this offset (exclusive). + * @param data integer array containing the following data + * data[0] = inputOffset + * data[1] = outputOffset + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int convertCharToByte(long converterHandle, + char[] input, int inEnd, + byte[] output, int outEnd, + int[] data, + boolean flush); + /** + * Converts an array of Unicode chars containing characters in an + * external encoding into an array of bytes. This method allows + * a buffer by buffer conversion of a data stream. The state of the + * conversion is saved between calls to convert. Among other things, + * this means multibyte input sequences can be split between calls. + * If a call to convert results in an Error, the conversion may be + * continued by calling convert again with suitably modified parameters. + * All conversions should be finished with a call to the flush method. + * + * @param converterHandle Address of converter object created by C code + * @param input char array containing text to be converted. + * @param inEnd stop conversion at this offset in input array (exclusive). + * @param output byte array to receive conversion result. + * @param outEnd stop writing to output array at this offset (exclusive). + * @param data integer array containing the following data + * data[0] = inputOffset + * data[1] = outputOffset + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int encode(long converterHandle, + char[] input, int inEnd, + byte[] output, int outEnd, + int[] data, + boolean flush); + /** + * Writes any remaining output to the output buffer and resets the + * converter to its initial state. + * + * @param converterHandle Address of converter object created by C code + * @param output byte array to receive flushed output. + * @param outEnd stop writing to output array at this offset (exclusive). + * @return int error code returned by ICU + * @param data integer array containing the following data + * data[0] = inputOffset + * data[1] = outputOffset + * @internal ICU 2.4 + */ + public static final native int flushCharToByte(long converterHandle, + byte[] output, + int outEnd, + int[] data); + /** + * Writes any remaining output to the output buffer and resets the + * converter to its initial state. + * + * @param converterHandle Address of converter object created by the native code + * @param output char array to receive flushed output. + * @param outEnd stop writing to output array at this offset (exclusive). + * @return int error code returned by ICU + * @param data integer array containing the following data + * data[0] = inputOffset + * data[1] = outputOffset + * @internal ICU 2.4 + */ + public static final native int flushByteToChar(long converterHandle, + char[] output, + int outEnd, + int[] data); + + /** + * Open the converter with the specified encoding + * + * @param converterHandle long array for recieving the adress of converter object + * created by the native code + * @param encoding string representing encoding + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native long openConverter(String encoding); + /** + * Resets the ByteToChar (toUnicode) state of specified converter + * + * @param converterHandle Address of converter object created by the native code + * @internal ICU 2.4 + */ + public static final native void resetByteToChar(long converterHandle); + + /** + * Resets the CharToByte (fromUnicode) state of specified converter + * + * @param converterHandle Address of converter object created by the native code + * @internal ICU 2.4 + */ + public static final native void resetCharToByte(long converterHandle); + + /** + * Closes the specified converter and releases the resources + * + * @param converterHandle Address of converter object created by the native code + * @internal ICU 2.4 + */ + public static final native void closeConverter(long converterHandle); + + /** + * Sets the substitution Unicode chars of the specified converter used + * by encoder + * @param converterHandle Address of converter object created by the native code + * @param subChars array of chars to used for substitution + * @param length length of the array + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int setSubstitutionChars( long converterHandle, + char[] subChars,int length); + /** + * Sets the substitution bytes of the specified converter used by decoder + * + * @param converterHandle Address of converter object created by the native code + * @param subChars array of bytes to used for substitution + * @param length length of the array + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int setSubstitutionBytes( long converterHandle, + byte[] subChars,int length); + /** + * Sets the substitution mode of CharToByte(fromUnicode) for the specified converter + * + * @param converterHandle Address of converter object created by the native code + * @param mode to set the true/false + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int setSubstitutionModeCharToByte(long converterHandle, + boolean mode); + /** + * Sets the substitution mode of CharToByte(fromUnicode) for the specified converter + * + * @param converterHandle Address of converter object created by the native code + * @param mode to set the true/false + * @return int error code returned by ICU + * @internal ICU 3.6 + */ + public static final native int setSubstitutionModeByteToChar(long converterHandle, + boolean mode); + /** + * Gets the numnber of invalid bytes in the specified converter object + * for the last error that has occured + * + * @param converterHandle Address of converter object created by the native code + * @param length array of int to recieve length of the array + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int countInvalidBytes(long converterHandle, int[] length); + + /** + * Gets the numnber of invalid chars in the specified converter object + * for the last error that has occured + * + * @param converterHandle Address of converter object created by the native code + * @param length array of int to recieve length of the array + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int countInvalidChars(long converterHandle, int[] length); + + /** + * Gets the number of bytes needed for converting a char + * + * @param converterHandle Address of converter object created by the native code + * @return number of bytes needed + * @internal ICU 2.4 + */ + public static final native int getMaxBytesPerChar(long converterHandle); + + /** + * Gets the number of bytes needed for converting a char + * + * @param converterHandle Address of converter object created by the native code + * @return number of bytes needed + * @internal ICU 3.2 + */ + public static final native int getMinBytesPerChar(long converterHandle); + + /** + * Gets the average numnber of bytes needed for converting a char + * + * @param converterHandle Address of converter object created by the native code + * @return number of bytes needed + * @internal ICU 2.4 + */ + public static final native float getAveBytesPerChar(long converterHandle); + + /** + * Gets the number of chars needed for converting a byte + * + * @param converterHandle Address of converter object created by the native code + * @return number of bytes needed + * @internal ICU 2.4 + */ + public static final native int getMaxCharsPerByte(long converterHandle); + + /** + * Gets the average numnber of chars needed for converting a byte + * + * @param converterHandle Address of converter object created by the native code + * @return number of bytes needed + * @internal ICU 2.4 + */ + public static final native float getAveCharsPerByte(long converterHandle); + + //CSDL: added by Jack + /** + * Determines whether charset1 contains charset2. + */ + public static final native boolean contains(long converterHandle1, long converterHandle2); + + public static final native byte[] getSubstitutionBytes(long converterHandle); + + /** + * Ascertains if a given Unicode code unit can + * be converted to the target encoding + * @param converterHandle Address of converter object created by the native code + * @param codeUnit the character to be converted + * @return true if a character can be converted + * @internal ICU 2.4 + * + */ + public static final native boolean canEncode(long converterHandle,int codeUnit); + + /** + * Ascertains if a given a byte sequence can be converted to Unicode + * @param converterHandle Address of converter object created by the native code + * @param bytes the bytes to be converted + * @return true if a character can be converted + * @internal ICU 2.4 + * + */ + public static final native boolean canDecode(long converterHandle,byte[] bytes); + + /** + * Gets the number of converters installed in the current installation of ICU + * @return int number of converters installed + * @internal ICU 2.4 + */ + public static final native int countAvailable(); + + /** + * Gets the canonical names of available converters + * @return Object[] names as an object array + * @internal ICU 2.4 + */ + public static final native String[] getAvailable(); + + /** + * Gets the number of aliases for a converter name + * @param enc encoding name + * @return number of aliases for the converter + * @internal ICU 2.4 + */ + public static final native int countAliases(String enc); + + /** + * Gets the aliases associated with the converter name + * @param enc converter name + * @return converter names as elements in an object array + * @internal ICU 2.4 + */ + public static final native String[] getAliases(String enc); + + /** + * Gets the canonical name of the converter + * @param enc converter name + * @return canonical name of the converter + * @internal ICU 2.4 + */ + public static final native String getCanonicalName(String enc); + + /** + * Gets the canonical name of the converter as defined by Java + * @param enc converter name + * @return canonical name of the converter + * @internal ICU 3.4 + */ + public static final native String getICUCanonicalName(String enc); + + /** + * Gets the canonical name of the converter as defined by Java + * @param icuCanonicalName converter name + * @return canonical name of the converter + * @internal ICU 3.4 + */ + public static final native String getJavaCanonicalName(String icuCanonicalName); + + /** + * Sets the callback to Unicode for ICU conveter. The default behaviour of ICU callback + * is to call the specified callback function for both illegal and unmapped sequences. + * @param converterHandle Adress of the converter object created by native code + * @param mode call back mode to set. This is either STOP_CALLBACK, SKIP_CALLBACK or SUBSTITUE_CALLBACK + * The converter performs the specified callback when an error occurs + * @param stopOnIllegal If true sets the alerts the converter callback to stop on an illegal sequence + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int setCallbackDecode(long converterHandle, int onMalformedInput, int onUnmappableInput, char[] subChars, int length); + + /** + * Sets the callback from Unicode for ICU conveter. The default behaviour of ICU callback + * is to call the specified callback function for both illegal and unmapped sequences. + * @param converterHandle Adress of the converter object created by native code + * @param mode call back mode to set. This is either STOP_CALLBACK, SKIP_CALLBACK or SUBSTITUE_CALLBACK + * The converter performs the specified callback when an error occurs + * @param stopOnIllegal If true sets the alerts the converter callback to stop on an illegal sequence + * @return int error code returned by ICU + * @internal ICU 2.4 + */ + public static final native int setCallbackEncode(long converterHandle, int onMalformedInput, int onUnmappableInput, byte[] subBytes, int length); + + /** + * Returns a thread safe clone of the converter + * @internal ICU 2.4 + */ + public static final native long safeClone(long converterHandle); + + /** @internal ICU 2.4 */ + public static final int STOP_CALLBACK = 0;//CodingErrorAction.REPORT + /** @internal ICU 2.4 */ + public static final int SKIP_CALLBACK = 1;//CodingErrorAction.IGNORE + /** @internal ICU 2.4 */ + public static final int SUBSTITUTE_CALLBACK = 2;//CodingErrorAction.REPLACE +} diff --git a/icu/src/main/java/com/ibm/icu4jni/converters/NativeConverter.java b/icu/src/main/java/com/ibm/icu4jni/converters/NativeConverter.java deleted file mode 100644 index aa0cd26..0000000 --- a/icu/src/main/java/com/ibm/icu4jni/converters/NativeConverter.java +++ /dev/null @@ -1,422 +0,0 @@ -/** -******************************************************************************* -* Copyright (C) 1996-2006, International Business Machines Corporation and * -* others. All Rights Reserved. * -******************************************************************************* -* -******************************************************************************* -*/ - -package com.ibm.icu4jni.converters; - -/** - * Class for accessing the underlying JNI methods - * @internal ICU 2.4 - */ -public final class NativeConverter{ - - //Native methods - - /** - * Converts an array of bytes containing characters in an external - * encoding into an array of Unicode characters. This method allows - * a buffer by buffer conversion of a data stream. The state of the - * conversion is saved between calls to convert. Among other things, - * this means multibyte input sequences can be split between calls. - * If a call to convert results in an Error, the conversion may be - * continued by calling convert again with suitably modified parameters. - * All conversions should be finished with a call to the flush method. - * - * @param converterHandle Address of converter object created by C code - * @param input byte array containing text to be converted. - * @param inEnd stop conversion at this offset in input array (exclusive). - * @param output character array to receive conversion result. - * @param outEnd stop writing to output array at this offset (exclusive). - * @param data integer array containing the following data - * data[0] = inputOffset - * data[1] = outputOffset - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - - public static final native int convertByteToChar( long converterHandle, - byte[] input, int inEnd, - char[] output, int outEnd, - int[] data, - boolean flush); - /** - * Converts an array of bytes containing characters in an external - * encoding into an array of Unicode characters. This method allows - * a buffer by buffer conversion of a data stream. The state of the - * conversion is saved between calls to convert. Among other things, - * this means multibyte input sequences can be split between calls. - * If a call to convert results in an Error, the conversion may be - * continued by calling convert again with suitably modified parameters. - * All conversions should be finished with a call to the flush method. - * - * @param converterHandle Address of converter object created by C code - * @param input byte array containing text to be converted. - * @param inEnd stop conversion at this offset in input array (exclusive). - * @param output character array to receive conversion result. - * @param outEnd stop writing to output array at this offset (exclusive). - * @param data integer array containing the following data - * data[0] = inputOffset - * data[1] = outputOffset - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int decode( long converterHandle, - byte[] input, int inEnd, - char[] output, int outEnd, - int[] data, - boolean flush); - /** - * Converts an array of Unicode chars containing characters in an - * external encoding into an array of bytes. This method allows - * a buffer by buffer conversion of a data stream. The state of the - * conversion is saved between calls to convert. Among other things, - * this means multibyte input sequences can be split between calls. - * If a call to convert results in an Error, the conversion may be - * continued by calling convert again with suitably modified parameters. - * All conversions should be finished with a call to the flush method. - * - * @param converterHandle Address of converter object created by C code - * @param input char array containing text to be converted. - * @param inEnd stop conversion at this offset in input array (exclusive). - * @param output byte array to receive conversion result. - * @param outEnd stop writing to output array at this offset (exclusive). - * @param data integer array containing the following data - * data[0] = inputOffset - * data[1] = outputOffset - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int convertCharToByte(long converterHandle, - char[] input, int inEnd, - byte[] output, int outEnd, - int[] data, - boolean flush); - /** - * Converts an array of Unicode chars containing characters in an - * external encoding into an array of bytes. This method allows - * a buffer by buffer conversion of a data stream. The state of the - * conversion is saved between calls to convert. Among other things, - * this means multibyte input sequences can be split between calls. - * If a call to convert results in an Error, the conversion may be - * continued by calling convert again with suitably modified parameters. - * All conversions should be finished with a call to the flush method. - * - * @param converterHandle Address of converter object created by C code - * @param input char array containing text to be converted. - * @param inEnd stop conversion at this offset in input array (exclusive). - * @param output byte array to receive conversion result. - * @param outEnd stop writing to output array at this offset (exclusive). - * @param data integer array containing the following data - * data[0] = inputOffset - * data[1] = outputOffset - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int encode(long converterHandle, - char[] input, int inEnd, - byte[] output, int outEnd, - int[] data, - boolean flush); - /** - * Writes any remaining output to the output buffer and resets the - * converter to its initial state. - * - * @param converterHandle Address of converter object created by C code - * @param output byte array to receive flushed output. - * @param outEnd stop writing to output array at this offset (exclusive). - * @return int error code returned by ICU - * @param data integer array containing the following data - * data[0] = inputOffset - * data[1] = outputOffset - * @internal ICU 2.4 - */ - public static final native int flushCharToByte(long converterHandle, - byte[] output, - int outEnd, - int[] data); - /** - * Writes any remaining output to the output buffer and resets the - * converter to its initial state. - * - * @param converterHandle Address of converter object created by the native code - * @param output char array to receive flushed output. - * @param outEnd stop writing to output array at this offset (exclusive). - * @return int error code returned by ICU - * @param data integer array containing the following data - * data[0] = inputOffset - * data[1] = outputOffset - * @internal ICU 2.4 - */ - public static final native int flushByteToChar(long converterHandle, - char[] output, - int outEnd, - int[] data); - - /** - * Open the converter with the specified encoding - * - * @param converterHandle long array for recieving the adress of converter object - * created by the native code - * @param encoding string representing encoding - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native long openConverter(String encoding); - /** - * Resets the ByteToChar (toUnicode) state of specified converter - * - * @param converterHandle Address of converter object created by the native code - * @internal ICU 2.4 - */ - public static final native void resetByteToChar(long converterHandle); - - /** - * Resets the CharToByte (fromUnicode) state of specified converter - * - * @param converterHandle Address of converter object created by the native code - * @internal ICU 2.4 - */ - public static final native void resetCharToByte(long converterHandle); - - /** - * Closes the specified converter and releases the resources - * - * @param converterHandle Address of converter object created by the native code - * @internal ICU 2.4 - */ - public static final native void closeConverter(long converterHandle); - - /** - * Sets the substitution Unicode chars of the specified converter used - * by encoder - * @param converterHandle Address of converter object created by the native code - * @param subChars array of chars to used for substitution - * @param length length of the array - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int setSubstitutionChars( long converterHandle, - char[] subChars,int length); - /** - * Sets the substitution bytes of the specified converter used by decoder - * - * @param converterHandle Address of converter object created by the native code - * @param subChars array of bytes to used for substitution - * @param length length of the array - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int setSubstitutionBytes( long converterHandle, - byte[] subChars,int length); - /** - * Sets the substitution mode of CharToByte(fromUnicode) for the specified converter - * - * @param converterHandle Address of converter object created by the native code - * @param mode to set the true/false - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int setSubstitutionModeCharToByte(long converterHandle, - boolean mode); - /** - * Sets the substitution mode of CharToByte(fromUnicode) for the specified converter - * - * @param converterHandle Address of converter object created by the native code - * @param mode to set the true/false - * @return int error code returned by ICU - * @internal ICU 3.6 - */ - public static final native int setSubstitutionModeByteToChar(long converterHandle, - boolean mode); - /** - * Gets the numnber of invalid bytes in the specified converter object - * for the last error that has occured - * - * @param converterHandle Address of converter object created by the native code - * @param length array of int to recieve length of the array - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int countInvalidBytes(long converterHandle, int[] length); - - /** - * Gets the numnber of invalid chars in the specified converter object - * for the last error that has occured - * - * @param converterHandle Address of converter object created by the native code - * @param length array of int to recieve length of the array - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int countInvalidChars(long converterHandle, int[] length); - - /** - * Gets the number of bytes needed for converting a char - * - * @param converterHandle Address of converter object created by the native code - * @return number of bytes needed - * @internal ICU 2.4 - */ - public static final native int getMaxBytesPerChar(long converterHandle); - - /** - * Gets the number of bytes needed for converting a char - * - * @param converterHandle Address of converter object created by the native code - * @return number of bytes needed - * @internal ICU 3.2 - */ - public static final native int getMinBytesPerChar(long converterHandle); - - /** - * Gets the average numnber of bytes needed for converting a char - * - * @param converterHandle Address of converter object created by the native code - * @return number of bytes needed - * @internal ICU 2.4 - */ - public static final native float getAveBytesPerChar(long converterHandle); - - /** - * Gets the number of chars needed for converting a byte - * - * @param converterHandle Address of converter object created by the native code - * @return number of bytes needed - * @internal ICU 2.4 - */ - public static final native int getMaxCharsPerByte(long converterHandle); - - /** - * Gets the average numnber of chars needed for converting a byte - * - * @param converterHandle Address of converter object created by the native code - * @return number of bytes needed - * @internal ICU 2.4 - */ - public static final native float getAveCharsPerByte(long converterHandle); - - //CSDL: added by Jack - /** - * Determines whether charset1 contains charset2. - */ - public static final native boolean contains(long converterHandle1, long converterHandle2); - - public static final native byte[] getSubstitutionBytes(long converterHandle); - - /** - * Ascertains if a given Unicode code unit can - * be converted to the target encoding - * @param converterHandle Address of converter object created by the native code - * @param codeUnit the character to be converted - * @return true if a character can be converted - * @internal ICU 2.4 - * - */ - public static final native boolean canEncode(long converterHandle,int codeUnit); - - /** - * Ascertains if a given a byte sequence can be converted to Unicode - * @param converterHandle Address of converter object created by the native code - * @param bytes the bytes to be converted - * @return true if a character can be converted - * @internal ICU 2.4 - * - */ - public static final native boolean canDecode(long converterHandle,byte[] bytes); - - /** - * Gets the number of converters installed in the current installation of ICU - * @return int number of converters installed - * @internal ICU 2.4 - */ - public static final native int countAvailable(); - - /** - * Gets the canonical names of available converters - * @return Object[] names as an object array - * @internal ICU 2.4 - */ - public static final native String[] getAvailable(); - - /** - * Gets the number of aliases for a converter name - * @param enc encoding name - * @return number of aliases for the converter - * @internal ICU 2.4 - */ - public static final native int countAliases(String enc); - - /** - * Gets the aliases associated with the converter name - * @param enc converter name - * @return converter names as elements in an object array - * @internal ICU 2.4 - */ - public static final native String[] getAliases(String enc); - - /** - * Gets the canonical name of the converter - * @param enc converter name - * @return canonical name of the converter - * @internal ICU 2.4 - */ - public static final native String getCanonicalName(String enc); - - /** - * Gets the canonical name of the converter as defined by Java - * @param enc converter name - * @return canonical name of the converter - * @internal ICU 3.4 - */ - public static final native String getICUCanonicalName(String enc); - - /** - * Gets the canonical name of the converter as defined by Java - * @param icuCanonicalName converter name - * @return canonical name of the converter - * @internal ICU 3.4 - */ - public static final native String getJavaCanonicalName(String icuCanonicalName); - - /** - * Sets the callback to Unicode for ICU conveter. The default behaviour of ICU callback - * is to call the specified callback function for both illegal and unmapped sequences. - * @param converterHandle Adress of the converter object created by native code - * @param mode call back mode to set. This is either STOP_CALLBACK, SKIP_CALLBACK or SUBSTITUE_CALLBACK - * The converter performs the specified callback when an error occurs - * @param stopOnIllegal If true sets the alerts the converter callback to stop on an illegal sequence - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int setCallbackDecode(long converterHandle, int onMalformedInput, int onUnmappableInput, char[] subChars, int length); - - /** - * Sets the callback from Unicode for ICU conveter. The default behaviour of ICU callback - * is to call the specified callback function for both illegal and unmapped sequences. - * @param converterHandle Adress of the converter object created by native code - * @param mode call back mode to set. This is either STOP_CALLBACK, SKIP_CALLBACK or SUBSTITUE_CALLBACK - * The converter performs the specified callback when an error occurs - * @param stopOnIllegal If true sets the alerts the converter callback to stop on an illegal sequence - * @return int error code returned by ICU - * @internal ICU 2.4 - */ - public static final native int setCallbackEncode(long converterHandle, int onMalformedInput, int onUnmappableInput, byte[] subBytes, int length); - - /** - * Returns a thread safe clone of the converter - * @internal ICU 2.4 - */ - public static final native long safeClone(long converterHandle); - - /** @internal ICU 2.4 */ - public static final int STOP_CALLBACK = 0;//CodingErrorAction.REPORT - /** @internal ICU 2.4 */ - public static final int SKIP_CALLBACK = 1;//CodingErrorAction.IGNORE - /** @internal ICU 2.4 */ - public static final int SUBSTITUTE_CALLBACK = 2;//CodingErrorAction.REPLACE -} diff --git a/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java b/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java index ca278ac..7ab1843 100644 --- a/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java +++ b/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java @@ -141,6 +141,9 @@ public class UCharacter { private static native boolean isLowerCaseImpl(int codePoint); public static int forName(String blockName) { + if (blockName == null) { + throw new NullPointerException(); + } return forname(blockName); } 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 483457d..4a7e1bf 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java @@ -407,21 +407,21 @@ public abstract class Collator implements Cloneable 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 == 5) { + } else if(index == 2 && index2 > index) { result[i] = new Locale( - locale.substring(0,2), - locale.substring(3,5), - locale.substring(6)); + locale.substring(0,index), + locale.substring(index + 1,index2), + locale.substring(index2 + 1)); } } diff --git a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java index 4dbc7e3..ddd4062 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormat.java @@ -42,6 +42,11 @@ public class DecimalFormat extends NumberFormat { private boolean useExponentialNotation = false; @SuppressWarnings("unused") private byte minExponentDigits = 0; + + private boolean negPrefNull; + private boolean negSuffNull; + private boolean posPrefNull; + private boolean posSuffNull; public DecimalFormat(String pattern, DecimalFormatSymbols icuSymbols) { this.addr = icuSymbols.getAddr(); @@ -123,10 +128,7 @@ public class DecimalFormat extends NumberFormat { throw new NullPointerException(); } - String fieldType = null; - if(field != null) { - fieldType = getFieldType(field.getFieldAttribute()); - } + String fieldType = getFieldType(field.getFieldAttribute()); Number number = (Number) value; @@ -158,15 +160,11 @@ public class DecimalFormat extends NumberFormat { @Override public StringBuffer format(long value, StringBuffer buffer, FieldPosition field) { - if(buffer == null) { + if(buffer == null || field == null) { throw new NullPointerException(); } - String fieldType = null; - - if(field != null) { - fieldType = getFieldType(field.getFieldAttribute()); - } + String fieldType = getFieldType(field.getFieldAttribute()); String result = NativeDecimalFormat.format(this.addr, value, field, fieldType, null); @@ -179,15 +177,11 @@ public class DecimalFormat extends NumberFormat { @Override public StringBuffer format(double value, StringBuffer buffer, FieldPosition field) { - if(buffer == null) { + if(buffer == null || field == null) { throw new NullPointerException(); } - String fieldType = null; - - if(field != null) { - fieldType = getFieldType(field.getFieldAttribute()); - } + String fieldType = getFieldType(field.getFieldAttribute()); String result = NativeDecimalFormat.format(this.addr, value, field, fieldType, null); @@ -232,22 +226,13 @@ public class DecimalFormat extends NumberFormat { if(number instanceof BigInteger) { BigInteger valBigInteger = (BigInteger) number; - if(valBigInteger.compareTo( - new BigInteger(String.valueOf(Long.MAX_VALUE))) > 0) { - throw(new UnsupportedOperationException( - "Number too big. BigInteger > Long.MAX_VALUE not yet supported.")); - } text = NativeDecimalFormat.format(this.addr, - valBigInteger.longValue(), null, null, attributes); + valBigInteger.toString(10), null, null, attributes, 0); } else if(number instanceof BigDecimal) { BigDecimal valBigDecimal = (BigDecimal) number; - if(valBigDecimal.compareTo( - new BigDecimal(String.valueOf(Double.MAX_VALUE))) > 0) { - throw(new UnsupportedOperationException( - "Number too big. BigDecimal > Double.MAX_VALUE not yet supported.")); - } text = NativeDecimalFormat.format(this.addr, - valBigDecimal.doubleValue(), null, null, attributes); + valBigDecimal.unscaledValue().toString(10), null,null, + attributes, valBigDecimal.scale()); } else { double dv = number.doubleValue(); long lv = number.longValue(); @@ -333,21 +318,33 @@ public class DecimalFormat extends NumberFormat { } public String getNegativePrefix() { + if (negPrefNull) { + return null; + } return NativeDecimalFormat.getTextAttribute(this.addr, UNumberFormatTextAttribute.UNUM_NEGATIVE_PREFIX.ordinal()); } public String getNegativeSuffix() { + if (negSuffNull) { + return null; + } return NativeDecimalFormat.getTextAttribute(this.addr, UNumberFormatTextAttribute.UNUM_NEGATIVE_SUFFIX.ordinal()); } public String getPositivePrefix() { + if (posPrefNull) { + return null; + } return NativeDecimalFormat.getTextAttribute(this.addr, UNumberFormatTextAttribute.UNUM_POSITIVE_PREFIX.ordinal()); } public String getPositiveSuffix() { + if (posSuffNull) { + return null; + } return NativeDecimalFormat.getTextAttribute(this.addr, UNumberFormatTextAttribute.UNUM_POSITIVE_SUFFIX.ordinal()); } @@ -430,23 +427,39 @@ public class DecimalFormat extends NumberFormat { } public void setNegativePrefix(String value) { - NativeDecimalFormat.setTextAttribute(this.addr, - UNumberFormatTextAttribute.UNUM_NEGATIVE_PREFIX.ordinal(), value); + negPrefNull = value == null; + if (!negPrefNull) { + NativeDecimalFormat.setTextAttribute(this.addr, + UNumberFormatTextAttribute.UNUM_NEGATIVE_PREFIX.ordinal(), + value); + } } public void setNegativeSuffix(String value) { - NativeDecimalFormat.setTextAttribute(this.addr, - UNumberFormatTextAttribute.UNUM_NEGATIVE_SUFFIX.ordinal(), value); + negSuffNull = value == null; + if (!negSuffNull) { + NativeDecimalFormat.setTextAttribute(this.addr, + UNumberFormatTextAttribute.UNUM_NEGATIVE_SUFFIX.ordinal(), + value); + } } public void setPositivePrefix(String value) { - NativeDecimalFormat.setTextAttribute(this.addr, - UNumberFormatTextAttribute.UNUM_POSITIVE_PREFIX.ordinal(), value); + posPrefNull = value == null; + if (!posPrefNull) { + NativeDecimalFormat.setTextAttribute(this.addr, + UNumberFormatTextAttribute.UNUM_POSITIVE_PREFIX.ordinal(), + value); + } } public void setPositiveSuffix(String value) { - NativeDecimalFormat.setTextAttribute(this.addr, - UNumberFormatTextAttribute.UNUM_POSITIVE_SUFFIX.ordinal(), value); + posSuffNull = value == null; + if (!posSuffNull) { + NativeDecimalFormat.setTextAttribute(this.addr, + UNumberFormatTextAttribute.UNUM_POSITIVE_SUFFIX.ordinal(), + value); + } } @Override diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java index c48f1d9..25249c7 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java @@ -16,7 +16,7 @@ package com.ibm.icu4jni.text; -public final class NativeBreakIterator +final class NativeBreakIterator { public NativeBreakIterator() { diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java index 8606a86..2242b69 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java @@ -16,7 +16,7 @@ package com.ibm.icu4jni.text; * @internal ICU 2.4 */ -public final class NativeCollation +final class NativeCollation { // collator methods --------------------------------------------- diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java index b3b9265..39f7307 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java @@ -19,7 +19,7 @@ package com.ibm.icu4jni.text; import java.text.FieldPosition; import java.text.ParsePosition; -public final class NativeDecimalFormat { +final class NativeDecimalFormat { enum UNumberFormatSymbol { UNUM_DECIMAL_SEPARATOR_SYMBOL, diff --git a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java index 9931f2d..c0aca3b 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java @@ -260,9 +260,13 @@ public final class RuleBasedCollator extends Collator */ public RuleBasedCollator(String rules) throws ParseException { - - if (rules.length() == 0) - throw new ParseException("Build rules empty.", 0); + // BEGIN android-changed + if (rules == null) { + throw new NullPointerException(); + } + // if (rules.length() == 0) + // throw new ParseException("Build rules empty.", 0); + // END android-changed m_collator_ = NativeCollation.openCollatorFromRules(rules, CollationAttribute.VALUE_OFF, CollationAttribute.VALUE_DEFAULT_STRENGTH); @@ -285,8 +289,13 @@ public final class RuleBasedCollator extends Collator */ public RuleBasedCollator(String rules, int strength) throws ParseException { - if (rules.length() == 0) - throw new ParseException("Build rules empty.", 0); + // BEGIN android-changed + if (rules == null) { + throw new NullPointerException(); + } + // if (rules.length() == 0) + // throw new ParseException("Build rules empty.", 0); + // END android-changed if (!CollationAttribute.checkStrength(strength)) throw ErrorCode.getException(ErrorCode.U_ILLEGAL_ARGUMENT_ERROR); @@ -320,6 +329,11 @@ public final class RuleBasedCollator extends Collator */ public RuleBasedCollator(String rules, int normalizationmode, int strength) { + // BEGIN android-added + if (rules == null) { + throw new NullPointerException(); + } + // END android-added if (!CollationAttribute.checkStrength(strength) || !CollationAttribute.checkNormalization(normalizationmode)) { throw ErrorCode.getException(ErrorCode.U_ILLEGAL_ARGUMENT_ERROR); diff --git a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java index 58ddf0e..3c865d8 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedNumberFormat.java @@ -85,8 +85,11 @@ public class RuleBasedNumberFormat extends NumberFormat { * @param locale the locale to use for this rule based number format */ public void open(RBNFType type, Locale locale) { - this.addr = openRBNFImpl(type.getType(), - locale.toString()); + 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); @@ -99,6 +102,9 @@ public class RuleBasedNumberFormat extends NumberFormat { * @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()); } @@ -111,6 +117,10 @@ public class RuleBasedNumberFormat extends NumberFormat { * @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()); } @@ -178,6 +188,9 @@ public class RuleBasedNumberFormat extends NumberFormat { @Override public Number parse(String string, ParsePosition position) { + if (string == null || position == null) { + throw new NullPointerException(); + } return parseRBNFImpl(this.addr, string, position, false); } @@ -194,6 +207,9 @@ public class RuleBasedNumberFormat extends NumberFormat { * @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); } diff --git a/icu/src/main/native/ConverterInterface.c b/icu/src/main/native/ConverterInterface.c index 1a16197..3996146 100644 --- a/icu/src/main/native/ConverterInterface.c +++ b/icu/src/main/native/ConverterInterface.c @@ -895,15 +895,17 @@ static jstring getCanonicalName(JNIEnv *env, jclass jClass,jstring enc) { UErrorCode error = U_ZERO_ERROR; const char* encName = (*env)->GetStringUTFChars(env,enc,NULL); const char* canonicalName = ""; - jstring ret; + // BEGIN android-changed + jstring ret = NULL; if(encName) { canonicalName = ucnv_getAlias(encName,0,&error); if(canonicalName !=NULL && strstr(canonicalName,",")!=0) { canonicalName = ucnv_getAlias(canonicalName,1,&error); } ret = ((*env)->NewStringUTF(env, canonicalName)); + (*env)->ReleaseStringUTFChars(env,enc,encName); } - (*env)->ReleaseStringUTFChars(env,enc,encName); + // END android-changed return ret; } @@ -1077,14 +1079,15 @@ static jint setCallbackEncode(JNIEnv *env, jclass jClass, jlong handle, jint onM } fromUNewContext->onMalformedInput = getFromUCallback(onMalformedInput); fromUNewContext->onUnmappableInput = getFromUCallback(onUnmappableInput); + // BEGIN android-changed if(sub!=NULL) { fromUNewContext->length = length; strncpy(fromUNewContext->subChars, sub, length); + (*env)->ReleasePrimitiveArrayCritical(env,subChars, sub, 0); }else{ errorCode = U_ILLEGAL_ARGUMENT_ERROR; } - - (*env)->ReleasePrimitiveArrayCritical(env,subChars, NULL, 0); + // END android-changed ucnv_setFromUCallBack(conv, fromUNewAction, @@ -1203,13 +1206,15 @@ static jint setCallbackDecode(JNIEnv *env, jclass jClass, jlong handle, jint onM } toUNewContext->onMalformedInput = getToUCallback(onMalformedInput); toUNewContext->onUnmappableInput = getToUCallback(onUnmappableInput); + // BEGIN android-changed if(sub!=NULL) { toUNewContext->length = length; u_strncpy(toUNewContext->subUChars, sub, length); + (*env)->ReleasePrimitiveArrayCritical(env,subChars, sub, 0); }else{ errorCode = U_ILLEGAL_ARGUMENT_ERROR; } - (*env)->ReleasePrimitiveArrayCritical(env,subChars, NULL, 0); + // END android-changed ucnv_setToUCallBack(conv, toUNewAction, toUNewContext, @@ -1358,7 +1363,7 @@ static JNINativeMethod gMethods[] = { }; int register_com_ibm_icu4jni_converters_NativeConverter(JNIEnv *_env) { - return jniRegisterNativeMethods(_env, "com/ibm/icu4jni/converters/NativeConverter", + return jniRegisterNativeMethods(_env, "com/ibm/icu4jni/charset/NativeConverter", gMethods, NELEM(gMethods)); } diff --git a/icu/src/main/native/DecimalFormatInterface.cpp b/icu/src/main/native/DecimalFormatInterface.cpp index b87cbb7..243efeb 100644 --- a/icu/src/main/native/DecimalFormatInterface.cpp +++ b/icu/src/main/native/DecimalFormatInterface.cpp @@ -121,7 +121,7 @@ static jstring getSymbol(JNIEnv *env, jclass clazz, jint addr, jint symbol) { uint32_t resultlength, reslenneeded; - // the errorcode returned by unum_setSymbol + // the errorcode returned by unum_getSymbol UErrorCode status = U_ZERO_ERROR; // get the pointer to the number format @@ -173,7 +173,7 @@ static jint getAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol) { static void setTextAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol, jstring text) { - // the errorcode returned by unum_setSymbol + // the errorcode returned by unum_setTextAttribute UErrorCode status = U_ZERO_ERROR; // get the pointer to the number format @@ -195,7 +195,7 @@ static jstring getTextAttribute(JNIEnv *env, jclass clazz, jint addr, uint32_t resultlength, reslenneeded; - // the errorcode returned by unum_setSymbol + // the errorcode returned by unum_getTextAttribute UErrorCode status = U_ZERO_ERROR; // get the pointer to the number format @@ -231,7 +231,7 @@ static jstring getTextAttribute(JNIEnv *env, jclass clazz, jint addr, static void applyPatternImpl(JNIEnv *env, jclass clazz, jint addr, jboolean localized, jstring pattern) { - // the errorcode returned by unum_setSymbol + // the errorcode returned by unum_applyPattern UErrorCode status = U_ZERO_ERROR; // get the pointer to the number format @@ -252,7 +252,7 @@ static jstring toPatternImpl(JNIEnv *env, jclass clazz, jint addr, uint32_t resultlength, reslenneeded; - // the errorcode returned by unum_setSymbol + // the errorcode returned by unum_toPattern UErrorCode status = U_ZERO_ERROR; // get the pointer to the number format @@ -744,13 +744,14 @@ static jobject parse(JNIEnv *env, jclass clazz, jint addr, jstring text, return env->NewObject(longClass, longInitMethodID, (jlong) resultInt64); default: - break; + return NULL; } } else { int scale = digits.fCount - digits.fDecimalAt; - digits.fDigits[digits.fCount] = 0; // mc: ATTENTION: Abuse of Implementation Knowlegde! + // ATTENTION: Abuse of Implementation Knowlegde! + digits.fDigits[digits.fCount] = 0; if (digits.fIsPositive) { resultStr = env->NewStringUTF(digits.fDigits); } else { @@ -758,7 +759,8 @@ static jobject parse(JNIEnv *env, jclass clazz, jint addr, jstring text, env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos); return env->NewObject(doubleClass, dblInitMethodID, (jdouble)-0); } else { - *(digits.fDigits - 1) = '-'; // mc: ATTENTION: Abuse of Implementation Knowlegde! + // ATTENTION: Abuse of Implementation Knowlegde! + *(digits.fDigits - 1) = '-'; resultStr = env->NewStringUTF(digits.fDigits - 1); } } @@ -769,7 +771,6 @@ static jobject parse(JNIEnv *env, jclass clazz, jint addr, jstring text, resultObject2 = env->NewObject(bigDecimalClass, bigDecimalInitMethodID, resultObject1, scale); return resultObject2; } - return NULL; // Don't see WHY, however!!! (Control never reaches here!!!) } static jint cloneImpl(JNIEnv *env, jclass clazz, jint addr) { diff --git a/icu/src/main/native/RBNFInterface.cpp b/icu/src/main/native/RBNFInterface.cpp index 17e7155..d9bf460 100644 --- a/icu/src/main/native/RBNFInterface.cpp +++ b/icu/src/main/native/RBNFInterface.cpp @@ -72,7 +72,7 @@ static jint openRBNFImpl1(JNIEnv* env, jclass clazz, } else if(type == 3) { style = URBNF_COUNT; } else { - printf("error"); + icuError(env, U_ILLEGAL_ARGUMENT_ERROR); } Locale loc = Locale::createFromName(localeChars); diff --git a/icu/src/main/native/ResourceInterface.cpp b/icu/src/main/native/ResourceInterface.cpp index a0c6922..562f480 100644 --- a/icu/src/main/native/ResourceInterface.cpp +++ b/icu/src/main/native/ResourceInterface.cpp @@ -420,6 +420,7 @@ static void getTimeZonesNative(JNIEnv* env, jclass clazz, const UnicodeString zoneID((UChar *)res, length); env->ReleaseStringChars(strObj, res); zones[i] = TimeZone::createTimeZone(zoneID); + env->DeleteLocalRef(strObj); } // 15th January 2008 -- cgit v1.1