summaryrefslogtreecommitdiffstats
path: root/icu/src/main
diff options
context:
space:
mode:
authorPeter Hallam <peterhal@google.com>2010-05-03 12:57:15 -0700
committerPeter Hallam <peterhal@google.com>2010-05-04 16:30:12 -0700
commit6b811c5daec1b28e6f63b57f98a032236f2c3cf7 (patch)
treea733f20e87a9739253d495c14d54e7d253e35771 /icu/src/main
parent0a98ab45e3566542f2d669eb0ffd28a560d97d28 (diff)
downloadlibcore-6b811c5daec1b28e6f63b57f98a032236f2c3cf7.zip
libcore-6b811c5daec1b28e6f63b57f98a032236f2c3cf7.tar.gz
libcore-6b811c5daec1b28e6f63b57f98a032236f2c3cf7.tar.bz2
Merge awt-kernel, icu, luni-kernel, prefs, security-kernel, x-net into luni
Merge xml except xmlpull and kxml into luni
Diffstat (limited to 'icu/src/main')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java360
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java434
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java116
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java120
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/common/ErrorCode.java205
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java185
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/regex/NativeRegEx.java132
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/CollationAttribute.java40
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java230
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/CollationKey.java122
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/Collator.java248
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java158
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java232
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java611
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeIDN.java44
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeNormalizer.java47
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java543
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/ICU.java311
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java321
-rw-r--r--icu/src/main/native/BidiWrapper.cpp180
-rw-r--r--icu/src/main/native/ErrorCode.cpp39
-rw-r--r--icu/src/main/native/ErrorCode.h35
-rw-r--r--icu/src/main/native/ICU.cpp710
-rw-r--r--icu/src/main/native/NativeBreakIterator.cpp143
-rw-r--r--icu/src/main/native/NativeCollation.cpp199
-rw-r--r--icu/src/main/native/NativeConverter.cpp1019
-rw-r--r--icu/src/main/native/NativeDecimalFormat.cpp608
-rw-r--r--icu/src/main/native/NativeIDN.cpp66
-rw-r--r--icu/src/main/native/NativeNormalizer.cpp50
-rw-r--r--icu/src/main/native/NativeRegEx.cpp356
-rw-r--r--icu/src/main/native/ScopedJavaUnicodeString.h57
-rw-r--r--icu/src/main/native/UCharacter.cpp203
-rw-r--r--icu/src/main/native/sub.mk31
33 files changed, 0 insertions, 8155 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java
deleted file mode 100644
index 9c74d68..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java
+++ /dev/null
@@ -1,360 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2006, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
- /**
- * A JNI interface for ICU converters.
- *
- *
- * @author Ram Viswanadha, IBM
- */
-package com.ibm.icu4jni.charset;
-
-import com.ibm.icu4jni.common.ErrorCode;
-// BEGIN android-removed
-// import com.ibm.icu4jni.converters.NativeConverter;
-// END android-removed
-
-
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import java.nio.ByteBuffer;
-
-public final class CharsetDecoderICU extends CharsetDecoder{
-
-
- private static final int INPUT_OFFSET = 0,
- OUTPUT_OFFSET = 1,
- INVALID_BYTES = 2,
- INPUT_HELD = 3,
- LIMIT = 4;
- /* data is 3 element array where
- * data[INPUT_OFFSET] = on input contains the start of input and on output the number of input chars consumed
- * data[OUTPUT_OFFSET] = on input contains the start of output and on output the number of output bytes written
- * data[INVALID_CHARS] = number of invalid chars
- * data[INPUT_HELD] = number of input chars held in the converter's state
- */
- private int[] data = new int[LIMIT];
-
- /* handle to the ICU converter that is opened */
- private long converterHandle=0;
-
-
- private byte[] input = null;
- private char[] output= null;
-
- // BEGIN android-added
- private byte[] allocatedInput = null;
- private char[] allocatedOutput = null;
- // END android-added
-
- // These instance variables are
- // always assigned in the methods
- // before being used. This class
- // inhrently multithread unsafe
- // so we dont have to worry about
- // synchronization
- private int inEnd;
- private int outEnd;
- private int ec;
- private int onUnmappableInput = NativeConverter.STOP_CALLBACK;;
- private int onMalformedInput = NativeConverter.STOP_CALLBACK;;
- private int savedInputHeldLen;
-
- /**
- * Constructs a new decoder for the given charset
- * @param cs for which the decoder is created
- * @param cHandle the address of ICU converter
- * @exception RuntimeException
- * @stable ICU 2.4
- */
- public CharsetDecoderICU(Charset cs,long cHandle){
- super(cs,
- NativeConverter.getAveCharsPerByte(cHandle),
- NativeConverter.getMaxCharsPerByte(cHandle)
- );
-
- char[] sub = replacement().toCharArray();
- ec = NativeConverter.setCallbackDecode(cHandle,
- onMalformedInput,
- onUnmappableInput,
- sub, sub.length);
- if(ErrorCode.isFailure(ec)){
- throw ErrorCode.getException(ec);
- }
- // store the converter handle
- converterHandle=cHandle;
-
- }
-
- /**
- * Sets this decoders replacement string. Substitutes the string in input if an
- * umappable or illegal sequence is encountered
- * @param newReplacement to replace the error bytes with
- * @stable ICU 2.4
- */
- protected void implReplaceWith(String newReplacement) {
- if(converterHandle > 0){
- if( newReplacement.length() > NativeConverter.getMaxBytesPerChar(converterHandle)) {
- throw new IllegalArgumentException();
- }
- ec =NativeConverter.setSubstitutionChars(converterHandle,
- newReplacement.toCharArray(),
- newReplacement.length()
- );
- if(ErrorCode.isFailure(ec)){
- throw ErrorCode.getException(ec);
- }
- }
- }
-
- /**
- * Sets the action to be taken if an illegal sequence is encountered
- * @param newAction action to be taken
- * @exception IllegalArgumentException
- * @stable ICU 2.4
- */
- protected final void implOnMalformedInput(CodingErrorAction newAction) {
- if(newAction.equals(CodingErrorAction.IGNORE)){
- onMalformedInput = NativeConverter.SKIP_CALLBACK;
- }else if(newAction.equals(CodingErrorAction.REPLACE)){
- onMalformedInput = NativeConverter.SUBSTITUTE_CALLBACK;
- }else if(newAction.equals(CodingErrorAction.REPORT)){
- onMalformedInput = NativeConverter.STOP_CALLBACK;
- }
- char[] sub = replacement().toCharArray();
- //System.out.println(" setting callbacks mfi " + onMalformedInput +" umi " + onUnmappableInput);
- ec = NativeConverter.setCallbackDecode(converterHandle, onMalformedInput, onUnmappableInput, sub, sub.length);
- if(ErrorCode.isFailure(ec)){
- throw ErrorCode.getException(ec);
- }
- }
-
- /**
- * Sets the action to be taken if an illegal sequence is encountered
- * @param newAction action to be taken
- * @exception IllegalArgumentException
- * @stable ICU 2.4
- */
- protected final void implOnUnmappableCharacter(CodingErrorAction newAction) {
- if(newAction.equals(CodingErrorAction.IGNORE)){
- onUnmappableInput = NativeConverter.SKIP_CALLBACK;
- }else if(newAction.equals(CodingErrorAction.REPLACE)){
- onUnmappableInput = NativeConverter.SUBSTITUTE_CALLBACK;
- }else if(newAction.equals(CodingErrorAction.REPORT)){
- onUnmappableInput = NativeConverter.STOP_CALLBACK;
- }
- char[] sub = replacement().toCharArray();
- ec = NativeConverter.setCallbackDecode(converterHandle,onMalformedInput, onUnmappableInput, sub, sub.length);
- if(ErrorCode.isFailure(ec)){
- throw ErrorCode.getException(ec);
- }
- }
-
- /**
- * Flushes any characters saved in the converter's internal buffer and
- * resets the converter.
- * @param out action to be taken
- * @return result of flushing action and completes the decoding all input.
- * Returns CoderResult.UNDERFLOW if the action succeeds.
- * @stable ICU 2.4
- */
- protected final CoderResult implFlush(CharBuffer out) {
- try{
-
- data[OUTPUT_OFFSET] = getArray(out);
-
- ec=NativeConverter.flushByteToChar(
- converterHandle, /* Handle to ICU Converter */
- output, /* input array of chars */
- outEnd, /* input index+1 to be written */
- data /* contains data, inOff,outOff */
- );
-
-
- /* If we don't have room for the output, throw an exception*/
- if (ErrorCode.isFailure(ec)) {
- if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
- return CoderResult.OVERFLOW;
- }else if (ec == ErrorCode.U_TRUNCATED_CHAR_FOUND ) {//CSDL: add this truncated character error handling
- if(data[INPUT_OFFSET]>0){
- return CoderResult.malformedForLength(data[INPUT_OFFSET]);
- }
- }else {
- ErrorCode.getException(ec);
- }
- }
- return CoderResult.UNDERFLOW;
- }finally{
- /* save the flushed data */
- setPosition(out);
- implReset();
- }
- }
-
- /**
- * Resets the to Unicode mode of converter
- * @stable ICU 2.4
- */
- protected void implReset() {
- NativeConverter.resetByteToChar(converterHandle);
- data[INPUT_OFFSET] = 0;
- data[OUTPUT_OFFSET] = 0;
- data[INVALID_BYTES] = 0;
- data[INPUT_HELD] = 0;
- savedInputHeldLen = 0;
- output = null;
- input = null;
- }
-
- /**
- * Decodes one or more bytes. The default behaviour of the converter
- * is stop and report if an error in input stream is encountered.
- * To set different behaviour use @see CharsetDecoder.onMalformedInput()
- * 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 in buffer to decode
- * @param out buffer to populate with decoded result
- * @return result of decoding action. Returns CoderResult.UNDERFLOW if the decoding
- * action succeeds or more input is needed for completing the decoding action.
- * @stable ICU 2.4
- */
- protected CoderResult decodeLoop(ByteBuffer in,CharBuffer out){
-
- if(!in.hasRemaining()){
- return CoderResult.UNDERFLOW;
- }
-
- data[INPUT_OFFSET] = getArray(in);
- data[OUTPUT_OFFSET]= getArray(out);
- data[INPUT_HELD] = 0;
-
- try{
- /* do the conversion */
- ec=NativeConverter.decode(
- converterHandle, /* Handle to ICU Converter */
- input, /* input array of bytes */
- inEnd, /* last index+1 to be converted */
- output, /* input array of chars */
- outEnd, /* input index+1 to be written */
- data, /* contains data, inOff,outOff */
- false /* donot flush the data */
- );
-
-
- /* return an error*/
- if(ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR){
- return CoderResult.OVERFLOW;
- }else if(ec==ErrorCode.U_INVALID_CHAR_FOUND){
- return CoderResult.malformedForLength(data[INVALID_BYTES]);
- }else if(ec==ErrorCode.U_ILLEGAL_CHAR_FOUND){
- return CoderResult.malformedForLength(data[INVALID_BYTES]);
- }
- /* decoding action succeded */
- return CoderResult.UNDERFLOW;
- }finally{
- setPosition(in);
- setPosition(out);
- }
- }
-
- /**
- * Releases the system resources by cleanly closing ICU converter opened
- * @stable ICU 2.4
- */
- protected void finalize()throws Throwable{
- NativeConverter.closeConverter(converterHandle);
- super.finalize();
- converterHandle = 0;
- }
-
- //------------------------------------------
- // private utility methods
- //------------------------------------------
-
- private final int getArray(CharBuffer out){
- if(out.hasArray()){
- // BEGIN android-changed: take arrayOffset into account
- output = out.array();
- outEnd = out.arrayOffset() + out.limit();
- return out.arrayOffset() + out.position();
- // END android-changed
- }else{
- outEnd = out.remaining();
- // BEGIN android-added
- if (allocatedOutput == null || (outEnd > allocatedOutput.length)) {
- allocatedOutput = new char[outEnd];
- }
- output = allocatedOutput;
- // END android-added
- //since the new
- // buffer start position
- // is 0
- return 0;
- }
-
- }
- private final int getArray(ByteBuffer in){
- if(in.hasArray()){
- // BEGIN android-changed: take arrayOffset into account
- input = in.array();
- inEnd = in.arrayOffset() + in.limit();
- return in.arrayOffset() + in.position() + savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/
- // END android-changed
- }else{
- inEnd = in.remaining();
- // BEGIN android-added
- if (allocatedInput == null || (inEnd > allocatedInput.length)) {
- allocatedInput = new byte[inEnd];
- }
- input = allocatedInput;
- // END android-added
- // save the current position
- int pos = in.position();
- in.get(input,0,inEnd);
- // reset the position
- in.position(pos);
- // the start position
- // of the new buffer
- // is whatever is savedInputLen
- return savedInputHeldLen;
- }
-
- }
- private final void setPosition(CharBuffer out){
- if(out.hasArray()){
- // BEGIN android-changed: take arrayOffset into account
- out.position(out.position() + data[OUTPUT_OFFSET] - out.arrayOffset());
- // END android-changed
- }else{
- out.put(output,0,data[OUTPUT_OFFSET]);
- }
- // BEGIN android-added
- // release reference to output array, which may not be ours
- output = null;
- // END android-added
- }
- private final void setPosition(ByteBuffer in){
-
- // ok was there input held in the previous invocation of decodeLoop
- // that resulted in output in this invocation?
- // BEGIN android-changed
- in.position(in.position() + data[INPUT_OFFSET] + savedInputHeldLen - data[INPUT_HELD]);
- savedInputHeldLen = data[INPUT_HELD];
- // release reference to input array, which may not be ours
- input = null;
- // END android-changed
- }
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java
deleted file mode 100644
index eada080..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2006, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-/**
- * A JNI interface for ICU converters.
- *
- *
- * @author Ram Viswanadha, IBM
- */
-package com.ibm.icu4jni.charset;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-
-import com.ibm.icu4jni.common.ErrorCode;
-// BEGIN android-removed
-// import com.ibm.icu4jni.converters.NativeConverter;
-// END android-removed
-
-public final class CharsetEncoderICU extends CharsetEncoder {
-
- private static final int INPUT_OFFSET = 0,
- OUTPUT_OFFSET = 1,
- INVALID_CHARS = 2,
- INPUT_HELD = 3,
- LIMIT = 4;
- /* data is 3 element array where
- * data[INPUT_OFFSET] = on input contains the start of input and on output the number of input chars consumed
- * data[OUTPUT_OFFSET] = on input contains the start of output and on output the number of output bytes written
- * data[INVALID_CHARS] = number of invalid chars
- * data[INPUT_HELD] = number of input chars held in the converter's state
- */
- private int[] data = new int[LIMIT];
- /* handle to the ICU converter that is opened */
- private long converterHandle=0;
-
- private char[] input = null;
- private byte[] output = null;
-
- // BEGIN android-added
- private char[] allocatedInput = null;
- private byte[] allocatedOutput = null;
- // END android-added
-
- // These instance variables are
- // always assigned in the methods
- // before being used. This class
- // inhrently multithread unsafe
- // so we dont have to worry about
- // synchronization
- private int inEnd;
- private int outEnd;
- private int ec;
- private int savedInputHeldLen;
- private int onUnmappableInput = NativeConverter.STOP_CALLBACK;;
- private int onMalformedInput = NativeConverter.STOP_CALLBACK;;
-
- /**
- * Construcs a new encoder for the given charset
- * @param cs for which the decoder is created
- * @param cHandle the address of ICU converter
- * @param replacement the substitution bytes
- * @stable ICU 2.4
- */
- public CharsetEncoderICU(Charset cs, long cHandle, byte[] replacement) {
- super(
- cs,
- (float) NativeConverter.getAveBytesPerChar(cHandle),
- (float) NativeConverter.getMaxBytesPerChar(cHandle),
- replacement);
- byte[] sub = replacement();
- // The default callback action on unmappable input
- // or malformed input is to ignore so we set ICU converter
- // callback to stop and report the error
- ec = NativeConverter.setCallbackEncode( cHandle,
- onMalformedInput,
- onUnmappableInput,
- sub, sub.length);
- converterHandle = cHandle;
- if (ErrorCode.isFailure(ec)) {
- throw ErrorCode.getException(ec);
- }
- }
-
- /**
- * Sets this encoders replacement string. Substitutes the string in output if an
- * umappable or illegal sequence is encountered
- * @param newReplacement to replace the error chars with
- * @stable ICU 2.4
- */
- protected void implReplaceWith(byte[] newReplacement) {
- if (converterHandle != 0) {
- if (newReplacement.length
- > NativeConverter.getMaxBytesPerChar(converterHandle)) {
- throw new IllegalArgumentException("Number of replacement Bytes are greater than max bytes per char");
- }
- ec = NativeConverter.setSubstitutionBytes(converterHandle,
- newReplacement,
- newReplacement.length);
- if (ErrorCode.isFailure(ec)) {
- throw ErrorCode.getException(ec);
- }
- }
- }
-
- /**
- * Sets the action to be taken if an illegal sequence is encountered
- * @param newAction action to be taken
- * @exception IllegalArgumentException
- * @stable ICU 2.4
- */
- protected void implOnMalformedInput(CodingErrorAction newAction) {
- onMalformedInput = NativeConverter.STOP_CALLBACK;
-
- if (newAction.equals(CodingErrorAction.IGNORE)) {
- onMalformedInput = NativeConverter.SKIP_CALLBACK;
- } else if (newAction.equals(CodingErrorAction.REPLACE)) {
- onMalformedInput = NativeConverter.SUBSTITUTE_CALLBACK;
- }
- byte[] sub = replacement();
- ec = NativeConverter.setCallbackEncode(converterHandle, onMalformedInput, onUnmappableInput, sub, sub.length);
- if (ErrorCode.isFailure(ec)) {
- throw ErrorCode.getException(ec);
- }
-
- }
-
- /**
- * Sets the action to be taken if an illegal sequence is encountered
- * @param newAction action to be taken
- * @exception IllegalArgumentException
- * @stable ICU 2.4
- */
- protected void implOnUnmappableCharacter(CodingErrorAction newAction) {
- onUnmappableInput = NativeConverter.STOP_CALLBACK;
-
- if (newAction.equals(CodingErrorAction.IGNORE)) {
- onUnmappableInput = NativeConverter.SKIP_CALLBACK;
- } else if (newAction.equals(CodingErrorAction.REPLACE)) {
- onUnmappableInput = NativeConverter.SUBSTITUTE_CALLBACK;
- }
- byte[] sub = replacement();
- ec = NativeConverter.setCallbackEncode(converterHandle, onMalformedInput, onUnmappableInput, sub, sub.length);
- if (ErrorCode.isFailure(ec)) {
- throw ErrorCode.getException(ec);
- }
- }
-
- /**
- * Flushes any characters saved in the converter's internal buffer and
- * resets the converter.
- * @param out action to be taken
- * @return result of flushing action and completes the decoding all input.
- * Returns CoderResult.UNDERFLOW if the action succeeds.
- * @stable ICU 2.4
- */
- protected CoderResult implFlush(ByteBuffer out) {
- try {
- data[OUTPUT_OFFSET] = getArray(out);
- ec = NativeConverter.flushCharToByte(converterHandle,/* Handle to ICU Converter */
- output, /* output array of chars */
- outEnd, /* output index+1 to be written */
- data /* contains data, inOff,outOff */
- );
-
- /* If we don't have room for the output, throw an exception*/
- if (ErrorCode.isFailure(ec)) {
- if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
- return CoderResult.OVERFLOW;
- }else if (ec == ErrorCode.U_TRUNCATED_CHAR_FOUND) {//CSDL: add this truncated character error handling
- if(data[INPUT_OFFSET]>0){
- return CoderResult.malformedForLength(data[INPUT_OFFSET]);
- }
- }else {
- ErrorCode.getException(ec);
- }
- }
- return CoderResult.UNDERFLOW;
- } finally {
- setPosition(out);
- implReset();
- }
- }
-
- /**
- * Resets the from Unicode mode of converter
- * @stable ICU 2.4
- */
- protected void implReset() {
- NativeConverter.resetCharToByte(converterHandle);
- data[INPUT_OFFSET] = 0;
- data[OUTPUT_OFFSET] = 0;
- data[INVALID_CHARS] = 0;
- data[INPUT_HELD] = 0;
- savedInputHeldLen = 0;
- }
-
- /**
- * Encodes one or more chars. The default behaviour of the
- * converter is stop and report if an error in input stream is encountered.
- * To set different behaviour use @see CharsetEncoder.onMalformedInput()
- * @param in buffer to decode
- * @param out buffer to populate with decoded result
- * @return result of decoding action. Returns CoderResult.UNDERFLOW if the decoding
- * action succeeds or more input is needed for completing the decoding action.
- * @stable ICU 2.4
- */
- protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
-
- if (!in.hasRemaining()) {
- return CoderResult.UNDERFLOW;
- }
-
- data[INPUT_OFFSET] = getArray(in);
- data[OUTPUT_OFFSET]= getArray(out);
- data[INPUT_HELD] = 0;
- // BEGIN android-added
- data[INVALID_CHARS] = 0; // Make sure we don't see earlier errors.
- // END android added
-
- try {
- /* do the conversion */
- ec = NativeConverter.encode(converterHandle,/* Handle to ICU Converter */
- input, /* input array of bytes */
- inEnd, /* last index+1 to be converted */
- output, /* output array of chars */
- outEnd, /* output index+1 to be written */
- data, /* contains data, inOff,outOff */
- false /* donot flush the data */
- );
- if (ErrorCode.isFailure(ec)) {
- /* If we don't have room for the output return error */
- if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
- return CoderResult.OVERFLOW;
- } else if (ec == ErrorCode.U_INVALID_CHAR_FOUND) {
- return CoderResult.unmappableForLength(data[INVALID_CHARS]);
- } else if (ec == ErrorCode.U_ILLEGAL_CHAR_FOUND) {
- // in.position(in.position() - 1);
- return CoderResult.malformedForLength(data[INVALID_CHARS]);
- }
- }
- return CoderResult.UNDERFLOW;
- } finally {
- /* save state */
- setPosition(in);
- setPosition(out);
- }
- }
-
- /**
- * Ascertains if a given Unicode character can
- * be converted to the target encoding
- *
- * @param c the character to be converted
- * @return true if a character can be converted
- * @stable ICU 2.4
- *
- */
- public boolean canEncode(char c) {
- return canEncode((int) c);
- }
-
- /**
- * Ascertains if a given Unicode code point (32bit value for handling surrogates)
- * can be converted to the target encoding. If the caller wants to test if a
- * surrogate pair can be converted to target encoding then the
- * responsibility of assembling the int value lies with the caller.
- * For assembling a code point the caller can use UTF16 class of ICU4J and do something like:
- * <pre>
- * while(i<mySource.length){
- * if(UTF16.isLeadSurrogate(mySource[i])&& i+1< mySource.length){
- * if(UTF16.isTrailSurrogate(mySource[i+1])){
- * int temp = UTF16.charAt(mySource,i,i+1,0);
- * if(!((CharsetEncoderICU) myConv).canEncode(temp)){
- * passed=false;
- * }
- * i++;
- * i++;
- * }
- * }
- * }
- * </pre>
- * or
- * <pre>
- * String src = new String(mySource);
- * int i,codepoint;
- * boolean passed = false;
- * while(i<src.length()){
- * codepoint = UTF16.charAt(src,i);
- * i+= (codepoint>0xfff)? 2:1;
- * if(!(CharsetEncoderICU) myConv).canEncode(codepoint)){
- * passed = false;
- * }
- * }
- * </pre>
- *
- * @param codepoint Unicode code point as int value
- * @return true if a character can be converted
- * @obsolete ICU 2.4
- * @deprecated ICU 3.4
- */
- public boolean canEncode(int codepoint) {
- return NativeConverter.canEncode(converterHandle, codepoint);
- }
-
- /**
- * Releases the system resources by cleanly closing ICU converter opened
- * @exception Throwable exception thrown by super class' finalize method
- * @stable ICU 2.4
- */
- protected void finalize() throws Throwable {
- NativeConverter.closeConverter(converterHandle);
- super.finalize();
- converterHandle=0;
- }
-
- //------------------------------------------
- // private utility methods
- //------------------------------------------
- private final int getArray(ByteBuffer out) {
- if(out.hasArray()){
- // BEGIN android-changed: take arrayOffset into account
- output = out.array();
- outEnd = out.arrayOffset() + out.limit();
- return out.arrayOffset() + out.position();
- // END android-changed
- }else{
- outEnd = out.remaining();
- // BEGIN android-added
- if (allocatedOutput == null || (outEnd > allocatedOutput.length)) {
- allocatedOutput = new byte[outEnd];
- }
- output = allocatedOutput;
- // END android-added
- //since the new
- // buffer start position
- // is 0
- return 0;
- }
- }
-
- private final int getArray(CharBuffer in) {
- if(in.hasArray()){
- // BEGIN android-changed: take arrayOffset into account
- input = in.array();
- inEnd = in.arrayOffset() + in.limit();
- return in.arrayOffset() + in.position() + savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/
- // END android-changed
- }else{
- inEnd = in.remaining();
- // BEGIN android-added
- if (allocatedInput == null || (inEnd > allocatedInput.length)) {
- allocatedInput = new char[inEnd];
- }
- input = allocatedInput;
- // END android-added
- // save the current position
- int pos = in.position();
- in.get(input,0,inEnd);
- // reset the position
- in.position(pos);
- // the start position
- // of the new buffer
- // is whatever is savedInputLen
- return savedInputHeldLen;
- }
-
- }
- private final void setPosition(ByteBuffer out) {
-
- if (out.hasArray()) {
- // in getArray method we accessed the
- // array backing the buffer directly and wrote to
- // it, so just just set the position and return.
- // This is done to avoid the creation of temp array.
- // BEGIN android-changed: take arrayOffset into account
- out.position(out.position() + data[OUTPUT_OFFSET] - out.arrayOffset());
- // END android-changed
- } else {
- out.put(output, 0, data[OUTPUT_OFFSET]);
- }
- // BEGIN android-added
- // release reference to output array, which may not be ours
- output = null;
- // END android-added
- }
- private final void setPosition(CharBuffer in){
-
-// BEGIN android-removed
-// // was there input held in the previous invocation of encodeLoop
-// // that resulted in output in this invocation?
-// if(data[OUTPUT_OFFSET]>0 && savedInputHeldLen>0){
-// int len = in.position() + data[INPUT_OFFSET] + savedInputHeldLen;
-// in.position(len);
-// savedInputHeldLen = data[INPUT_HELD];
-// }else{
-// in.position(in.position() + data[INPUT_OFFSET] + savedInputHeldLen);
-// savedInputHeldLen = data[INPUT_HELD];
-// in.position(in.position() - savedInputHeldLen);
-// }
-// END android-removed
-
-// BEGIN android-added
- // Slightly rewired original code to make it cleaner. Also
- // added a fix for the problem where input charatcers got
- // lost when invalid characters were encountered. Not sure
- // what happens when data[INVALID_CHARS] is > 1, though,
- // since we never saw that happening.
- int len = in.position() + data[INPUT_OFFSET] + savedInputHeldLen;
- len -= data[INVALID_CHARS]; // Otherwise position becomes wrong.
- in.position(len);
- savedInputHeldLen = data[INPUT_HELD];
- // was there input held in the previous invocation of encodeLoop
- // that resulted in output in this invocation?
- if(!(data[OUTPUT_OFFSET]>0 && savedInputHeldLen>0)){
- in.position(in.position() - savedInputHeldLen);
- }
-// END android-added
-
- // BEGIN android-added
- // release reference to input array, which may not be ours
- input = null;
- // END android-added
- }
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java
deleted file mode 100644
index fe0f920..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.charset;
-
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.util.HashMap;
-import java.util.Map;
-
-public final class CharsetICU extends Charset {
- private final String icuCanonicalName;
- /**
- * Constructor to create a the CharsetICU object
- * @param canonicalName the canonical name as a string
- * @param aliases the alias set as an array of strings
- * @stable ICU 2.4
- */
- protected CharsetICU(String canonicalName, String icuCanonName, String[] aliases) {
- super(canonicalName, aliases);
- icuCanonicalName = icuCanonName;
- }
- /**
- * Returns a new decoder instance of this charset object
- * @return a new decoder object
- * @stable ICU 2.4
- */
- public CharsetDecoder newDecoder() {
- long converterHandle = NativeConverter.openConverter(icuCanonicalName);
- return new CharsetDecoderICU(this, converterHandle);
- }
-
- // hardCoded list of replacement bytes
- private static final Map<String, byte[]> subByteMap = new HashMap<String, byte[]>();
- static {
- subByteMap.put("UTF-32", new byte[]{0x00, 0x00, (byte)0xfe, (byte)0xff});
- subByteMap.put("ibm-16684_P110-2003", new byte[]{0x40, 0x40}); // make \u3000 the sub char
- subByteMap.put("ibm-971_P100-1995", new byte[]{(byte)0xa1, (byte)0xa1}); // make \u3000 the sub char
- }
- /**
- * Returns a new encoder object of the charset
- * @return a new encoder
- * @stable ICU 2.4
- */
- public CharsetEncoder newEncoder() {
- // the arrays are locals and not
- // instance variables since the
- // methods on this class need to
- // be thread safe
- long converterHandle = NativeConverter.openConverter(icuCanonicalName);
-
- //According to the contract all converters should have non-empty replacement
- byte[] replacement = NativeConverter.getSubstitutionBytes(converterHandle);
-
- try {
- return new CharsetEncoderICU(this,converterHandle, replacement);
- } catch (IllegalArgumentException ex) {
- // work around for the non-sensical check in the nio API that
- // a substitution character must be mappable while decoding!!
- replacement = subByteMap.get(icuCanonicalName);
- if (replacement == null) {
- replacement = new byte[NativeConverter.getMinBytesPerChar(converterHandle)];
- for(int i = 0; i < replacement.length; ++i) {
- replacement[i]= 0x3f;
- }
- }
- NativeConverter.setSubstitutionBytes(converterHandle, replacement, replacement.length);
- return new CharsetEncoderICU(this,converterHandle, replacement);
- }
- }
-
- /**
- * Ascertains if a charset is a sub set of this charset
- * @param cs charset to test
- * @return true if the given charset is a subset of this charset
- * @stable ICU 2.4
- *
- * //CSDL: major changes by Jack
- */
- public boolean contains(Charset cs){
- if (null == cs) {
- return false;
- } else if (this.equals(cs)) {
- return true;
- }
-
- long converterHandle1 = 0;
- long converterHandle2 = 0;
-
- try {
- converterHandle1 = NativeConverter.openConverter(this.name());
- if (converterHandle1 > 0) {
- converterHandle2 = NativeConverter.openConverter(cs.name());
- if (converterHandle2 > 0) {
- return NativeConverter.contains(converterHandle1,
- converterHandle2);
- }
- }
- return false;
- } finally {
- if (0 != converterHandle1) {
- NativeConverter.closeConverter(converterHandle1);
- if (0 != converterHandle2) {
- NativeConverter.closeConverter(converterHandle2);
- }
- }
- }
- }
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java b/icu/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java
deleted file mode 100644
index 6a97c27..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2006, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.charset;
-
-import java.nio.charset.Charset;
-
-public final class NativeConverter {
- /**
- * Converts an array of bytes containing characters in an external
- * encoding into an array of Unicode characters. This method allows
- * buffer-by-buffer conversion of a data stream. The state of the
- * conversion is saved between calls. Among other things,
- * this means multibyte input sequences can be split between calls.
- * If a call to results in an error, the conversion may be
- * continued by calling this method 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 native int decode(long converterHandle, byte[] input, int inEnd,
- char[] output, int outEnd, int[] data, boolean flush);
-
- /**
- * Converts an array of Unicode chars to an array of bytes in an external encoding.
- * 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 results in an error, the conversion may be
- * continued by calling this method 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 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 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 native int flushByteToChar(long converterHandle, char[] output, int outEnd, int[] data);
-
- public static native long openConverter(String encoding);
- public static native void closeConverter(long converterHandle);
-
- public static native void resetByteToChar(long converterHandle);
- public static native void resetCharToByte(long converterHandle);
-
- public static native int setSubstitutionChars(long converterHandle, char[] subChars,int length);
- public static native int setSubstitutionBytes(long converterHandle, byte[] subChars,int length);
- public static native byte[] getSubstitutionBytes(long converterHandle);
-
- public static native int getMaxBytesPerChar(long converterHandle);
- public static native int getMinBytesPerChar(long converterHandle);
- public static native float getAveBytesPerChar(long converterHandle);
- public static native int getMaxCharsPerByte(long converterHandle);
- public static native float getAveCharsPerByte(long converterHandle);
-
- public static native boolean contains(long converterHandle1, long converterHandle2);
-
- public static native boolean canEncode(long converterHandle, int codeUnit);
-
- public static native String[] getAvailableCharsetNames();
- public static native Charset charsetForName(String charsetName);
-
- public static final int STOP_CALLBACK = 0;//CodingErrorAction.REPORT
- public static final int SKIP_CALLBACK = 1;//CodingErrorAction.IGNORE
- public static final int SUBSTITUTE_CALLBACK = 2;//CodingErrorAction.REPLACE
- public static native int setCallbackDecode(long converterHandle, int onMalformedInput, int onUnmappableInput, char[] subChars, int length);
- public static native int setCallbackEncode(long converterHandle, int onMalformedInput, int onUnmappableInput, byte[] subBytes, int length);
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/common/ErrorCode.java b/icu/src/main/java/com/ibm/icu4jni/common/ErrorCode.java
deleted file mode 100644
index 023f165..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/common/ErrorCode.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
-******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-******************************************************************************
-*
-******************************************************************************
-*/
-
-package com.ibm.icu4jni.common;
-
-/**
-* Error exception class mapping ICU error codes of the enum UErrorCode
-* @author syn wee quek
-* @internal
-*/
-public final class ErrorCode extends Exception
-{
-
- // public methods --------------------------------------------------------
-
- /**
- * Generic mapping from the error codes to java default exceptions.
- * @param error error code
- * @return java default exception that maps to the argument error code,
- * otherwise if error is not a valid error code, null is returned.
- * @stable ICU 2.4
- */
- public static final RuntimeException getException(int error)
- {
- if (error <= U_ZERO_ERROR && error >= U_ERROR_LIMIT) {
- return null;
- }
- String errorname = ERROR_NAMES_[U_ILLEGAL_ARGUMENT_ERROR];
- switch (error) {
- case U_ILLEGAL_ARGUMENT_ERROR :
- return new IllegalArgumentException(errorname);
- case U_INDEX_OUTOFBOUNDS_ERROR :
- return new ArrayIndexOutOfBoundsException(errorname);
- case U_BUFFER_OVERFLOW_ERROR :
- return new ArrayIndexOutOfBoundsException(errorname);
- case U_UNSUPPORTED_ERROR :
- return new UnsupportedOperationException(errorname);
- default :
- return new RuntimeException(errorname);
- }
- }
-
- // public static data member ---------------------------------------------
-
- /**
- * Start of information results (semantically successful)
- */
- public static final int U_ERROR_INFO_START = -128;
- /**
- * A resource bundle lookup returned a fallback result (not an error)
- */
- public static final int U_USING_FALLBACK_ERROR = -128;
- /**
- * A resource bundle lookup returned a result from the root locale (not an
- * error)
- */
- public static final int U_USING_DEFAULT_ERROR = -127;
- /**
- * A SafeClone operation required allocating memory (informational
- * only
- */
- public static final int U_SAFECLONE_ALLOCATED_ERROR = -126;
- /**
- * This must always be the last warning value to indicate the limit for
- * UErrorCode warnings (last warning code +1)
- */
- public static final int U_ERROR_INFO_LIMIT = -125;
-
- /**
- * No error, no warning
- */
- public static final int U_ZERO_ERROR = 0;
- /**
- * Start of codes indicating failure
- */
- public static final int U_ILLEGAL_ARGUMENT_ERROR = 1;
- public static final int U_MISSING_RESOURCE_ERROR = 2;
- public static final int U_INVALID_FORMAT_ERROR = 3;
- public static final int U_FILE_ACCESS_ERROR = 4;
- /**
- * Indicates a bug in the library code
- */
- public static final int U_INTERNAL_PROGRAM_ERROR = 5;
- public static final int U_MESSAGE_PARSE_ERROR = 6;
- /**
- * Memory allocation error
- */
- public static final int U_MEMORY_ALLOCATION_ERROR = 7;
- public static final int U_INDEX_OUTOFBOUNDS_ERROR = 8;
- /**
- * Equivalent to Java ParseException
- */
- public static final int U_PARSE_ERROR = 9;
- /**
- * In the Character conversion routines: Invalid character or sequence was
- * encountered
- */
- public static final int U_INVALID_CHAR_FOUND = 10;
- /**
- * In the Character conversion routines: More bytes are required to complete
- * the conversion successfully
- */
- public static final int U_TRUNCATED_CHAR_FOUND = 11;
- /**
- * In codeset conversion: a sequence that does NOT belong in the codepage has
- * been encountered
- */
- public static final int U_ILLEGAL_CHAR_FOUND = 12;
- /**
- * Conversion table file found, but corrupted
- */
- public static final int U_INVALID_TABLE_FORMAT = 13;
- /**
- * Conversion table file not found
- */
- public static final int U_INVALID_TABLE_FILE = 14;
- /**
- * A result would not fit in the supplied buffer
- */
- public static final int U_BUFFER_OVERFLOW_ERROR = 15;
- /**
- * Requested operation not supported in current context
- */
- public static final int U_UNSUPPORTED_ERROR = 16;
- /**
- * an operation is requested over a resource that does not support it
- */
- public static final int U_RESOURCE_TYPE_MISMATCH = 17;
- /**
- * ISO-2022 illlegal escape sequence
- */
- public static final int U_ILLEGAL_ESCAPE_SEQUENCE = 18;
- /**
- * ISO-2022 unsupported escape sequence
- */
- public static final int U_UNSUPPORTED_ESCAPE_SEQUENCE = 19;
- /**
- * No space available for in-buffer expansion for Arabic shaping
- */
- public static final int U_NO_SPACE_AVAILABLE = 20;
- /**
- * This must always be the last value to indicate the limit for UErrorCode
- * (last error code +1)
- */
- public static final int U_ERROR_LIMIT = 21;
- /**
- * Load library flag
- */
- public static boolean LIBRARY_LOADED = false;
-
- // private data member ----------------------------------------------------
-
- /**
- * Array of error code names corresponding to the errorcodes.
- * ie ERROR_NAMES_[0] = name of U_ZERO_ERROR
- */
- private static final String ERROR_NAMES_[] = {
- "U_ZERO_ERROR", "U_ILLEGAL_ARGUMENT_ERROR",
- "U_MISSING_RESOURCE_ERROR", "U_INVALID_FORMAT_ERROR",
- "U_FILE_ACCESS_ERROR", "U_INTERNAL_PROGRAM_ERROR",
- "U_MESSAGE_PARSE_ERROR", "U_MEMORY_ALLOCATION_ERROR",
- "U_INDEX_OUTOFBOUNDS_ERROR", "U_PARSE_ERROR",
- "U_INVALID_CHAR_FOUND", "U_TRUNCATED_CHAR_FOUND",
- "U_ILLEGAL_CHAR_FOUND", "U_INVALID_TABLE_FORMAT",
- "U_INVALID_TABLE_FILE", "U_BUFFER_OVERFLOW_ERROR",
- "U_UNSUPPORTED_ERROR", "U_RESOURCE_TYPE_MISMATCH",
- "U_ILLEGAL_ESCAPE_SEQUENCE", "U_UNSUPPORTED_ESCAPE_SEQUENCE"
- };
- /**
- * Returns the error name of the input error code
- * @param ec int value of the error code
- * @return String name of the error code
- * @stable ICU 2.4
- */
- public static String getErrorName(int ec){
- return ERROR_NAMES_[ec];
- }
-
- /**
- * Returns true if the input error code denotes success
- * @param ec int value of the error code
- * @return boolean
- * @stable ICU 2.4
- */
- public static boolean isSuccess(int ec){
- return (ec<=U_ZERO_ERROR);
- }
-
- /**
- * Returns true if the input error code denotes failure
- * @param ec int value of the error code
- * @return boolean
- * @stable ICU 2.4
- */
- public static boolean isFailure(int ec){
- return (ec>U_ZERO_ERROR);
- }
-}
-
diff --git a/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java b/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java
deleted file mode 100644
index 08fe26a..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java
+++ /dev/null
@@ -1,185 +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.lang;
-
-import java.lang.Character.UnicodeBlock;
-
-public final class UCharacter {
-
- public static native boolean isDefined(int codePoint);
- public static native boolean isDigit(int codePoint);
- public static native boolean isIdentifierIgnorable(int codePoint);
- public static native boolean isLetter(int codePoint);
- public static native boolean isLetterOrDigit(int codePoint);
- public static native boolean isLowerCase(int codePoint);
- public static native boolean isMirrored(int codePoint);
- public static native boolean isSpaceChar(int codePoint);
- public static native boolean isTitleCase(int codePoint);
- public static native boolean isUnicodeIdentifierPart(int codePoint);
- public static native boolean isUnicodeIdentifierStart(int codePoint);
- public static native boolean isUpperCase(int codePoint);
- public static native boolean isWhitespace(int codePoint);
- public static native byte getDirectionality(int codePoint);
- public static native int digit(int codePoint, int radix);
- public static native int forName(String blockName);
- public static native int getNumericValue(int codePoint);
- public static native int getType(int codePoint);
- public static native int of(int codePoint);
- public static native int toLowerCase(int codePoint);
- public static native int toTitleCase(int codePoint);
- public static native int toUpperCase(int codePoint);
- public static native String toLowerCase(String s, String localeName);
- public static native String toUpperCase(String s, String localeName);
-
- public static UnicodeBlock[] getBlockTable() {
- /**
- * The indices of the entries of this table correspond with the value
- * of the ICU enum UBlockCode. When updating ICU it's necessary
- * to check if there where any changes for the properties
- * used by java.lang.Character.
- * The enum is defined in common/unicode/uchar.h
- */
- UnicodeBlock[] result = new UnicodeBlock[] { null,
- UnicodeBlock.BASIC_LATIN,
- UnicodeBlock.LATIN_1_SUPPLEMENT,
- UnicodeBlock.LATIN_EXTENDED_A,
- UnicodeBlock.LATIN_EXTENDED_B,
- UnicodeBlock.IPA_EXTENSIONS,
- UnicodeBlock.SPACING_MODIFIER_LETTERS,
- UnicodeBlock.COMBINING_DIACRITICAL_MARKS,
- UnicodeBlock.GREEK,
- UnicodeBlock.CYRILLIC,
- UnicodeBlock.ARMENIAN,
- UnicodeBlock.HEBREW,
- UnicodeBlock.ARABIC,
- UnicodeBlock.SYRIAC,
- UnicodeBlock.THAANA,
- UnicodeBlock.DEVANAGARI,
- UnicodeBlock.BENGALI,
- UnicodeBlock.GURMUKHI,
- UnicodeBlock.GUJARATI,
- UnicodeBlock.ORIYA,
- UnicodeBlock.TAMIL,
- UnicodeBlock.TELUGU,
- UnicodeBlock.KANNADA,
- UnicodeBlock.MALAYALAM,
- UnicodeBlock.SINHALA,
- UnicodeBlock.THAI,
- UnicodeBlock.LAO,
- UnicodeBlock.TIBETAN,
- UnicodeBlock.MYANMAR,
- UnicodeBlock.GEORGIAN,
- UnicodeBlock.HANGUL_JAMO,
- UnicodeBlock.ETHIOPIC,
- UnicodeBlock.CHEROKEE,
- UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS,
- UnicodeBlock.OGHAM,
- UnicodeBlock.RUNIC,
- UnicodeBlock.KHMER,
- UnicodeBlock.MONGOLIAN,
- UnicodeBlock.LATIN_EXTENDED_ADDITIONAL,
- UnicodeBlock.GREEK_EXTENDED,
- UnicodeBlock.GENERAL_PUNCTUATION,
- UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS,
- UnicodeBlock.CURRENCY_SYMBOLS,
- UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS,
- UnicodeBlock.LETTERLIKE_SYMBOLS,
- UnicodeBlock.NUMBER_FORMS,
- UnicodeBlock.ARROWS,
- UnicodeBlock.MATHEMATICAL_OPERATORS,
- UnicodeBlock.MISCELLANEOUS_TECHNICAL,
- UnicodeBlock.CONTROL_PICTURES,
- UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION,
- UnicodeBlock.ENCLOSED_ALPHANUMERICS,
- UnicodeBlock.BOX_DRAWING,
- UnicodeBlock.BLOCK_ELEMENTS,
- UnicodeBlock.GEOMETRIC_SHAPES,
- UnicodeBlock.MISCELLANEOUS_SYMBOLS,
- UnicodeBlock.DINGBATS,
- UnicodeBlock.BRAILLE_PATTERNS,
- UnicodeBlock.CJK_RADICALS_SUPPLEMENT,
- UnicodeBlock.KANGXI_RADICALS,
- UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS,
- UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION,
- UnicodeBlock.HIRAGANA,
- UnicodeBlock.KATAKANA,
- UnicodeBlock.BOPOMOFO,
- UnicodeBlock.HANGUL_COMPATIBILITY_JAMO,
- UnicodeBlock.KANBUN,
- UnicodeBlock.BOPOMOFO_EXTENDED,
- UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS,
- UnicodeBlock.CJK_COMPATIBILITY,
- UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A,
- UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS,
- UnicodeBlock.YI_SYLLABLES,
- UnicodeBlock.YI_RADICALS,
- UnicodeBlock.HANGUL_SYLLABLES,
- UnicodeBlock.HIGH_SURROGATES,
- UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES,
- UnicodeBlock.LOW_SURROGATES,
- UnicodeBlock.PRIVATE_USE_AREA,
- UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS,
- UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS,
- UnicodeBlock.ARABIC_PRESENTATION_FORMS_A,
- UnicodeBlock.COMBINING_HALF_MARKS,
- UnicodeBlock.CJK_COMPATIBILITY_FORMS,
- UnicodeBlock.SMALL_FORM_VARIANTS,
- UnicodeBlock.ARABIC_PRESENTATION_FORMS_B,
- UnicodeBlock.SPECIALS,
- UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS,
- UnicodeBlock.OLD_ITALIC,
- UnicodeBlock.GOTHIC,
- UnicodeBlock.DESERET,
- UnicodeBlock.BYZANTINE_MUSICAL_SYMBOLS,
- UnicodeBlock.MUSICAL_SYMBOLS,
- UnicodeBlock.MATHEMATICAL_ALPHANUMERIC_SYMBOLS,
- UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B,
- UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT,
- UnicodeBlock.TAGS,
- UnicodeBlock.CYRILLIC_SUPPLEMENTARY,
- UnicodeBlock.TAGALOG,
- UnicodeBlock.HANUNOO,
- UnicodeBlock.BUHID,
- UnicodeBlock.TAGBANWA,
- UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A,
- UnicodeBlock.SUPPLEMENTAL_ARROWS_A,
- UnicodeBlock.SUPPLEMENTAL_ARROWS_B,
- UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B,
- UnicodeBlock.SUPPLEMENTAL_MATHEMATICAL_OPERATORS,
- UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS,
- UnicodeBlock.VARIATION_SELECTORS,
- UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_A,
- UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_B,
- UnicodeBlock.LIMBU,
- UnicodeBlock.TAI_LE,
- UnicodeBlock.KHMER_SYMBOLS,
- UnicodeBlock.PHONETIC_EXTENSIONS,
- UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS,
- UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS,
- UnicodeBlock.LINEAR_B_SYLLABARY,
- UnicodeBlock.LINEAR_B_IDEOGRAMS,
- UnicodeBlock.AEGEAN_NUMBERS,
- UnicodeBlock.UGARITIC,
- UnicodeBlock.SHAVIAN,
- UnicodeBlock.OSMANYA,
- UnicodeBlock.CYPRIOT_SYLLABARY,
- UnicodeBlock.TAI_XUAN_JING_SYMBOLS,
- UnicodeBlock.VARIATION_SELECTORS_SUPPLEMENT
- };
- return result;
- }
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/regex/NativeRegEx.java b/icu/src/main/java/com/ibm/icu4jni/regex/NativeRegEx.java
deleted file mode 100644
index a8ce8a6..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/regex/NativeRegEx.java
+++ /dev/null
@@ -1,132 +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.regex;
-
-public final class NativeRegEx {
- private NativeRegEx() {
- }
-
- /**
- * Opens (compiles) an ICU regular expression.
- */
- public static native int open(String pattern, int flags);
-
- /**
- * Makes a copy of a compiled regular expression.
- */
- public static native int clone(int regex);
-
- /**
- * Closes the regular expression, recovering all resources (memory) it was
- * holding.
- */
- public static native void close(int regex);
-
- /**
- * Sets the subject text string upon which the regular expression will look
- * for matches.
- */
- public static native void setText(int regex, String text);
-
- /**
- * Attempts to match the input string, beginning at startIndex, against the
- * pattern.
- */
- public static native boolean matches(int regex, int startIndex);
-
- /**
- * Attempts to match the input string, starting from the specified index,
- * against the pattern.
- */
- public static native boolean lookingAt(int regex, int startIndex);
-
- /**
- * Finds the first matching substring of the input string that matches the
- * pattern.
- */
- public static native boolean find(int regex, int startIndex);
-
- /**
- * Finds the first matching substring of the input string that matches the
- * pattern.
- */
- public static native boolean findNext(int regex);
-
- /**
- * Gets the number of capturing groups in this regular expression's pattern.
- */
- public static native int groupCount(int regex);
-
- /**
- * Gets all the group information for the current match of the pattern.
- */
- public static native void startEnd(int regex, int[] startEnd);
-
- /**
- * Sets the region of the input to be considered during matching.
- */
- public static native void setRegion(int regex, int start, int end);
-
- /**
- * Queries the start of the region of the input to be considered during
- * matching.
- */
- public static native int regionStart(int regex);
-
- /**
- * Queries the end of the region of the input to be considered during
- * matching.
- */
- public static native int regionEnd(int regex);
-
- /**
- * Controls the transparency of the region bounds.
- */
- public static native void useTransparentBounds(int regex, boolean value);
-
- /**
- * Queries the transparency of the region bounds.
- */
- public static native boolean hasTransparentBounds(int regex);
-
- /**
- * Controls the anchoring property of the region bounds.
- */
- public static native void useAnchoringBounds(int regex, boolean value);
-
- /**
- * Queries the anchoring property of the region bounds.
- */
- public static native boolean hasAnchoringBounds(int regex);
-
- /**
- * Queries whether we hit the end of the input during the last match.
- */
- public static native boolean hitEnd(int regex);
-
- /**
- * Queries whether more input might change a current match, but wouldn't
- * destroy it.
- */
- public static native boolean requireEnd(int regex);
-
- /**
- * Resets the matcher, cause a current match to be lost, and sets the
- * position at which a subsequent findNext() would start.
- */
- public static native void reset(int regex, int position);
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/CollationAttribute.java b/icu/src/main/java/com/ibm/icu4jni/text/CollationAttribute.java
deleted file mode 100644
index eaf626f..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/CollationAttribute.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-/**
- * TODO: move these constants into NativeCollation.
- */
-public final class CollationAttribute {
- // Values from the native UColAttributeValue enum.
- public static final int VALUE_DEFAULT = -1;
- public static final int VALUE_PRIMARY = 0;
- public static final int VALUE_SECONDARY = 1;
- public static final int VALUE_TERTIARY = 2;
- public static final int VALUE_DEFAULT_STRENGTH = VALUE_TERTIARY;
- public static final int VALUE_QUATERNARY = 3;
- public static final int VALUE_IDENTICAL = 15;
- public static final int VALUE_OFF = 16;
- public static final int VALUE_ON = 17;
- public static final int VALUE_SHIFTED = 20;
- public static final int VALUE_NON_IGNORABLE = 21;
- public static final int VALUE_LOWER_FIRST = 24;
- public static final int VALUE_UPPER_FIRST = 25;
- public static final int VALUE_ON_WITHOUT_HANGUL = 28;
- public static final int VALUE_ATTRIBUTE_VALUE_COUNT = 29;
- // Values from the UColAttribute enum.
- public static final int FRENCH_COLLATION = 0;
- public static final int ALTERNATE_HANDLING = 1;
- public static final int CASE_FIRST = 2;
- public static final int CASE_LEVEL = 3;
- public static final int NORMALIZATION_MODE = 4;
- public static final int DECOMPOSITION_MODE = NORMALIZATION_MODE;
- public static final int STRENGTH = 5;
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java b/icu/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java
deleted file mode 100644
index 0f5bae4..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-import java.text.CharacterIterator;
-
-
-/**
-* Collation element iterator JNI wrapper.
-* Iterates over the collation elements of a data string.
-* The iterator supports both forward and backwards full iteration, ie if
-* backwards iteration is performed in the midst of a forward iteration, the
-* result is undefined.
-* To perform a backwards iteration in the midst of a forward iteration,
-* reset() has to be called.
-* This will shift the position to either the start or the last character in the
-* data string depending on whether next() is called or previous().
-* <pre>
-* RuleBasedCollator coll = Collator.getInstance();
-* CollationElementIterator iterator = coll.getCollationElementIterator("abc");
-* int ce = 0;
-* while (ce != CollationElementIterator.NULLORDER) {
-* ce = iterator.next();
-* }
-* iterator.reset();
-* while (ce != CollationElementIterator.NULLORDER) {
-* ce = iterator.previous();
-* }
-* </pre>
-* @author syn wee quek
-* @stable ICU 2.4
-*/
-
-public final class CollationElementIterator
-{
- // public data member -------------------------------------------
-
- /**
- * @stable ICU 2.4
- */
- public static final int NULLORDER = 0xFFFFFFFF;
-
- // public methods -----------------------------------------------
-
- /**
- * Reset the collation elements to their initial state.
- * This will move the 'cursor' to the beginning of the text.
- * @stable ICU 2.4
- */
- public void reset()
- {
- NativeCollation.reset(m_collelemiterator_);
- }
-
- /**
- * Get the ordering priority of the next collation element in the text.
- * A single character may contain more than one collation element.
- * @return next collation elements ordering, or NULLORDER if the end of the
- * text is reached.
- * @stable ICU 2.4
- */
- public int next()
- {
- return NativeCollation.next(m_collelemiterator_);
- }
-
- /**
- * Get the ordering priority of the previous collation element in the text.
- * A single character may contain more than one collation element.
- * @return previous collation element ordering, or NULLORDER if the end of
- * the text is reached.
- * @stable ICU 2.4
- */
- public int previous()
- {
- return NativeCollation.previous(m_collelemiterator_);
- }
-
- /**
- * Get the maximum length of any expansion sequences that end with the
- * specified comparison order.
- * @param order collation order returned by previous or next.
- * @return maximum size of the expansion sequences ending with the collation
- * element or 1 if collation element does not occur at the end of
- * any expansion sequence
- * @stable ICU 2.4
- */
- public int getMaxExpansion(int order)
- {
- return NativeCollation.getMaxExpansion(m_collelemiterator_, order);
- }
-
- /**
- * Set the text containing the collation elements.
- * @param source text containing the collation elements.
- * @stable ICU 2.4
- */
- public void setText(String source)
- {
- NativeCollation.setText(m_collelemiterator_, source);
- }
-
- // BEGIN android-added
- public void setText(CharacterIterator source)
- {
- NativeCollation.setText(m_collelemiterator_, source.toString());
- }
- // END android-added
-
- /**
- * Get the offset of the current source character.
- * This is an offset into the text of the character containing the current
- * collation elements.
- * @return offset of the current source character.
- * @stable ICU 2.4
- */
- public int getOffset()
- {
- return NativeCollation.getOffset(m_collelemiterator_);
- }
-
- /**
- * Set the offset of the current source character.
- * This is an offset into the text of the character to be processed.
- * @param offset The desired character offset.
- * @stable ICU 2.4
- */
- public void setOffset(int offset)
- {
- NativeCollation.setOffset(m_collelemiterator_, offset);
- }
-
- /**
- * Gets the primary order of a collation order.
- * @param order the collation order
- * @return the primary order of a collation order.
- * @stable ICU 2.4
- */
- public static int primaryOrder(int order)
- {
- return ((order & PRIMARY_ORDER_MASK_) >> PRIMARY_ORDER_SHIFT_) &
- UNSIGNED_16_BIT_MASK_;
- }
-
- /**
- * Gets the secondary order of a collation order.
- * @param order the collation order
- * @return the secondary order of a collation order.
- * @stable ICU 2.4
- */
- public static int secondaryOrder(int order)
- {
- return (order & SECONDARY_ORDER_MASK_) >> SECONDARY_ORDER_SHIFT_;
- }
-
- /**
- * Gets the tertiary order of a collation order.
- * @param order the collation order
- * @return the tertiary order of a collation order.
- * @stable ICU 2.4
- */
- public static int tertiaryOrder(int order)
- {
- return order & TERTIARY_ORDER_MASK_;
- }
-
- // protected constructor ----------------------------------------
-
- /**
- * CollationElementIteratorJNI constructor.
- * The only caller of this class should be
- * RuleBasedCollator.getCollationElementIterator().
- * @param collelemiteratoraddress address of C collationelementiterator
- */
- CollationElementIterator(int collelemiteratoraddress)
- {
- m_collelemiterator_ = collelemiteratoraddress;
- }
-
- // protected methods --------------------------------------------
-
- /**
- * Garbage collection.
- * Close C collator and reclaim memory.
- * @stable ICU 2.4
- */
- protected void finalize()
- {
- NativeCollation.closeElements(m_collelemiterator_);
- }
-
- // private data members -----------------------------------------
-
- /**
- * C collator
- */
- private int m_collelemiterator_;
-
- /**
- * ICU constant primary order mask for collation elements
- */
- private static final int PRIMARY_ORDER_MASK_ = 0xffff0000;
- /**
- * ICU constant secondary order mask for collation elements
- */
- private static final int SECONDARY_ORDER_MASK_ = 0x0000ff00;
- /**
- * ICU constant tertiary order mask for collation elements
- */
- private static final int TERTIARY_ORDER_MASK_ = 0x000000ff;
- /**
- * ICU constant primary order shift for collation elements
- */
- private static final int PRIMARY_ORDER_SHIFT_ = 16;
- /**
- * ICU constant secondary order shift for collation elements
- */
- private static final int SECONDARY_ORDER_SHIFT_ = 8;
- /**
- * Unsigned 16 bit mask
- */
- private static final int UNSIGNED_16_BIT_MASK_ = 0x0000FFFF;
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/CollationKey.java b/icu/src/main/java/com/ibm/icu4jni/text/CollationKey.java
deleted file mode 100644
index dbd714c..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/CollationKey.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-/**
- * A concrete implementation of the abstract java.text.CollationKey.
- */
-public final class CollationKey extends java.text.CollationKey {
- /**
- * The key.
- */
- private final byte[] bytes;
-
- /**
- * Cached hash value.
- */
- private int hashCode;
-
- CollationKey(String source, byte[] bytes) {
- super(source);
- this.bytes = bytes;
- }
-
- public int compareTo(java.text.CollationKey other) {
- // Get the bytes from the other collation key.
- final byte[] rhsBytes;
- if (other instanceof CollationKey) {
- rhsBytes = ((CollationKey) other).bytes;
- } else {
- rhsBytes = other.toByteArray();
- }
-
- if (bytes == null || bytes.length == 0) {
- if (rhsBytes == null || rhsBytes.length == 0) {
- return 0;
- }
- return -1;
- } else {
- if (rhsBytes == null || rhsBytes.length == 0) {
- return 1;
- }
- }
-
- int count = Math.min(bytes.length, rhsBytes.length);
- for (int i = 0; i < count; ++i) {
- int s = bytes[i] & 0xff;
- int t = rhsBytes[i] & 0xff;
- if (s < t) {
- return -1;
- }
- if (s > t) {
- return 1;
- }
- }
- if (bytes.length < rhsBytes.length) {
- return -1;
- }
- if (bytes.length > rhsBytes.length) {
- return 1;
- }
- return 0;
- }
-
- /**
- * Checks if target object is equal to this object.
- * Target is first casted to CollationKey and bitwise compared.
- * @param target comparison object
- * @return true if both objects are equal, false otherwise
- * @stable ICU 2.4
- */
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof CollationKey)) {
- return false;
- }
- return compareTo((CollationKey) object) == 0;
- }
-
- /**
- * Creates a hash code for this CollationKey.
- * Compute the hash by iterating sparsely over about 32 (up to 63) bytes
- * spaced evenly through the string. For each byte, multiply the previous
- * hash value by a prime number and add the new byte in, like a linear
- * congruential random number generator, producing a pseudo-random
- * deterministic value well distributed over the output range.
- * @return hash value of collation key. Hash value is never 0.
- * @stable ICU 2.4
- */
- public int hashCode() {
- if (hashCode == 0) {
- if (bytes != null && bytes.length != 0) {
- int len = bytes.length;
- int inc = ((len - 32) / 32) + 1;
- for (int i = 0; i < len;) {
- hashCode = (hashCode * 37) + bytes[i];
- i += inc;
- }
- }
- if (hashCode == 0) {
- hashCode = 1;
- }
- }
- return hashCode;
- }
-
- public byte[] toByteArray() {
- if (bytes == null || bytes.length == 0) {
- return null;
- }
- return bytes.clone();
- }
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
deleted file mode 100644
index 9eb85ea..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-import com.ibm.icu4jni.text.RuleBasedCollator;
-import java.util.Locale;
-
-public abstract class Collator implements Cloneable {
- /**
- * Strongest collator strength value. Typically used to denote differences
- * between base characters. See class documentation for more explanation.
- * @see #setStrength
- * @see #getStrength
- * @stable ICU 2.4
- */
- public final static int PRIMARY = CollationAttribute.VALUE_PRIMARY;
-
- /**
- * Second level collator strength value.
- * Accents in the characters are considered secondary differences.
- * Other differences between letters can also be considered secondary
- * differences, depending on the language.
- * See class documentation for more explanation.
- * @see #setStrength
- * @see #getStrength
- * @stable ICU 2.4
- */
- public final static int SECONDARY = CollationAttribute.VALUE_SECONDARY;
-
- /**
- * Third level collator strength value.
- * Upper and lower case differences in characters are distinguished at this
- * strength level. In addition, a variant of a letter differs from the base
- * form on the tertiary level.
- * See class documentation for more explanation.
- * @see #setStrength
- * @see #getStrength
- * @stable ICU 2.4
- */
- public final static int TERTIARY = CollationAttribute.VALUE_TERTIARY;
-
- /**
- * Fourth level collator strength value.
- * When punctuation is ignored
- * <a href="http://www-124.ibm.com/icu/userguide/Collate_Concepts.html#Ignoring_Punctuation">
- * (see Ignoring Punctuations in the user guide)</a> at PRIMARY to TERTIARY
- * strength, an additional strength level can
- * be used to distinguish words with and without punctuation.
- * See class documentation for more explanation.
- * @see #setStrength
- * @see #getStrength
- * @stable ICU 2.4
- */
- public final static int QUATERNARY = CollationAttribute.VALUE_QUATERNARY;
-
- /**
- * <p>
- * Smallest Collator strength value. When all other strengths are equal,
- * the IDENTICAL strength is used as a tiebreaker. The Unicode code point
- * values of the NFD form of each string are compared, just in case there
- * is no difference.
- * See class documentation for more explanation.
- * </p>
- * <p>
- * Note this value is different from JDK's
- * </p>
- * @stable ICU 2.4
- */
- public final static int IDENTICAL = CollationAttribute.VALUE_IDENTICAL;
-
- /**
- * <p>Decomposition mode value. With NO_DECOMPOSITION set, Strings
- * will not be decomposed for collation. This is the default
- * decomposition setting unless otherwise specified by the locale
- * used to create the Collator.</p>
- *
- * <p><strong>Note</strong> this value is different from the JDK's.</p>
- * @see #CANONICAL_DECOMPOSITION
- * @see #getDecomposition
- * @see #setDecomposition
- * @stable ICU 2.4
- */
- public final static int NO_DECOMPOSITION = CollationAttribute.VALUE_OFF;
-
- /**
- * <p>Decomposition mode value. With CANONICAL_DECOMPOSITION set,
- * characters that are canonical variants according to the Unicode standard
- * will be decomposed for collation.</p>
- *
- * <p>CANONICAL_DECOMPOSITION corresponds to Normalization Form D as
- * described in <a href="http://www.unicode.org/unicode/reports/tr15/">
- * Unicode Technical Report #15</a>.
- * </p>
- * @see #NO_DECOMPOSITION
- * @see #getDecomposition
- * @see #setDecomposition
- * @stable ICU 2.4
- */
- public final static int CANONICAL_DECOMPOSITION = CollationAttribute.VALUE_ON;
-
- public static Collator getInstance(Locale locale) {
- return new RuleBasedCollator(locale);
- }
-
- public boolean equals(String source, String target) {
- return (compare(source, target) == 0);
- }
-
- public abstract boolean equals(Object target);
-
- public abstract Object clone() throws CloneNotSupportedException;
-
- /**
- * The comparison function compares the character data stored in two
- * different strings. Returns information about whether a string is less
- * than, greater than or equal to another string.
- * <p>Example of use:
- * <pre>
- * . Collator myCollation = Collator.getInstance(Locale::US);
- * . myCollation.setStrength(CollationAttribute.VALUE_PRIMARY);
- * . // result would be CollationAttribute.VALUE_EQUAL
- * . // ("abc" == "ABC")
- * . // (no primary difference between "abc" and "ABC")
- * . int result = myCollation.compare("abc", "ABC",3);
- * . myCollation.setStrength(CollationAttribute.VALUE_TERTIARY);
- * . // result would be Collation.LESS (abc" &lt;&lt;&lt; "ABC")
- * . // (with tertiary difference between "abc" and "ABC")
- * . int result = myCollation.compare("abc", "ABC",3);
- * </pre>
- * @stable ICU 2.4
- */
- public abstract int compare(String source, String target);
-
- /**
- * Get the decomposition mode of this Collator.
- * @return the decomposition mode
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public abstract int getDecomposition();
-
- /**
- * Set the normalization mode used int this object
- * The normalization mode influences how strings are compared.
- * @param mode desired normalization mode
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public abstract void setDecomposition(int mode);
-
- /**
- * Determines the minimum strength that will be use in comparison or
- * transformation.
- * <p>
- * E.g. with strength == SECONDARY, the tertiary difference is ignored
- * </p>
- * <p>
- * E.g. with strength == PRIMARY, the secondary and tertiary difference
- * are ignored.
- * </p>
- * @return the current comparison level.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public abstract int getStrength();
-
- /**
- * Gets the attribute to be used in comparison or transformation.
- * @param type the attribute to be set from CollationAttribute
- * @return value attribute value from CollationAttribute
- * @stable ICU 2.4
- */
- public abstract int getAttribute(int type);
-
- /**
- * Sets the minimum strength to be used in comparison or transformation.
- * <p>Example of use:
- * <pre>
- * . Collator myCollation = Collator.createInstance(Locale::US);
- * . myCollation.setStrength(PRIMARY);
- * . // result will be "abc" == "ABC"
- * . // tertiary differences will be ignored
- * . int result = myCollation->compare("abc", "ABC");
- * </pre>
- * @param strength the new comparison level.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public abstract void setStrength(int strength);
-
- /**
- * Sets the attribute to be used in comparison or transformation.
- * <p>Example of use:
- * <pre>
- * . Collator myCollation = Collator.createInstance(Locale::US);
- * . myCollation.setAttribute(CollationAttribute.CASE_LEVEL,
- * . CollationAttribute.VALUE_ON);
- * . int result = myCollation->compare("\\u30C3\\u30CF",
- * . "\\u30C4\\u30CF");
- * . // result will be -1.
- * </pre>
- * @param type the attribute to be set from CollationAttribute
- * @param value attribute value from CollationAttribute
- * @stable ICU 2.4
- */
- public abstract void setAttribute(int type, int value);
-
- /**
- * Get the sort key as an CollationKey object from the argument string.
- * To retrieve sort key in terms of byte arrays, use the method as below<br>
- * <code>
- * Collator collator = Collator.getInstance();
- * CollationKey collationKey = collator.getCollationKey("string");
- * byte[] array = collationKey.toByteArray();
- * </code><br>
- * Byte array result are zero-terminated and can be compared using
- * java.util.Arrays.equals();
- * @param source string to be processed.
- * @return the sort key
- * @stable ICU 2.4
- */
- public abstract CollationKey getCollationKey(String source);
-
- /**
- * Returns a hash of this collation object
- * @return hash of this collation object
- * @stable ICU 2.4
- */
- public abstract int hashCode();
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
deleted file mode 100644
index 272d525..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
+++ /dev/null
@@ -1,158 +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.CharacterIterator;
-import java.text.StringCharacterIterator;
-import java.util.Locale;
-
-public final class NativeBreakIterator implements Cloneable {
- // Acceptable values for the 'type' field.
- private static final int BI_CHAR_INSTANCE = 1;
- private static final int BI_WORD_INSTANCE = 2;
- private static final int BI_LINE_INSTANCE = 3;
- private static final int BI_SENT_INSTANCE = 4;
-
- private final int addr;
- private final int type;
- private CharacterIterator charIter;
-
- private NativeBreakIterator(int iterAddr, int type) {
- this.addr = iterAddr;
- this.type = type;
- this.charIter = new StringCharacterIterator("");
- }
-
- @Override
- public Object clone() {
- int cloneAddr = cloneImpl(this.addr);
- NativeBreakIterator clone = new NativeBreakIterator(cloneAddr, this.type);
- // The RI doesn't clone the CharacterIterator.
- clone.charIter = this.charIter;
- return clone;
- }
-
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof NativeBreakIterator)) {
- return false;
- }
- // TODO: is this sufficient? shouldn't we be checking the underlying rules?
- NativeBreakIterator rhs = (NativeBreakIterator) object;
- return type == rhs.type && charIter.equals(rhs.charIter);
- }
-
- @Override
- public int hashCode() {
- return 42; // No-one uses BreakIterator as a hash key.
- }
-
- @Override
- protected void finalize() {
- closeBreakIteratorImpl(this.addr);
- }
-
- public int current() {
- return currentImpl(this.addr);
- }
-
- public int first() {
- return firstImpl(this.addr);
- }
-
- public int following(int offset) {
- return followingImpl(this.addr, offset);
- }
-
- public CharacterIterator getText() {
- int newLoc = currentImpl(this.addr);
- this.charIter.setIndex(newLoc);
- return this.charIter;
- }
-
- public int last() {
- return lastImpl(this.addr);
- }
-
- public int next(int n) {
- return nextImpl(this.addr, n);
- }
-
- public int next() {
- return nextImpl(this.addr, 1);
- }
-
- public int previous() {
- return previousImpl(this.addr);
- }
-
- public void setText(CharacterIterator newText) {
- this.charIter = newText;
- StringBuilder sb = new StringBuilder();
- for (char c = newText.first(); c != CharacterIterator.DONE; c = newText.next()) {
- sb.append(c);
- }
- setTextImpl(this.addr, sb.toString());
- }
-
- public void setText(String newText) {
- setText(new StringCharacterIterator(newText));
- }
-
- public boolean isBoundary(int offset) {
- return isBoundaryImpl(this.addr, offset);
- }
-
- public int preceding(int offset) {
- return precedingImpl(this.addr, offset);
- }
-
- public static NativeBreakIterator getCharacterInstance(Locale where) {
- return new NativeBreakIterator(getCharacterInstanceImpl(where.toString()), BI_CHAR_INSTANCE);
- }
-
- public static NativeBreakIterator getLineInstance(Locale where) {
- return new NativeBreakIterator(getLineInstanceImpl(where.toString()), BI_LINE_INSTANCE);
- }
-
- public static NativeBreakIterator getSentenceInstance(Locale where) {
- return new NativeBreakIterator(getSentenceInstanceImpl(where.toString()), BI_SENT_INSTANCE);
- }
-
- public static NativeBreakIterator getWordInstance(Locale where) {
- return new NativeBreakIterator(getWordInstanceImpl(where.toString()), BI_WORD_INSTANCE);
- }
-
- private static native int getCharacterInstanceImpl(String locale);
- private static native int getWordInstanceImpl(String locale);
- private static native int getLineInstanceImpl(String locale);
- private static native int getSentenceInstanceImpl(String locale);
- private static native void closeBreakIteratorImpl(int addr);
- private static native void setTextImpl(int addr, String text);
- private static native int cloneImpl(int addr);
- private static native int precedingImpl(int addr, int offset);
- private static native boolean isBoundaryImpl(int addr, int offset);
- private static native int nextImpl(int addr, int n);
- private static native int previousImpl(int addr);
- private static native int currentImpl(int addr);
- private static native int firstImpl(int addr);
- private static native int followingImpl(int addr, int offset);
- private static native int lastImpl(int addr);
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
deleted file mode 100644
index d481790..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-/**
-* Package static class for declaring all native methods for collation use.
-* @author syn wee quek
-* @internal ICU 2.4
-*/
-
-final class NativeCollation
-{
- // collator methods ---------------------------------------------
-
- public NativeCollation() {
-
- }
-
- /**
- * Method to create a new C Collator using the argument locale rules.
- * @param locale locale name
- * @return new c collator
- * @internal ICU 2.4
- */
- static native int openCollator(String locale);
-
- /**
- * Method to create a new C Collator using the argument rules.
- * @param rules , set of collation rules
- * @param normalizationmode default normalization mode
- * @param collationstrength default collation strength
- * @return new c collator
- * @internal ICU 2.4
- */
- static native int openCollatorFromRules(String rules,
- int normalizationmode,
- int collationstrength);
-
- /**
- * Close a C collator
- * Once closed, a UCollatorOld should not be used.
- * @param collatoraddress The UCollatorOld to close
- * @internal ICU 2.4
- */
- static native void closeCollator(int collatoraddress);
-
- /**
- * Compare two strings.
- * The strings will be compared using the normalization mode and options
- * specified in openCollator or openCollatorFromRules
- * @param collatoraddress address of the c collator
- * @param source The source string.
- * @param target The target string.
- * @return result of the comparison, Collation.EQUAL,
- * Collation.GREATER or Collation.LESS
- * @internal ICU 2.4
- */
- static native int compare(int collatoraddress, String source,
- String target);
-
- /**
- * Get the normalization mode for this object.
- * The normalization mode influences how strings are compared.
- * @param collatoraddress
- * @return normalization mode; one of the values from Normalization
- * @internal ICU 2.4
- */
- static native int getNormalization(int collatoraddress);
-
- /**
- * Set the normalization mode used int this object
- * The normalization mode influences how strings are compared.
- * @param collatoraddress the address of the C collator
- * @param normalizationmode desired normalization mode; one of the values
- * from Normalization
- * @internal ICU 2.4
- */
- static native void setNormalization(int collatoraddress,
- int normalizationmode);
-
- /**
- * Get the collation rules from a UCollator.
- * The rules will follow the rule syntax.
- * @param collatoraddress the address of the C collator
- * @return collation rules.
- * @internal ICU 2.4
- */
- static native String getRules(int collatoraddress);
-
- /**
- * Get a sort key for the argument string
- * Sort keys may be compared using java.util.Arrays.equals
- * @param collatoraddress address of the C collator
- * @param source string for key to be generated
- * @return sort key
- * @internal ICU 2.4
- */
- static native byte[] getSortKey(int collatoraddress, String source);
-
- /**
- * Gets the version information for collation.
- * @param collatoraddress address of the C collator
- * @return version information
- * @internal ICU 2.4
- */
- // private native String getVersion(int collatoraddress);
-
- /**
- * Universal attribute setter.
- * @param collatoraddress address of the C collator
- * @param type type of attribute to be set
- * @param value attribute value
- * @exception RuntimeException when error occurs while setting attribute value
- * @internal ICU 2.4
- */
- static native void setAttribute(int collatoraddress, int type, int value);
-
- /**
- * Universal attribute getter
- * @param collatoraddress address of the C collator
- * @param type type of attribute to be set
- * @return attribute value
- * @exception RuntimeException thrown when error occurs while getting attribute value
- * @internal ICU 2.4
- */
- static native int getAttribute(int collatoraddress, int type);
-
- /**
- * Thread safe cloning operation
- * @param collatoraddress address of C collator to be cloned
- * @return address of the new clone
- * @exception RuntimeException thrown when error occurs while cloning
- * @internal ICU 2.4
- */
- static native int safeClone(int collatoraddress);
-
- /**
- * Create a CollationElementIterator object that will iterator over the
- * elements in a string, using the collation rules defined in this
- * RuleBasedCollator
- * @param collatoraddress address of C collator
- * @param source string to iterate over
- * @return address of C collationelementiterator
- * @internal ICU 2.4
- */
- static native int getCollationElementIterator(int collatoraddress,
- String source);
-
-
- // collationelementiterator methods -------------------------------------
-
- /**
- * Close a C collation element iterator.
- * @param address of C collation element iterator to close.
- * @internal ICU 2.4
- */
- static native void closeElements(int address);
-
- /**
- * Reset the collation elements to their initial state.
- * This will move the 'cursor' to the beginning of the text.
- * @param address of C collation element iterator to reset.
- * @internal ICU 2.4
- */
- static native void reset(int address);
-
- /**
- * Get the ordering priority of the next collation element in the text.
- * A single character may contain more than one collation element.
- * @param address if C collation elements containing the text.
- * @return next collation elements ordering, or NULLORDER if the end of the
- * text is reached.
- * @internal ICU 2.4
- */
- static native int next(int address);
-
- /**
- * Get the ordering priority of the previous collation element in the text.
- * A single character may contain more than one collation element.
- * @param address of the C collation element iterator containing the text.
- * @return previous collation element ordering, or NULLORDER if the end of
- * the text is reached.
- * @internal ICU 2.4
- */
- static native int previous(int address);
-
- /**
- * Get the maximum length of any expansion sequences that end with the
- * specified comparison order.
- * @param address of the C collation element iterator containing the text.
- * @param order collation order returned by previous or next.
- * @return maximum length of any expansion sequences ending with the
- * specified order.
- * @internal ICU 2.4
- */
- static native int getMaxExpansion(int address, int order);
-
- /**
- * Set the text containing the collation elements.
- * @param address of the C collation element iterator to be set
- * @param source text containing the collation elements.
- * @internal ICU 2.4
- */
- static native void setText(int address, String source);
-
- /**
- * Get the offset of the current source character.
- * This is an offset into the text of the character containing the current
- * collation elements.
- * @param address of the C collation elements iterator to query.
- * @return offset of the current source character.
- * @internal ICU 2.4
- */
- static native int getOffset(int address);
-
- /**
- * Set the offset of the current source character.
- * This is an offset into the text of the character to be processed.
- * @param address of the C collation element iterator to set.
- * @param offset The desired character offset.
- * @internal ICU 2.4
- */
- static native void setOffset(int address, int offset);
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
deleted file mode 100644
index 6f751d5..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
+++ /dev/null
@@ -1,611 +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 com.ibm.icu4jni.util.LocaleData;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.math.RoundingMode;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.text.DecimalFormatSymbols;
-import java.text.FieldPosition;
-import java.text.Format;
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.Currency;
-import java.util.Locale;
-
-public final class NativeDecimalFormat {
- /**
- * Constants corresponding to the native type UNumberFormatSymbol, for setSymbol.
- */
- private static final int UNUM_DECIMAL_SEPARATOR_SYMBOL = 0;
- private static final int UNUM_GROUPING_SEPARATOR_SYMBOL = 1;
- private static final int UNUM_PATTERN_SEPARATOR_SYMBOL = 2;
- private static final int UNUM_PERCENT_SYMBOL = 3;
- private static final int UNUM_ZERO_DIGIT_SYMBOL = 4;
- private static final int UNUM_DIGIT_SYMBOL = 5;
- private static final int UNUM_MINUS_SIGN_SYMBOL = 6;
- private static final int UNUM_PLUS_SIGN_SYMBOL = 7;
- private static final int UNUM_CURRENCY_SYMBOL = 8;
- private static final int UNUM_INTL_CURRENCY_SYMBOL = 9;
- private static final int UNUM_MONETARY_SEPARATOR_SYMBOL = 10;
- private static final int UNUM_EXPONENTIAL_SYMBOL = 11;
- private static final int UNUM_PERMILL_SYMBOL = 12;
- private static final int UNUM_PAD_ESCAPE_SYMBOL = 13;
- private static final int UNUM_INFINITY_SYMBOL = 14;
- private static final int UNUM_NAN_SYMBOL = 15;
- private static final int UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16;
- private static final int UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17;
- private static final int UNUM_FORMAT_SYMBOL_COUNT = 18;
-
- /**
- * Constants corresponding to the native type UNumberFormatAttribute, for
- * getAttribute/setAttribute.
- */
- private static final int UNUM_PARSE_INT_ONLY = 0;
- private static final int UNUM_GROUPING_USED = 1;
- private static final int UNUM_DECIMAL_ALWAYS_SHOWN = 2;
- private static final int UNUM_MAX_INTEGER_DIGITS = 3;
- private static final int UNUM_MIN_INTEGER_DIGITS = 4;
- private static final int UNUM_INTEGER_DIGITS = 5;
- private static final int UNUM_MAX_FRACTION_DIGITS = 6;
- private static final int UNUM_MIN_FRACTION_DIGITS = 7;
- private static final int UNUM_FRACTION_DIGITS = 8;
- private static final int UNUM_MULTIPLIER = 9;
- private static final int UNUM_GROUPING_SIZE = 10;
- private static final int UNUM_ROUNDING_MODE = 11;
- private static final int UNUM_ROUNDING_INCREMENT = 12;
- private static final int UNUM_FORMAT_WIDTH = 13;
- private static final int UNUM_PADDING_POSITION = 14;
- private static final int UNUM_SECONDARY_GROUPING_SIZE = 15;
- private static final int UNUM_SIGNIFICANT_DIGITS_USED = 16;
- private static final int UNUM_MIN_SIGNIFICANT_DIGITS = 17;
- private static final int UNUM_MAX_SIGNIFICANT_DIGITS = 18;
- private static final int UNUM_LENIENT_PARSE = 19;
-
- /**
- * Constants corresponding to the native type UNumberFormatTextAttribute, for
- * getTextAttribute/setTextAttribute.
- */
- private static final int UNUM_POSITIVE_PREFIX = 0;
- private static final int UNUM_POSITIVE_SUFFIX = 1;
- private static final int UNUM_NEGATIVE_PREFIX = 2;
- private static final int UNUM_NEGATIVE_SUFFIX = 3;
- private static final int UNUM_PADDING_CHARACTER = 4;
- private static final int UNUM_CURRENCY_CODE = 5;
- private static final int UNUM_DEFAULT_RULESET = 6;
- private static final int UNUM_PUBLIC_RULESETS = 7;
-
- /**
- * The address of the ICU DecimalFormat* on the native heap.
- */
- private final int addr;
-
- /**
- * The last pattern we gave to ICU, so we can make repeated applications cheap.
- * This helps in cases like String.format("%.2f,%.2f\n", x, y) where the DecimalFormat is
- * reused.
- */
- private String lastPattern;
-
- // TODO: store all these in DecimalFormat instead!
- private boolean negPrefNull;
- private boolean negSuffNull;
- private boolean posPrefNull;
- private boolean posSuffNull;
-
- /**
- * Cache the BigDecimal form of the multiplier. This is null until we've
- * formatted a BigDecimal (with a multiplier that is not 1), or the user has
- * explicitly called {@link #setMultiplier(int)} with any multiplier.
- */
- private BigDecimal multiplierBigDecimal = null;
-
- public NativeDecimalFormat(String pattern, DecimalFormatSymbols dfs) {
- try {
- this.addr = openDecimalFormatImpl(pattern, dfs.getCurrencySymbol(),
- dfs.getDecimalSeparator(), dfs.getDigit(), dfs.getGroupingSeparator(),
- dfs.getInfinity(), dfs.getInternationalCurrencySymbol(), dfs.getMinusSign(),
- dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
- dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
- this.lastPattern = pattern;
- } catch (NullPointerException npe) {
- throw npe;
- } catch (RuntimeException re) {
- throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern);
- }
- }
-
- // Used to implement clone.
- private NativeDecimalFormat(NativeDecimalFormat other) {
- this.addr = cloneDecimalFormatImpl(other.addr);
- this.lastPattern = other.lastPattern;
- this.negPrefNull = other.negPrefNull;
- this.negSuffNull = other.negSuffNull;
- this.posPrefNull = other.posPrefNull;
- this.posSuffNull = other.posSuffNull;
- }
-
- // TODO: remove this and just have DecimalFormat.hashCode do the right thing itself.
- @Override
- public int hashCode() {
- return this.getPositivePrefix().hashCode();
- }
-
- @Override
- public Object clone() {
- return new NativeDecimalFormat(this);
- }
-
- @Override
- protected void finalize() {
- closeDecimalFormatImpl(this.addr);
- }
-
- /**
- * Note: this doesn't check that the underlying native DecimalFormat objects' configured
- * native DecimalFormatSymbols objects are equal. It is assumed that the
- * caller (DecimalFormat) will check the DecimalFormatSymbols objects
- * instead, for performance.
- *
- * This is also unreasonably expensive, calling down to JNI multiple times.
- *
- * TODO: remove this and just have DecimalFormat.equals do the right thing itself.
- */
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof NativeDecimalFormat)) {
- return false;
- }
- NativeDecimalFormat obj = (NativeDecimalFormat) object;
- if (obj.addr == this.addr) {
- return true;
- }
- return obj.toPattern().equals(this.toPattern()) &&
- obj.isDecimalSeparatorAlwaysShown() == this.isDecimalSeparatorAlwaysShown() &&
- obj.getGroupingSize() == this.getGroupingSize() &&
- obj.getMultiplier() == this.getMultiplier() &&
- obj.getNegativePrefix().equals(this.getNegativePrefix()) &&
- obj.getNegativeSuffix().equals(this.getNegativeSuffix()) &&
- obj.getPositivePrefix().equals(this.getPositivePrefix()) &&
- obj.getPositiveSuffix().equals(this.getPositiveSuffix()) &&
- obj.getMaximumIntegerDigits() == this.getMaximumIntegerDigits() &&
- obj.getMaximumFractionDigits() == this.getMaximumFractionDigits() &&
- obj.getMinimumIntegerDigits() == this.getMinimumIntegerDigits() &&
- obj.getMinimumFractionDigits() == this.getMinimumFractionDigits() &&
- obj.isGroupingUsed() == this.isGroupingUsed();
- }
-
- /**
- * Copies the DecimalFormatSymbols settings into our native peer in bulk.
- */
- public void setDecimalFormatSymbols(final DecimalFormatSymbols dfs) {
- setDecimalFormatSymbols(this.addr, dfs.getCurrencySymbol(), dfs.getDecimalSeparator(),
- dfs.getDigit(), dfs.getGroupingSeparator(), dfs.getInfinity(),
- dfs.getInternationalCurrencySymbol(), dfs.getMinusSign(),
- dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
- dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
- }
-
- private BigDecimal applyMultiplier(BigDecimal valBigDecimal) {
- if (multiplierBigDecimal == null) {
- multiplierBigDecimal = BigDecimal.valueOf(getMultiplier());
- }
- // Get new value by multiplying multiplier.
- return valBigDecimal.multiply(multiplierBigDecimal);
- }
-
- public StringBuffer formatBigDecimal(BigDecimal value, StringBuffer buffer, FieldPosition field) {
- if (buffer == null || field == null) {
- throw new NullPointerException();
- }
- if (getMultiplier() != 1) {
- value = applyMultiplier(value);
- }
- StringBuilder val = new StringBuilder();
- val.append(value.unscaledValue().toString(10));
- int scale = value.scale();
- scale = makeScalePositive(scale, val);
- String fieldType = getFieldType(field.getFieldAttribute());
- String result = format(this.addr, val.toString(), field, fieldType, null, scale);
- return buffer.append(result);
- }
-
- public StringBuffer formatBigInteger(BigInteger value, StringBuffer buffer, FieldPosition field) {
- if (buffer == null || field == null) {
- throw new NullPointerException();
- }
- String fieldType = getFieldType(field.getFieldAttribute());
- String result = format(this.addr, value.toString(10), field, fieldType, null, 0);
- return buffer.append(result);
- }
-
- public StringBuffer format(long value, StringBuffer buffer, FieldPosition field) {
- if (buffer == null || field == null) {
- throw new NullPointerException();
- }
- String fieldType = getFieldType(field.getFieldAttribute());
- buffer.append(format(this.addr, value, field, fieldType, null));
- return buffer;
- }
-
- public StringBuffer format(double value, StringBuffer buffer, FieldPosition field) {
- if (buffer == null || field == null) {
- throw new NullPointerException();
- }
- String fieldType = getFieldType(field.getFieldAttribute());
- buffer.append(format(this.addr, value, field, fieldType, null));
- return buffer;
- }
-
- public void applyLocalizedPattern(String pattern) {
- applyPattern(this.addr, true, pattern);
- lastPattern = null;
- }
-
- public void applyPattern(String pattern) {
- if (lastPattern != null && pattern.equals(lastPattern)) {
- return;
- }
- applyPattern(this.addr, false, pattern);
- lastPattern = pattern;
- }
-
- public AttributedCharacterIterator formatToCharacterIterator(Object object) {
- if (!(object instanceof Number)) {
- throw new IllegalArgumentException();
- }
- Number number = (Number) object;
- String text = null;
- StringBuffer attributes = new StringBuffer();
-
- if(number instanceof BigInteger) {
- BigInteger valBigInteger = (BigInteger) number;
- text = format(this.addr, valBigInteger.toString(10), null, null, attributes, 0);
- } else if(number instanceof BigDecimal) {
- BigDecimal valBigDecimal = (BigDecimal) number;
- if (getMultiplier() != 1) {
- valBigDecimal = applyMultiplier(valBigDecimal);
- }
- StringBuilder val = new StringBuilder();
- val.append(valBigDecimal.unscaledValue().toString(10));
- int scale = valBigDecimal.scale();
- scale = makeScalePositive(scale, val);
- text = format(this.addr, val.toString(), null, null, attributes, scale);
- } else if (number instanceof Double || number instanceof Float) {
- double dv = number.doubleValue();
- text = format(this.addr, dv, null, null, attributes);
- } else {
- long lv = number.longValue();
- text = format(this.addr, lv, null, null, attributes);
- }
-
- AttributedString as = new AttributedString(text);
-
- String[] attrs = attributes.toString().split(";");
- // add NumberFormat field attributes to the AttributedString
- int size = attrs.length / 3;
- if(size * 3 != attrs.length) {
- return as.getIterator();
- }
- for (int i = 0; i < size; i++) {
- Format.Field attribute = getField(attrs[3*i]);
- as.addAttribute(attribute, attribute, Integer.parseInt(attrs[3*i+1]),
- Integer.parseInt(attrs[3*i+2]));
- }
-
- // return the CharacterIterator from AttributedString
- return as.getIterator();
- }
-
- private int makeScalePositive(int scale, StringBuilder val) {
- if (scale < 0) {
- scale = -scale;
- for (int i = scale; i > 0; i--) {
- val.append('0');
- }
- scale = 0;
- }
- return scale;
- }
-
- public String toLocalizedPattern() {
- return toPatternImpl(this.addr, true);
- }
-
- public String toPattern() {
- return toPatternImpl(this.addr, false);
- }
-
- public Number parse(String string, ParsePosition position) {
- return parse(addr, string, position);
- }
-
- // start getter and setter
-
- public int getMaximumFractionDigits() {
- return getAttribute(this.addr, UNUM_MAX_FRACTION_DIGITS);
- }
-
- public int getMaximumIntegerDigits() {
- return getAttribute(this.addr, UNUM_MAX_INTEGER_DIGITS);
- }
-
- public int getMinimumFractionDigits() {
- return getAttribute(this.addr, UNUM_MIN_FRACTION_DIGITS);
- }
-
- public int getMinimumIntegerDigits() {
- return getAttribute(this.addr, UNUM_MIN_INTEGER_DIGITS);
- }
-
- public int getGroupingSize() {
- return getAttribute(this.addr, UNUM_GROUPING_SIZE);
- }
-
- public int getMultiplier() {
- return getAttribute(this.addr, UNUM_MULTIPLIER);
- }
-
- public String getNegativePrefix() {
- if (negPrefNull) {
- return null;
- }
- return getTextAttribute(this.addr, UNUM_NEGATIVE_PREFIX);
- }
-
- public String getNegativeSuffix() {
- if (negSuffNull) {
- return null;
- }
- return getTextAttribute(this.addr, UNUM_NEGATIVE_SUFFIX);
- }
-
- public String getPositivePrefix() {
- if (posPrefNull) {
- return null;
- }
- return getTextAttribute(this.addr, UNUM_POSITIVE_PREFIX);
- }
-
- public String getPositiveSuffix() {
- if (posSuffNull) {
- return null;
- }
- return getTextAttribute(this.addr, UNUM_POSITIVE_SUFFIX);
- }
-
- public boolean isDecimalSeparatorAlwaysShown() {
- return getAttribute(this.addr, UNUM_DECIMAL_ALWAYS_SHOWN) != 0;
- }
-
- public boolean isParseIntegerOnly() {
- return getAttribute(this.addr, UNUM_PARSE_INT_ONLY) != 0;
- }
-
- public boolean isGroupingUsed() {
- return getAttribute(this.addr, UNUM_GROUPING_USED) != 0;
- }
-
- public void setDecimalSeparatorAlwaysShown(boolean value) {
- int i = value ? -1 : 0;
- setAttribute(this.addr, UNUM_DECIMAL_ALWAYS_SHOWN, i);
- }
-
- public void setCurrency(Currency currency) {
- setSymbol(this.addr, UNUM_CURRENCY_SYMBOL, currency.getSymbol());
- setSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL, currency.getCurrencyCode());
- }
-
- public void setGroupingSize(int value) {
- setAttribute(this.addr, UNUM_GROUPING_SIZE, value);
- }
-
- public void setGroupingUsed(boolean value) {
- int i = value ? -1 : 0;
- setAttribute(this.addr, UNUM_GROUPING_USED, i);
- }
-
- public void setMaximumFractionDigits(int value) {
- setAttribute(this.addr, UNUM_MAX_FRACTION_DIGITS, value);
- }
-
- public void setMaximumIntegerDigits(int value) {
- setAttribute(this.addr, UNUM_MAX_INTEGER_DIGITS, value);
- }
-
- public void setMinimumFractionDigits(int value) {
- setAttribute(this.addr, UNUM_MIN_FRACTION_DIGITS, value);
- }
-
- public void setMinimumIntegerDigits(int value) {
- setAttribute(this.addr, UNUM_MIN_INTEGER_DIGITS, value);
- }
-
- public void setMultiplier(int value) {
- setAttribute(this.addr, UNUM_MULTIPLIER, value);
- // Update the cached BigDecimal for multiplier.
- multiplierBigDecimal = BigDecimal.valueOf(value);
- }
-
- public void setNegativePrefix(String value) {
- negPrefNull = value == null;
- if (!negPrefNull) {
- setTextAttribute(this.addr, UNUM_NEGATIVE_PREFIX, value);
- }
- }
-
- public void setNegativeSuffix(String value) {
- negSuffNull = value == null;
- if (!negSuffNull) {
- setTextAttribute(this.addr, UNUM_NEGATIVE_SUFFIX, value);
- }
- }
-
- public void setPositivePrefix(String value) {
- posPrefNull = value == null;
- if (!posPrefNull) {
- setTextAttribute(this.addr, UNUM_POSITIVE_PREFIX, value);
- }
- }
-
- public void setPositiveSuffix(String value) {
- posSuffNull = value == null;
- if (!posSuffNull) {
- setTextAttribute(this.addr, UNUM_POSITIVE_SUFFIX, value);
- }
- }
-
- public void setParseIntegerOnly(boolean value) {
- int i = value ? -1 : 0;
- setAttribute(this.addr, UNUM_PARSE_INT_ONLY, i);
- }
-
- static protected 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;
- }
-
- protected Format.Field getField(String type) {
- if(type.equals("")) {
- return null;
- }
- if(type.equals("sign")) {
- return NumberFormat.Field.SIGN;
- }
- if(type.equals("integer")) {
- return NumberFormat.Field.INTEGER;
- }
- if(type.equals("fraction")) {
- return NumberFormat.Field.FRACTION;
- }
- if(type.equals("exponent")) {
- return NumberFormat.Field.EXPONENT;
- }
- if(type.equals("exponent_sign")) {
- return NumberFormat.Field.EXPONENT_SIGN;
- }
- if(type.equals("exponent_symbol")) {
- return NumberFormat.Field.EXPONENT_SYMBOL;
- }
- if(type.equals("currency")) {
- return NumberFormat.Field.CURRENCY;
- }
- if(type.equals("grouping_separator")) {
- return NumberFormat.Field.GROUPING_SEPARATOR;
- }
- if(type.equals("decimal_separator")) {
- return NumberFormat.Field.DECIMAL_SEPARATOR;
- }
- if(type.equals("percent")) {
- return NumberFormat.Field.PERCENT;
- }
- if(type.equals("permille")) {
- return NumberFormat.Field.PERMILLE;
- }
- return null;
- }
-
- private static void applyPattern(int addr, boolean localized, String pattern) {
- try {
- applyPatternImpl(addr, localized, pattern);
- } catch (NullPointerException npe) {
- throw npe;
- } catch (RuntimeException re) {
- throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern);
- }
- }
-
- public void setRoundingMode(RoundingMode roundingMode, double roundingIncrement) {
- final int nativeRoundingMode;
- switch (roundingMode) {
- case CEILING: nativeRoundingMode = 0; break;
- case FLOOR: nativeRoundingMode = 1; break;
- case DOWN: nativeRoundingMode = 2; break;
- case UP: nativeRoundingMode = 3; break;
- case HALF_EVEN: nativeRoundingMode = 4; break;
- case HALF_DOWN: nativeRoundingMode = 5; break;
- case HALF_UP: nativeRoundingMode = 6; break;
- default: throw new AssertionError();
- }
- setRoundingMode(addr, nativeRoundingMode, roundingIncrement);
- }
-
- private static native void applyPatternImpl(int addr, boolean localized, String pattern);
- private static native int cloneDecimalFormatImpl(int addr);
- private static native void closeDecimalFormatImpl(int addr);
- private static native String format(int addr, long value, FieldPosition position, String fieldType, StringBuffer attributes);
- private static native String format(int addr, double value, FieldPosition position, String fieldType, StringBuffer attributes);
- private static native String format(int addr, String value, FieldPosition position, String fieldType, StringBuffer attributes, int scale);
- private static native int getAttribute(int addr, int symbol);
- private static native String getTextAttribute(int addr, int symbol);
- private static native int openDecimalFormatImpl(String pattern, String currencySymbol,
- char decimalSeparator, char digit, char groupingSeparator, String infinity,
- String internationalCurrencySymbol, char minusSign, char monetaryDecimalSeparator,
- String nan, char patternSeparator, char percent, char perMill, char zeroDigit);
- private static native Number parse(int addr, String string, ParsePosition position);
- private static native void setDecimalFormatSymbols(int addr, String currencySymbol,
- char decimalSeparator, char digit, char groupingSeparator, String infinity,
- String internationalCurrencySymbol, char minusSign, char monetaryDecimalSeparator,
- String nan, char patternSeparator, char percent, char perMill, char zeroDigit);
- private static native void setSymbol(int addr, int symbol, String str);
- private static native void setAttribute(int addr, int symbol, int i);
- private static native void setRoundingMode(int addr, int roundingMode, double roundingIncrement);
- private static native void setTextAttribute(int addr, int symbol, String str);
- private static native String toPatternImpl(int addr, boolean localized);
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeIDN.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeIDN.java
deleted file mode 100644
index b973131..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeIDN.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.ibm.icu4jni.text;
-
-public class NativeIDN {
- public static String toASCII(String s, int flags) {
- return convert(s, flags, true);
- }
-
- public static String toUnicode(String s, int flags) {
- try {
- return convert(s, flags, false);
- } catch (IllegalArgumentException ex) {
- // The RI documentation explicitly states that this method can't fail.
- // ICU4C disagrees, as does the RI in practice.
- // The RI just returns the input string if it can't
- return s;
- }
- }
-
- private static String convert(String s, int flags, boolean toAscii) {
- if (s == null) {
- throw new NullPointerException();
- }
- return convertImpl(s, flags, toAscii);
- }
- private static native String convertImpl(String s, int flags, boolean toAscii);
-
- private NativeIDN() {}
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeNormalizer.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeNormalizer.java
deleted file mode 100644
index f14b6c1..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeNormalizer.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.ibm.icu4jni.text;
-
-import java.text.Normalizer.Form;
-
-public final class NativeNormalizer {
- public static boolean isNormalized(CharSequence src, Form form) {
- return isNormalizedImpl(src.toString(), toUNormalizationMode(form));
- }
-
- public static String normalize(CharSequence src, Form form) {
- return normalizeImpl(src.toString(), toUNormalizationMode(form));
- }
-
- private static int toUNormalizationMode(Form form) {
- // Translates Java enum constants to ICU int constants.
- // See UNormalizationMode in "unicode/unorm.h". Stable API since ICU 2.0.
- switch (form) {
- case NFC: return 4;
- case NFD: return 2;
- case NFKC: return 5;
- case NFKD: return 3;
- }
- throw new AssertionError("unknown Normalizer.Form " + form);
- }
-
- private static native String normalizeImpl(String src, int form);
-
- private static native boolean isNormalizedImpl(String src, int form);
-
- private NativeNormalizer() {}
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java b/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java
deleted file mode 100644
index 8e048dd..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java
+++ /dev/null
@@ -1,543 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-import java.util.Locale;
-import java.text.CharacterIterator;
-import java.text.ParseException;
-
-/**
-* Concrete implementation class for Collation.
-* <p>
-* The collation table is composed of a list of collation rules, where each
-* rule is of three forms:
-* <pre>
-* < modifier >
-* < relation > < text-argument >
-* < reset > < text-argument >
-* </pre>
-* <p>
-* <code>RuleBasedCollator</code> has the following restrictions for efficiency
-* (other subclasses may be used for more complex languages) :
-* <ol>
-* <li> If a French secondary ordering is specified it applies to the whole
-* collator object.
-* <li> All non-mentioned Unicode characters are at the end of the collation
-* order.
-* <li> If a character is not located in the RuleBasedCollator, the default
-* Unicode Collation Algorithm (UCA) rule-based table is automatically
-* searched as a backup.
-* </ol>
-*
-* The following demonstrates how to create your own collation rules:
-* <UL Type=disc>
-* <LI><strong>Text-Argument</strong>: A text-argument is any sequence of
-* characters, excluding special characters (that is, common whitespace
-* characters [0009-000D, 0020] and rule syntax characters [0021-002F,
-* 003A-0040, 005B-0060, 007B-007E]). If those characters are desired,
-* you can put them in single quotes (e.g. ampersand => '&'). Note that
-* unquoted white space characters are ignored; e.g. <code>b c</code> is
-* treated as <code>bc</code>.
-* <LI><strong>Modifier</strong>: There is a single modifier which is used
-* to specify that all accents (secondary differences) are backwards.
-* <p>'@' : Indicates that accents are sorted backwards, as in French.
-* <LI><strong>Relation</strong>: The relations are the following:
-* <UL Type=square>
-* <LI>'<' : Greater, as a letter difference (primary)
-* <LI>';' : Greater, as an accent difference (secondary)
-* <LI>',' : Greater, as a case difference (tertiary)
-* <LI>'=' : Equal
-* </UL>
-* <LI><strong>Reset</strong>: There is a single reset which is used
-* primarily for contractions and expansions, but which can also be used
-* to add a modification at the end of a set of rules.
-* <p>'&' : Indicates that the next rule follows the position to where
-* the reset text-argument would be sorted.
-* </UL>
-*
-* <p>
-* This sounds more complicated than it is in practice. For example, the
-* following are equivalent ways of expressing the same thing:
-* <blockquote>
-* <pre>
-* a < b < c
-* a < b & b < c
-* a < c & a < b
-* </pre>
-* </blockquote>
-* Notice that the order is important, as the subsequent item goes immediately
-* after the text-argument. The following are not equivalent:
-* <blockquote>
-* <pre>
-* a < b & a < c
-* a < c & a < b
-* </pre>
-* </blockquote>
-* Either the text-argument must already be present in the sequence, or some
-* initial substring of the text-argument must be present. (e.g. "a < b & ae <
-* e" is valid since "a" is present in the sequence before "ae" is reset). In
-* this latter case, "ae" is not entered and treated as a single character;
-* instead, "e" is sorted as if it were expanded to two characters: "a"
-* followed by an "e". This difference appears in natural languages: in
-* traditional Spanish "ch" is treated as though it contracts to a single
-* character (expressed as "c < ch < d"), while in traditional German a-umlaut
-* is treated as though it expanded to two characters (expressed as "a,A < b,B
-* ... & ae;? & AE;?"). [? and ? are, of course, the escape sequences for
-* a-umlaut.]
-* <p>
-* <strong>Ignorable Characters</strong>
-* <p>
-* For ignorable characters, the first rule must start with a relation (the
-* examples we have used above are really fragments; "a < b" really should be
-* "< a < b"). If, however, the first relation is not "<", then all the all
-* text-arguments up to the first "<" are ignorable. For example, ", - < a < b"
-* makes "-" an ignorable character, as we saw earlier in the word
-* "black-birds". In the samples for different languages, you see that most
-* accents are ignorable.
-*
-* <p><strong>Normalization and Accents</strong>
-* <p>
-* <code>RuleBasedCollator</code> automatically processes its rule table to
-* include both pre-composed and combining-character versions of accented
-* characters. Even if the provided rule string contains only base characters
-* and separate combining accent characters, the pre-composed accented
-* characters matching all canonical combinations of characters from the rule
-* string will be entered in the table.
-* <p>
-* This allows you to use a RuleBasedCollator to compare accented strings even
-* when the collator is set to NO_DECOMPOSITION. However, if the strings to be
-* collated contain combining sequences that may not be in canonical order, you
-* should set the collator to CANONICAL_DECOMPOSITION to enable sorting of
-* combining sequences.
-* For more information, see
-* <A HREF="http://www.aw.com/devpress">The Unicode Standard, Version 3.0</A>.)
-*
-* <p><strong>Errors</strong>
-* <p>
-* The following are errors:
-* <UL Type=disc>
-* <LI>A text-argument contains unquoted punctuation symbols
-* (e.g. "a < b-c < d").
-* <LI>A relation or reset character not followed by a text-argument
-* (e.g. "a < , b").
-* <LI>A reset where the text-argument (or an initial substring of the
-* text-argument) is not already in the sequence or allocated in the
-* default UCA table.
-* (e.g. "a < b & e < f")
-* </UL>
-* If you produce one of these errors, a <code>RuleBasedCollator</code> throws
-* a <code>ParseException</code>.
-*
-* <p><strong>Examples</strong>
-* <p>Simple: "< a < b < c < d"
-* <p>Norwegian: "< a,A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J
-* < k,K< l,L< m,M< n,N< o,O< p,P< q,Q< r,R< s,S< t,T
-* < u,U< v,V< w,W< x,X< y,Y< z,Z
-* < ?=a?,?=A?
-* ;aa,AA< ?,?< ?,?"
-*
-* <p>
-* Normally, to create a rule-based Collator object, you will use
-* <code>Collator</code>'s factory method <code>getInstance</code>.
-* However, to create a rule-based Collator object with specialized rules
-* tailored to your needs, you construct the <code>RuleBasedCollator</code>
-* with the rules contained in a <code>String</code> object. For example:
-* <blockquote>
-* <pre>
-* String Simple = "< a < b < c < d";
-* RuleBasedCollator mySimple = new RuleBasedCollator(Simple);
-* </pre>
-* </blockquote>
-* Or:
-* <blockquote>
-* <pre>
-* String Norwegian = "< a,A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J" +
-* "< k,K< l,L< m,M< n,N< o,O< p,P< q,Q< r,R< s,S< t,T" +
-* "< u,U< v,V< w,W< x,X< y,Y< z,Z" +
-* "< ?=a?,?=A?" +
-* ";aa,AA< ?,?< ?,?";
-* RuleBasedCollator myNorwegian = new RuleBasedCollator(Norwegian);
-* </pre>
-* </blockquote>
-*
-* <p>
-* Combining <code>Collator</code>s is as simple as concatenating strings.
-* Here's an example that combines two <code>Collator</code>s from two
-* different locales:
-* <blockquote>
-* <pre>
-* // Create an en_US Collator object
-* RuleBasedCollator en_USCollator = (RuleBasedCollator)
-* Collator.getInstance(new Locale("en", "US", ""));
-* // Create a da_DK Collator object
-* RuleBasedCollator da_DKCollator = (RuleBasedCollator)
-* Collator.getInstance(new Locale("da", "DK", ""));
-* // Combine the two
-* // First, get the collation rules from en_USCollator
-* String en_USRules = en_USCollator.getRules();
-* // Second, get the collation rules from da_DKCollator
-* String da_DKRules = da_DKCollator.getRules();
-* RuleBasedCollator newCollator =
-* new RuleBasedCollator(en_USRules + da_DKRules);
-* // newCollator has the combined rules
-* </pre>
-* </blockquote>
-*
-* <p>
-* Another more interesting example would be to make changes on an existing
-* table to create a new <code>Collator</code> object. For example, add
-* "& C < ch, cH, Ch, CH" to the <code>en_USCollator</code> object to create
-* your own:
-* <blockquote>
-* <pre>
-* // Create a new Collator object with additional rules
-* String addRules = "& C < ch, cH, Ch, CH";
-* RuleBasedCollator myCollator =
-* new RuleBasedCollator(en_USCollator + addRules);
-* // myCollator contains the new rules
-* </pre>
-* </blockquote>
-*
-* <p>
-* The following example demonstrates how to change the order of
-* non-spacing accents,
-* <blockquote>
-* <pre>
-* // old rule
-* String oldRules = "=?;?;?" // main accents Diaeresis 00A8, Macron 00AF
-* // Acute 00BF
-* + "< a , A ; ae, AE ; ? , ?"
-* + "< b , B < c, C < e, E & C < d, D";
-* // change the order of accent characters
-* String addOn = "& ?;?;?;"; // Acute 00BF, Macron 00AF, Diaeresis 00A8
-* RuleBasedCollator myCollator = new RuleBasedCollator(oldRules + addOn);
-* </pre>
-* </blockquote>
-*
-* <p>
-* The last example shows how to put new primary ordering in before the
-* default setting. For example, in Japanese <code>Collator</code>, you
-* can either sort English characters before or after Japanese characters,
-* <blockquote>
-* <pre>
-* // get en_US Collator rules
-* RuleBasedCollator en_USCollator =
-* (RuleBasedCollator)Collator.getInstance(Locale.US);
-* // add a few Japanese character to sort before English characters
-* // suppose the last character before the first base letter 'a' in
-* // the English collation rule is ?
-* String jaString = "& \\u30A2 , \\u30FC < \\u30C8";
-* RuleBasedCollator myJapaneseCollator = new
-* RuleBasedCollator(en_USCollator.getRules() + jaString);
-* </pre>
-* </blockquote>
-* <P>
-* @author syn wee quek
-* @stable ICU 2.4
-*/
-public final class RuleBasedCollator extends Collator {
- private int m_collator_;
- private int m_hashcode_ = 0;
-
- /**
- * RuleBasedCollator constructor. This takes the table rules and builds a
- * collation table out of them. Please see RuleBasedCollator class
- * description for more details on the collation rule syntax.
- * @param rules the collation rules to build the collation table from.
- * @exception ParseException thrown if rules are empty or a Runtime error
- * if collator can not be created.
- * @stable ICU 2.4
- */
- public RuleBasedCollator(String rules) throws ParseException {
- if (rules == null) {
- throw new NullPointerException();
- }
- m_collator_ = NativeCollation.openCollatorFromRules(rules,
- CollationAttribute.VALUE_OFF, CollationAttribute.VALUE_DEFAULT_STRENGTH);
- }
-
- /**
- * RuleBasedCollator constructor. This takes the table rules and builds a
- * collation table out of them. Please see RuleBasedCollator class
- * description for more details on the collation rule syntax.
- * @param rules the collation rules to build the collation table from.
- * @param strength collation strength
- * @exception ParseException thrown if rules are empty or a Runtime error
- * if collator can not be created.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public RuleBasedCollator(String rules, int strength) throws ParseException {
- if (rules == null) {
- throw new NullPointerException();
- }
- m_collator_ = NativeCollation.openCollatorFromRules(rules, CollationAttribute.VALUE_OFF, strength);
- }
-
- /**
- * RuleBasedCollator constructor. This takes the table rules and builds a
- * collation table out of them. Please see RuleBasedCollator class
- * description for more details on the collation rule syntax.
- * <p>Note API change starting from release 2.4. Prior to release 2.4, the
- * normalizationMode argument values are from the class
- * com.ibm.icu4jni.text.Normalization. In 2.4,
- * the valid normalizationMode arguments for this API are
- * CollationAttribute.VALUE_ON and CollationAttribute.VALUE_OFF.
- * </p>
- * @param rules the collation rules to build the collation table from.
- * @param strength collation strength
- * @param normalizationMode normalization mode
- * @exception IllegalArgumentException thrown when constructor error occurs
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public RuleBasedCollator(String rules, int normalizationMode, int strength) {
- if (rules == null) {
- throw new NullPointerException();
- }
- m_collator_ = NativeCollation.openCollatorFromRules(rules, normalizationMode, strength);
- }
-
- /**
- * Makes a complete copy of the current object.
- * @return a copy of this object if data clone is a success, otherwise null
- * @stable ICU 2.4
- */
- public Object clone() {
- RuleBasedCollator result = null;
- int collatoraddress = NativeCollation.safeClone(m_collator_);
- result = new RuleBasedCollator(collatoraddress);
- return (Collator)result;
- }
-
- /**
- * The comparison function compares the character data stored in two
- * different strings. Returns information about whether a string is less
- * than, greater than or equal to another string.
- * <p>Example of use:
- * <br>
- * <code>
- * Collator myCollation = Collator.createInstance(Locale::US);
- * myCollation.setStrength(CollationAttribute.VALUE_PRIMARY);
- * // result would be 0 ("abc" == "ABC")
- * // (no primary difference between "abc" and "ABC")
- * int result = myCollation.compare("abc", "ABC",3);
- * myCollation.setStrength(CollationAttribute.VALUE_TERTIARY);
- * // result would be -1 (abc" &lt;&lt;&lt; "ABC")
- * // (with tertiary difference between "abc" and "ABC")
- * int result = myCollation.compare("abc", "ABC",3);
- * </code>
- */
- public int compare(String source, String target) {
- return NativeCollation.compare(m_collator_, source, target);
- }
-
- /**
- * Get the normalization mode for this object.
- * The normalization mode influences how strings are compared.
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public int getDecomposition() {
- return NativeCollation.getNormalization(m_collator_);
- }
-
- /**
- * <p>Sets the decomposition mode of the Collator object on or off.
- * If the decomposition mode is set to on, string would be decomposed into
- * NFD format where necessary before sorting.</p>
- * </p>
- * @param decompositionmode the new decomposition mode
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public void setDecomposition(int decompositionmode) {
- NativeCollation.setAttribute(m_collator_,
- CollationAttribute.NORMALIZATION_MODE, decompositionmode);
- }
-
- /**
- * Determines the minimum strength that will be use in comparison or
- * transformation.
- * <p>
- * E.g. with strength == CollationAttribute.VALUE_SECONDARY, the tertiary difference
- * is ignored
- * </p>
- * <p>
- * E.g. with strength == PRIMARY, the secondary and tertiary difference are
- * ignored.
- * </p>
- * @return the current comparison level.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public int getStrength() {
- return NativeCollation.getAttribute(m_collator_, CollationAttribute.STRENGTH);
- }
-
- /**
- * Sets the minimum strength to be used in comparison or transformation.
- * <p>Example of use:
- * <br>
- * <code>
- * Collator myCollation = Collator.createInstance(Locale::US);
- * myCollation.setStrength(PRIMARY);
- * // result will be "abc" == "ABC"
- * // tertiary differences will be ignored
- * int result = myCollation->compare("abc", "ABC");
- * </code>
- * @param strength the new comparison level.
- * @exception IllegalArgumentException when argument does not belong to any collation strength
- * mode or error occurs while setting data.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public void setStrength(int strength) {
- NativeCollation.setAttribute(m_collator_, CollationAttribute.STRENGTH, strength);
- }
-
- /**
- * Sets the attribute to be used in comparison or transformation.
- * <p>Example of use:
- * <br>
- * <code>
- * Collator myCollation = Collator.createInstance(Locale::US);
- * myCollation.setAttribute(CollationAttribute.CASE_LEVEL,
- * CollationAttribute.VALUE_ON);
- * int result = myCollation->compare("\\u30C3\\u30CF",
- * "\\u30C4\\u30CF");
- * // result will be -1
- * </code>
- * @param type the attribute to be set from CollationAttribute
- * @param value attribute value from CollationAttribute
- * @stable ICU 2.4
- */
- public void setAttribute(int type, int value) {
- NativeCollation.setAttribute(m_collator_, type, value);
- }
-
- /**
- * Gets the attribute to be used in comparison or transformation.
- * @param type the attribute to be set from CollationAttribute
- * @return value attribute value from CollationAttribute
- * @stable ICU 2.4
- */
- public int getAttribute(int type) {
- return NativeCollation.getAttribute(m_collator_, type);
- }
-
- public CollationKey getCollationKey(String source) {
- if (source == null) {
- return null;
- }
- byte[] key = NativeCollation.getSortKey(m_collator_, source);
- if (key == null) {
- return null;
- }
- return new CollationKey(source, key);
- }
-
- /**
- * Get the collation rules of this Collation object
- * The rules will follow the rule syntax.
- * @return collation rules.
- * @stable ICU 2.4
- */
- public String getRules() {
- return NativeCollation.getRules(m_collator_);
- }
-
- /**
- * Create a CollationElementIterator object that will iterator over the
- * elements in a string, using the collation rules defined in this
- * RuleBasedCollator
- * @param source string to iterate over
- * @return address of C collationelement
- * @exception IllegalArgumentException thrown when error occurs
- * @stable ICU 2.4
- */
- public CollationElementIterator getCollationElementIterator(String source) {
- CollationElementIterator result = new CollationElementIterator(
- NativeCollation.getCollationElementIterator(m_collator_, source));
- // result.setOwnCollationElementIterator(true);
- return result;
- }
-
- public CollationElementIterator getCollationElementIterator(CharacterIterator it) {
- // We only implement the String-based API, so build a string from the iterator.
- return getCollationElementIterator(characterIteratorToString(it));
- }
-
- private String characterIteratorToString(CharacterIterator it) {
- StringBuilder result = new StringBuilder();
- for (char ch = it.current(); ch != CharacterIterator.DONE; ch = it.next()) {
- result.append(ch);
- }
- return result.toString();
- }
-
- @Override
- public int hashCode() {
- return 42; // No-one uses RuleBasedCollator as a hash key.
- }
-
- /**
- * Checks if argument object is equals to this object.
- * @param target object
- * @return true if source is equivalent to target, false otherwise
- * @stable ICU 2.4
- */
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof RuleBasedCollator)) {
- return false;
- }
- RuleBasedCollator rhs = (RuleBasedCollator) object;
- return getRules().equals(rhs.getRules()) &&
- getStrength() == rhs.getStrength() &&
- getDecomposition() == rhs.getDecomposition();
- }
-
- RuleBasedCollator(Locale locale) {
- m_collator_ = NativeCollation.openCollator(locale.toString());
- }
-
- @Override
- protected void finalize() {
- NativeCollation.closeCollator(m_collator_);
- }
-
- private RuleBasedCollator(int addr) {
- m_collator_ = addr;
- }
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/ICU.java b/icu/src/main/java/com/ibm/icu4jni/util/ICU.java
deleted file mode 100644
index b684068..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/util/ICU.java
+++ /dev/null
@@ -1,311 +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.util;
-
-import java.util.Locale;
-import java.util.TimeZone;
-import java.util.logging.Logger;
-
-/**
- * Makes ICU data accessible to Java.
- */
-public final class ICU {
- /**
- * Cache for ISO language names.
- */
- private static String[] isoLanguages;
-
- /**
- * Cache for ISO country names.
- */
- private static String[] isoCountries;
-
- /**
- * Available timezones cache.
- */
- private static String[] availableTimezones;
-
- /**
- * Returns an array of ISO language names (two-letter codes), fetched either
- * from ICU's database or from our memory cache.
- *
- * @return The array.
- */
- public static String[] getISOLanguages() {
- if (isoLanguages == null) {
- isoLanguages = getISOLanguagesNative();
- }
- return isoLanguages.clone();
- }
-
- /**
- * Returns an array of ISO country names (two-letter codes), fetched either
- * from ICU's database or from our memory cache.
- *
- * @return The array.
- */
- public static String[] getISOCountries() {
- if (isoCountries == null) {
- isoCountries = getISOCountriesNative();
- }
- return isoCountries.clone();
- }
-
- /**
- * Returns an array of names of timezones that are available in the system,
- * fetched either from the TimeZone class or from our memory cache.
- *
- * @return The array.
- */
- public static String[] getKnownTimezones() {
- if (availableTimezones == null) {
- availableTimezones = TimeZone.getAvailableIDs();
- }
- return availableTimezones.clone();
- }
-
- /**
- * Returns the display name for the given time zone using the given locale.
- *
- * @param id The time zone ID, for example "Europe/Berlin"
- * @param daylight Indicates whether daylight savings is in use
- * @param style The style, 0 for long, 1 for short
- * @param locale The locale name, for example "en_US".
- * @return The desired display name
- */
- public static String getDisplayTimeZone(String id, boolean daylight, int style, String locale) {
- // If we already have the strings, linear search through them is 10x quicker than
- // calling ICU for just the one we want.
- if (DefaultTimeZones.locale.equals(locale)) {
- String result = lookupDisplayTimeZone(DefaultTimeZones.names, id, daylight, style);
- if (result != null) {
- return result;
- }
- }
- return getDisplayTimeZoneNative(id, daylight, style, locale);
- }
-
- public static String lookupDisplayTimeZone(String[][] zoneStrings, String id, boolean daylight, int style) {
- for (String[] row : zoneStrings) {
- if (row[0].equals(id)) {
- if (daylight) {
- return (style == TimeZone.LONG) ? row[3] : row[4];
- } else {
- return (style == TimeZone.LONG) ? row[1] : row[2];
- }
- }
- }
- return null;
- }
-
- /**
- * Initialization holder for default time zone names. This class will
- * be preloaded by the zygote to share the time and space costs of setting
- * up the list of time zone names, so although it looks like the lazy
- * initialization idiom, it's actually the opposite.
- */
- private static class DefaultTimeZones {
- /**
- * Name of default locale at the time this class was initialized.
- */
- private static final String locale = Locale.getDefault().toString();
-
- /**
- * Names of time zones for the default locale.
- */
- private static final String[][] names = createTimeZoneNamesFor(locale);
- }
-
- /**
- * Creates array of time zone names for the given locale. This method takes
- * about 2s to run on a 400MHz ARM11.
- */
- private static String[][] createTimeZoneNamesFor(String locale) {
- long start = System.currentTimeMillis();
-
- /*
- * The following code is optimized for fast native response (the time a
- * method call can be in native code is limited). It prepares an empty
- * array to keep native code from having to create new Java objects. It
- * also fill in the time zone IDs to speed things up a bit. There's one
- * array for each time zone name type. (standard/long, standard/short,
- * daylight/long, daylight/short) The native method that fetches these
- * strings is faster if it can do all entries of one type, before having
- * to change to the next type. That's why the array passed down to
- * native has 5 entries, each providing space for all time zone names of
- * one type. Likely this access to the fields is much faster in the
- * native code because there's less array access overhead.
- */
- String[][] arrayToFill = new String[5][];
- arrayToFill[0] = getKnownTimezones();
- arrayToFill[1] = new String[availableTimezones.length];
- arrayToFill[2] = new String[availableTimezones.length];
- arrayToFill[3] = new String[availableTimezones.length];
- arrayToFill[4] = new String[availableTimezones.length];
-
- /*
- * Fill in the zone names in native.
- */
- getTimeZonesNative(arrayToFill, locale);
-
- /*
- * Finally we need to reorder the entries so we get the expected result.
- */
- String[][] result = new String[availableTimezones.length][5];
- for (int i = 0; i < availableTimezones.length; i++) {
- result[i][0] = arrayToFill[0][i];
- result[i][1] = arrayToFill[1][i];
- result[i][2] = arrayToFill[2][i];
- result[i][3] = arrayToFill[3][i];
- result[i][4] = arrayToFill[4][i];
- }
-
- Logger.global.info("Loaded time zone names for " + locale + " in "
- + (System.currentTimeMillis() - start) + "ms.");
-
- return result;
- }
-
- /**
- * Returns the display names for all given timezones using the given locale.
- *
- * @return An array of time zone strings. Each row represents one time zone.
- * The first columns holds the ID of the time zone, for example
- * "Europe/Berlin". The other columns then hold for each row the
- * four time zone names with and without daylight savings and in
- * long and short format. It's exactly the array layout required by
- * the TimeZone class.
- */
- public static String[][] getDisplayTimeZones(String locale) {
- String defaultLocale = Locale.getDefault().toString();
- if (locale == null) {
- locale = defaultLocale;
- }
-
- // If locale == default and the default locale hasn't changed since
- // DefaultTimeZones loaded, return the cached names.
- // TODO: We should force a reboot if the default locale changes.
- if (defaultLocale.equals(locale) && DefaultTimeZones.locale.equals(defaultLocale)) {
- return clone2dStringArray(DefaultTimeZones.names);
- }
-
- return createTimeZoneNamesFor(locale);
- }
-
- public static String[][] clone2dStringArray(String[][] array) {
- String[][] result = new String[array.length][];
- for (int i = 0; i < array.length; ++i) {
- result[i] = array[i].clone();
- }
- 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;
- }
-
- private static Locale[] availableLocalesCache;
- public static Locale[] getAvailableLocales() {
- if (availableLocalesCache == null) {
- availableLocalesCache = localesFromStrings(getAvailableLocalesNative());
- }
- return availableLocalesCache.clone();
- }
-
- public static Locale[] getAvailableBreakIteratorLocales() {
- return localesFromStrings(getAvailableBreakIteratorLocalesNative());
- }
-
- public static Locale[] getAvailableCalendarLocales() {
- return localesFromStrings(getAvailableCalendarLocalesNative());
- }
-
- public static Locale[] getAvailableCollatorLocales() {
- return localesFromStrings(getAvailableCollatorLocalesNative());
- }
-
- public static Locale[] getAvailableDateFormatLocales() {
- return localesFromStrings(getAvailableDateFormatLocalesNative());
- }
-
- public static Locale[] getAvailableDateFormatSymbolsLocales() {
- return getAvailableDateFormatLocales();
- }
-
- public static Locale[] getAvailableDecimalFormatSymbolsLocales() {
- return getAvailableNumberFormatLocales();
- }
-
- public static Locale[] getAvailableNumberFormatLocales() {
- return localesFromStrings(getAvailableNumberFormatLocalesNative());
- }
-
- // --- Native methods accessing ICU's database ----------------------------
-
- private static native String[] getAvailableBreakIteratorLocalesNative();
- private static native String[] getAvailableCalendarLocalesNative();
- private static native String[] getAvailableCollatorLocalesNative();
- private static native String[] getAvailableDateFormatLocalesNative();
- private static native String[] getAvailableLocalesNative();
- private static native String[] getAvailableNumberFormatLocalesNative();
-
- public static native String getCurrencyCodeNative(String locale);
- public static native int getCurrencyFractionDigitsNative(String currencyCode);
- public static native String getCurrencySymbolNative(String locale, String currencyCode);
-
- public static native String getDisplayCountryNative(String countryCode, String locale);
- public static native String getDisplayLanguageNative(String languageCode, String locale);
- public static native String getDisplayVariantNative(String variantCode, String locale);
-
- public static native String getISO3CountryNative(String locale);
- public static native String getISO3LanguageNative(String locale);
-
- private static native String[] getISOLanguagesNative();
- private static native String[] getISOCountriesNative();
-
- private static native void getTimeZonesNative(String[][] arrayToFill, String locale);
-
- private static native String getDisplayTimeZoneNative(String id, boolean isDST, int style,
- String locale);
-
- static native boolean initLocaleDataImpl(String locale, LocaleData result);
-}
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java b/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java
deleted file mode 100644
index e27bd54..0000000
--- a/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Copyright (C) 2009 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.util;
-
-import java.text.DateFormat;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Locale;
-
-/**
- * Passes locale-specific from ICU native code to Java.
- * <p>
- * Note that you share these; you must not alter any of the fields, nor their array elements
- * in the case of arrays. If you ever expose any of these things to user code, you must give
- * them a clone rather than the original.
- */
-public final class LocaleData {
- // A cache for the locale-specific data.
- private static final HashMap<String, LocaleData> localeDataCache = new HashMap<String, LocaleData>();
-
- public Integer firstDayOfWeek;
- public Integer minimalDaysInFirstWeek;
-
- public String[] amPm;
-
- public String[] eras;
-
- public String[] longMonthNames;
- public String[] shortMonthNames;
-
- public String[] longWeekdayNames;
- public String[] shortWeekdayNames;
-
- public String fullTimeFormat;
- public String longTimeFormat;
- public String mediumTimeFormat;
- public String shortTimeFormat;
-
- public String fullDateFormat;
- public String longDateFormat;
- public String mediumDateFormat;
- public String shortDateFormat;
-
- // DecimalFormatSymbols.
- public char zeroDigit;
- public char digit;
- public char decimalSeparator;
- public char groupingSeparator;
- public char patternSeparator;
- public char percent;
- public char perMill;
- public char monetarySeparator;
- public char minusSign;
- public String exponentSeparator;
- public String infinity;
- public String NaN;
-
- public String currencySymbol;
- public String internationalCurrencySymbol;
-
- public String numberPattern;
- public String integerPattern;
- public String currencyPattern;
- public String percentPattern;
-
- private LocaleData() {
- }
-
- /**
- * Returns a shared LocaleData for the given locale.
- */
- public static LocaleData get(Locale locale) {
- if (locale == null) {
- locale = Locale.getDefault();
- }
- String localeName = locale.toString();
- synchronized (localeDataCache) {
- LocaleData localeData = localeDataCache.get(localeName);
- if (localeData != null) {
- return localeData;
- }
- }
- LocaleData newLocaleData = makeLocaleData(locale);
- synchronized (localeDataCache) {
- LocaleData localeData = localeDataCache.get(localeName);
- if (localeData != null) {
- return localeData;
- }
- localeDataCache.put(localeName, newLocaleData);
- return newLocaleData;
- }
- }
-
- private static LocaleData makeLocaleData(Locale locale) {
- String language = locale.getLanguage();
- String country = locale.getCountry();
- String variant = locale.getVariant();
- // Start with data from the parent (next-most-specific) locale...
- LocaleData result = new LocaleData();
- if (!variant.isEmpty()) {
- result.overrideWithDataFrom(get(new Locale(language, country, "")));
- } else if (!country.isEmpty()) {
- result.overrideWithDataFrom(get(new Locale(language, "", "")));
- } else if (!language.isEmpty()) {
- result.overrideWithDataFrom(get(Locale.ROOT));
- }
- // Override with data from this locale.
- result.overrideWithDataFrom(initLocaleData(locale));
- return result;
- }
-
- @Override public String toString() {
- return "LocaleData[" +
- "firstDayOfWeek=" + firstDayOfWeek + "," +
- "minimalDaysInFirstWeek=" + minimalDaysInFirstWeek + "," +
- "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 + "," +
- "shortTimeFormat=" + shortTimeFormat + "," +
- "fullDateFormat=" + fullDateFormat + "," +
- "longDateFormat=" + longDateFormat + "," +
- "mediumDateFormat=" + mediumDateFormat + "," +
- "shortDateFormat=" + shortDateFormat + "," +
- "zeroDigit=" + zeroDigit + "," +
- "digit=" + digit + "," +
- "decimalSeparator=" + decimalSeparator + "," +
- "groupingSeparator=" + groupingSeparator + "," +
- "patternSeparator=" + patternSeparator + "," +
- "percent=" + percent + "," +
- "perMill=" + perMill + "," +
- "monetarySeparator=" + monetarySeparator + "," +
- "minusSign=" + minusSign + "," +
- "exponentSeparator=" + exponentSeparator + "," +
- "infinity=" + infinity + "," +
- "NaN=" + NaN + "," +
- "currencySymbol=" + currencySymbol + "," +
- "internationalCurrencySymbol=" + internationalCurrencySymbol + "," +
- "numberPattern=" + numberPattern + "," +
- "integerPattern=" + integerPattern + "," +
- "currencyPattern=" + currencyPattern + "," +
- "percentPattern=" + percentPattern + "]";
- }
-
- private void overrideWithDataFrom(LocaleData overrides) {
- if (overrides.firstDayOfWeek != null) {
- firstDayOfWeek = overrides.firstDayOfWeek;
- }
- if (overrides.minimalDaysInFirstWeek != null) {
- minimalDaysInFirstWeek = overrides.minimalDaysInFirstWeek;
- }
- if (overrides.amPm != null) {
- amPm = overrides.amPm;
- }
- if (overrides.eras != null) {
- eras = overrides.eras;
- }
- if (overrides.longMonthNames != null) {
- longMonthNames = overrides.longMonthNames;
- }
- if (overrides.shortMonthNames != null) {
- shortMonthNames = overrides.shortMonthNames;
- }
- if (overrides.longWeekdayNames != null) {
- longWeekdayNames = overrides.longWeekdayNames;
- }
- if (overrides.shortWeekdayNames != null) {
- shortWeekdayNames = overrides.shortWeekdayNames;
- }
- if (overrides.fullTimeFormat != null) {
- fullTimeFormat = overrides.fullTimeFormat;
- }
- if (overrides.longTimeFormat != null) {
- longTimeFormat = overrides.longTimeFormat;
- }
- if (overrides.mediumTimeFormat != null) {
- mediumTimeFormat = overrides.mediumTimeFormat;
- }
- if (overrides.shortTimeFormat != null) {
- shortTimeFormat = overrides.shortTimeFormat;
- }
- if (overrides.fullDateFormat != null) {
- fullDateFormat = overrides.fullDateFormat;
- }
- if (overrides.longDateFormat != null) {
- longDateFormat = overrides.longDateFormat;
- }
- if (overrides.mediumDateFormat != null) {
- mediumDateFormat = overrides.mediumDateFormat;
- }
- if (overrides.shortDateFormat != null) {
- shortDateFormat = overrides.shortDateFormat;
- }
- if (overrides.zeroDigit != '\0') {
- zeroDigit = overrides.zeroDigit;
- }
- if (overrides.digit != '\0') {
- digit = overrides.digit;
- }
- if (overrides.decimalSeparator != '\0') {
- decimalSeparator = overrides.decimalSeparator;
- }
- if (overrides.groupingSeparator != '\0') {
- groupingSeparator = overrides.groupingSeparator;
- }
- if (overrides.patternSeparator != '\0') {
- patternSeparator = overrides.patternSeparator;
- }
- if (overrides.percent != '\0') {
- percent = overrides.percent;
- }
- if (overrides.perMill != '\0') {
- perMill = overrides.perMill;
- }
- if (overrides.monetarySeparator != '\0') {
- monetarySeparator = overrides.monetarySeparator;
- }
- if (overrides.minusSign != '\0') {
- minusSign = overrides.minusSign;
- }
- if (overrides.exponentSeparator != null) {
- exponentSeparator = overrides.exponentSeparator;
- }
- if (overrides.NaN != null) {
- NaN = overrides.NaN;
- }
- if (overrides.infinity != null) {
- infinity = overrides.infinity;
- }
- if (overrides.currencySymbol != null) {
- currencySymbol = overrides.currencySymbol;
- }
- if (overrides.internationalCurrencySymbol != null) {
- internationalCurrencySymbol = overrides.internationalCurrencySymbol;
- }
- if (overrides.numberPattern != null) {
- numberPattern = overrides.numberPattern;
- }
- if (overrides.integerPattern != null) {
- integerPattern = overrides.integerPattern;
- }
- if (overrides.currencyPattern != null) {
- currencyPattern = overrides.currencyPattern;
- }
- if (overrides.percentPattern != null) {
- percentPattern = overrides.percentPattern;
- }
- }
-
- public String getDateFormat(int style) {
- switch (style) {
- case DateFormat.SHORT:
- return shortDateFormat;
- case DateFormat.MEDIUM:
- return mediumDateFormat;
- case DateFormat.LONG:
- return longDateFormat;
- case DateFormat.FULL:
- return fullDateFormat;
- }
- throw new AssertionError();
- }
-
- public String getTimeFormat(int style) {
- switch (style) {
- case DateFormat.SHORT:
- return shortTimeFormat;
- case DateFormat.MEDIUM:
- return mediumTimeFormat;
- case DateFormat.LONG:
- return longTimeFormat;
- case DateFormat.FULL:
- return fullTimeFormat;
- }
- throw new AssertionError();
- }
-
- private static LocaleData initLocaleData(Locale locale) {
- LocaleData localeData = new LocaleData();
- if (!ICU.initLocaleDataImpl(locale.toString(), localeData)) {
- throw new AssertionError("couldn't initialize LocaleData for locale " + locale);
- }
- if (localeData.fullTimeFormat != null) {
- // There are some full time format patterns in ICU that use the pattern character 'v'.
- // Java doesn't accept this, so we replace it with 'z' which has about the same result
- // as 'v', the timezone name.
- // 'v' -> "PT", 'z' -> "PST", v is the generic timezone and z the standard tz
- // "vvvv" -> "Pacific Time", "zzzz" -> "Pacific Standard Time"
- localeData.fullTimeFormat = localeData.fullTimeFormat.replace('v', 'z');
- }
- if (localeData.numberPattern != null) {
- // The number pattern might contain positive and negative subpatterns. Arabic, for
- // example, might look like "#,##0.###;#,##0.###-" because the minus sign should be
- // written last. Macedonian supposedly looks something like "#,##0.###;(#,##0.###)".
- // (The negative subpattern is optional, though, and not present in most locales.)
- // By only swallowing '#'es and ','s after the '.', we ensure that we don't
- // accidentally eat too much.
- localeData.integerPattern = localeData.numberPattern.replaceAll("\\.[#,]*", "");
- }
- return localeData;
- }
-}
diff --git a/icu/src/main/native/BidiWrapper.cpp b/icu/src/main/native/BidiWrapper.cpp
deleted file mode 100644
index 03efa92..0000000
--- a/icu/src/main/native/BidiWrapper.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#define LOG_TAG "BidiWrapper"
-
-#include <JNIHelp.h>
-#include "ErrorCode.h"
-#include "UniquePtr.h"
-#include "unicode/ubidi.h"
-#include <stdlib.h>
-#include <string.h>
-
-struct BiDiData {
- BiDiData(UBiDi* biDi) : mBiDi(biDi), mEmbeddingLevels(NULL) {
- }
-
- ~BiDiData() {
- ubidi_close(mBiDi);
- }
-
- UBiDiLevel* embeddingLevels() {
- return reinterpret_cast<UBiDiLevel*>(&mEmbeddingLevels[0]);
- }
-
- void setEmbeddingLevels(jbyte* newEmbeddingLevels) {
- mEmbeddingLevels.reset(newEmbeddingLevels);
- }
-
- UBiDi* uBiDi() {
- return mBiDi;
- }
-
-private:
- UBiDi* mBiDi;
- UniquePtr<jbyte[]> mEmbeddingLevels;
-
- // Disallow copy and assignment.
- BiDiData(const BiDiData&);
- void operator=(const BiDiData&);
-};
-
-static BiDiData* biDiData(jlong ptr) {
- return reinterpret_cast<BiDiData*>(static_cast<uintptr_t>(ptr));
-}
-
-static UBiDi* uBiDi(jlong ptr) {
- return reinterpret_cast<BiDiData*>(static_cast<uintptr_t>(ptr))->uBiDi();
-}
-
-static jlong BidiWrapper_ubidi_open(JNIEnv* env, jclass) {
- return reinterpret_cast<uintptr_t>(new BiDiData(ubidi_open()));
-}
-
-static void BidiWrapper_ubidi_close(JNIEnv* env, jclass, jlong ptr) {
- delete biDiData(ptr);
-}
-
-static void BidiWrapper_ubidi_setPara(JNIEnv* env, jclass, jlong ptr, jcharArray text, jint length, jbyte paraLevel, jbyteArray newEmbeddingLevels) {
- BiDiData* data = biDiData(ptr);
- // Copy the new embedding levels from the Java heap to the native heap.
- if (newEmbeddingLevels != NULL) {
- jbyte* dst;
- data->setEmbeddingLevels(dst = new jbyte[length]);
- env->GetByteArrayRegion(newEmbeddingLevels, 0, length, dst);
- } else {
- data->setEmbeddingLevels(NULL);
- }
- UErrorCode err = U_ZERO_ERROR;
- jchar* chars = env->GetCharArrayElements(text, NULL);
- ubidi_setPara(data->uBiDi(), chars, length, paraLevel, data->embeddingLevels(), &err);
- env->ReleaseCharArrayElements(text, chars, 0);
- icu4jni_error(env, err);
-}
-
-static jlong BidiWrapper_ubidi_setLine(JNIEnv* env, jclass, jlong ptr, jint start, jint limit) {
- UErrorCode err = U_ZERO_ERROR;
- UBiDi* sized = ubidi_openSized(limit - start, 0, &err);
- if (icu4jni_error(env, err) != FALSE) {
- return 0;
- }
- UniquePtr<BiDiData> lineData(new BiDiData(sized));
- ubidi_setLine(uBiDi(ptr), start, limit, lineData->uBiDi(), &err);
- icu4jni_error(env, err);
- return reinterpret_cast<uintptr_t>(lineData.release());
-}
-
-static jint BidiWrapper_ubidi_getDirection(JNIEnv * env, jclass clazz, jlong ptr) {
- return ubidi_getDirection(uBiDi(ptr));
-}
-
-static jint BidiWrapper_ubidi_getLength(JNIEnv* env, jclass, jlong ptr) {
- return ubidi_getLength(uBiDi(ptr));
-}
-
-static jbyte BidiWrapper_ubidi_getParaLevel(JNIEnv* env, jclass, jlong ptr) {
- return ubidi_getParaLevel(uBiDi(ptr));
-}
-
-static jbyteArray BidiWrapper_ubidi_getLevels(JNIEnv* env, jclass, jlong ptr) {
- UErrorCode err = U_ZERO_ERROR;
- const UBiDiLevel* levels = ubidi_getLevels(uBiDi(ptr), &err);
- if (icu4jni_error(env, err)) {
- return NULL;
- }
- int len = ubidi_getLength(uBiDi(ptr));
- jbyteArray result = env->NewByteArray(len);
- env->SetByteArrayRegion(result, 0, len, reinterpret_cast<const jbyte*>(levels));
- return result;
-}
-
-static jint BidiWrapper_ubidi_countRuns(JNIEnv* env, jclass, jlong ptr) {
- UErrorCode err = U_ZERO_ERROR;
- int count = ubidi_countRuns(uBiDi(ptr), &err);
- icu4jni_error(env, err);
- return count;
-}
-
-static jobjectArray BidiWrapper_ubidi_getRuns(JNIEnv* env, jclass, jlong ptr) {
- UBiDi* ubidi = uBiDi(ptr);
- UErrorCode err = U_ZERO_ERROR;
- int runCount = ubidi_countRuns(ubidi, &err);
- if (icu4jni_error(env, err)) {
- return NULL;
- }
- jclass bidiRunClass = env->FindClass("org/apache/harmony/text/BidiRun");
- jmethodID bidiRunConstructor = env->GetMethodID(bidiRunClass, "<init>", "(III)V");
- jobjectArray runs = env->NewObjectArray(runCount, bidiRunClass, NULL);
- UBiDiLevel level = 0;
- int start = 0;
- int limit = 0;
- for (int i = 0; i < runCount; ++i) {
- ubidi_getLogicalRun(ubidi, start, &limit, &level);
- jobject run = env->NewObject(bidiRunClass, bidiRunConstructor, start, limit, level);
- env->SetObjectArrayElement(runs, i, run);
- start = limit;
- }
- return runs;
-}
-
-static jintArray BidiWrapper_ubidi_reorderVisual(JNIEnv* env, jclass, jbyteArray levels, jint length) {
- UniquePtr<int[]> local_indexMap(new int[length]);
- jbyte* local_levelBytes = env->GetByteArrayElements(levels, NULL);
- UBiDiLevel* local_levels = reinterpret_cast<UBiDiLevel*>(local_levelBytes);
- ubidi_reorderVisual(local_levels, length, &local_indexMap[0]);
- jintArray result = env->NewIntArray(length);
- env->SetIntArrayRegion(result, 0, length, &local_indexMap[0]);
- env->ReleaseByteArrayElements(levels, local_levelBytes, 0);
- return result;
-}
-
-static JNINativeMethod gMethods[] = {
- { "ubidi_close", "(J)V", (void*) BidiWrapper_ubidi_close },
- { "ubidi_countRuns", "(J)I", (void*) BidiWrapper_ubidi_countRuns },
- { "ubidi_getDirection", "(J)I", (void*) BidiWrapper_ubidi_getDirection },
- { "ubidi_getLength", "(J)I", (void*) BidiWrapper_ubidi_getLength },
- { "ubidi_getLevels", "(J)[B", (void*) BidiWrapper_ubidi_getLevels },
- { "ubidi_getParaLevel", "(J)B", (void*) BidiWrapper_ubidi_getParaLevel },
- { "ubidi_getRuns", "(J)[Lorg/apache/harmony/text/BidiRun;", (void*) BidiWrapper_ubidi_getRuns },
- { "ubidi_open", "()J", (void*) BidiWrapper_ubidi_open },
- { "ubidi_reorderVisual", "([BI)[I", (void*) BidiWrapper_ubidi_reorderVisual },
- { "ubidi_setLine", "(JII)J", (void*) BidiWrapper_ubidi_setLine },
- { "ubidi_setPara", "(J[CIB[B)V", (void*) BidiWrapper_ubidi_setPara },
-};
-int register_org_apache_harmony_text_BidiWrapper(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "org/apache/harmony/text/BidiWrapper",
- gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/ErrorCode.cpp b/icu/src/main/native/ErrorCode.cpp
deleted file mode 100644
index a9d0691..0000000
--- a/icu/src/main/native/ErrorCode.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-#include "ErrorCode.h"
-#include "JNIHelp.h"
-
-/**
-* Checks if an error has occurred, throwing a suitable exception if so.
-* @param env JNI environment
-* @param errorCode code to determine if it is an error
-* @return 0 if errorCode is not an error, 1 if errorCode is an error, but the
-* creation of the exception to be thrown fails
- * @exception thrown if errorCode represents an error
-*/
-UBool icu4jni_error(JNIEnv *env, UErrorCode errorCode)
-{
- const char* message = u_errorName(errorCode);
- if (errorCode <= U_ZERO_ERROR || errorCode >= U_ERROR_LIMIT) {
- return 0;
- }
-
- switch (errorCode) {
- case U_ILLEGAL_ARGUMENT_ERROR:
- return jniThrowException(env, "java/lang/IllegalArgumentException", message);
- case U_INDEX_OUTOFBOUNDS_ERROR:
- case U_BUFFER_OVERFLOW_ERROR:
- return jniThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", message);
- case U_UNSUPPORTED_ERROR:
- return jniThrowException(env, "java/lang/UnsupportedOperationException", message);
- default:
- return jniThrowRuntimeException(env, message);
- }
-}
diff --git a/icu/src/main/native/ErrorCode.h b/icu/src/main/native/ErrorCode.h
deleted file mode 100644
index e42a519..0000000
--- a/icu/src/main/native/ErrorCode.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*******************************************************************************
-*/
-
-#ifndef ERRORCODE_H
-#define ERRORCODE_H
-
-#include <jni.h>
-#include "unicode/utypes.h"
-#include "unicode/putil.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
-* Checks if an error has occured.
-* Throws a generic Java RuntimeException if an error has occured.
-* @param env JNI environment variable
-* @param errorcode code to determine if it is an erro
-* @return 0 if errorcode is not an error, 1 if errorcode is an error, but the
-* creation of the exception to be thrown fails
-* @exception thrown if errorcode represents an error
-*/
-UBool icu4jni_error(JNIEnv *env, UErrorCode errorcode);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/icu/src/main/native/ICU.cpp b/icu/src/main/native/ICU.cpp
deleted file mode 100644
index 4f08513..0000000
--- a/icu/src/main/native/ICU.cpp
+++ /dev/null
@@ -1,710 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "ICU"
-
-#include "JNIHelp.h"
-#include "ScopedUtfChars.h"
-#include "UniquePtr.h"
-#include "cutils/log.h"
-#include "unicode/numfmt.h"
-#include "unicode/locid.h"
-#include "unicode/ubrk.h"
-#include "unicode/ucal.h"
-#include "unicode/ucol.h"
-#include "unicode/udat.h"
-#include "unicode/gregocal.h"
-#include "unicode/ucurr.h"
-#include "unicode/calendar.h"
-#include "unicode/datefmt.h"
-#include "unicode/dtfmtsym.h"
-#include "unicode/decimfmt.h"
-#include "unicode/dcfmtsym.h"
-#include "unicode/uclean.h"
-#include "unicode/smpdtfmt.h"
-#include "unicode/strenum.h"
-#include "unicode/ustring.h"
-#include "unicode/timezone.h"
-#include "ErrorCode.h"
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <sys/time.h>
-
-static jclass string_class;
-
-class ScopedResourceBundle {
-public:
- ScopedResourceBundle(UResourceBundle* bundle) : mBundle(bundle) {
- }
-
- ~ScopedResourceBundle() {
- if (mBundle != NULL) {
- ures_close(mBundle);
- }
- }
-
- UResourceBundle* get() {
- return mBundle;
- }
-
-private:
- UResourceBundle* mBundle;
-
- // Disallow copy and assignment.
- ScopedResourceBundle(const ScopedResourceBundle&);
- void operator=(const ScopedResourceBundle&);
-};
-
-static Locale getLocale(JNIEnv* env, jstring localeName) {
- return Locale::createFromName(ScopedUtfChars(env, localeName).c_str());
-}
-
-static jint getCurrencyFractionDigitsNative(JNIEnv* env, jclass, jstring currencyCode) {
- UErrorCode status = U_ZERO_ERROR;
- UniquePtr<NumberFormat> fmt(NumberFormat::createCurrencyInstance(status));
- if (U_FAILURE(status)) {
- return -1;
- }
- const jchar* cCode = env->GetStringChars(currencyCode, NULL);
- fmt->setCurrency(cCode, status);
- env->ReleaseStringChars(currencyCode, cCode);
- if (U_FAILURE(status)) {
- return -1;
- }
- // for CurrencyFormats the minimum and maximum fraction digits are the same.
- return fmt->getMinimumFractionDigits();
-}
-
-static jstring getCurrencyCodeNative(JNIEnv* env, jclass, jstring key) {
- UErrorCode status = U_ZERO_ERROR;
- ScopedResourceBundle supplData(ures_openDirect(NULL, "supplementalData", &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ScopedResourceBundle currencyMap(ures_getByKey(supplData.get(), "CurrencyMap", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- const char* keyChars = env->GetStringUTFChars(key, NULL);
- ScopedResourceBundle currency(ures_getByKey(currencyMap.get(), keyChars, NULL, &status));
- env->ReleaseStringUTFChars(key, keyChars);
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ScopedResourceBundle currencyElem(ures_getByIndex(currency.get(), 0, NULL, &status));
- if (U_FAILURE(status)) {
- return env->NewStringUTF("None");
- }
-
- // check if there is a 'to' date. If there is, the currency isn't used anymore.
- ScopedResourceBundle currencyTo(ures_getByKey(currencyElem.get(), "to", NULL, &status));
- if (!U_FAILURE(status)) {
- // return and let the caller throw an exception
- return NULL;
- }
- // We need to reset 'status'. It works like errno in that ICU doesn't set it
- // to U_ZERO_ERROR on success: it only touches it on error, and the test
- // above means it now holds a failure code.
- status = U_ZERO_ERROR;
-
- ScopedResourceBundle currencyId(ures_getByKey(currencyElem.get(), "id", NULL, &status));
- if (U_FAILURE(status)) {
- // No id defined for this country
- return env->NewStringUTF("None");
- }
-
- int length;
- const jchar* id = ures_getString(currencyId.get(), &length, &status);
- if (U_FAILURE(status) || length == 0) {
- return env->NewStringUTF("None");
- }
- return env->NewString(id, length);
-}
-
-static jstring getCurrencySymbolNative(JNIEnv* env, jclass, jstring locale, jstring currencyCode) {
- // LOGI("ENTER getCurrencySymbolNative");
-
- const char* locName = env->GetStringUTFChars(locale, NULL);
- UErrorCode status = U_ZERO_ERROR;
- ScopedResourceBundle root(ures_open(NULL, locName, &status));
- env->ReleaseStringUTFChars(locale, locName);
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ScopedResourceBundle currencies(ures_getByKey(root.get(), "Currencies", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- const char* currName = env->GetStringUTFChars(currencyCode, NULL);
- ScopedResourceBundle currencyElems(ures_getByKey(currencies.get(), currName, NULL, &status));
- env->ReleaseStringUTFChars(currencyCode, currName);
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- int currSymbL;
- const jchar* currSymbU = ures_getStringByIndex(currencyElems.get(), 0, &currSymbL, &status);
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- return (currSymbL == 0) ? NULL : env->NewString(currSymbU, currSymbL);
-}
-
-static jstring getDisplayCountryNative(JNIEnv* env, jclass, jstring targetLocale, jstring locale) {
-
- Locale loc = getLocale(env, locale);
- Locale targetLoc = getLocale(env, targetLocale);
-
- UnicodeString str;
- targetLoc.getDisplayCountry(loc, str);
- return env->NewString(str.getBuffer(), str.length());
-}
-
-static jstring getDisplayLanguageNative(JNIEnv* env, jclass, jstring targetLocale, jstring locale) {
-
- Locale loc = getLocale(env, locale);
- Locale targetLoc = getLocale(env, targetLocale);
-
- UnicodeString str;
- targetLoc.getDisplayLanguage(loc, str);
- return env->NewString(str.getBuffer(), str.length());
-}
-
-static jstring getDisplayVariantNative(JNIEnv* env, jclass, jstring targetLocale, jstring locale) {
- Locale loc = getLocale(env, locale);
- Locale targetLoc = getLocale(env, targetLocale);
- UnicodeString str;
- targetLoc.getDisplayVariant(loc, str);
- return env->NewString(str.getBuffer(), str.length());
-}
-
-static jstring getISO3CountryNative(JNIEnv* env, jclass, jstring locale) {
- Locale loc = getLocale(env, locale);
- return env->NewStringUTF(loc.getISO3Country());
-}
-
-static jstring getISO3LanguageNative(JNIEnv* env, jclass, jstring locale) {
- Locale loc = getLocale(env, locale);
- return env->NewStringUTF(loc.getISO3Language());
-}
-
-static jobjectArray toStringArray(JNIEnv* env, const char* const* strings) {
- size_t count = 0;
- while (strings[count] != NULL) {
- ++count;
- }
- jobjectArray result = env->NewObjectArray(count, string_class, NULL);
- for (size_t i = 0; i < count; ++i) {
- jstring s = env->NewStringUTF(strings[i]);
- env->SetObjectArrayElement(result, i, s);
- env->DeleteLocalRef(s);
- }
- return result;
-}
-
-static jobjectArray getISOCountriesNative(JNIEnv* env, jclass) {
- return toStringArray(env, Locale::getISOCountries());
-}
-
-static jobjectArray getISOLanguagesNative(JNIEnv* env, jclass) {
- return toStringArray(env, Locale::getISOLanguages());
-}
-
-template <typename Counter, typename Getter>
-static jobjectArray getAvailableLocales(JNIEnv* env, Counter* counter, Getter* getter) {
- size_t count = (*counter)();
- jobjectArray result = env->NewObjectArray(count, string_class, NULL);
- for (size_t i = 0; i < count; ++i) {
- jstring s = env->NewStringUTF((*getter)(i));
- env->SetObjectArrayElement(result, i, s);
- env->DeleteLocalRef(s);
- }
- return result;
-}
-
-static jobjectArray getAvailableLocalesNative(JNIEnv* env, jclass) {
- return getAvailableLocales(env, uloc_countAvailable, uloc_getAvailable);
-}
-
-static jobjectArray getAvailableBreakIteratorLocalesNative(JNIEnv* env, jclass) {
- return getAvailableLocales(env, ubrk_countAvailable, ubrk_getAvailable);
-}
-
-static jobjectArray getAvailableCalendarLocalesNative(JNIEnv* env, jclass) {
- return getAvailableLocales(env, ucal_countAvailable, ucal_getAvailable);
-}
-
-static jobjectArray getAvailableCollatorLocalesNative(JNIEnv* env, jclass) {
- return getAvailableLocales(env, ucol_countAvailable, ucol_getAvailable);
-}
-
-static jobjectArray getAvailableDateFormatLocalesNative(JNIEnv* env, jclass) {
- return getAvailableLocales(env, udat_countAvailable, udat_getAvailable);
-}
-
-static jobjectArray getAvailableNumberFormatLocalesNative(JNIEnv* env, jclass) {
- return getAvailableLocales(env, unum_countAvailable, unum_getAvailable);
-}
-
-static TimeZone* timeZoneFromId(JNIEnv* env, jstring id) {
- const jchar* chars = env->GetStringChars(id, NULL);
- const UnicodeString zoneID(reinterpret_cast<const UChar*>(chars), env->GetStringLength(id));
- env->ReleaseStringChars(id, chars);
- return TimeZone::createTimeZone(zoneID);
-}
-
-static jstring formatDate(JNIEnv* env, const SimpleDateFormat& fmt, const UDate& when) {
- UnicodeString str;
- fmt.format(when, str);
- return env->NewString(str.getBuffer(), str.length());
-}
-
-static void getTimeZonesNative(JNIEnv* env, jclass, jobjectArray outerArray, jstring locale) {
- // get all timezone objects
- jobjectArray zoneIdArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 0);
- int count = env->GetArrayLength(zoneIdArray);
- TimeZone* zones[count];
- for(int i = 0; i < count; i++) {
- jstring id = (jstring) env->GetObjectArrayElement(zoneIdArray, i);
- zones[i] = timeZoneFromId(env, id);
- env->DeleteLocalRef(id);
- }
-
- Locale loc = getLocale(env, locale);
-
- UErrorCode status = U_ZERO_ERROR;
- UnicodeString longPattern("zzzz","");
- SimpleDateFormat longFormat(longPattern, loc, status);
- UnicodeString shortPattern("z","");
- SimpleDateFormat shortFormat(shortPattern, loc, status);
-
- jobjectArray longStdTimeArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 1);
- jobjectArray shortStdTimeArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 2);
- jobjectArray longDlTimeArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 3);
- jobjectArray shortDlTimeArray = (jobjectArray) env->GetObjectArrayElement(outerArray, 4);
-
- // 15th January 2008
- UDate date1 = 1203105600000.0;
- // 15th July 2008
- UDate date2 = 1218826800000.0;
-
- for (int i = 0; i < count; ++i) {
- TimeZone* tz = zones[i];
- longFormat.setTimeZone(*tz);
- shortFormat.setTimeZone(*tz);
-
- int32_t daylightOffset;
- int32_t rawOffset;
- tz->getOffset(date1, false, rawOffset, daylightOffset, status);
- UDate standardDate;
- UDate daylightSavingDate;
- if (daylightOffset != 0) {
- // The Timezone is reporting that we are in daylight time
- // for the winter date. The dates are for the wrong hemisphere,
- // swap them.
- standardDate = date2;
- daylightSavingDate = date1;
- } else {
- standardDate = date1;
- daylightSavingDate = date2;
- }
-
- jstring content = formatDate(env, shortFormat, daylightSavingDate);
- env->SetObjectArrayElement(shortDlTimeArray, i, content);
- env->DeleteLocalRef(content);
-
- content = formatDate(env, shortFormat, standardDate);
- env->SetObjectArrayElement(shortStdTimeArray, i, content);
- env->DeleteLocalRef(content);
-
- content = formatDate(env, longFormat, daylightSavingDate);
- env->SetObjectArrayElement(longDlTimeArray, i, content);
- env->DeleteLocalRef(content);
-
- content = formatDate(env, longFormat, standardDate);
- env->SetObjectArrayElement(longStdTimeArray, i, content);
- env->DeleteLocalRef(content);
-
- delete tz;
- }
-}
-
-static jstring getDisplayTimeZoneNative(JNIEnv* env, jclass, jstring zoneId, jboolean isDST, jint style, jstring localeId) {
- UniquePtr<TimeZone> zone(timeZoneFromId(env, zoneId));
- Locale locale = getLocale(env, localeId);
- // Try to get the display name of the TimeZone according to the Locale
- UnicodeString displayName;
- zone->getDisplayName((UBool)isDST, (style == 0 ? TimeZone::SHORT : TimeZone::LONG), locale, displayName);
- return env->NewString(displayName.getBuffer(), displayName.length());
-}
-
-static bool getDayIntVector(JNIEnv* env, UResourceBundle* gregorian, int* values) {
- // get the First day of week and the minimal days in first week numbers
- UErrorCode status = U_ZERO_ERROR;
- ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "DateTimeElements", NULL, &status));
- if (U_FAILURE(status)) {
- return false;
- }
-
- int intVectSize;
- const int* result = ures_getIntVector(gregorianElems.get(), &intVectSize, &status);
- if (U_FAILURE(status) || intVectSize != 2) {
- return false;
- }
-
- values[0] = result[0];
- values[1] = result[1];
- return true;
-}
-
-static jobjectArray getAmPmMarkers(JNIEnv* env, UResourceBundle* gregorian) {
- UErrorCode status = U_ZERO_ERROR;
- ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "AmPmMarkers", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ures_resetIterator(gregorianElems.get());
-
- int lengthAm, lengthPm;
- const jchar* am = ures_getStringByIndex(gregorianElems.get(), 0, &lengthAm, &status);
- const jchar* pm = ures_getStringByIndex(gregorianElems.get(), 1, &lengthPm, &status);
-
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- jobjectArray amPmMarkers = env->NewObjectArray(2, string_class, NULL);
- jstring amU = env->NewString(am, lengthAm);
- env->SetObjectArrayElement(amPmMarkers, 0, amU);
- env->DeleteLocalRef(amU);
- jstring pmU = env->NewString(pm, lengthPm);
- env->SetObjectArrayElement(amPmMarkers, 1, pmU);
- env->DeleteLocalRef(pmU);
-
- return amPmMarkers;
-}
-
-static jobjectArray getEras(JNIEnv* env, UResourceBundle* gregorian) {
- UErrorCode status = U_ZERO_ERROR;
- ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "eras", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ScopedResourceBundle eraElems(ures_getByKey(gregorianElems.get(), "abbreviated", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- int eraCount = ures_getSize(eraElems.get());
- jobjectArray eras = env->NewObjectArray(eraCount, string_class, NULL);
-
- ures_resetIterator(eraElems.get());
- for (int i = 0; i < eraCount; ++i) {
- int eraLength;
- const jchar* era = ures_getStringByIndex(eraElems.get(), i, &eraLength, &status);
- if (U_FAILURE(status)) {
- return NULL;
- }
- jstring eraU = env->NewString(era, eraLength);
- env->SetObjectArrayElement(eras, i, eraU);
- env->DeleteLocalRef(eraU);
- }
- return eras;
-}
-
-static jobjectArray getMonthNames(JNIEnv* env, UResourceBundle* gregorian, bool longNames) {
- UErrorCode status = U_ZERO_ERROR;
- ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "monthNames", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ScopedResourceBundle monthNameElems(ures_getByKey(gregorianElems.get(), "format", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ScopedResourceBundle monthNameElemsFormat(ures_getByKey(monthNameElems.get(), longNames ? "wide" : "abbreviated", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ures_resetIterator(monthNameElemsFormat.get());
- int monthCount = ures_getSize(monthNameElemsFormat.get());
- // the array length is +1 because the harmony locales had an empty string at the end of their month name array
- jobjectArray months = env->NewObjectArray(monthCount + 1, string_class, NULL);
- for (int i = 0; i < monthCount; ++i) {
- int monthNameLength;
- const jchar* month = ures_getStringByIndex(monthNameElemsFormat.get(), i, &monthNameLength, &status);
- if (U_FAILURE(status)) {
- return NULL;
- }
- jstring monthU = env->NewString(month, monthNameLength);
- env->SetObjectArrayElement(months, i, monthU);
- env->DeleteLocalRef(monthU);
- }
-
- jstring monthU = env->NewStringUTF("");
- env->SetObjectArrayElement(months, monthCount, monthU);
- env->DeleteLocalRef(monthU);
-
- return months;
-}
-
-static jobjectArray getLongMonthNames(JNIEnv* env, UResourceBundle* gregorian) {
- return getMonthNames(env, gregorian, true);
-}
-
-static jobjectArray getShortMonthNames(JNIEnv* env, UResourceBundle* gregorian) {
- return getMonthNames(env, gregorian, false);
-}
-
-static jobjectArray getWeekdayNames(JNIEnv* env, UResourceBundle* gregorian, bool longNames) {
- UErrorCode status = U_ZERO_ERROR;
- ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "dayNames", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ScopedResourceBundle dayNameElems(ures_getByKey(gregorianElems.get(), "format", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ScopedResourceBundle dayNameElemsFormat(ures_getByKey(dayNameElems.get(), longNames ? "wide" : "abbreviated", NULL, &status));
- if (U_FAILURE(status)) {
- return NULL;
- }
-
- ures_resetIterator(dayNameElemsFormat.get());
- int dayCount = ures_getSize(dayNameElemsFormat.get());
- jobjectArray weekdays = env->NewObjectArray(dayCount + 1, string_class, NULL);
- // first entry in the weekdays array is an empty string
- env->SetObjectArrayElement(weekdays, 0, env->NewStringUTF(""));
- for(int i = 0; i < dayCount; i++) {
- int dayNameLength;
- const jchar* day = ures_getStringByIndex(dayNameElemsFormat.get(), i, &dayNameLength, &status);
- if(U_FAILURE(status)) {
- return NULL;
- }
- jstring dayU = env->NewString(day, dayNameLength);
- env->SetObjectArrayElement(weekdays, i + 1, dayU);
- env->DeleteLocalRef(dayU);
- }
- return weekdays;
-}
-
-static jobjectArray getLongWeekdayNames(JNIEnv* env, UResourceBundle* gregorian) {
- return getWeekdayNames(env, gregorian, true);
-}
-
-static jobjectArray getShortWeekdayNames(JNIEnv* env, UResourceBundle* gregorian) {
- return getWeekdayNames(env, gregorian, false);
-}
-
-static jstring getIntCurrencyCode(JNIEnv* env, jstring locale) {
- ScopedUtfChars localeChars(env, locale);
-
- // Extract the 2-character country name.
- if (strlen(localeChars.c_str()) < 5) {
- return NULL;
- }
- if (localeChars[3] < 'A' || localeChars[3] > 'Z' || localeChars[4] < 'A' || localeChars[4] > 'Z') {
- return NULL;
- }
-
- char country[3] = { localeChars[3], localeChars[4], 0 };
- return getCurrencyCodeNative(env, NULL, env->NewStringUTF(country));
-}
-
-static void setIntegerField(JNIEnv* env, jobject obj, const char* fieldName, int value) {
- // Convert our int to a java.lang.Integer.
- // TODO: switch to Integer.valueOf, add error checking.
- jclass integerClass = env->FindClass("java/lang/Integer");
- jmethodID constructor = env->GetMethodID(integerClass, "<init>", "(I)V");
- jobject integerValue = env->NewObject(integerClass, constructor, value);
- // Set the field.
- jclass localeDataClass = env->FindClass("com/ibm/icu4jni/util/LocaleData");
- jfieldID fid = env->GetFieldID(localeDataClass, fieldName, "Ljava/lang/Integer;");
- env->SetObjectField(obj, fid, integerValue);
-}
-
-static void setStringField(JNIEnv* env, jobject obj, const char* fieldName, jstring value) {
- jclass localeDataClass = env->FindClass("com/ibm/icu4jni/util/LocaleData");
- jfieldID fid = env->GetFieldID(localeDataClass, fieldName, "Ljava/lang/String;");
- env->SetObjectField(obj, fid, value);
-}
-
-static void setStringArrayField(JNIEnv* env, jobject obj, const char* fieldName, jobjectArray value) {
- jclass localeDataClass = env->FindClass("com/ibm/icu4jni/util/LocaleData");
- jfieldID fid = env->GetFieldID(localeDataClass, fieldName, "[Ljava/lang/String;");
- env->SetObjectField(obj, fid, value);
-}
-
-static void setStringField(JNIEnv* env, jobject obj, const char* fieldName, UResourceBundle* bundle, int index) {
- UErrorCode status = U_ZERO_ERROR;
- int charCount;
- const UChar* chars = ures_getStringByIndex(bundle, index, &charCount, &status);
- if (U_SUCCESS(status)) {
- setStringField(env, obj, fieldName, env->NewString(chars, charCount));
- } else {
- LOGE("Error setting String field %s from ICU resource: %s", fieldName, u_errorName(status));
- }
-}
-
-static void setCharField(JNIEnv* env, jobject obj, const char* fieldName, UResourceBundle* bundle, int index) {
- UErrorCode status = U_ZERO_ERROR;
- int charCount;
- const UChar* chars = ures_getStringByIndex(bundle, index, &charCount, &status);
- if (U_SUCCESS(status)) {
- jclass localeDataClass = env->FindClass("com/ibm/icu4jni/util/LocaleData");
- jfieldID fid = env->GetFieldID(localeDataClass, fieldName, "C");
- env->SetCharField(obj, fid, chars[0]);
- } else {
- LOGE("Error setting char field %s from ICU resource: %s", fieldName, u_errorName(status));
- }
-}
-
-static jboolean initLocaleDataImpl(JNIEnv* env, jclass, jstring locale, jobject localeData) {
- const char* loc = env->GetStringUTFChars(locale, NULL);
- UErrorCode status = U_ZERO_ERROR;
- ScopedResourceBundle root(ures_openU(NULL, loc, &status));
- env->ReleaseStringUTFChars(locale, loc);
- if (U_FAILURE(status)) {
- LOGE("Error getting ICU resource bundle: %s", u_errorName(status));
- status = U_ZERO_ERROR;
- return JNI_FALSE;
- }
-
- ScopedResourceBundle calendar(ures_getByKey(root.get(), "calendar", NULL, &status));
- if (U_FAILURE(status)) {
- LOGE("Error getting ICU calendar resource bundle: %s", u_errorName(status));
- return JNI_FALSE;
- }
-
- ScopedResourceBundle gregorian(ures_getByKey(calendar.get(), "gregorian", NULL, &status));
- if (U_FAILURE(status)) {
- LOGE("Error getting ICU gregorian resource bundle: %s", u_errorName(status));
- return JNI_FALSE;
- }
-
- int firstDayVals[2];
- if (getDayIntVector(env, gregorian.get(), firstDayVals)) {
- setIntegerField(env, localeData, "firstDayOfWeek", firstDayVals[0]);
- setIntegerField(env, localeData, "minimalDaysInFirstWeek", firstDayVals[1]);
- }
-
- setStringArrayField(env, localeData, "amPm", getAmPmMarkers(env, gregorian.get()));
- setStringArrayField(env, localeData, "eras", getEras(env, gregorian.get()));
-
- setStringArrayField(env, localeData, "longMonthNames", getLongMonthNames(env, gregorian.get()));
- setStringArrayField(env, localeData, "shortMonthNames", getShortMonthNames(env, gregorian.get()));
- setStringArrayField(env, localeData, "longWeekdayNames", getLongWeekdayNames(env, gregorian.get()));
- setStringArrayField(env, localeData, "shortWeekdayNames", getShortWeekdayNames(env, gregorian.get()));
-
- ScopedResourceBundle gregorianElems(ures_getByKey(gregorian.get(), "DateTimePatterns", NULL, &status));
- if (U_SUCCESS(status)) {
- setStringField(env, localeData, "fullTimeFormat", gregorianElems.get(), 0);
- setStringField(env, localeData, "longTimeFormat", gregorianElems.get(), 1);
- setStringField(env, localeData, "mediumTimeFormat", gregorianElems.get(), 2);
- setStringField(env, localeData, "shortTimeFormat", gregorianElems.get(), 3);
- setStringField(env, localeData, "fullDateFormat", gregorianElems.get(), 4);
- setStringField(env, localeData, "longDateFormat", gregorianElems.get(), 5);
- setStringField(env, localeData, "mediumDateFormat", gregorianElems.get(), 6);
- setStringField(env, localeData, "shortDateFormat", gregorianElems.get(), 7);
- }
- status = U_ZERO_ERROR;
-
- ScopedResourceBundle numberElements(ures_getByKey(root.get(), "NumberElements", NULL, &status));
- if (U_SUCCESS(status) && ures_getSize(numberElements.get()) >= 11) {
- setCharField(env, localeData, "zeroDigit", numberElements.get(), 4);
- setCharField(env, localeData, "digit", numberElements.get(), 5);
- setCharField(env, localeData, "decimalSeparator", numberElements.get(), 0);
- setCharField(env, localeData, "groupingSeparator", numberElements.get(), 1);
- setCharField(env, localeData, "patternSeparator", numberElements.get(), 2);
- setCharField(env, localeData, "percent", numberElements.get(), 3);
- setCharField(env, localeData, "perMill", numberElements.get(), 8);
- setCharField(env, localeData, "monetarySeparator", numberElements.get(), 0);
- setCharField(env, localeData, "minusSign", numberElements.get(), 6);
- setStringField(env, localeData, "exponentSeparator", numberElements.get(), 7);
- setStringField(env, localeData, "infinity", numberElements.get(), 9);
- setStringField(env, localeData, "NaN", numberElements.get(), 10);
- }
- status = U_ZERO_ERROR;
-
- jstring internationalCurrencySymbol = getIntCurrencyCode(env, locale);
- jstring currencySymbol = NULL;
- if (internationalCurrencySymbol != NULL) {
- currencySymbol = getCurrencySymbolNative(env, NULL, locale, internationalCurrencySymbol);
- } else {
- internationalCurrencySymbol = env->NewStringUTF("XXX");
- }
- if (currencySymbol == NULL) {
- // This is the UTF-8 encoding of U+00A4 (CURRENCY SIGN).
- currencySymbol = env->NewStringUTF("\xc2\xa4");
- }
- setStringField(env, localeData, "currencySymbol", currencySymbol);
- setStringField(env, localeData, "internationalCurrencySymbol", internationalCurrencySymbol);
-
- ScopedResourceBundle numberPatterns(ures_getByKey(root.get(), "NumberPatterns", NULL, &status));
- if (U_SUCCESS(status) && ures_getSize(numberPatterns.get()) >= 3) {
- setStringField(env, localeData, "numberPattern", numberPatterns.get(), 0);
- setStringField(env, localeData, "currencyPattern", numberPatterns.get(), 1);
- setStringField(env, localeData, "percentPattern", numberPatterns.get(), 2);
- }
-
- return JNI_TRUE;
-}
-
-static JNINativeMethod gMethods[] = {
- {"getAvailableBreakIteratorLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableBreakIteratorLocalesNative},
- {"getAvailableCalendarLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableCalendarLocalesNative},
- {"getAvailableCollatorLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableCollatorLocalesNative},
- {"getAvailableDateFormatLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableDateFormatLocalesNative},
- {"getAvailableLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableLocalesNative},
- {"getAvailableNumberFormatLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableNumberFormatLocalesNative},
- {"getCurrencyCodeNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getCurrencyCodeNative},
- {"getCurrencyFractionDigitsNative", "(Ljava/lang/String;)I", (void*) getCurrencyFractionDigitsNative},
- {"getCurrencySymbolNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getCurrencySymbolNative},
- {"getDisplayCountryNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayCountryNative},
- {"getDisplayLanguageNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayLanguageNative},
- {"getDisplayTimeZoneNative", "(Ljava/lang/String;ZILjava/lang/String;)Ljava/lang/String;", (void*) getDisplayTimeZoneNative},
- {"getDisplayVariantNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayVariantNative},
- {"getISO3CountryNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getISO3CountryNative},
- {"getISO3LanguageNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getISO3LanguageNative},
- {"getISOCountriesNative", "()[Ljava/lang/String;", (void*) getISOCountriesNative},
- {"getISOLanguagesNative", "()[Ljava/lang/String;", (void*) getISOLanguagesNative},
- {"getTimeZonesNative", "([[Ljava/lang/String;Ljava/lang/String;)V", (void*) getTimeZonesNative},
- {"initLocaleDataImpl", "(Ljava/lang/String;Lcom/ibm/icu4jni/util/LocaleData;)Z", (void*) initLocaleDataImpl},
-};
-int register_com_ibm_icu4jni_util_Resources(JNIEnv* env) {
- jclass stringclass = env->FindClass("java/lang/String");
- if (stringclass == NULL) {
- return -1;
- }
- string_class = (jclass) env->NewGlobalRef(stringclass);
-
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/util/ICU", gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/NativeBreakIterator.cpp b/icu/src/main/native/NativeBreakIterator.cpp
deleted file mode 100644
index 0be7630..0000000
--- a/icu/src/main/native/NativeBreakIterator.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "NativeBreakIterator"
-
-#include "JNIHelp.h"
-#include "ErrorCode.h"
-#include "ScopedUtfChars.h"
-#include "unicode/ubrk.h"
-#include "unicode/putil.h"
-#include <stdlib.h>
-
-static jint getIterator(JNIEnv* env, jstring locale, UBreakIteratorType type) {
- UErrorCode status = U_ZERO_ERROR;
- ScopedUtfChars localeChars(env, locale);
- if (!localeChars.c_str()) {
- return 0;
- }
- UBreakIterator* it = ubrk_open(type, localeChars.c_str(), NULL, 0, &status);
- icu4jni_error(env, status);
- return reinterpret_cast<uintptr_t>(it);
-}
-
-static jint getCharacterInstanceImpl(JNIEnv* env, jclass clazz, jstring locale) {
- return getIterator(env, locale, UBRK_CHARACTER);
-}
-
-static jint getLineInstanceImpl(JNIEnv* env, jclass, jstring locale) {
- return getIterator(env, locale, UBRK_LINE);
-}
-
-static jint getSentenceInstanceImpl(JNIEnv* env, jclass, jstring locale) {
- return getIterator(env, locale, UBRK_SENTENCE);
-}
-
-static jint getWordInstanceImpl(JNIEnv* env, jclass, jstring locale) {
- return getIterator(env, locale, UBRK_WORD);
-}
-
-static UBreakIterator* breakIterator(jint address) {
- return reinterpret_cast<UBreakIterator*>(static_cast<uintptr_t>(address));
-}
-
-static void closeBreakIteratorImpl(JNIEnv* env, jclass, jint address) {
- ubrk_close(breakIterator(address));
-}
-
-static jint cloneImpl(JNIEnv* env, jclass, jint address) {
- UErrorCode status = U_ZERO_ERROR;
- jint bufferSize = U_BRK_SAFECLONE_BUFFERSIZE;
- UBreakIterator* it = ubrk_safeClone(breakIterator(address), NULL, &bufferSize, &status);
- icu4jni_error(env, status);
- return reinterpret_cast<uintptr_t>(it);
-}
-
-static void setTextImpl(JNIEnv* env, jclass, jint address, jstring text) {
- UErrorCode status = U_ZERO_ERROR;
- const UChar* chars = env->GetStringChars(text, NULL);
- ubrk_setText(breakIterator(address), chars, env->GetStringLength(text), &status);
- env->ReleaseStringChars(text, chars);
- icu4jni_error(env, status);
-}
-
-static jboolean isBoundaryImpl(JNIEnv*, jclass, jint address, jint offset) {
- return ubrk_isBoundary(breakIterator(address), offset);
-}
-
-static jint nextImpl(JNIEnv* env, jclass, jint address, jint n) {
- UBreakIterator* bi = breakIterator(address);
- if (n < 0) {
- while (n++ < -1) {
- ubrk_previous(bi);
- }
- return ubrk_previous(bi);
- } else if (n == 0) {
- return ubrk_current(bi);
- } else {
- while (n-- > 1) {
- ubrk_next(bi);
- }
- return ubrk_next(bi);
- }
- return -1;
-}
-
-static jint precedingImpl(JNIEnv*, jclass, jint address, jint offset) {
- return ubrk_preceding(breakIterator(address), offset);
-}
-
-static jint firstImpl(JNIEnv*, jclass, jint address) {
- return ubrk_first(breakIterator(address));
-}
-
-static jint followingImpl(JNIEnv*, jclass, jint address, jint offset) {
- return ubrk_following(breakIterator(address), offset);
-}
-
-static jint currentImpl(JNIEnv*, jclass, jint address) {
- return ubrk_current(breakIterator(address));
-}
-
-static jint previousImpl(JNIEnv*, jclass, jint address) {
- return ubrk_previous(breakIterator(address));
-}
-
-static jint lastImpl(JNIEnv*, jclass, jint address) {
- return ubrk_last(breakIterator(address));
-}
-
-static JNINativeMethod gMethods[] = {
- { "cloneImpl", "(I)I", (void*) cloneImpl },
- { "closeBreakIteratorImpl", "(I)V", (void*) closeBreakIteratorImpl },
- { "currentImpl", "(I)I", (void*) currentImpl },
- { "firstImpl", "(I)I", (void*) firstImpl },
- { "followingImpl", "(II)I", (void*) followingImpl },
- { "getCharacterInstanceImpl", "(Ljava/lang/String;)I", (void*) getCharacterInstanceImpl },
- { "getLineInstanceImpl", "(Ljava/lang/String;)I", (void*) getLineInstanceImpl },
- { "getSentenceInstanceImpl", "(Ljava/lang/String;)I", (void*) getSentenceInstanceImpl },
- { "getWordInstanceImpl", "(Ljava/lang/String;)I", (void*) getWordInstanceImpl },
- { "isBoundaryImpl", "(II)Z", (void*) isBoundaryImpl },
- { "lastImpl", "(I)I", (void*) lastImpl },
- { "nextImpl", "(II)I", (void*) nextImpl },
- { "precedingImpl", "(II)I", (void*) precedingImpl },
- { "previousImpl", "(I)I", (void*) previousImpl },
- { "setTextImpl", "(ILjava/lang/String;)V", (void*) setTextImpl },
-};
-int register_com_ibm_icu4jni_text_NativeBreakIterator(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeBreakIterator",
- gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/NativeCollation.cpp b/icu/src/main/native/NativeCollation.cpp
deleted file mode 100644
index 9a092e8..0000000
--- a/icu/src/main/native/NativeCollation.cpp
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-#define LOG_TAG "NativeCollation"
-
-#include "ErrorCode.h"
-#include "JNIHelp.h"
-#include "ScopedJavaUnicodeString.h"
-#include "ScopedUtfChars.h"
-#include "UniquePtr.h"
-#include "ucol_imp.h"
-#include "unicode/ucol.h"
-#include "unicode/ucoleitr.h"
-
-static UCollator* toCollator(jint address) {
- return reinterpret_cast<UCollator*>(static_cast<uintptr_t>(address));
-}
-
-static UCollationElements* toCollationElements(jint address) {
- return reinterpret_cast<UCollationElements*>(static_cast<uintptr_t>(address));
-}
-
-static void closeCollator(JNIEnv* env, jclass, jint address) {
- ucol_close(toCollator(address));
-}
-
-static void closeElements(JNIEnv* env, jclass, jint address) {
- ucol_closeElements(toCollationElements(address));
-}
-
-static jint compare(JNIEnv* env, jclass, jint address, jstring lhs0, jstring rhs0) {
- ScopedJavaUnicodeString lhs(env, lhs0);
- ScopedJavaUnicodeString rhs(env, rhs0);
- return ucol_strcoll(toCollator(address),
- lhs.unicodeString().getBuffer(), lhs.unicodeString().length(),
- rhs.unicodeString().getBuffer(), rhs.unicodeString().length());
-}
-
-static jint getAttribute(JNIEnv* env, jclass, jint address, jint type) {
- UErrorCode status = U_ZERO_ERROR;
- jint result = ucol_getAttribute(toCollator(address), (UColAttribute) type, &status);
- icu4jni_error(env, status);
- return result;
-}
-
-static jint getCollationElementIterator(JNIEnv* env, jclass, jint address, jstring source0) {
- ScopedJavaUnicodeString source(env, source0);
- UErrorCode status = U_ZERO_ERROR;
- UCollationElements* result = ucol_openElements(toCollator(address),
- source.unicodeString().getBuffer(), source.unicodeString().length(), &status);
- icu4jni_error(env, status);
- return static_cast<jint>(reinterpret_cast<uintptr_t>(result));
-}
-
-static jint getMaxExpansion(JNIEnv* env, jclass, jint address, jint order) {
- return ucol_getMaxExpansion(toCollationElements(address), order);
-}
-
-static jint getNormalization(JNIEnv* env, jclass, jint address) {
- UErrorCode status = U_ZERO_ERROR;
- jint result = ucol_getAttribute(toCollator(address), UCOL_NORMALIZATION_MODE, &status);
- icu4jni_error(env, status);
- return result;
-}
-
-static void setNormalization(JNIEnv* env, jclass, jint address, jint mode) {
- UErrorCode status = U_ZERO_ERROR;
- ucol_setAttribute(toCollator(address), UCOL_NORMALIZATION_MODE, UColAttributeValue(mode), &status);
- icu4jni_error(env, status);
-}
-
-static jint getOffset(JNIEnv* env, jclass, jint address) {
- return ucol_getOffset(toCollationElements(address));
-}
-
-static jstring getRules(JNIEnv* env, jclass, jint address) {
- int32_t length = 0;
- const UChar* rules = ucol_getRules(toCollator(address), &length);
- return env->NewString(rules, length);
-}
-
-static jbyteArray getSortKey(JNIEnv* env, jclass, jint address, jstring source0) {
- ScopedJavaUnicodeString source(env, source0);
- const UCollator* collator = toCollator(address);
- uint8_t byteArray[UCOL_MAX_BUFFER * 2];
- UniquePtr<uint8_t[]> largerByteArray;
- uint8_t *usedByteArray = byteArray;
- const UChar* chars = source.unicodeString().getBuffer();
- size_t charCount = source.unicodeString().length();
- size_t byteArraySize = ucol_getSortKey(collator, chars, charCount, usedByteArray, sizeof(byteArray) - 1);
- if (byteArraySize > sizeof(byteArray) - 1) {
- // didn't fit, try again with a larger buffer.
- largerByteArray.reset(new uint8_t[byteArraySize + 1]);
- usedByteArray = largerByteArray.get();
- byteArraySize = ucol_getSortKey(collator, chars, charCount, usedByteArray, byteArraySize);
- }
- if (byteArraySize == 0) {
- return NULL;
- }
- jbyteArray result = env->NewByteArray(byteArraySize);
- env->SetByteArrayRegion(result, 0, byteArraySize, reinterpret_cast<jbyte*>(usedByteArray));
- return result;
-}
-
-static jint next(JNIEnv* env, jclass, jint address) {
- UErrorCode status = U_ZERO_ERROR;
- jint result = ucol_next(toCollationElements(address), &status);
- icu4jni_error(env, status);
- return result;
-}
-
-static jint openCollator(JNIEnv* env, jclass, jstring localeName) {
- ScopedUtfChars localeChars(env, localeName);
- UErrorCode status = U_ZERO_ERROR;
- UCollator* c = ucol_open(localeChars.c_str(), &status);
- icu4jni_error(env, status);
- return static_cast<jint>(reinterpret_cast<uintptr_t>(c));
-}
-
-static jint openCollatorFromRules(JNIEnv* env, jclass, jstring rules0, jint mode, jint strength) {
- ScopedJavaUnicodeString rules(env, rules0);
- UErrorCode status = U_ZERO_ERROR;
- UCollator* c = ucol_openRules(rules.unicodeString().getBuffer(), rules.unicodeString().length(),
- UColAttributeValue(mode), UCollationStrength(strength), NULL, &status);
- icu4jni_error(env, status);
- return static_cast<jint>(reinterpret_cast<uintptr_t>(c));
-}
-
-static jint previous(JNIEnv* env, jclass, jint address) {
- UErrorCode status = U_ZERO_ERROR;
- jint result = ucol_previous(toCollationElements(address), &status);
- icu4jni_error(env, status);
- return result;
-}
-
-static void reset(JNIEnv* env, jclass, jint address) {
- ucol_reset(toCollationElements(address));
-}
-
-static jint safeClone(JNIEnv* env, jclass, jint address) {
- UErrorCode status = U_ZERO_ERROR;
- jint bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
- UCollator* c = ucol_safeClone(toCollator(address), NULL, &bufferSize, &status);
- icu4jni_error(env, status);
- return static_cast<jint>(reinterpret_cast<uintptr_t>(c));
-}
-
-static void setAttribute(JNIEnv* env, jclass, jint address, jint type, jint value) {
- UErrorCode status = U_ZERO_ERROR;
- ucol_setAttribute(toCollator(address), (UColAttribute)type, (UColAttributeValue)value, &status);
- icu4jni_error(env, status);
-}
-
-static void setOffset(JNIEnv* env, jclass, jint address, jint offset) {
- UErrorCode status = U_ZERO_ERROR;
- ucol_setOffset(toCollationElements(address), offset, &status);
- icu4jni_error(env, status);
-}
-
-static void setText(JNIEnv* env, jclass, jint address, jstring source0) {
- ScopedJavaUnicodeString source(env, source0);
- UErrorCode status = U_ZERO_ERROR;
- ucol_setText(toCollationElements(address),
- source.unicodeString().getBuffer(), source.unicodeString().length(), &status);
- icu4jni_error(env, status);
-}
-
-static JNINativeMethod gMethods[] = {
- { "openCollator", "(Ljava/lang/String;)I", (void*) openCollator },
- { "openCollatorFromRules", "(Ljava/lang/String;II)I", (void*) openCollatorFromRules },
- { "closeCollator", "(I)V", (void*) closeCollator },
- { "compare", "(ILjava/lang/String;Ljava/lang/String;)I", (void*) compare },
- { "getNormalization", "(I)I", (void*) getNormalization },
- { "setNormalization", "(II)V", (void*) setNormalization },
- { "getRules", "(I)Ljava/lang/String;", (void*) getRules },
- { "getSortKey", "(ILjava/lang/String;)[B", (void*) getSortKey },
- { "setAttribute", "(III)V", (void*) setAttribute },
- { "getAttribute", "(II)I", (void*) getAttribute },
- { "safeClone", "(I)I", (void*) safeClone },
- { "getCollationElementIterator", "(ILjava/lang/String;)I", (void*) getCollationElementIterator },
- { "closeElements", "(I)V", (void*) closeElements },
- { "reset", "(I)V", (void*) reset },
- { "next", "(I)I", (void*) next },
- { "previous", "(I)I", (void*) previous },
- { "getMaxExpansion", "(II)I", (void*) getMaxExpansion },
- { "setText", "(ILjava/lang/String;)V", (void*) setText },
- { "getOffset", "(I)I", (void*) getOffset },
- { "setOffset", "(II)V", (void*) setOffset }
-};
-int register_com_ibm_icu4jni_text_NativeCollator(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeCollation",
- gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/NativeConverter.cpp b/icu/src/main/native/NativeConverter.cpp
deleted file mode 100644
index 8b3952e..0000000
--- a/icu/src/main/native/NativeConverter.cpp
+++ /dev/null
@@ -1,1019 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2006, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-/*
- * @(#) icujniinterface.c 1.2 00/10/11
- *
- * (C) Copyright IBM Corp. 2000 - All Rights Reserved
- * A JNI wrapper to ICU native converter Interface
- * @author: Ram Viswanadha
- */
-
-#define LOG_TAG "NativeConverter"
-
-#include "ErrorCode.h"
-#include "JNIHelp.h"
-#include "ScopedUtfChars.h"
-#include "UniquePtr.h"
-#include "unicode/ucnv.h"
-#include "unicode/ucnv_cb.h"
-#include "unicode/uset.h"
-#include "unicode/ustring.h"
-#include "unicode/utypes.h"
-#include <stdlib.h>
-#include <string.h>
-
-#define com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK 0L
-#define com_ibm_icu4jni_converters_NativeConverter_SKIP_CALLBACK 1L
-#define com_ibm_icu4jni_converters_NativeConverter_SUBSTITUTE_CALLBACK 2L
-
-/* Prototype of callback for substituting user settable sub chars */
-static void JNI_TO_U_CALLBACK_SUBSTITUTE
- (const void *,UConverterToUnicodeArgs *,const char* ,int32_t ,UConverterCallbackReason ,UErrorCode * );
-
-static jlong openConverter(JNIEnv* env, jclass, jstring converterName) {
- ScopedUtfChars converterNameChars(env, converterName);
- if (!converterNameChars.c_str()) {
- return 0;
- }
- UErrorCode errorCode = U_ZERO_ERROR;
- UConverter* conv = ucnv_open(converterNameChars.c_str(), &errorCode);
- icu4jni_error(env, errorCode);
- return (jlong) conv;
-}
-
-static void closeConverter(JNIEnv* env, jclass, jlong handle) {
- UConverter* cnv = (UConverter*)(long)handle;
- if (cnv) {
- // BEGIN android-added
- // Free up any contexts created in setCallback[Encode|Decode]()
- UConverterToUCallback toAction;
- UConverterFromUCallback fromAction;
- void* context1 = NULL;
- void* context2 = NULL;
- // TODO: ICU API bug?
- // The documentation clearly states that the caller owns the returned
- // pointers: http://icu-project.org/apiref/icu4c/ucnv_8h.html
- ucnv_getToUCallBack(cnv, &toAction, const_cast<const void**>(&context1));
- ucnv_getFromUCallBack(cnv, &fromAction, const_cast<const void**>(&context2));
- // END android-added
- ucnv_close(cnv);
- // BEGIN android-added
- if (context1 != NULL) {
- free(context1);
- }
- if (context2 != NULL) {
- free(context2);
- }
- // END android-added
- }
-}
-
-/**
- * Converts a buffer of Unicode code units to target encoding
- * @param env environment handle for JNI
- * @param jClass handle for the class
- * @param handle address of ICU converter
- * @param source buffer of Unicode chars to convert
- * @param sourceEnd limit of the source buffer
- * @param target buffer to recieve the converted bytes
- * @param targetEnd the limit of the target buffer
- * @param data buffer to recieve state of the current conversion
- * @param flush boolean that specifies end of source input
- */
-static jint convertCharToByte(JNIEnv *env, jclass, jlong handle, jcharArray source, jint sourceEnd, jbyteArray target, jint targetEnd, jintArray data, jboolean flush) {
-
- UErrorCode errorCode =U_ZERO_ERROR;
- UConverter* cnv = (UConverter*)handle;
- if(cnv) {
- jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
- if(myData) {
- jint* sourceOffset = &myData[0];
- jint* targetOffset = &myData[1];
- const jchar* uSource =(jchar*) env->GetPrimitiveArrayCritical(source, NULL);
- if(uSource) {
- jbyte* uTarget=(jbyte*) env->GetPrimitiveArrayCritical(target,NULL);
- if(uTarget) {
- const jchar* mySource = uSource+ *sourceOffset;
- const UChar* mySourceLimit= uSource+sourceEnd;
- char* cTarget = reinterpret_cast<char*>(uTarget+ *targetOffset);
- const char* cTargetLimit = reinterpret_cast<const char*>(uTarget+targetEnd);
-
- ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&mySource,
- mySourceLimit,NULL,(UBool) flush, &errorCode);
-
- *sourceOffset = (jint) (mySource - uSource)-*sourceOffset;
- *targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset;
- if(U_FAILURE(errorCode)) {
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
- env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- return errorCode;
-}
-
-static jint encode(JNIEnv *env, jclass, jlong handle, jcharArray source, jint sourceEnd, jbyteArray target, jint targetEnd, jintArray data, jboolean flush) {
-
- UErrorCode ec = UErrorCode(convertCharToByte(env, NULL,handle,source,sourceEnd, target,targetEnd,data,flush));
- UConverter* cnv = (UConverter*)handle;
- jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
-
- if(cnv && myData) {
-
- UErrorCode errorCode = U_ZERO_ERROR;
- myData[3] = ucnv_fromUCountPending(cnv, &errorCode);
-
- if(ec == U_ILLEGAL_CHAR_FOUND || ec == U_INVALID_CHAR_FOUND) {
- int8_t count =32;
- UChar invalidUChars[32];
- ucnv_getInvalidUChars(cnv,invalidUChars,&count,&errorCode);
-
- if(U_SUCCESS(errorCode)) {
- myData[2] = count;
- }
- }
- }
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return ec;
-}
-
-/**
- * Converts a buffer of encoded bytes to Unicode code units
- * @param env environment handle for JNI
- * @param jClass handle for the class
- * @param handle address of ICU converter
- * @param source buffer of Unicode chars to convert
- * @param sourceEnd limit of the source buffer
- * @param target buffer to recieve the converted bytes
- * @param targetEnd the limit of the target buffer
- * @param data buffer to recieve state of the current conversion
- * @param flush boolean that specifies end of source input
- */
-static jint convertByteToChar(JNIEnv *env, jclass, jlong handle, jbyteArray source, jint sourceEnd, jcharArray target, jint targetEnd, jintArray data, jboolean flush) {
-
- UErrorCode errorCode =U_ZERO_ERROR;
- UConverter* cnv = (UConverter*)handle;
- if(cnv) {
- jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
- if(myData) {
- jint* sourceOffset = &myData[0];
- jint* targetOffset = &myData[1];
-
- const jbyte* uSource =(jbyte*) env->GetPrimitiveArrayCritical(source, NULL);
- if(uSource) {
- jchar* uTarget=(jchar*) env->GetPrimitiveArrayCritical(target,NULL);
- if(uTarget) {
- const jbyte* mySource = uSource+ *sourceOffset;
- const char* mySourceLimit = reinterpret_cast<const char*>(uSource+sourceEnd);
- UChar* cTarget=uTarget+ *targetOffset;
- const UChar* cTargetLimit=uTarget+targetEnd;
-
- ucnv_toUnicode( cnv , &cTarget, cTargetLimit,(const char**)&mySource,
- mySourceLimit,NULL,(UBool) flush, &errorCode);
-
- *sourceOffset = mySource - uSource - *sourceOffset ;
- *targetOffset = cTarget - uTarget - *targetOffset;
- if(U_FAILURE(errorCode)) {
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
- env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(source,(jchar*)uSource,0);
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- return errorCode;
-}
-
-static jint decode(JNIEnv *env, jclass, jlong handle, jbyteArray source, jint sourceEnd, jcharArray target, jint targetEnd, jintArray data, jboolean flush) {
-
- jint ec = convertByteToChar(env, NULL,handle,source,sourceEnd, target,targetEnd,data,flush);
-
- jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
- UConverter* cnv = (UConverter*)handle;
-
- if(myData && cnv) {
- UErrorCode errorCode = U_ZERO_ERROR;
- myData[3] = ucnv_toUCountPending(cnv, &errorCode);
-
- if(ec == U_ILLEGAL_CHAR_FOUND || ec == U_INVALID_CHAR_FOUND ) {
- char invalidChars[32] = {'\0'};
- int8_t len = 32;
- ucnv_getInvalidChars(cnv,invalidChars,&len,&errorCode);
-
- if(U_SUCCESS(errorCode)) {
- myData[2] = len;
- }
- }
- }
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return ec;
-}
-
-static void resetByteToChar(JNIEnv* env, jclass, jlong handle) {
- UConverter* cnv = (UConverter*)handle;
- if (cnv) {
- ucnv_resetToUnicode(cnv);
- }
-}
-
-static void resetCharToByte(JNIEnv* env, jclass, jlong handle) {
- UConverter* cnv = (UConverter*)handle;
- if (cnv) {
- ucnv_resetFromUnicode(cnv);
- }
-}
-
-static jint getMaxBytesPerChar(JNIEnv *env, jclass, jlong handle) {
- UConverter* cnv = (UConverter*)handle;
- return (cnv != NULL) ? ucnv_getMaxCharSize(cnv) : -1;
-}
-
-static jint getMinBytesPerChar(JNIEnv *env, jclass, jlong handle) {
- UConverter* cnv = (UConverter*)handle;
- return (cnv != NULL) ? ucnv_getMinCharSize(cnv) : -1;
-}
-
-static jfloat getAveBytesPerChar(JNIEnv *env, jclass, jlong handle) {
- UConverter* cnv = (UConverter*)handle;
- if (cnv) {
- jfloat max = (jfloat)ucnv_getMaxCharSize(cnv);
- jfloat min = (jfloat)ucnv_getMinCharSize(cnv);
- return (jfloat) ( (max+min)/2 );
- }
- return -1;
-}
-
-static jint flushByteToChar(JNIEnv *env, jclass,jlong handle, jcharArray target, jint targetEnd, jintArray data) {
-
- UErrorCode errorCode =U_ZERO_ERROR;
- UConverter* cnv = (UConverter*)handle;
- if(cnv) {
- jbyte source ='\0';
- jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
- if(myData) {
- jint* targetOffset = &myData[1];
- jchar* uTarget=(jchar*) env->GetPrimitiveArrayCritical(target,NULL);
- if(uTarget) {
- const jbyte* mySource = &source;
- const char* mySourceLimit = reinterpret_cast<char*>(&source);
- UChar* cTarget=uTarget+ *targetOffset;
- const UChar* cTargetLimit=uTarget+targetEnd;
-
- ucnv_toUnicode( cnv , &cTarget, cTargetLimit,(const char**)&mySource,
- mySourceLimit,NULL,TRUE, &errorCode);
-
-
- *targetOffset = (jint) ((jchar*)cTarget - uTarget)- *targetOffset;
- if(U_FAILURE(errorCode)) {
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
-
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- return errorCode;
-}
-
-static jint flushCharToByte (JNIEnv *env, jclass, jlong handle, jbyteArray target, jint targetEnd, jintArray data) {
-
- UErrorCode errorCode =U_ZERO_ERROR;
- UConverter* cnv = (UConverter*)handle;
- jchar source = '\0';
- if(cnv) {
- jint* myData = (jint*) env->GetPrimitiveArrayCritical(data,NULL);
- if(myData) {
- jint* targetOffset = &myData[1];
- jbyte* uTarget=(jbyte*) env->GetPrimitiveArrayCritical(target,NULL);
- if(uTarget) {
- const jchar* mySource = &source;
- const UChar* mySourceLimit= &source;
- char* cTarget = reinterpret_cast<char*>(uTarget+ *targetOffset);
- const char* cTargetLimit = reinterpret_cast<char*>(uTarget+targetEnd);
-
- ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&mySource,
- mySourceLimit,NULL,TRUE, &errorCode);
-
-
- *targetOffset = (jint) ((jbyte*)cTarget - uTarget)- *targetOffset;
- if(U_FAILURE(errorCode)) {
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
-
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(target,uTarget,0);
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(data,(jint*)myData,0);
- return errorCode;
- }
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- return errorCode;
-}
-
-static void toChars(const UChar* us, char* cs, int32_t length) {
- while (length > 0) {
- UChar u = *us++;
- *cs++=(char)u;
- --length;
- }
-}
-static jint setSubstitutionBytes(JNIEnv *env, jclass, jlong handle, jbyteArray subChars, jint length) {
- UConverter* cnv = (UConverter*) handle;
- UErrorCode errorCode = U_ZERO_ERROR;
- if (cnv) {
- jbyte* u_subChars = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(subChars, NULL));
- if (u_subChars) {
- char mySubChars[length];
- toChars((UChar*)u_subChars,&mySubChars[0],length);
- ucnv_setSubstChars(cnv,mySubChars, (char)length,&errorCode);
- if(U_FAILURE(errorCode)) {
- env->ReleasePrimitiveArrayCritical(subChars,mySubChars,0);
- return errorCode;
- }
- } else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(subChars,u_subChars,0);
- return errorCode;
- }
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- return errorCode;
-}
-
-
-#define VALUE_STRING_LENGTH 32
-
-struct SubCharStruct {
- int length;
- UChar subChars[256];
- UBool stopOnIllegal;
-};
-
-
-static UErrorCode
-setToUCallbackSubs(UConverter* cnv,UChar* subChars, int32_t length,UBool stopOnIllegal ) {
- SubCharStruct* substitutionCharS = (SubCharStruct*) malloc(sizeof(SubCharStruct));
- UErrorCode errorCode = U_ZERO_ERROR;
- if(substitutionCharS) {
- UConverterToUCallback toUOldAction;
- void* toUOldContext=NULL;
- void* toUNewContext=NULL ;
- if(subChars) {
- u_strncpy(substitutionCharS->subChars,subChars,length);
- }else{
- substitutionCharS->subChars[length++] =0xFFFD;
- }
- substitutionCharS->subChars[length]=0;
- substitutionCharS->length = length;
- substitutionCharS->stopOnIllegal = stopOnIllegal;
- toUNewContext = substitutionCharS;
-
- ucnv_setToUCallBack(cnv,
- JNI_TO_U_CALLBACK_SUBSTITUTE,
- toUNewContext,
- &toUOldAction,
- (const void**)&toUOldContext,
- &errorCode);
-
- if(toUOldContext) {
- SubCharStruct* temp = (SubCharStruct*) toUOldContext;
- free(temp);
- }
-
- return errorCode;
- }
- return U_MEMORY_ALLOCATION_ERROR;
-}
-static jint setSubstitutionChars(JNIEnv *env, jclass, jlong handle, jcharArray subChars, jint length) {
-
- UErrorCode errorCode = U_ZERO_ERROR;
- UConverter* cnv = (UConverter*) handle;
- jchar* u_subChars=NULL;
- if(cnv) {
- if(subChars) {
- int len = env->GetArrayLength(subChars);
- u_subChars = reinterpret_cast<jchar*>(env->GetPrimitiveArrayCritical(subChars,NULL));
- if(u_subChars) {
- errorCode = setToUCallbackSubs(cnv,u_subChars,len,FALSE);
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- env->ReleasePrimitiveArrayCritical(subChars,u_subChars,0);
- return errorCode;
- }
- }
- return U_ILLEGAL_ARGUMENT_ERROR;
-}
-
-
-static void JNI_TO_U_CALLBACK_SUBSTITUTE( const void *context, UConverterToUnicodeArgs *toArgs, const char* codeUnits, int32_t length, UConverterCallbackReason reason, UErrorCode * err) {
-
- if(context) {
- SubCharStruct* temp = (SubCharStruct*)context;
- if( temp) {
- if(temp->stopOnIllegal==FALSE) {
- if (reason > UCNV_IRREGULAR) {
- return;
- }
- /* reset the error */
- *err = U_ZERO_ERROR;
- ucnv_cbToUWriteUChars(toArgs,temp->subChars ,temp->length , 0, err);
- }else{
- if(reason != UCNV_UNASSIGNED) {
- /* the caller must have set
- * the error code accordingly
- */
- return;
- }else{
- *err = U_ZERO_ERROR;
- ucnv_cbToUWriteUChars(toArgs,temp->subChars ,temp->length , 0, err);
- return;
- }
- }
- }
- }
- return;
-}
-
-static jboolean canEncode(JNIEnv *env, jclass, jlong handle, jint codeUnit) {
-
- UErrorCode errorCode =U_ZERO_ERROR;
- UConverter* cnv = (UConverter*)handle;
- if(cnv) {
- UChar source[3];
- UChar *mySource=source;
- const UChar* sourceLimit = (codeUnit<0x010000) ? &source[1] : &source[2];
- char target[5];
- char *myTarget = target;
- const char* targetLimit = &target[4];
- int i=0;
- UTF_APPEND_CHAR(&source[0],i,2,codeUnit);
-
- ucnv_fromUnicode(cnv,&myTarget,targetLimit,
- (const UChar**)&mySource,
- sourceLimit,NULL, TRUE,&errorCode);
-
- if(U_SUCCESS(errorCode)) {
- return (jboolean)TRUE;
- }
- }
- return (jboolean)FALSE;
-}
-
-/*
- * If a charset listed in the IANA Charset Registry is supported by an implementation
- * of the Java platform then its canonical name must be the name listed in the registry.
- * Many charsets are given more than one name in the registry, in which case the registry
- * identifies one of the names as MIME-preferred. If a charset has more than one registry
- * name then its canonical name must be the MIME-preferred name and the other names in
- * the registry must be valid aliases. If a supported charset is not listed in the IANA
- * registry then its canonical name must begin with one of the strings "X-" or "x-".
- */
-static jstring getJavaCanonicalName(JNIEnv *env, const char* icuCanonicalName) {
- UErrorCode status = U_ZERO_ERROR;
-
- // Check to see if this is a well-known MIME or IANA name.
- const char* cName = NULL;
- if ((cName = ucnv_getStandardName(icuCanonicalName, "MIME", &status)) != NULL) {
- return env->NewStringUTF(cName);
- } else if ((cName = ucnv_getStandardName(icuCanonicalName, "IANA", &status)) != NULL) {
- return env->NewStringUTF(cName);
- }
-
- // Check to see if an alias already exists with "x-" prefix, if yes then
- // make that the canonical name.
- int32_t aliasCount = ucnv_countAliases(icuCanonicalName, &status);
- for (int i = 0; i < aliasCount; ++i) {
- const char* name = ucnv_getAlias(icuCanonicalName, i, &status);
- if (name != NULL && name[0] == 'x' && name[1] == '-') {
- return env->NewStringUTF(name);
- }
- }
-
- // As a last resort, prepend "x-" to any alias and make that the canonical name.
- status = U_ZERO_ERROR;
- const char* name = ucnv_getStandardName(icuCanonicalName, "UTR22", &status);
- if (name == NULL && strchr(icuCanonicalName, ',') != NULL) {
- name = ucnv_getAlias(icuCanonicalName, 1, &status);
- }
- // If there is no UTR22 canonical name then just return the original name.
- if (name == NULL) {
- name = icuCanonicalName;
- }
- UniquePtr<char[]> result(new char[2 + strlen(name) + 1]);
- strcpy(&result[0], "x-");
- strcat(&result[0], name);
- return env->NewStringUTF(&result[0]);
-}
-
-static jobjectArray getAvailableCharsetNames(JNIEnv *env, jclass) {
- int32_t num = ucnv_countAvailable();
- jobjectArray result = env->NewObjectArray(num, env->FindClass("java/lang/String"), NULL);
- for (int i = 0; i < num; ++i) {
- const char* name = ucnv_getAvailableName(i);
- jstring javaCanonicalName = getJavaCanonicalName(env, name);
- env->SetObjectArrayElement(result, i, javaCanonicalName);
- env->DeleteLocalRef(javaCanonicalName);
- }
- return result;
-}
-
-static jobjectArray getAliases(JNIEnv* env, const char* icuCanonicalName) {
- // Get an upper bound on the number of aliases...
- const char* myEncName = icuCanonicalName;
- UErrorCode error = U_ZERO_ERROR;
- int32_t aliasCount = ucnv_countAliases(myEncName, &error);
- if (aliasCount == 0 && myEncName[0] == 'x' && myEncName[1] == '-') {
- myEncName = myEncName + 2;
- aliasCount = ucnv_countAliases(myEncName, &error);
- }
- if (!U_SUCCESS(error)) {
- return NULL;
- }
-
- // Collect the aliases we want...
- const char* aliasArray[aliasCount];
- int actualAliasCount = 0;
- for(int i = 0; i < aliasCount; ++i) {
- const char* name = ucnv_getAlias(myEncName, (uint16_t) i, &error);
- if (!U_SUCCESS(error)) {
- return NULL;
- }
- // TODO: why do we ignore these ones?
- if (strchr(name, '+') == 0 && strchr(name, ',') == 0) {
- aliasArray[actualAliasCount++]= name;
- }
- }
-
- // Convert our C++ char*[] into a Java String[]...
- jobjectArray result = env->NewObjectArray(actualAliasCount, env->FindClass("java/lang/String"), NULL);
- for (int i = 0; i < actualAliasCount; ++i) {
- jstring alias = env->NewStringUTF(aliasArray[i]);
- env->SetObjectArrayElement(result, i, alias);
- env->DeleteLocalRef(alias);
- }
- return result;
-}
-
-static const char* getICUCanonicalName(const char* name) {
- UErrorCode error = U_ZERO_ERROR;
- const char* canonicalName = NULL;
- if ((canonicalName = ucnv_getCanonicalName(name, "MIME", &error)) != NULL) {
- return canonicalName;
- } else if((canonicalName = ucnv_getCanonicalName(name, "IANA", &error)) != NULL) {
- return canonicalName;
- } else if((canonicalName = ucnv_getCanonicalName(name, "", &error)) != NULL) {
- return canonicalName;
- } else if((canonicalName = ucnv_getAlias(name, 0, &error)) != NULL) {
- /* we have some aliases in the form x-blah .. match those first */
- return canonicalName;
- } else if (strstr(name, "x-") == name) {
- /* check if the converter can be opened with the name given */
- error = U_ZERO_ERROR;
- UConverter* conv = ucnv_open(name + 2, &error);
- if (conv != NULL) {
- ucnv_close(conv);
- return name + 2;
- }
- }
- return NULL;
-}
-
-#define SUBS_ARRAY_CAPACITY 256
-struct EncoderCallbackContext {
- int length;
- char subChars[SUBS_ARRAY_CAPACITY];
- UConverterFromUCallback onUnmappableInput;
- UConverterFromUCallback onMalformedInput;
-};
-
-static void CHARSET_ENCODER_CALLBACK(const void *context,
- UConverterFromUnicodeArgs *fromArgs,
- const UChar* codeUnits,
- int32_t length,
- UChar32 codePoint,
- UConverterCallbackReason reason,
- UErrorCode * status) {
- if(context) {
- EncoderCallbackContext* ctx = (EncoderCallbackContext*)context;
-
- if(ctx) {
- UConverterFromUCallback realCB = NULL;
- switch(reason) {
- case UCNV_UNASSIGNED:
- realCB = ctx->onUnmappableInput;
- break;
- case UCNV_ILLEGAL:/*malformed input*/
- case UCNV_IRREGULAR:/*malformed input*/
- realCB = ctx->onMalformedInput;
- break;
- /*
- case UCNV_RESET:
- ucnv_resetToUnicode(args->converter);
- break;
- case UCNV_CLOSE:
- ucnv_close(args->converter);
- break;
- case UCNV_CLONE:
- ucnv_clone(args->clone);
- */
- default:
- *status = U_ILLEGAL_ARGUMENT_ERROR;
- return;
- }
- if (realCB == NULL) {
- *status = U_INTERNAL_PROGRAM_ERROR;
- } else {
- realCB(context, fromArgs, codeUnits, length, codePoint, reason, status);
- }
- }
- }
-}
-
-static void JNI_FROM_U_CALLBACK_SUBSTITUTE_ENCODER(const void *context,
- UConverterFromUnicodeArgs *fromArgs,
- const UChar* codeUnits,
- int32_t length,
- UChar32 codePoint,
- UConverterCallbackReason reason,
- UErrorCode * err) {
- if(context) {
- EncoderCallbackContext* temp = (EncoderCallbackContext*)context;
- *err = U_ZERO_ERROR;
- ucnv_cbFromUWriteBytes(fromArgs,temp->subChars ,temp->length , 0, err);
- }
- return;
-}
-
-static UConverterFromUCallback getFromUCallback(int32_t mode) {
- switch(mode) {
- default: /* falls through */
- case com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK:
- return UCNV_FROM_U_CALLBACK_STOP;
- case com_ibm_icu4jni_converters_NativeConverter_SKIP_CALLBACK:
- return UCNV_FROM_U_CALLBACK_SKIP ;
- case com_ibm_icu4jni_converters_NativeConverter_SUBSTITUTE_CALLBACK:
- return JNI_FROM_U_CALLBACK_SUBSTITUTE_ENCODER;
- }
-}
-
-static jint setCallbackEncode(JNIEnv *env, jclass, jlong handle, jint onMalformedInput, jint onUnmappableInput, jbyteArray subChars, jint length) {
-
- UConverter* conv = (UConverter*)handle;
- UErrorCode errorCode =U_ZERO_ERROR;
-
- if(conv) {
-
- UConverterFromUCallback fromUOldAction = NULL;
- void* fromUOldContext = NULL;
- EncoderCallbackContext* fromUNewContext=NULL;
- UConverterFromUCallback fromUNewAction=NULL;
- jbyte* sub = (jbyte*) env->GetPrimitiveArrayCritical(subChars, NULL);
- ucnv_getFromUCallBack(conv, &fromUOldAction, const_cast<const void**>(&fromUOldContext));
-
- /* fromUOldContext can only be DecodeCallbackContext since
- the converter created is private data for the decoder
- and callbacks can only be set via this method!
- */
- if(fromUOldContext==NULL) {
- fromUNewContext = (EncoderCallbackContext*) malloc(sizeof(EncoderCallbackContext));
- fromUNewAction = CHARSET_ENCODER_CALLBACK;
- }else{
- fromUNewContext = (EncoderCallbackContext*) fromUOldContext;
- fromUNewAction = fromUOldAction;
- fromUOldAction = NULL;
- fromUOldContext = NULL;
- }
- fromUNewContext->onMalformedInput = getFromUCallback(onMalformedInput);
- fromUNewContext->onUnmappableInput = getFromUCallback(onUnmappableInput);
- // BEGIN android-changed
- if(sub!=NULL) {
- fromUNewContext->length = length;
- const char* src = const_cast<const char*>(reinterpret_cast<char*>(sub));
- strncpy(fromUNewContext->subChars, src, length);
- env->ReleasePrimitiveArrayCritical(subChars, sub, 0);
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- // END android-changed
-
- ucnv_setFromUCallBack(conv,
- fromUNewAction,
- fromUNewContext,
- &fromUOldAction,
- (const void**)&fromUOldContext,
- &errorCode);
-
-
- return errorCode;
- }
- return U_ILLEGAL_ARGUMENT_ERROR;
-}
-
-struct DecoderCallbackContext {
- int length;
- UChar subUChars[256];
- UConverterToUCallback onUnmappableInput;
- UConverterToUCallback onMalformedInput;
-};
-
-static void JNI_TO_U_CALLBACK_SUBSTITUTE_DECODER(const void *context,
- UConverterToUnicodeArgs *toArgs,
- const char* codeUnits,
- int32_t length,
- UConverterCallbackReason reason,
- UErrorCode * err) {
- if(context) {
- DecoderCallbackContext* temp = (DecoderCallbackContext*)context;
- *err = U_ZERO_ERROR;
- ucnv_cbToUWriteUChars(toArgs,temp->subUChars ,temp->length , 0, err);
- }
- return;
-}
-
-static UConverterToUCallback getToUCallback(int32_t mode) {
- switch(mode) {
- default: /* falls through */
- case com_ibm_icu4jni_converters_NativeConverter_STOP_CALLBACK:
- return UCNV_TO_U_CALLBACK_STOP;
- case com_ibm_icu4jni_converters_NativeConverter_SKIP_CALLBACK:
- return UCNV_TO_U_CALLBACK_SKIP ;
- case com_ibm_icu4jni_converters_NativeConverter_SUBSTITUTE_CALLBACK:
- return JNI_TO_U_CALLBACK_SUBSTITUTE_DECODER;
- }
-}
-
-static void CHARSET_DECODER_CALLBACK(const void *context,
- UConverterToUnicodeArgs *args,
- const char* codeUnits,
- int32_t length,
- UConverterCallbackReason reason,
- UErrorCode *status ) {
-
- if(context) {
- DecoderCallbackContext* ctx = (DecoderCallbackContext*)context;
-
- if(ctx) {
- UConverterToUCallback realCB = NULL;
- switch(reason) {
- case UCNV_UNASSIGNED:
- realCB = ctx->onUnmappableInput;
- break;
- case UCNV_ILLEGAL:/*malformed input*/
- case UCNV_IRREGULAR:/*malformed input*/
- realCB = ctx->onMalformedInput;
- break;
- /*
- case UCNV_RESET:
- ucnv_resetToUnicode(args->converter);
- break;
- case UCNV_CLOSE:
- ucnv_close(args->converter);
- break;
- case UCNV_CLONE:
- ucnv_clone(args->clone);
- */
- default:
- *status = U_ILLEGAL_ARGUMENT_ERROR;
- return;
- }
- if (realCB == NULL) {
- *status = U_INTERNAL_PROGRAM_ERROR;
- } else {
- realCB(context, args, codeUnits, length, reason, status);
- }
- }
- }
-}
-
-static jint setCallbackDecode(JNIEnv *env, jclass, jlong handle, jint onMalformedInput, jint onUnmappableInput, jcharArray subChars, jint length) {
-
- UConverter* conv = (UConverter*)handle;
- UErrorCode errorCode =U_ZERO_ERROR;
- if(conv) {
-
- UConverterToUCallback toUOldAction ;
- void* toUOldContext;
- DecoderCallbackContext* toUNewContext = NULL;
- UConverterToUCallback toUNewAction = NULL;
- jchar* sub = (jchar*) env->GetPrimitiveArrayCritical(subChars, NULL);
-
- ucnv_getToUCallBack(conv, &toUOldAction, const_cast<const void**>(&toUOldContext));
-
- /* toUOldContext can only be DecodeCallbackContext since
- the converter created is private data for the decoder
- and callbacks can only be set via this method!
- */
- if(toUOldContext==NULL) {
- toUNewContext = (DecoderCallbackContext*) malloc(sizeof(DecoderCallbackContext));
- toUNewAction = CHARSET_DECODER_CALLBACK;
- }else{
- toUNewContext = reinterpret_cast<DecoderCallbackContext*>(toUOldContext);
- toUNewAction = toUOldAction;
- toUOldAction = NULL;
- toUOldContext = NULL;
- }
- toUNewContext->onMalformedInput = getToUCallback(onMalformedInput);
- toUNewContext->onUnmappableInput = getToUCallback(onUnmappableInput);
- // BEGIN android-changed
- if(sub!=NULL) {
- toUNewContext->length = length;
- u_strncpy(toUNewContext->subUChars, sub, length);
- env->ReleasePrimitiveArrayCritical(subChars, sub, 0);
- }else{
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- }
- // END android-changed
- ucnv_setToUCallBack(conv,
- toUNewAction,
- toUNewContext,
- &toUOldAction,
- (const void**)&toUOldContext,
- &errorCode);
-
- return errorCode;
- }
- return U_ILLEGAL_ARGUMENT_ERROR;
-}
-
-static jint getMaxCharsPerByte(JNIEnv *env, jclass, jlong handle) {
- /*
- * currently we know that max number of chars per byte is 2
- */
- return 2;
-}
-
-static jfloat getAveCharsPerByte(JNIEnv *env, jclass, jlong handle) {
- return (1 / (jfloat) getMaxBytesPerChar(env, NULL, handle));
-}
-
-static jbyteArray getSubstitutionBytes(JNIEnv *env, jclass, jlong handle) {
- const UConverter * cnv = (const UConverter *) handle;
- if (cnv) {
- UErrorCode status = U_ZERO_ERROR;
- char subBytes[10];
- int8_t len =(char)10;
- ucnv_getSubstChars(cnv,subBytes,&len,&status);
- if(U_SUCCESS(status)) {
- jbyteArray arr = env->NewByteArray(len);
- if (arr) {
- env->SetByteArrayRegion(arr,0,len,(jbyte*)subBytes);
- }
- return arr;
- }
- }
- return env->NewByteArray(0);
-}
-
-static jboolean contains(JNIEnv* env, jclass, jlong handle1, jlong handle2) {
- UErrorCode status = U_ZERO_ERROR;
- const UConverter * cnv1 = (const UConverter *) handle1;
- const UConverter * cnv2 = (const UConverter *) handle2;
- UBool bRet = 0;
-
- if(cnv1 != NULL && cnv2 != NULL) {
- /* open charset 1 */
- USet* set1 = uset_open(1, 2);
- ucnv_getUnicodeSet(cnv1, set1, UCNV_ROUNDTRIP_SET, &status);
-
- if(U_SUCCESS(status)) {
- /* open charset 2 */
- status = U_ZERO_ERROR;
- USet* set2 = uset_open(1, 2);
- ucnv_getUnicodeSet(cnv2, set2, UCNV_ROUNDTRIP_SET, &status);
-
- /* contains? */
- if(U_SUCCESS(status)) {
- bRet = uset_containsAll(set1, set2);
- uset_close(set2);
- }
- uset_close(set1);
- }
- }
- return bRet;
-}
-
-static jobject charsetForName(JNIEnv* env, jclass, jstring charsetName) {
- ScopedUtfChars charsetNameChars(env, charsetName);
- if (!charsetNameChars.c_str()) {
- return NULL;
- }
- // Get ICU's canonical name for this charset.
- const char* icuCanonicalName = getICUCanonicalName(charsetNameChars.c_str());
- if (icuCanonicalName == NULL) {
- return NULL;
- }
- // Get Java's canonical name for this charset.
- jstring javaCanonicalName = getJavaCanonicalName(env, icuCanonicalName);
- if (env->ExceptionOccurred()) {
- return NULL;
- }
-
- // Check that this charset is supported.
- // ICU doesn't offer any "isSupported", so we just open and immediately close.
- // We ignore the UErrorCode because ucnv_open returning NULL is all the information we need.
- UErrorCode dummy = U_ZERO_ERROR;
- UConverter* conv = ucnv_open(icuCanonicalName, &dummy);
- if (conv == NULL) {
- return NULL;
- }
- ucnv_close(conv);
-
- // Get the aliases for this charset.
- jobjectArray aliases = getAliases(env, icuCanonicalName);
- if (env->ExceptionOccurred()) {
- return NULL;
- }
-
- // Construct the CharsetICU object.
- jclass charsetClass = env->FindClass("com/ibm/icu4jni/charset/CharsetICU");
- if (env->ExceptionOccurred()) {
- return NULL;
- }
- jmethodID charsetConstructor = env->GetMethodID(charsetClass, "<init>",
- "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V");
- if (env->ExceptionOccurred()) {
- return NULL;
- }
- return env->NewObject(charsetClass, charsetConstructor,
- javaCanonicalName, env->NewStringUTF(icuCanonicalName), aliases);
-}
-
-static JNINativeMethod gMethods[] = {
- { "canEncode", "(JI)Z", (void*) canEncode },
- { "charsetForName", "(Ljava/lang/String;)Ljava/nio/charset/Charset;", (void*) charsetForName },
- { "closeConverter", "(J)V", (void*) closeConverter },
- { "contains", "(JJ)Z", (void*) contains },
- { "decode", "(J[BI[CI[IZ)I", (void*) decode },
- { "encode", "(J[CI[BI[IZ)I", (void*) encode },
- { "flushByteToChar", "(J[CI[I)I", (void*) flushByteToChar },
- { "flushCharToByte", "(J[BI[I)I", (void*) flushCharToByte },
- { "getAvailableCharsetNames", "()[Ljava/lang/String;", (void*) getAvailableCharsetNames },
- { "getAveBytesPerChar", "(J)F", (void*) getAveBytesPerChar },
- { "getAveCharsPerByte", "(J)F", (void*) getAveCharsPerByte },
- { "getMaxBytesPerChar", "(J)I", (void*) getMaxBytesPerChar },
- { "getMaxCharsPerByte", "(J)I", (void*) getMaxCharsPerByte },
- { "getMinBytesPerChar", "(J)I", (void*) getMinBytesPerChar },
- { "getSubstitutionBytes", "(J)[B", (void*) getSubstitutionBytes },
- { "openConverter", "(Ljava/lang/String;)J", (void*) openConverter },
- { "resetByteToChar", "(J)V", (void*) resetByteToChar },
- { "resetCharToByte", "(J)V", (void*) resetCharToByte },
- { "setCallbackDecode", "(JII[CI)I", (void*) setCallbackDecode },
- { "setCallbackEncode", "(JII[BI)I", (void*) setCallbackEncode },
- { "setSubstitutionBytes", "(J[BI)I", (void*) setSubstitutionBytes },
- { "setSubstitutionChars", "(J[CI)I", (void*) setSubstitutionChars },
-};
-int register_com_ibm_icu4jni_converters_NativeConverter(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/charset/NativeConverter",
- gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/NativeDecimalFormat.cpp b/icu/src/main/native/NativeDecimalFormat.cpp
deleted file mode 100644
index 8f39a39..0000000
--- a/icu/src/main/native/NativeDecimalFormat.cpp
+++ /dev/null
@@ -1,608 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "NativeDecimalFormat"
-
-#include "JNIHelp.h"
-#include "cutils/log.h"
-#include "unicode/unum.h"
-#include "unicode/numfmt.h"
-#include "unicode/decimfmt.h"
-#include "unicode/fmtable.h"
-#include "unicode/ustring.h"
-#include "digitlst.h"
-#include "ErrorCode.h"
-#include "ScopedJavaUnicodeString.h"
-#include <stdlib.h>
-#include <string.h>
-
-static DecimalFormat* toDecimalFormat(jint addr) {
- return reinterpret_cast<DecimalFormat*>(static_cast<uintptr_t>(addr));
-}
-
-static DecimalFormatSymbols* makeDecimalFormatSymbols(JNIEnv* env,
- jstring currencySymbol0, jchar decimalSeparator, jchar digit,
- jchar groupingSeparator0, jstring infinity0,
- jstring internationalCurrencySymbol0, jchar minusSign,
- jchar monetaryDecimalSeparator, jstring nan0, jchar patternSeparator,
- jchar percent, jchar perMill, jchar zeroDigit) {
- ScopedJavaUnicodeString currencySymbol(env, currencySymbol0);
- ScopedJavaUnicodeString infinity(env, infinity0);
- ScopedJavaUnicodeString internationalCurrencySymbol(env, internationalCurrencySymbol0);
- ScopedJavaUnicodeString nan(env, nan0);
- UnicodeString groupingSeparator(groupingSeparator0);
-
- DecimalFormatSymbols* result = new DecimalFormatSymbols;
- result->setSymbol(DecimalFormatSymbols::kCurrencySymbol, currencySymbol.unicodeString());
- result->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, UnicodeString(decimalSeparator));
- result->setSymbol(DecimalFormatSymbols::kDigitSymbol, UnicodeString(digit));
- result->setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, groupingSeparator);
- result->setSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol, groupingSeparator);
- result->setSymbol(DecimalFormatSymbols::kInfinitySymbol, infinity.unicodeString());
- result->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, internationalCurrencySymbol.unicodeString());
- result->setSymbol(DecimalFormatSymbols::kMinusSignSymbol, UnicodeString(minusSign));
- result->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, UnicodeString(monetaryDecimalSeparator));
- result->setSymbol(DecimalFormatSymbols::kNaNSymbol, nan.unicodeString());
- result->setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, UnicodeString(patternSeparator));
- result->setSymbol(DecimalFormatSymbols::kPercentSymbol, UnicodeString(percent));
- result->setSymbol(DecimalFormatSymbols::kPerMillSymbol, UnicodeString(perMill));
- result->setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, UnicodeString(zeroDigit));
- return result;
-}
-
-static void setDecimalFormatSymbols(JNIEnv* env, jclass, jint addr,
- jstring currencySymbol, jchar decimalSeparator, jchar digit,
- jchar groupingSeparator, jstring infinity,
- jstring internationalCurrencySymbol, jchar minusSign,
- jchar monetaryDecimalSeparator, jstring nan, jchar patternSeparator,
- jchar percent, jchar perMill, jchar zeroDigit) {
- DecimalFormatSymbols* symbols = makeDecimalFormatSymbols(env,
- currencySymbol, decimalSeparator, digit, groupingSeparator,
- infinity, internationalCurrencySymbol, minusSign,
- monetaryDecimalSeparator, nan, patternSeparator, percent, perMill,
- zeroDigit);
- toDecimalFormat(addr)->adoptDecimalFormatSymbols(symbols);
-}
-
-static jint openDecimalFormatImpl(JNIEnv* env, jclass clazz, jstring pattern0,
- jstring currencySymbol, jchar decimalSeparator, jchar digit,
- jchar groupingSeparator, jstring infinity,
- jstring internationalCurrencySymbol, jchar minusSign,
- jchar monetaryDecimalSeparator, jstring nan, jchar patternSeparator,
- jchar percent, jchar perMill, jchar zeroDigit) {
- if (pattern0 == NULL) {
- jniThrowNullPointerException(env, NULL);
- return 0;
- }
- UErrorCode status = U_ZERO_ERROR;
- UParseError parseError;
- ScopedJavaUnicodeString pattern(env, pattern0);
- DecimalFormatSymbols* symbols = makeDecimalFormatSymbols(env,
- currencySymbol, decimalSeparator, digit, groupingSeparator,
- infinity, internationalCurrencySymbol, minusSign,
- monetaryDecimalSeparator, nan, patternSeparator, percent, perMill,
- zeroDigit);
- DecimalFormat* fmt = new DecimalFormat(pattern.unicodeString(), symbols, parseError, status);
- if (fmt == NULL) {
- delete symbols;
- }
- icu4jni_error(env, status);
- return static_cast<jint>(reinterpret_cast<uintptr_t>(fmt));
-}
-
-static void closeDecimalFormatImpl(JNIEnv* env, jclass, jint addr) {
- delete toDecimalFormat(addr);
-}
-
-static void setRoundingMode(JNIEnv* env, jclass, jint addr, jint mode, jdouble increment) {
- DecimalFormat* fmt = toDecimalFormat(addr);
- fmt->setRoundingMode(static_cast<DecimalFormat::ERoundingMode>(mode));
- fmt->setRoundingIncrement(increment);
-}
-
-static void setSymbol(JNIEnv* env, jclass, jint addr, jint symbol, jstring s) {
- const UChar* chars = env->GetStringChars(s, NULL);
- const int32_t charCount = env->GetStringLength(s);
- UErrorCode status = U_ZERO_ERROR;
- UNumberFormat* fmt = reinterpret_cast<UNumberFormat*>(static_cast<uintptr_t>(addr));
- unum_setSymbol(fmt, static_cast<UNumberFormatSymbol>(symbol), chars, charCount, &status);
- icu4jni_error(env, status);
- env->ReleaseStringChars(s, chars);
-}
-
-static void setAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol,
- jint value) {
-
- UNumberFormat *fmt = (UNumberFormat *)(int)addr;
-
- unum_setAttribute(fmt, (UNumberFormatAttribute) symbol, value);
-}
-
-static jint getAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol) {
-
- UNumberFormat *fmt = (UNumberFormat *)(int)addr;
-
- int res = unum_getAttribute(fmt, (UNumberFormatAttribute) symbol);
-
- return res;
-}
-
-static void setTextAttribute(JNIEnv *env, jclass clazz, jint addr, jint symbol,
- jstring text) {
-
- // the errorcode returned by unum_setTextAttribute
- UErrorCode status = U_ZERO_ERROR;
-
- // get the pointer to the number format
- UNumberFormat *fmt = (UNumberFormat *)(int)addr;
-
- const UChar *textChars = env->GetStringChars(text, NULL);
- int textLen = env->GetStringLength(text);
-
- unum_setTextAttribute(fmt, (UNumberFormatTextAttribute) symbol, textChars,
- textLen, &status);
-
- env->ReleaseStringChars(text, textChars);
-
- icu4jni_error(env, status);
-}
-
-static jstring getTextAttribute(JNIEnv *env, jclass clazz, jint addr,
- jint symbol) {
-
- uint32_t resultlength, reslenneeded;
-
- // the errorcode returned by unum_getTextAttribute
- UErrorCode status = U_ZERO_ERROR;
-
- // get the pointer to the number format
- UNumberFormat *fmt = (UNumberFormat *)(int)addr;
-
- UChar* result = NULL;
- resultlength=0;
-
- // find out how long the result will be
- reslenneeded=unum_getTextAttribute(fmt, (UNumberFormatTextAttribute) symbol,
- result, resultlength, &status);
-
- result = NULL;
- if(status==U_BUFFER_OVERFLOW_ERROR) {
- status=U_ZERO_ERROR;
- resultlength=reslenneeded+1;
- result=(UChar*)malloc(sizeof(UChar) * resultlength);
- reslenneeded=unum_getTextAttribute(fmt,
- (UNumberFormatTextAttribute) symbol, result, resultlength,
- &status);
- }
- if (icu4jni_error(env, status) != FALSE) {
- return NULL;
- }
-
- jstring res = env->NewString(result, reslenneeded);
-
- free(result);
-
- return res;
-}
-
-static void applyPatternImpl(JNIEnv *env, jclass clazz, jint addr, jboolean localized, jstring pattern0) {
- if (pattern0 == NULL) {
- jniThrowNullPointerException(env, NULL);
- return;
- }
- ScopedJavaUnicodeString pattern(env, pattern0);
- DecimalFormat* fmt = toDecimalFormat(addr);
- UErrorCode status = U_ZERO_ERROR;
- if (localized) {
- fmt->applyLocalizedPattern(pattern.unicodeString(), status);
- } else {
- fmt->applyPattern(pattern.unicodeString(), status);
- }
- icu4jni_error(env, status);
-}
-
-static jstring toPatternImpl(JNIEnv *env, jclass, jint addr, jboolean localized) {
- DecimalFormat* fmt = toDecimalFormat(addr);
- UnicodeString pattern;
- if (localized) {
- fmt->toLocalizedPattern(pattern);
- } else {
- fmt->toPattern(pattern);
- }
- return env->NewString(pattern.getBuffer(), pattern.length());
-}
-
-template <typename T>
-static jstring format(JNIEnv *env, jint addr, jobject field, jstring fieldType, jobject attributes, T val) {
- UErrorCode status = U_ZERO_ERROR;
-
- DecimalFormat::AttributeBuffer attrBuffer;
- attrBuffer.buffer = NULL;
- DecimalFormat::AttributeBuffer* attrBufferPtr = NULL;
- if (attributes != NULL || (fieldType != NULL && field != NULL)) {
- attrBufferPtr = &attrBuffer;
- // ICU requires that this is dynamically allocated and non-zero size.
- // ICU grows it in chunks of 128 bytes, so that's a reasonable initial size.
- attrBuffer.bufferSize = 128;
- attrBuffer.buffer = new char[attrBuffer.bufferSize];
- attrBuffer.buffer[0] = '\0';
- }
-
- FieldPosition fp;
- fp.setField(FieldPosition::DONT_CARE);
-
- UnicodeString str;
- DecimalFormat* fmt = toDecimalFormat(addr);
- fmt->format(val, str, fp, attrBufferPtr);
-
- if (attrBufferPtr && strlen(attrBuffer.buffer) > 0) {
- // check if we want to get all attributes
- if (attributes != NULL) {
- jstring attrString = env->NewStringUTF(attrBuffer.buffer + 1); // cut off the leading ';'
- jclass stringBufferClass = env->FindClass("java/lang/StringBuffer");
- jmethodID appendMethodID = env->GetMethodID(stringBufferClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
- env->CallObjectMethod(attributes, appendMethodID, attrString);
- }
-
- // check if we want one special attribute returned in the given FieldPos
- if (fieldType != NULL && field != NULL) {
- const char* fieldName = env->GetStringUTFChars(fieldType, NULL);
-
- const char* delimiter = ";";
- char* context = NULL;
- char* resattr = strtok_r(attrBuffer.buffer, delimiter, &context);
-
- while (resattr != NULL && strcmp(resattr, fieldName) != 0) {
- resattr = strtok_r(NULL, delimiter, &context);
- }
-
- if (resattr != NULL && strcmp(resattr, fieldName) == 0) {
- resattr = strtok_r(NULL, delimiter, &context);
- int begin = (int) strtol(resattr, NULL, 10);
- resattr = strtok_r(NULL, delimiter, &context);
- int end = (int) strtol(resattr, NULL, 10);
-
- jclass fieldPositionClass = env->FindClass("java/text/FieldPosition");
- jmethodID setBeginIndexMethodID = env->GetMethodID(fieldPositionClass, "setBeginIndex", "(I)V");
- jmethodID setEndIndexMethodID = env->GetMethodID(fieldPositionClass, "setEndIndex", "(I)V");
- env->CallVoidMethod(field, setBeginIndexMethodID, (jint) begin);
- env->CallVoidMethod(field, setEndIndexMethodID, (jint) end);
- }
- env->ReleaseStringUTFChars(fieldType, fieldName);
- }
- }
-
- jstring result = env->NewString(str.getBuffer(), str.length());
- delete[] attrBuffer.buffer;
- return result;
-}
-
-static jstring formatLong(JNIEnv* env, jclass, jint addr, jlong value,
- jobject field, jstring fieldType, jobject attributes) {
- int64_t longValue = value;
- return format(env, addr, field, fieldType, attributes, longValue);
-}
-
-static jstring formatDouble(JNIEnv* env, jclass, jint addr, jdouble value,
- jobject field, jstring fieldType, jobject attributes) {
- double doubleValue = value;
- return format(env, addr, field, fieldType, attributes, doubleValue);
-}
-
-static jstring formatDigitList(JNIEnv *env, jclass clazz, jint addr, jstring value,
- jobject field, jstring fieldType, jobject attributes, jint scale) {
-
- // const char * valueUTF = env->GetStringUTFChars(value, NULL);
- // LOGI("ENTER formatDigitList: %s, scale: %d", valueUTF, scale);
- // env->ReleaseStringUTFChars(value, valueUTF);
-
- if (scale < 0) {
- icu4jni_error(env, U_ILLEGAL_ARGUMENT_ERROR);
- return NULL;
- }
-
- const char * fieldName = NULL;
- if(fieldType != NULL) {
- fieldName = env->GetStringUTFChars(fieldType, NULL);
- }
-
- uint32_t reslenneeded;
-
- // prepare digit list
-
- const char *valueChars = env->GetStringUTFChars(value, NULL);
-
- bool isInteger = (scale == 0);
- bool isPositive = (*valueChars != '-');
-
- // skip the '-' if the number is negative
- const char *digits = (isPositive ? valueChars : valueChars + 1);
- int length = strlen(digits);
-
- DecimalFormat* fmt = toDecimalFormat(addr);
-
- // The length of our digit list buffer must be the actual string length + 3,
- // because ICU will append some additional characters at the head and at the
- // tail of the string, in order to keep strtod() happy:
- //
- // - The sign "+" or "-" is appended at the head
- // - The exponent "e" and the "\0" terminator is appended at the tail
- //
- // In retrospect, the changes to ICU's DigitList that were necessary for
- // big numbers look a bit hacky. It would make sense to rework all this
- // once ICU 4.x has been integrated into Android. Ideally, big number
- // support would make it into ICU itself, so we don't need our private
- // fix anymore.
- DigitList digitList(length + 3);
- digitList.fCount = length;
- strcpy(digitList.fDigits, digits);
- env->ReleaseStringUTFChars(value, valueChars);
-
- digitList.fDecimalAt = digitList.fCount - scale;
- digitList.fIsPositive = isPositive;
- digitList.fRoundingMode = fmt->getRoundingMode();
- digitList.round(fmt->getMaximumFractionDigits() + digitList.fDecimalAt);
-
- UChar *result = NULL;
-
- FieldPosition fp;
- fp.setField(FieldPosition::DONT_CARE);
- fp.setBeginIndex(0);
- fp.setEndIndex(0);
-
- UErrorCode status = U_ZERO_ERROR;
-
- DecimalFormat::AttributeBuffer *attrBuffer = NULL;
- attrBuffer = (DecimalFormat::AttributeBuffer *) calloc(sizeof(DecimalFormat::AttributeBuffer), 1);
- attrBuffer->bufferSize = 128;
- attrBuffer->buffer = (char *) calloc(129 * sizeof(char), 1);
-
- UnicodeString res;
-
- fmt->subformat(res, fp, attrBuffer, digitList, isInteger);
-
- reslenneeded = res.extract(NULL, 0, status);
-
- if(status==U_BUFFER_OVERFLOW_ERROR) {
- status=U_ZERO_ERROR;
-
- result = (UChar*)malloc(sizeof(UChar) * (reslenneeded + 1));
-
- res.extract(result, reslenneeded + 1, status);
-
- if (icu4jni_error(env, status) != FALSE) {
- if(fieldType != NULL) {
- env->ReleaseStringUTFChars(fieldType, fieldName);
- }
- free(result);
- free(attrBuffer->buffer);
- free(attrBuffer);
- return NULL;
- }
-
- } else {
- if(fieldType != NULL) {
- env->ReleaseStringUTFChars(fieldType, fieldName);
- }
- free(attrBuffer->buffer);
- free(attrBuffer);
- return NULL;
- }
-
- int attrLength = (strlen(attrBuffer->buffer) + 1 );
-
- if(attrLength > 1) {
-
- // check if we want to get all attributes
- if(attributes != NULL) {
- // prepare the classes and method ids
- const char * stringBufferClassName = "java/lang/StringBuffer";
- jclass stringBufferClass = env->FindClass(stringBufferClassName);
- jmethodID appendMethodID = env->GetMethodID(stringBufferClass,
- "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
-
- jstring attrString = env->NewStringUTF(attrBuffer->buffer + 1); // cut off the leading ';'
- env->CallObjectMethod(attributes, appendMethodID, attrString);
- }
-
- // check if we want one special attribute returned in the given FieldPos
- if(fieldName != NULL && field != NULL) {
- const char *delimiter = ";";
- int begin;
- int end;
- char * resattr;
- resattr = strtok(attrBuffer->buffer, delimiter);
-
- while(resattr != NULL && strcmp(resattr, fieldName) != 0) {
- resattr = strtok(NULL, delimiter);
- }
-
- if(resattr != NULL && strcmp(resattr, fieldName) == 0) {
-
- // prepare the classes and method ids
- const char * fieldPositionClassName =
- "java/text/FieldPosition";
- jclass fieldPositionClass = env->FindClass(
- fieldPositionClassName);
- jmethodID setBeginIndexMethodID = env->GetMethodID(
- fieldPositionClass, "setBeginIndex", "(I)V");
- jmethodID setEndIndexMethodID = env->GetMethodID(
- fieldPositionClass, "setEndIndex", "(I)V");
-
-
- resattr = strtok(NULL, delimiter);
- begin = (int) strtol(resattr, NULL, 10);
- resattr = strtok(NULL, delimiter);
- end = (int) strtol(resattr, NULL, 10);
-
- env->CallVoidMethod(field, setBeginIndexMethodID, (jint) begin);
- env->CallVoidMethod(field, setEndIndexMethodID, (jint) end);
- }
- }
- }
-
- if(fieldType != NULL) {
- env->ReleaseStringUTFChars(fieldType, fieldName);
- }
-
- jstring resulting = env->NewString(result, reslenneeded);
-
- free(attrBuffer->buffer);
- free(attrBuffer);
- free(result);
- // const char * resultUTF = env->GetStringUTFChars(resulting, NULL);
- // LOGI("RETURN formatDigitList: %s", resultUTF);
- // env->ReleaseStringUTFChars(resulting, resultUTF);
-
- return resulting;
-}
-
-static jobject parse(JNIEnv *env, jclass clazz, jint addr, jstring text,
- jobject position) {
- // TODO: cache these?
- jclass parsePositionClass = env->FindClass("java/text/ParsePosition");
- jclass longClass = env->FindClass("java/lang/Long");
- jclass doubleClass = env->FindClass("java/lang/Double");
- jclass bigDecimalClass = env->FindClass("java/math/BigDecimal");
- jclass bigIntegerClass = env->FindClass("java/math/BigInteger");
-
- jmethodID getIndexMethodID = env->GetMethodID(parsePositionClass,
- "getIndex", "()I");
- jmethodID setIndexMethodID = env->GetMethodID(parsePositionClass,
- "setIndex", "(I)V");
- jmethodID setErrorIndexMethodID = env->GetMethodID(parsePositionClass,
- "setErrorIndex", "(I)V");
-
- jmethodID longInitMethodID = env->GetMethodID(longClass, "<init>", "(J)V");
- jmethodID dblInitMethodID = env->GetMethodID(doubleClass, "<init>", "(D)V");
- jmethodID bigDecimalInitMethodID = env->GetMethodID(bigDecimalClass, "<init>", "(Ljava/math/BigInteger;I)V");
- jmethodID bigIntegerInitMethodID = env->GetMethodID(bigIntegerClass, "<init>", "(Ljava/lang/String;)V");
- jmethodID doubleValueMethodID = env->GetMethodID(bigDecimalClass, "doubleValue", "()D");
-
- // make sure the ParsePosition is valid. Actually icu4c would parse a number
- // correctly even if the parsePosition is set to -1, but since the RI fails
- // for that case we have to fail too
- int parsePos = env->CallIntMethod(position, getIndexMethodID, NULL);
- const int strlength = env->GetStringLength(text);
- if(parsePos < 0 || parsePos > strlength) {
- return NULL;
- }
-
- ParsePosition pp;
- pp.setIndex(parsePos);
-
- DigitList digits;
-
- UNumberFormat *fmt = (UNumberFormat *)(int)addr;
- Formattable res;
- bool resultAssigned;
- jchar *str = (UChar *)env->GetStringChars(text, NULL);
- const UnicodeString src((UChar*)str, strlength, strlength);
- ((const DecimalFormat*)fmt)->parse(src, resultAssigned, res, pp, FALSE, digits);
- env->ReleaseStringChars(text, str);
-
- if(pp.getErrorIndex() == -1) {
- parsePos = pp.getIndex();
- } else {
- env->CallVoidMethod(position, setErrorIndexMethodID,
- (jint) pp.getErrorIndex());
- return NULL;
- }
-
- Formattable::Type numType = res.getType();
- UErrorCode fmtStatus;
-
- double resultDouble;
- long resultLong;
- int64_t resultInt64;
- jstring resultStr;
- jobject resultObject1, resultObject2;
-
- if (resultAssigned)
- {
- switch(numType) {
- case Formattable::kDouble:
- resultDouble = res.getDouble();
- env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
- return env->NewObject(doubleClass, dblInitMethodID,
- (jdouble) resultDouble);
- case Formattable::kLong:
- resultLong = res.getLong();
- env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
- return env->NewObject(longClass, longInitMethodID,
- (jlong) resultLong);
- case Formattable::kInt64:
- resultInt64 = res.getInt64();
- env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
- return env->NewObject(longClass, longInitMethodID,
- (jlong) resultInt64);
- default:
- return NULL;
- }
- }
- else
- {
- int scale = digits.fCount - digits.fDecimalAt;
- // ATTENTION: Abuse of Implementation Knowlegde!
- digits.fDigits[digits.fCount] = 0;
- if (digits.fIsPositive) {
- resultStr = env->NewStringUTF(digits.fDigits);
- } else {
- if (digits.fCount == 0) {
- env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
- return env->NewObject(doubleClass, dblInitMethodID, (jdouble)-0);
- } else {
- // ATTENTION: Abuse of Implementation Knowlegde!
- *(digits.fDigits - 1) = '-';
- resultStr = env->NewStringUTF(digits.fDigits - 1);
- }
- }
-
- env->CallVoidMethod(position, setIndexMethodID, (jint) parsePos);
-
- resultObject1 = env->NewObject(bigIntegerClass, bigIntegerInitMethodID, resultStr);
- resultObject2 = env->NewObject(bigDecimalClass, bigDecimalInitMethodID, resultObject1, scale);
- return resultObject2;
- }
-}
-
-static jint cloneDecimalFormatImpl(JNIEnv *env, jclass, jint addr) {
- DecimalFormat* fmt = toDecimalFormat(addr);
- return static_cast<jint>(reinterpret_cast<uintptr_t>(fmt->clone()));
-}
-
-static JNINativeMethod gMethods[] = {
- {"applyPatternImpl", "(IZLjava/lang/String;)V", (void*) applyPatternImpl},
- {"cloneDecimalFormatImpl", "(I)I", (void*) cloneDecimalFormatImpl},
- {"closeDecimalFormatImpl", "(I)V", (void*) closeDecimalFormatImpl},
- {"format", "(IDLjava/text/FieldPosition;Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/String;", (void*) formatDouble},
- {"format", "(IJLjava/text/FieldPosition;Ljava/lang/String;Ljava/lang/StringBuffer;)Ljava/lang/String;", (void*) formatLong},
- {"format", "(ILjava/lang/String;Ljava/text/FieldPosition;Ljava/lang/String;Ljava/lang/StringBuffer;I)Ljava/lang/String;", (void*) formatDigitList},
- {"getAttribute", "(II)I", (void*) getAttribute},
- {"getTextAttribute", "(II)Ljava/lang/String;", (void*) getTextAttribute},
- {"openDecimalFormatImpl", "(Ljava/lang/String;Ljava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)I", (void*) openDecimalFormatImpl},
- {"parse", "(ILjava/lang/String;Ljava/text/ParsePosition;)Ljava/lang/Number;", (void*) parse},
- {"setAttribute", "(III)V", (void*) setAttribute},
- {"setDecimalFormatSymbols", "(ILjava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)V", (void*) setDecimalFormatSymbols},
- {"setSymbol", "(IILjava/lang/String;)V", (void*) setSymbol},
- {"setRoundingMode", "(IID)V", (void*) setRoundingMode},
- {"setTextAttribute", "(IILjava/lang/String;)V", (void*) setTextAttribute},
- {"toPatternImpl", "(IZ)Ljava/lang/String;", (void*) toPatternImpl},
-};
-int register_com_ibm_icu4jni_text_NativeDecimalFormat(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeDecimalFormat", gMethods,
- NELEM(gMethods));
-}
diff --git a/icu/src/main/native/NativeIDN.cpp b/icu/src/main/native/NativeIDN.cpp
deleted file mode 100644
index e8052fc..0000000
--- a/icu/src/main/native/NativeIDN.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "NativeIDN"
-
-#include "ErrorCode.h"
-#include "JNIHelp.h"
-#include "ScopedJavaUnicodeString.h"
-#include "unicode/uidna.h"
-
-static bool isLabelSeparator(const UChar ch) {
- switch (ch) {
- case 0x3002: // ideographic full stop
- case 0xff0e: // fullwidth full stop
- case 0xff61: // halfwidth ideographic full stop
- return true;
- default:
- return false;
- }
-}
-
-static jstring convertImpl(JNIEnv* env, jclass, jstring s, jint flags, jboolean toAscii) {
- ScopedJavaUnicodeString sus(env, s);
- const UChar* src = sus.unicodeString().getBuffer();
- const size_t srcLength = sus.unicodeString().length();
- UChar dst[256];
- UErrorCode status = U_ZERO_ERROR;
- size_t resultLength = toAscii
- ? uidna_IDNToASCII(src, srcLength, &dst[0], sizeof(dst), flags, NULL, &status)
- : uidna_IDNToUnicode(src, srcLength, &dst[0], sizeof(dst), flags, NULL, &status);
- if (U_FAILURE(status)) {
- jniThrowException(env, "java/lang/IllegalArgumentException", u_errorName(status));
- return NULL;
- }
- if (!toAscii) {
- // ICU only translates separators to ASCII for toASCII.
- // Java expects the translation for toUnicode too.
- // We may as well do this here, while the string is still mutable.
- for (size_t i = 0; i < resultLength; ++i) {
- if (isLabelSeparator(dst[i])) {
- dst[i] = '.';
- }
- }
- }
- return env->NewString(&dst[0], resultLength);
-}
-
-static JNINativeMethod gMethods[] = {
- {"convertImpl", "(Ljava/lang/String;IZ)Ljava/lang/String;", (void*) convertImpl},
-};
-int register_com_ibm_icu4jni_text_NativeIDN(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeIDN", gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/NativeNormalizer.cpp b/icu/src/main/native/NativeNormalizer.cpp
deleted file mode 100644
index 257cf9b..0000000
--- a/icu/src/main/native/NativeNormalizer.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "NativeNormalizer"
-
-#include "ErrorCode.h"
-#include "JNIHelp.h"
-#include "ScopedJavaUnicodeString.h"
-#include "unicode/normlzr.h"
-
-static jstring normalizeImpl(JNIEnv* env, jclass, jstring s, jint intMode) {
- ScopedJavaUnicodeString src(env, s);
- UNormalizationMode mode = static_cast<UNormalizationMode>(intMode);
- UErrorCode errorCode = U_ZERO_ERROR;
- UnicodeString dst;
- Normalizer::normalize(src.unicodeString(), mode, 0, dst, errorCode);
- icu4jni_error(env, errorCode);
- return dst.isBogus() ? NULL : env->NewString(dst.getBuffer(), dst.length());
-}
-
-static jboolean isNormalizedImpl(JNIEnv* env, jclass, jstring s, jint intMode) {
- ScopedJavaUnicodeString src(env, s);
- UNormalizationMode mode = static_cast<UNormalizationMode>(intMode);
- UErrorCode errorCode = U_ZERO_ERROR;
- UBool result = Normalizer::isNormalized(src.unicodeString(), mode, errorCode);
- icu4jni_error(env, errorCode);
- return result;
-}
-
-static JNINativeMethod gMethods[] = {
- {"normalizeImpl", "(Ljava/lang/String;I)Ljava/lang/String;", (void*) normalizeImpl},
- {"isNormalizedImpl", "(Ljava/lang/String;I)Z", (void*) isNormalizedImpl},
-};
-int register_com_ibm_icu4jni_text_NativeNormalizer(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeNormalizer",
- gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/NativeRegEx.cpp b/icu/src/main/native/NativeRegEx.cpp
deleted file mode 100644
index 511f1e4..0000000
--- a/icu/src/main/native/NativeRegEx.cpp
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "NativeRegEx"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "unicode/uregex.h"
-#include "unicode/utypes.h"
-#include "unicode/parseerr.h"
-
-#include <jni.h>
-#include <JNIHelp.h>
-
-static jchar EMPTY_STRING = 0;
-
-/**
- * A data structure that ties together an ICU regular expression and the
- * character data it refers to (but does not have a copy of), so we can
- * manage memory properly.
- */
-struct RegExData {
- // A pointer to the ICU regular expression
- URegularExpression* regex;
- // A pointer to (a copy of) the input text that *we* manage
- jchar* text;
-};
-
-static void throwPatternSyntaxException(JNIEnv* env, UErrorCode status,
- jstring pattern, UParseError error)
-{
- jclass clazz = env->FindClass("java/util/regex/PatternSyntaxException");
- jmethodID method = env->GetMethodID(clazz, "<init>",
- "(Ljava/lang/String;Ljava/lang/String;I)V");
-
- jstring message = env->NewStringUTF(u_errorName(status));
- jthrowable except = (jthrowable)(env->NewObject(clazz, method, message,
- pattern, error.offset));
- env->Throw(except);
-}
-
-static void throwRuntimeException(JNIEnv* env, UErrorCode status) {
- jniThrowRuntimeException(env, u_errorName(status));
-}
-
-static void _close(JNIEnv* env, jclass clazz, RegExData* data)
-{
- if (data->regex != NULL) {
- uregex_close(data->regex);
- }
-
- if (data->text != &EMPTY_STRING) {
- delete[] data->text;
- }
-
- free(data);
-}
-
-static RegExData* open(JNIEnv* env, jclass clazz, jstring pattern, jint flags)
-{
- flags = flags | UREGEX_ERROR_ON_UNKNOWN_ESCAPES;
-
- RegExData* data = (RegExData*)calloc(sizeof(RegExData), 1);
-
- UErrorCode status = U_ZERO_ERROR;
- UParseError error;
- error.offset = -1;
-
- jchar const * patternRaw;
- int patternLen = env->GetStringLength(pattern);
- if (patternLen == 0) {
- data->regex = uregex_open(&EMPTY_STRING, -1, flags, &error, &status);
- } else {
- jchar const * patternRaw = env->GetStringChars(pattern, NULL);
- data->regex = uregex_open(patternRaw, patternLen, flags, &error,
- &status);
- env->ReleaseStringChars(pattern, patternRaw);
- }
-
- if (!U_SUCCESS(status)) {
- _close(env, clazz, data);
- throwPatternSyntaxException(env, status, pattern, error);
- data = NULL;
- }
-
- return data;
-}
-
-static RegExData* _clone(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
-
- URegularExpression* clonedRegex = uregex_clone(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-
- RegExData* result = (RegExData*)calloc(sizeof(RegExData), 1);
- result->regex = clonedRegex;
-
- return result;
-}
-
-static void setText(JNIEnv* env, jclass clazz, RegExData* data, jstring text)
-{
- UErrorCode status = U_ZERO_ERROR;
-
- uregex_setText(data->regex, &EMPTY_STRING, 0, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- return;
- }
-
- if (data->text != &EMPTY_STRING) {
- delete[] data->text;
- data->text = NULL;
- }
-
- int textLen = env->GetStringLength(text);
- if (textLen == 0) {
- data->text = &EMPTY_STRING;
- } else {
- data->text = new jchar[textLen + 1];
- env->GetStringRegion(text, 0, textLen, data->text);
- data->text[textLen] = 0;
- }
-
- uregex_setText(data->regex, data->text, textLen, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-}
-
-static jboolean matches(JNIEnv* env, jclass clazz, RegExData* data,
- jint startIndex)
-{
- UErrorCode status = U_ZERO_ERROR;
-
- jboolean result = uregex_matches(data->regex, startIndex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-
- return result;
-}
-
-static jboolean lookingAt(JNIEnv* env, jclass clazz, RegExData* data,
- jint startIndex)
-{
- UErrorCode status = U_ZERO_ERROR;
-
- jboolean result = uregex_lookingAt(data->regex, startIndex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-
- return result;
-}
-
-static jboolean find(JNIEnv* env, jclass clazz, RegExData* data,
- jint startIndex)
-{
- UErrorCode status = U_ZERO_ERROR;
-
- jboolean result = uregex_find(data->regex, startIndex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-
- return result;
-}
-
-static jboolean findNext(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
-
- jboolean result = uregex_findNext(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-
- return result;
-}
-
-static jint groupCount(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
-
- jint result = uregex_groupCount(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-
- return result;
-}
-
-static void startEnd(JNIEnv* env, jclass clazz, RegExData* data,
- jintArray offsets)
-{
- UErrorCode status = U_ZERO_ERROR;
-
- jint * offsetsRaw = env->GetIntArrayElements(offsets, NULL);
-
- int groupCount = uregex_groupCount(data->regex, &status);
- for (int i = 0; i <= groupCount && U_SUCCESS(status); i++) {
- offsetsRaw[2 * i + 0] = uregex_start(data->regex, i, &status);
- offsetsRaw[2 * i + 1] = uregex_end(data->regex, i, &status);
- }
-
- env->ReleaseIntArrayElements(offsets, offsetsRaw, 0);
-
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-}
-
-static void setRegion(JNIEnv* env, jclass clazz, RegExData* data, jint start,
- jint end)
-{
- UErrorCode status = U_ZERO_ERROR;
- uregex_setRegion(data->regex, start, end, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-}
-
-static jint regionStart(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
- int result = uregex_regionStart(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
- return result;
-}
-
-static jint regionEnd(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
- int result = uregex_regionEnd(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
- return result;
-}
-
-static void useTransparentBounds(JNIEnv* env, jclass clazz, RegExData* data,
- jboolean value)
-{
- UErrorCode status = U_ZERO_ERROR;
- uregex_useTransparentBounds(data->regex, value, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-}
-
-static jboolean hasTransparentBounds(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
- jboolean result = uregex_hasTransparentBounds(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
- return result;
-}
-
-static void useAnchoringBounds(JNIEnv* env, jclass clazz, RegExData* data,
- jboolean value)
-{
- UErrorCode status = U_ZERO_ERROR;
- uregex_useAnchoringBounds(data->regex, value, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-}
-
-static jboolean hasAnchoringBounds(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
- jboolean result = uregex_hasAnchoringBounds(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
- return result;
-}
-
-static jboolean hitEnd(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
- jboolean result = uregex_hitEnd(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
- return result;
-}
-
-static jboolean requireEnd(JNIEnv* env, jclass clazz, RegExData* data)
-{
- UErrorCode status = U_ZERO_ERROR;
- jboolean result = uregex_requireEnd(data->regex, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
- return result;
-}
-
-static void reset(JNIEnv* env, jclass clazz, RegExData* data, jint position)
-{
- UErrorCode status = U_ZERO_ERROR;
- uregex_reset(data->regex, position, &status);
- if (!U_SUCCESS(status)) {
- throwRuntimeException(env, status);
- }
-}
-
-static JNINativeMethod gMethods[] = {
- { "open", "(Ljava/lang/String;I)I", (void*)open },
- { "clone", "(I)I", (void*)_clone },
- { "close", "(I)V", (void*)_close },
- { "setText", "(ILjava/lang/String;)V", (void*)setText },
- { "matches", "(II)Z", (void*)matches },
- { "lookingAt", "(II)Z", (void*)lookingAt },
- { "find", "(II)Z", (void*)find },
- { "findNext", "(I)Z", (void*)findNext },
- { "groupCount", "(I)I", (void*)groupCount },
- { "startEnd", "(I[I)V", (void*)startEnd },
- { "setRegion", "(III)V", (void*)setRegion },
- { "regionStart", "(I)I", (void*)regionStart },
- { "regionEnd", "(I)I", (void*)regionEnd },
- { "useTransparentBounds", "(IZ)V", (void*)useTransparentBounds },
- { "hasTransparentBounds", "(I)Z", (void*)hasTransparentBounds },
- { "useAnchoringBounds", "(IZ)V", (void*)useAnchoringBounds },
- { "hasAnchoringBounds", "(I)Z", (void*)hasAnchoringBounds },
- { "hitEnd", "(I)Z", (void*)hitEnd },
- { "requireEnd", "(I)Z", (void*)requireEnd },
- { "reset", "(II)V", (void*)reset },
-};
-int register_com_ibm_icu4jni_regex_NativeRegEx(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/regex/NativeRegEx",
- gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/ScopedJavaUnicodeString.h b/icu/src/main/native/ScopedJavaUnicodeString.h
deleted file mode 100644
index b108a6b..0000000
--- a/icu/src/main/native/ScopedJavaUnicodeString.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef SCOPED_JAVA_UNICODE_STRING_H_included
-#define SCOPED_JAVA_UNICODE_STRING_H_included
-
-#include "JNIHelp.h"
-#include "unicode/unistr.h"
-
-// A smart pointer that provides access to an ICU UnicodeString given a JNI
-// jstring. We give ICU a direct pointer to the characters on the Java heap.
-// It's clever enough to copy-on-write if necessary.
-class ScopedJavaUnicodeString {
-public:
- ScopedJavaUnicodeString(JNIEnv* env, jstring s) : mEnv(env), mString(s) {
- mChars = env->GetStringChars(mString, NULL);
- const int32_t charCount = env->GetStringLength(mString);
- mUnicodeString.setTo(false, mChars, charCount);
- }
-
- ~ScopedJavaUnicodeString() {
- mEnv->ReleaseStringChars(mString, mChars);
- }
-
- const UnicodeString& unicodeString() const {
- return mUnicodeString;
- }
-
- UnicodeString& unicodeString() {
- return mUnicodeString;
- }
-
-private:
- JNIEnv* mEnv;
- jstring mString;
- const UChar* mChars;
- UnicodeString mUnicodeString;
-
- // Disallow copy and assignment.
- ScopedJavaUnicodeString(const ScopedJavaUnicodeString&);
- void operator=(const ScopedJavaUnicodeString&);
-};
-
-#endif // SCOPED_JAVA_UNICODE_STRING_H_included
diff --git a/icu/src/main/native/UCharacter.cpp b/icu/src/main/native/UCharacter.cpp
deleted file mode 100644
index abad16a..0000000
--- a/icu/src/main/native/UCharacter.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "UCharacter"
-
-#include "JNIHelp.h"
-#include "ScopedJavaUnicodeString.h"
-#include "ScopedUtfChars.h"
-#include "unicode/locid.h"
-#include "unicode/uchar.h"
-#include <math.h>
-#include <stdlib.h>
-
-static jint digitImpl(JNIEnv*, jclass, jint codePoint, jint radix) {
- return u_digit(codePoint, radix);
-}
-
-static jint getTypeImpl(JNIEnv*, jclass, jint codePoint) {
- return u_charType(codePoint);
-}
-
-static jbyte getDirectionalityImpl(JNIEnv*, jclass, jint codePoint) {
- return u_charDirection(codePoint);
-}
-
-static jboolean isMirroredImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isMirrored(codePoint);
-}
-
-static jint getNumericValueImpl(JNIEnv*, jclass, jint codePoint){
- // The letters A-Z in their uppercase ('\u0041' through '\u005A'),
- // lowercase ('\u0061' through '\u007A'),
- // and full width variant ('\uFF21' through '\uFF3A'
- // and '\uFF41' through '\uFF5A') forms
- // have numeric values from 10 through 35. This is independent of the
- // Unicode specification, which does not assign numeric values to these
- // char values.
- if (codePoint >= 0x41 && codePoint <= 0x5A) {
- return codePoint - 0x37;
- }
- if (codePoint >= 0x61 && codePoint <= 0x7A) {
- return codePoint - 0x57;
- }
- if (codePoint >= 0xFF21 && codePoint <= 0xFF3A) {
- return codePoint - 0xFF17;
- }
- if (codePoint >= 0xFF41 && codePoint <= 0xFF5A) {
- return codePoint - 0xFF37;
- }
-
- double result = u_getNumericValue(codePoint);
-
- if (result == U_NO_NUMERIC_VALUE) {
- return -1;
- } else if (result < 0 || floor(result + 0.5) != result) {
- return -2;
- }
-
- return result;
-}
-
-static jboolean isDefinedImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isdefined(codePoint);
-}
-
-static jboolean isDigitImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isdigit(codePoint);
-}
-
-static jboolean isIdentifierIgnorableImpl(JNIEnv*, jclass, jint codePoint) {
- // Java also returns TRUE for U+0085 Next Line (it omits U+0085 from whitespace ISO controls)
- if(codePoint == 0x0085) {
- return JNI_TRUE;
- }
- return u_isIDIgnorable(codePoint);
-}
-
-static jboolean isLetterImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isalpha(codePoint);
-}
-
-static jboolean isLetterOrDigitImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isalnum(codePoint);
-}
-
-static jboolean isSpaceCharImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isJavaSpaceChar(codePoint);
-}
-
-static jboolean isTitleCaseImpl(JNIEnv*, jclass, jint codePoint) {
- return u_istitle(codePoint);
-}
-
-static jboolean isUnicodeIdentifierPartImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isIDPart(codePoint);
-}
-
-static jboolean isUnicodeIdentifierStartImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isIDStart(codePoint);
-}
-
-static jboolean isWhitespaceImpl(JNIEnv*, jclass, jint codePoint) {
- // Java omits U+0085
- if(codePoint == 0x0085) {
- return JNI_FALSE;
- }
- return u_isWhitespace(codePoint);
-}
-
-static jint toLowerCaseImpl(JNIEnv*, jclass, jint codePoint) {
- return u_tolower(codePoint);
-}
-
-static jint toTitleCaseImpl(JNIEnv*, jclass, jint codePoint) {
- return u_totitle(codePoint);
-}
-
-static jint toUpperCaseImpl(JNIEnv*, jclass, jint codePoint) {
- return u_toupper(codePoint);
-}
-
-static jstring toLowerCaseStringImpl(JNIEnv* env, jclass, jstring javaString, jstring localeName) {
- ScopedJavaUnicodeString scopedString(env, javaString);
- UnicodeString& s(scopedString.unicodeString());
- UnicodeString original(s);
- s.toLower(Locale::createFromName(ScopedUtfChars(env, localeName).c_str()));
- return s == original ? javaString : env->NewString(s.getBuffer(), s.length());
-}
-
-static jstring toUpperCaseStringImpl(JNIEnv* env, jclass, jstring javaString, jstring localeName) {
- ScopedJavaUnicodeString scopedString(env, javaString);
- UnicodeString& s(scopedString.unicodeString());
- UnicodeString original(s);
- s.toUpper(Locale::createFromName(ScopedUtfChars(env, localeName).c_str()));
- return s == original ? javaString : env->NewString(s.getBuffer(), s.length());
-}
-
-static jboolean isUpperCaseImpl(JNIEnv*, jclass, jint codePoint) {
- return u_isupper(codePoint);
-}
-
-static jboolean isLowerCaseImpl(JNIEnv*, jclass, jint codePoint) {
- return u_islower(codePoint);
-}
-
-static int forNameImpl(JNIEnv* env, jclass, jstring blockName) {
- if (blockName == NULL) {
- jniThrowNullPointerException(env, NULL);
- return -1;
- }
- const char* bName = env->GetStringUTFChars(blockName, NULL);
- int result = u_getPropertyValueEnum(UCHAR_BLOCK, bName);
- env->ReleaseStringUTFChars(blockName, bName);
- return result;
-}
-
-static int ofImpl(JNIEnv*, jclass, jint codePoint) {
- return ublock_getCode(codePoint);
-}
-
-static JNINativeMethod gMethods[] = {
- { "digit", "(II)I", (void*) digitImpl },
- { "forName", "(Ljava/lang/String;)I", (void*) forNameImpl },
- { "getDirectionality", "(I)B", (void*) getDirectionalityImpl },
- { "getNumericValue", "(I)I", (void*) getNumericValueImpl },
- { "getType", "(I)I", (void*) getTypeImpl },
- { "isDefined", "(I)Z", (void*) isDefinedImpl },
- { "isDigit", "(I)Z", (void*) isDigitImpl },
- { "isIdentifierIgnorable", "(I)Z", (void*) isIdentifierIgnorableImpl },
- { "isLetter", "(I)Z", (void*) isLetterImpl },
- { "isLetterOrDigit", "(I)Z", (void*) isLetterOrDigitImpl },
- { "isLowerCase", "(I)Z", (void*) isLowerCaseImpl },
- { "isMirrored", "(I)Z", (void*) isMirroredImpl },
- { "isSpaceChar", "(I)Z", (void*) isSpaceCharImpl },
- { "isTitleCase", "(I)Z", (void*) isTitleCaseImpl },
- { "isUnicodeIdentifierPart", "(I)Z", (void*) isUnicodeIdentifierPartImpl },
- { "isUnicodeIdentifierStart", "(I)Z", (void*) isUnicodeIdentifierStartImpl },
- { "isUpperCase", "(I)Z", (void*) isUpperCaseImpl },
- { "isWhitespace", "(I)Z", (void*) isWhitespaceImpl },
- { "of", "(I)I", (void*) ofImpl },
- { "toLowerCase", "(I)I", (void*) toLowerCaseImpl },
- { "toTitleCase", "(I)I", (void*) toTitleCaseImpl },
- { "toUpperCase", "(I)I", (void*) toUpperCaseImpl },
- { "toLowerCase", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) toLowerCaseStringImpl },
- { "toUpperCase", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) toUpperCaseStringImpl },
-};
-int register_com_ibm_icu4jni_lang_UCharacter(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/lang/UCharacter",
- gMethods, NELEM(gMethods));
-}
diff --git a/icu/src/main/native/sub.mk b/icu/src/main/native/sub.mk
deleted file mode 100644
index 599c102..0000000
--- a/icu/src/main/native/sub.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-# This file is included by the top-level libcore Android.mk.
-# It's not a normal makefile, so we don't include CLEAR_VARS
-# or BUILD_*_LIBRARY.
-
-LOCAL_SRC_FILES := \
- BidiWrapper.cpp \
- ErrorCode.cpp \
- ICU.cpp \
- NativeBreakIterator.cpp \
- NativeCollation.cpp \
- NativeConverter.cpp \
- NativeDecimalFormat.cpp \
- NativeIDN.cpp \
- NativeNormalizer.cpp \
- NativeRegEx.cpp \
- UCharacter.cpp
-
-LOCAL_C_INCLUDES += \
- external/icu4c/common \
- external/icu4c/i18n
-
-# Any shared/static libs that are listed here must also
-# be listed in libs/nativehelper/Android.mk.
-# TODO: fix this requirement
-
-LOCAL_SHARED_LIBRARIES += \
- libicudata \
- libicuuc \
- libicui18n
-
-LOCAL_STATIC_LIBRARIES +=