ICU-12748 Add @Overrides and fix whitespace, thanks to Eclipse
X-SVN-Rev: 39313
This commit is contained in:
parent
96df443f84
commit
c1425af28f
@ -27,6 +27,7 @@ class Charset88591 extends CharsetASCII {
|
||||
super(cs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoopCoreOptimized(ByteBuffer source, CharBuffer target,
|
||||
byte[] sourceArray, char[] targetArray, int oldSource, int offset, int limit) {
|
||||
|
||||
@ -40,6 +41,7 @@ class Charset88591 extends CharsetASCII {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoopCoreUnoptimized(ByteBuffer source, CharBuffer target) {
|
||||
byte ch;
|
||||
/*
|
||||
@ -54,7 +56,7 @@ class Charset88591 extends CharsetASCII {
|
||||
return CoderResult.OVERFLOW;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CoderResult.UNDERFLOW;
|
||||
}
|
||||
}
|
||||
@ -64,6 +66,7 @@ class Charset88591 extends CharsetASCII {
|
||||
super(cs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final CoderResult encodeLoopCoreOptimized(CharBuffer source, ByteBuffer target,
|
||||
char[] sourceArray, byte[] targetArray, int oldSource, int offset, int limit,
|
||||
boolean flush) {
|
||||
@ -74,7 +77,7 @@ class Charset88591 extends CharsetASCII {
|
||||
* char in the source is within the correct range
|
||||
*/
|
||||
for (i = oldSource; i < limit; i++) {
|
||||
ch = (int) sourceArray[i];
|
||||
ch = sourceArray[i];
|
||||
if ((ch & 0xff00) == 0) {
|
||||
targetArray[i + offset] = (byte) ch;
|
||||
} else {
|
||||
@ -95,6 +98,7 @@ class Charset88591 extends CharsetASCII {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final CoderResult encodeLoopCoreUnoptimized(CharBuffer source, ByteBuffer target, boolean flush) {
|
||||
int ch;
|
||||
|
||||
@ -102,9 +106,9 @@ class Charset88591 extends CharsetASCII {
|
||||
* perform 88591 conversion from the source buffer to the target buffer, making sure
|
||||
* each char in the source is within the correct range
|
||||
*/
|
||||
|
||||
|
||||
while (source.hasRemaining()) {
|
||||
ch = (int) source.get();
|
||||
ch = source.get();
|
||||
if ((ch & 0xff00) == 0) {
|
||||
if (target.hasRemaining()) {
|
||||
target.put((byte) ch);
|
||||
@ -119,20 +123,23 @@ class Charset88591 extends CharsetASCII {
|
||||
return encodeMalformedOrUnmappable(source, ch, flush);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CoderResult.UNDERFLOW;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoder88591(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoder88591(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
setFillIn.add(0,0xff);
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ class CharsetASCII extends CharsetICU {
|
||||
super(cs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
boolean flush) {
|
||||
if (!source.hasRemaining()) {
|
||||
@ -62,7 +63,7 @@ class CharsetASCII extends CharsetICU {
|
||||
int sourceOffset = source.arrayOffset();
|
||||
int sourceIndex = oldSource + sourceOffset;
|
||||
int sourceLength = source.limit() - oldSource;
|
||||
|
||||
|
||||
char[] targetArray = target.array();
|
||||
int targetOffset = target.arrayOffset();
|
||||
int targetIndex = oldTarget + targetOffset;
|
||||
@ -140,7 +141,7 @@ class CharsetASCII extends CharsetICU {
|
||||
*/
|
||||
while (source.hasRemaining()) {
|
||||
ch = source.get() & 0xff;
|
||||
|
||||
|
||||
if ((ch & 0x80) == 0) {
|
||||
if (target.hasRemaining()) {
|
||||
target.put((char)ch);
|
||||
@ -155,7 +156,7 @@ class CharsetASCII extends CharsetICU {
|
||||
return decodeMalformedOrUnmappable(ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CoderResult.UNDERFLOW;
|
||||
}
|
||||
|
||||
@ -179,11 +180,13 @@ class CharsetASCII extends CharsetICU {
|
||||
|
||||
private final static int NEED_TO_WRITE_BOM = 1;
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
fromUnicodeStatus = NEED_TO_WRITE_BOM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
boolean flush) {
|
||||
if (!source.hasRemaining()) {
|
||||
@ -246,9 +249,9 @@ class CharsetASCII extends CharsetICU {
|
||||
}
|
||||
} else {
|
||||
/* unoptimized loop */
|
||||
|
||||
|
||||
cr = encodeLoopCoreUnoptimized(source, target, flush);
|
||||
|
||||
|
||||
if (cr == CoderResult.OVERFLOW) {
|
||||
source.position(source.position() - 1); /* rewind by 1 */
|
||||
}
|
||||
@ -274,7 +277,7 @@ class CharsetASCII extends CharsetICU {
|
||||
* perform ascii conversion from the source array to the target array, making sure each
|
||||
* char in the source is within the correct range
|
||||
*/
|
||||
for (i = oldSource; i < limit && (((ch = (int) sourceArray[i]) & 0xff80) == 0); i++)
|
||||
for (i = oldSource; i < limit && (((ch = sourceArray[i]) & 0xff80) == 0); i++)
|
||||
targetArray[i + offset] = (byte) ch;
|
||||
|
||||
/*
|
||||
@ -292,14 +295,14 @@ class CharsetASCII extends CharsetICU {
|
||||
|
||||
protected CoderResult encodeLoopCoreUnoptimized(CharBuffer source, ByteBuffer target, boolean flush) {
|
||||
int ch;
|
||||
|
||||
|
||||
/*
|
||||
* perform ascii conversion from the source buffer to the target buffer, making sure
|
||||
* each char in the source is within the correct range
|
||||
*/
|
||||
while (source.hasRemaining()) {
|
||||
ch = (int) source.get();
|
||||
|
||||
ch = source.get();
|
||||
|
||||
if ((ch & 0xff80) == 0) {
|
||||
if (target.hasRemaining()) {
|
||||
target.put((byte) ch);
|
||||
@ -314,7 +317,7 @@ class CharsetASCII extends CharsetICU {
|
||||
return encodeMalformedOrUnmappable(source, ch, flush);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CoderResult.UNDERFLOW;
|
||||
}
|
||||
|
||||
@ -331,7 +334,7 @@ class CharsetASCII extends CharsetICU {
|
||||
private final CoderResult encodeTrail(CharBuffer source, char lead, boolean flush) {
|
||||
/*
|
||||
* ASCII doesn't support characters in the BMP, so if handleSurrogates returns null,
|
||||
* we leave fromUChar32 alone (it should store a new codepoint) and call it unmappable.
|
||||
* we leave fromUChar32 alone (it should store a new codepoint) and call it unmappable.
|
||||
*/
|
||||
CoderResult cr = handleSurrogates(source, lead);
|
||||
if (cr != null) {
|
||||
@ -344,14 +347,17 @@ class CharsetASCII extends CharsetICU {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderASCII(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderASCII(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
setFillIn.add(0,0x7f);
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ import com.ibm.icu.text.UnicodeSet;
|
||||
* @author krajwade
|
||||
*
|
||||
*/
|
||||
class CharsetBOCU1 extends CharsetICU {
|
||||
class CharsetBOCU1 extends CharsetICU {
|
||||
/* BOCU constants and macros */
|
||||
|
||||
|
||||
/* initial value for "prev": middle of the ASCII range */
|
||||
private static final byte BOCU1_ASCII_PREV = 0x40;
|
||||
|
||||
|
||||
/* bounding byte values for differences */
|
||||
private static final int BOCU1_MIN = 0x21;
|
||||
private static final int BOCU1_MIDDLE = 0x90;
|
||||
@ -45,7 +45,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
|
||||
/* number of trail bytes */
|
||||
private static final int BOCU1_TRAIL_COUNT =((BOCU1_MAX_TRAIL-BOCU1_MIN+1)+BOCU1_TRAIL_CONTROLS_COUNT);
|
||||
|
||||
|
||||
/*
|
||||
* number of positive and negative single-byte codes
|
||||
* (counting 0==BOCU1_MIDDLE among the positive ones)
|
||||
@ -84,8 +84,8 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
|
||||
/* The length of a byte sequence, according to the lead byte (!=BOCU1_RESET). */
|
||||
/* private static int BOCU1_LENGTH_FROM_LEAD(int lead) {
|
||||
return ((BOCU1_START_NEG_2<=(lead) && (lead)<BOCU1_START_POS_2) ? 1 :
|
||||
(BOCU1_START_NEG_3<=(lead) && (lead)<BOCU1_START_POS_3) ? 2 :
|
||||
return ((BOCU1_START_NEG_2<=(lead) && (lead)<BOCU1_START_POS_2) ? 1 :
|
||||
(BOCU1_START_NEG_3<=(lead) && (lead)<BOCU1_START_POS_3) ? 2 :
|
||||
(BOCU1_START_NEG_4<=(lead) && (lead)<BOCU1_START_POS_4) ? 3 : 4);
|
||||
}*/
|
||||
|
||||
@ -93,7 +93,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
private static int BOCU1_LENGTH_FROM_PACKED(int packed) {
|
||||
return (((packed)&UConverterConstants.UNSIGNED_INT_MASK)<0x04000000 ? (packed)>>24 : 4);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Byte value map for control codes,
|
||||
* from external byte values 0x00..0x20
|
||||
@ -123,7 +123,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
* from trail byte values 0..19 (0..0x13) as used in the difference calculation
|
||||
* to external byte values 0x00..0x20.
|
||||
*/
|
||||
private static final int[]
|
||||
private static final int[]
|
||||
bocu1TrailToByte = {
|
||||
/* 0 1 2 3 4 5 6 7 */
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x10, 0x11,
|
||||
@ -134,8 +134,8 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
/* 10 11 12 13 */
|
||||
0x1c, 0x1d, 0x1e, 0x1f
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 12 commonly used C0 control codes (and space) are only used to encode
|
||||
* themselves directly,
|
||||
@ -166,8 +166,8 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
*/
|
||||
private static int BOCU1_TRAIL_TO_BYTE(int trail) {
|
||||
return ((trail)>=BOCU1_TRAIL_CONTROLS_COUNT ? (trail)+BOCU1_TRAIL_BYTE_OFFSET : bocu1TrailToByte[trail]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* BOCU-1 implementation functions ------------------------------------------ */
|
||||
private static int BOCU1_SIMPLE_PREV(int c){
|
||||
return (((c)&~0x7f)+BOCU1_ASCII_PREV);
|
||||
@ -201,7 +201,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
private static int BOCU1_PREV(int c) {
|
||||
return ((c)<0x3040 || (c)>0xd7a3 ? BOCU1_SIMPLE_PREV(c) : bocu1Prev(c));
|
||||
}
|
||||
|
||||
|
||||
protected byte[] fromUSubstitution = new byte[]{(byte)0x1A};
|
||||
|
||||
/* Faster versions of packDiff() for single-byte-encoded diff values. */
|
||||
@ -219,35 +219,35 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
/** Is a diff value encodable in two bytes? */
|
||||
private static boolean DIFF_IS_DOUBLE(int diff){
|
||||
return (BOCU1_REACH_NEG_2<=(diff) && (diff)<=BOCU1_REACH_POS_2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CharsetBOCU1(String icuCanonicalName, String javaCanonicalName, String[] aliases){
|
||||
super(icuCanonicalName, javaCanonicalName, aliases);
|
||||
maxBytesPerChar = 4;
|
||||
maxBytesPerChar = 4;
|
||||
minBytesPerChar = 1;
|
||||
maxCharsPerByte = 1;
|
||||
}
|
||||
|
||||
|
||||
class CharsetEncoderBOCU extends CharsetEncoderICU {
|
||||
public CharsetEncoderBOCU(CharsetICU cs) {
|
||||
super(cs,fromUSubstitution);
|
||||
}
|
||||
|
||||
|
||||
int sourceIndex, nextSourceIndex;
|
||||
int prev, c , diff;
|
||||
boolean checkNegative;
|
||||
boolean LoopAfterTrail;
|
||||
int targetCapacity;
|
||||
CoderResult cr;
|
||||
|
||||
CoderResult cr;
|
||||
|
||||
/* label values for supporting behavior similar to goto in C */
|
||||
private static final int fastSingle=0;
|
||||
private static final int getTrail=1;
|
||||
private static final int regularLoop=2;
|
||||
|
||||
|
||||
private boolean LabelLoop; //used to break the while loop
|
||||
private int labelType = fastSingle; //labeType is set to fastSingle to start the code from fastSingle:
|
||||
|
||||
|
||||
/**
|
||||
* Integer division and modulo with negative numerators
|
||||
* yields negative modulo results and quotients that are one more than
|
||||
@ -263,15 +263,15 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
*/
|
||||
private int NEGDIVMOD(int n, int d, int m) {
|
||||
diff = n;
|
||||
(m)=(diff)%(d);
|
||||
(diff)/=(d);
|
||||
if((m)<0) {
|
||||
(m)=(diff)%(d);
|
||||
(diff)/=(d);
|
||||
if((m)<0) {
|
||||
--(diff);
|
||||
(m)+=(d);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode a difference -0x10ffff..0x10ffff in 1..4 bytes
|
||||
* and return a packed integer with them.
|
||||
@ -385,32 +385,33 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush){
|
||||
cr = CoderResult.UNDERFLOW;
|
||||
|
||||
|
||||
LabelLoop = true; //used to break the while loop
|
||||
checkNegative = false; // its value is set to true to get out of while loop when c = -c
|
||||
LoopAfterTrail = false; // its value is set to true to ignore code before getTrail:
|
||||
|
||||
|
||||
/*set up the local pointers*/
|
||||
targetCapacity = target.limit() - target.position();
|
||||
c = fromUChar32;
|
||||
prev = fromUnicodeStatus;
|
||||
|
||||
|
||||
if(prev==0){
|
||||
prev = BOCU1_ASCII_PREV;
|
||||
}
|
||||
|
||||
|
||||
/*sourceIndex ==-1 if the current characte began in the previous buffer*/
|
||||
sourceIndex = c == 0 ? 0: -1;
|
||||
nextSourceIndex = 0;
|
||||
|
||||
|
||||
/*conversion loop*/
|
||||
if(c!=0 && targetCapacity>0){
|
||||
labelType = getTrail;
|
||||
}
|
||||
|
||||
|
||||
while(LabelLoop){
|
||||
switch(labelType){
|
||||
case fastSingle:
|
||||
@ -424,12 +425,12 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return cr;
|
||||
}
|
||||
|
||||
private int fastSingle(CharBuffer source, ByteBuffer target, IntBuffer offsets){
|
||||
//fastSingle:
|
||||
|
||||
private int fastSingle(CharBuffer source, ByteBuffer target, IntBuffer offsets){
|
||||
//fastSingle:
|
||||
/*fast loop for single-byte differences*/
|
||||
/*use only one loop counter variable , targetCapacity, not also source*/
|
||||
diff = source.limit() - source.position();
|
||||
@ -464,7 +465,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
}
|
||||
return regularLoop;
|
||||
}
|
||||
|
||||
|
||||
private int getTrail(CharBuffer source, ByteBuffer target, IntBuffer offsets){
|
||||
if(source.hasRemaining()){
|
||||
/*test the following code unit*/
|
||||
@ -493,11 +494,11 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
/*regular loop for all classes*/
|
||||
while(LoopAfterTrail || source.hasRemaining()){
|
||||
if(LoopAfterTrail || targetCapacity>0){
|
||||
|
||||
|
||||
if(!LoopAfterTrail){
|
||||
c = source.get();
|
||||
++nextSourceIndex;
|
||||
|
||||
|
||||
if(c<=0x20){
|
||||
/*
|
||||
* ISO C0 control & space:
|
||||
@ -512,11 +513,11 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
offsets.put(sourceIndex++);
|
||||
}
|
||||
--targetCapacity;
|
||||
|
||||
|
||||
sourceIndex=nextSourceIndex;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(UTF16.isLeadSurrogate((char)c)){
|
||||
getTrail(source, target, offsets);
|
||||
if(checkNegative){
|
||||
@ -524,11 +525,11 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(LoopAfterTrail){
|
||||
LoopAfterTrail = false;
|
||||
LoopAfterTrail = false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* all other Unicode code points c==U+0021..U+10ffff
|
||||
* are encoded with the difference c-prev
|
||||
@ -576,7 +577,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
int length; /*will be 2..4*/
|
||||
diff = packDiff(diff);
|
||||
length = BOCU1_LENGTH_FROM_PACKED(diff);
|
||||
|
||||
|
||||
/*write the output character bytes from diff and length*/
|
||||
/*from the first if in the loop we know that targetCapacity>0*/
|
||||
if(length<=targetCapacity){
|
||||
@ -631,7 +632,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
break;
|
||||
}
|
||||
errorBufferLength = length;
|
||||
|
||||
|
||||
/* now output what fits into the regular target */
|
||||
diff>>=8*length; /* length was reduced by targetCapacity */
|
||||
switch(targetCapacity) {
|
||||
@ -667,7 +668,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
cr = CoderResult.OVERFLOW;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*set the converter state back into UConverter*/
|
||||
fromUChar32 = c<0 ? -c :0;
|
||||
@ -676,26 +677,26 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
labelType = fastSingle;
|
||||
return labelType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class CharsetDecoderBOCU extends CharsetDecoderICU{
|
||||
public CharsetDecoderBOCU(CharsetICU cs) {
|
||||
super(cs);
|
||||
}
|
||||
|
||||
|
||||
int byteIndex;
|
||||
int sourceIndex, nextSourceIndex;
|
||||
int prev, c , diff, count;
|
||||
byte[] bytes;
|
||||
CoderResult cr;
|
||||
|
||||
|
||||
/* label values for supporting behavior similar to goto in C */
|
||||
private static final int fastSingle=0;
|
||||
private static final int getTrail=1;
|
||||
private static final int regularLoop=2;
|
||||
private static final int endLoop=3;
|
||||
|
||||
|
||||
private boolean LabelLoop;//used to break the while loop
|
||||
private boolean afterTrail; // its value is set to true to ignore code after getTrail:
|
||||
private int labelType;
|
||||
@ -711,8 +712,8 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
|
||||
/* BOCU-1-from-Unicode conversion functions --------------------------------- */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function for BOCU-1 decoder; handles multi-byte lead bytes.
|
||||
*
|
||||
@ -758,7 +759,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
/* return the state for decoding the trail byte(s) */
|
||||
return (diffValue<<2)|countValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function for BOCU-1 decoder; handles multi-byte trail bytes.
|
||||
*
|
||||
@ -788,37 +789,38 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
return b*(BOCU1_TRAIL_COUNT*BOCU1_TRAIL_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
boolean flush){
|
||||
cr = CoderResult.UNDERFLOW;
|
||||
|
||||
LabelLoop = true;
|
||||
afterTrail = false;
|
||||
|
||||
LabelLoop = true;
|
||||
afterTrail = false;
|
||||
labelType = fastSingle; // labelType is set to fastSingle so t
|
||||
|
||||
|
||||
/*get the converter state*/
|
||||
prev = toUnicodeStatus;
|
||||
|
||||
|
||||
if(prev==0){
|
||||
prev = BOCU1_ASCII_PREV;
|
||||
}
|
||||
diff = mode;
|
||||
count = diff&3;
|
||||
diff>>=2;
|
||||
|
||||
|
||||
byteIndex = toULength;
|
||||
bytes = toUBytesArray;
|
||||
|
||||
|
||||
/* sourceIndex=-1 if the current character began in the previous buffer */
|
||||
sourceIndex=byteIndex==0 ? 0 : -1;
|
||||
nextSourceIndex=0;
|
||||
|
||||
|
||||
/* conversion "loop" similar to _SCSUToUnicodeWithOffsets() */
|
||||
if(count>0 && byteIndex>0 && target.position()<target.limit()) {
|
||||
labelType = getTrail;
|
||||
}
|
||||
|
||||
|
||||
while(LabelLoop){
|
||||
switch(labelType){
|
||||
case fastSingle:
|
||||
@ -835,10 +837,10 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return cr;
|
||||
}
|
||||
|
||||
|
||||
private int fastSingle(ByteBuffer source, CharBuffer target, IntBuffer offsets){
|
||||
labelType = regularLoop;
|
||||
/* fast loop for single-byte differences */
|
||||
@ -855,7 +857,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
target.put((char)c);
|
||||
if(offsets!=null){
|
||||
offsets.put(nextSourceIndex++);
|
||||
}
|
||||
}
|
||||
prev = BOCU1_SIMPLE_PREV(c);
|
||||
} else {
|
||||
break;
|
||||
@ -867,7 +869,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
target.put((char)c);
|
||||
if(offsets!=null){
|
||||
offsets.put(nextSourceIndex++);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@ -877,7 +879,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
sourceIndex=nextSourceIndex; /* wrong if offsets==NULL but does not matter */
|
||||
return labelType;
|
||||
}
|
||||
|
||||
|
||||
private int getTrail(ByteBuffer source, CharBuffer target, IntBuffer offsets){
|
||||
labelType = regularLoop;
|
||||
for(;;) {
|
||||
@ -911,9 +913,9 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
}
|
||||
afterTrail = true;
|
||||
return labelType;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private int afterGetTrail(ByteBuffer source, CharBuffer target, IntBuffer offsets){
|
||||
/* decode a sequence of single and lead bytes */
|
||||
while(afterTrail || source.hasRemaining()) {
|
||||
@ -994,11 +996,11 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(afterTrail){
|
||||
afterTrail = false;
|
||||
}
|
||||
|
||||
|
||||
/* calculate the next prev and output c */
|
||||
prev = BOCU1_PREV(c);
|
||||
if(c<=0xffff) {
|
||||
@ -1031,7 +1033,7 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
labelType = endLoop;
|
||||
return labelType;
|
||||
}
|
||||
|
||||
|
||||
private void endLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets){
|
||||
if(cr.isMalformed()) {
|
||||
/* set the converter state in UConverter to deal with the next character */
|
||||
@ -1045,18 +1047,21 @@ class CharsetBOCU1 extends CharsetICU {
|
||||
toULength=byteIndex;
|
||||
LabelLoop = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderBOCU(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderBOCU(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
CharsetICU.getCompleteUnicodeSet(setFillIn);
|
||||
}
|
||||
|
@ -19,10 +19,11 @@ class CharsetCESU8 extends CharsetUTF8 {
|
||||
public CharsetCESU8(String icuCanonicalName, String javaCanonicalName, String[] aliases) {
|
||||
super(icuCanonicalName, javaCanonicalName, aliases);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
getCompleteUnicodeSet(setFillIn);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,13 @@ import java.nio.charset.CoderResult;
|
||||
|
||||
/**
|
||||
* <h2> Callback API for CharsetICU API </h2>
|
||||
*
|
||||
* CharsetCallback class defines some error behaviour functions called
|
||||
*
|
||||
* CharsetCallback class defines some error behaviour functions called
|
||||
* by CharsetDecoderICU and CharsetEncoderICU. The class also provides
|
||||
* the facility by which clients can write their own callbacks.
|
||||
*
|
||||
* These functions, although public, should NEVER be called directly.
|
||||
* They should be used as parameters to the onUmappableCharacter() and
|
||||
* They should be used as parameters to the onUmappableCharacter() and
|
||||
* onMalformedInput() methods, to set the behaviour of a converter
|
||||
* when it encounters UNMAPPED/INVALID sequences.
|
||||
* Currently the only way to set callbacks is by using CodingErrorAction.
|
||||
@ -44,7 +44,7 @@ public class CharsetCallback {
|
||||
// private static final String SKIP_STOP_ON_ILLEGAL = "i";
|
||||
|
||||
// /*
|
||||
// * FROM_U_CALLBACK_ESCAPE context option to escape the code unit according to ICU (%UXXXX)
|
||||
// * FROM_U_CALLBACK_ESCAPE context option to escape the code unit according to ICU (%UXXXX)
|
||||
// */
|
||||
// private static final String ESCAPE_ICU = null;
|
||||
|
||||
@ -92,36 +92,36 @@ public class CharsetCallback {
|
||||
* For a list of the default ignorable code points, use this link: http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[%3ADI%3A]&g=
|
||||
*
|
||||
* This list should be sync with the one in ucnv_err.c
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static boolean IS_DEFAULT_IGNORABLE_CODE_POINT(int c) {
|
||||
return ((c == 0x00AD) ||
|
||||
(c == 0x034F) ||
|
||||
(c == 0x061C) ||
|
||||
(c == 0x115F) ||
|
||||
(c == 0x1160) ||
|
||||
(0x17B4 <= c && c <= 0x17B5) ||
|
||||
(0x180B <= c && c <= 0x180E) ||
|
||||
(0x200B <= c && c <= 0x200F) ||
|
||||
(0x202A <= c && c <= 0x202E) ||
|
||||
(c == 0x2060) ||
|
||||
(0x2066 <= c && c <= 0x2069) ||
|
||||
(0x2061 <= c && c <= 0x2064) ||
|
||||
(0x206A <= c && c <= 0x206F) ||
|
||||
(c == 0x3164) ||
|
||||
(0x0FE00 <= c && c <= 0x0FE0F) ||
|
||||
(c == 0x0FEFF) ||
|
||||
(c == 0x0FFA0) ||
|
||||
(0x01BCA0 <= c && c <= 0x01BCA3) ||
|
||||
(0x01D173 <= c && c <= 0x01D17A) ||
|
||||
(c == 0x0E0001) ||
|
||||
(0x0E0020 <= c && c <= 0x0E007F) ||
|
||||
(0x0E0100 <= c && c <= 0x0E01EF) ||
|
||||
(c == 0x2065) ||
|
||||
(0x0FFF0 <= c && c <= 0x0FFF8) ||
|
||||
(c == 0x0E0000) ||
|
||||
(0x0E0002 <= c && c <= 0x0E001F) ||
|
||||
(0x0E0080 <= c && c <= 0x0E00FF) ||
|
||||
return ((c == 0x00AD) ||
|
||||
(c == 0x034F) ||
|
||||
(c == 0x061C) ||
|
||||
(c == 0x115F) ||
|
||||
(c == 0x1160) ||
|
||||
(0x17B4 <= c && c <= 0x17B5) ||
|
||||
(0x180B <= c && c <= 0x180E) ||
|
||||
(0x200B <= c && c <= 0x200F) ||
|
||||
(0x202A <= c && c <= 0x202E) ||
|
||||
(c == 0x2060) ||
|
||||
(0x2066 <= c && c <= 0x2069) ||
|
||||
(0x2061 <= c && c <= 0x2064) ||
|
||||
(0x206A <= c && c <= 0x206F) ||
|
||||
(c == 0x3164) ||
|
||||
(0x0FE00 <= c && c <= 0x0FE0F) ||
|
||||
(c == 0x0FEFF) ||
|
||||
(c == 0x0FFA0) ||
|
||||
(0x01BCA0 <= c && c <= 0x01BCA3) ||
|
||||
(0x01D173 <= c && c <= 0x01D17A) ||
|
||||
(c == 0x0E0001) ||
|
||||
(0x0E0020 <= c && c <= 0x0E007F) ||
|
||||
(0x0E0100 <= c && c <= 0x0E01EF) ||
|
||||
(c == 0x2065) ||
|
||||
(0x0FFF0 <= c && c <= 0x0FFF8) ||
|
||||
(c == 0x0E0000) ||
|
||||
(0x0E0002 <= c && c <= 0x0E001F) ||
|
||||
(0x0E0080 <= c && c <= 0x0E00FF) ||
|
||||
(0x0E01F0 <= c && c <= 0x0E0FFF)
|
||||
);
|
||||
}
|
||||
@ -133,12 +133,12 @@ public class CharsetCallback {
|
||||
/**
|
||||
* This function is called when the bytes in the source cannot be handled,
|
||||
* and this function is meant to handle or fix the error if possible.
|
||||
*
|
||||
*
|
||||
* @return Result of decoding action. This returned object is set to an error
|
||||
* if this function could not handle the conversion.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, CoderResult cr);
|
||||
}
|
||||
@ -154,17 +154,18 @@ public class CharsetCallback {
|
||||
* if this function could not handle the conversion.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, int cp, CoderResult cr);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Skip callback
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public static final Encoder FROM_U_CALLBACK_SKIP = new Encoder() {
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
@Override
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, int cp, CoderResult cr){
|
||||
if(context==null){
|
||||
return CoderResult.UNDERFLOW;
|
||||
@ -183,7 +184,8 @@ public class CharsetCallback {
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public static final Decoder TO_U_CALLBACK_SKIP = new Decoder() {
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
@Override
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, CoderResult cr){
|
||||
if(context==null){
|
||||
@ -202,9 +204,10 @@ public class CharsetCallback {
|
||||
* Write substitute callback
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public static final Encoder FROM_U_CALLBACK_SUBSTITUTE = new Encoder(){
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
public static final Encoder FROM_U_CALLBACK_SUBSTITUTE = new Encoder(){
|
||||
@Override
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, int cp, CoderResult cr){
|
||||
if (cr.isUnmappable() && IS_DEFAULT_IGNORABLE_CODE_POINT(cp)) {
|
||||
return CoderResult.UNDERFLOW;
|
||||
@ -227,7 +230,8 @@ public class CharsetCallback {
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public static final Decoder TO_U_CALLBACK_SUBSTITUTE = new Decoder() {
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
@Override
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, CoderResult cr){
|
||||
|
||||
@ -238,7 +242,7 @@ public class CharsetCallback {
|
||||
if (replacementChar.length == 1 && (replacementChar[0] == kSubstituteChar1[0] || replacementChar[0] == kSubstituteChar[0])) {
|
||||
useReplacement = false;
|
||||
}
|
||||
|
||||
|
||||
/* could optimize this case, just one uchar */
|
||||
if(decoder.invalidCharLength == 1 && cs.subChar1 != 0) {
|
||||
return CharsetDecoderICU.toUWriteUChars(decoder, useReplacement ? replacementChar : kSubstituteChar1, 0, useReplacement ? replacementChar.length : 1, target, offsets, source.position());
|
||||
@ -252,8 +256,9 @@ public class CharsetCallback {
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public static final Encoder FROM_U_CALLBACK_STOP = new Encoder() {
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
@Override
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, int cp, CoderResult cr){
|
||||
if (cr.isUnmappable() && IS_DEFAULT_IGNORABLE_CODE_POINT(cp)) {
|
||||
return CoderResult.UNDERFLOW;
|
||||
@ -266,12 +271,13 @@ public class CharsetCallback {
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public static final Decoder TO_U_CALLBACK_STOP = new Decoder() {
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
@Override
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, CoderResult cr){
|
||||
return cr;
|
||||
}
|
||||
};
|
||||
};
|
||||
private static final int VALUE_STRING_LENGTH = 32;
|
||||
private static final char UNICODE_PERCENT_SIGN_CODEPOINT = 0x0025;
|
||||
private static final char UNICODE_U_CODEPOINT = 0x0055;
|
||||
@ -291,17 +297,18 @@ public class CharsetCallback {
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
public static final Encoder FROM_U_CALLBACK_ESCAPE = new Encoder() {
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
@Override
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, int cp, CoderResult cr){
|
||||
char[] valueString = new char[VALUE_STRING_LENGTH];
|
||||
int valueStringLength = 0;
|
||||
int i = 0;
|
||||
|
||||
|
||||
if (cr.isUnmappable() && IS_DEFAULT_IGNORABLE_CODE_POINT(cp)) {
|
||||
return CoderResult.UNDERFLOW;
|
||||
}
|
||||
|
||||
|
||||
if (context == null || !(context instanceof String)) {
|
||||
while (i < length) {
|
||||
valueString[valueStringLength++] = UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
||||
@ -317,7 +324,7 @@ public class CharsetCallback {
|
||||
}
|
||||
} else if (((String)context).equals(ESCAPE_C)) {
|
||||
valueString[valueStringLength++] = UNICODE_RS_CODEPOINT; /* adding \ */
|
||||
|
||||
|
||||
if (length == 2) {
|
||||
valueString[valueStringLength++] = UNICODE_U_CODEPOINT; /* adding U */
|
||||
valueStringLength = itou(valueString, valueStringLength, cp, 16, 8);
|
||||
@ -376,13 +383,14 @@ public class CharsetCallback {
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
public static final Decoder TO_U_CALLBACK_ESCAPE = new Decoder() {
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
@Override
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context,
|
||||
ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, CoderResult cr){
|
||||
char[] uniValueString = new char[VALUE_STRING_LENGTH];
|
||||
int valueStringLength = 0;
|
||||
int i = 0;
|
||||
|
||||
|
||||
if (context == null || !(context instanceof String)) {
|
||||
while (i < length) {
|
||||
uniValueString[valueStringLength++] = UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */
|
||||
@ -420,12 +428,12 @@ public class CharsetCallback {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cr = CharsetDecoderICU.toUWriteUChars(decoder, uniValueString, 0, valueStringLength, target, offsets, 0);
|
||||
|
||||
|
||||
return cr;
|
||||
}
|
||||
};
|
||||
};
|
||||
/***
|
||||
* Java port of uprv_itou() in ICU4C used by TO_U_CALLBACK_ESCAPE and FROM_U_CALLBACK_ESCAPE.
|
||||
* Fills in a char string with the radix-based representation of a number padded with zeroes
|
||||
@ -436,13 +444,13 @@ public class CharsetCallback {
|
||||
int digit;
|
||||
int j;
|
||||
char temp;
|
||||
|
||||
|
||||
do {
|
||||
digit = i % radix;
|
||||
buffer[sourceIndex + length++] = (char)(digit <= 9 ? (0x0030+digit) : (0x0030+digit+7));
|
||||
i = i/radix;
|
||||
} while (i != 0 && (sourceIndex + length) < buffer.length);
|
||||
|
||||
|
||||
while (length < minwidth) {
|
||||
buffer[sourceIndex + length++] = (char)0x0030; /* zero padding */
|
||||
}
|
||||
@ -452,7 +460,7 @@ public class CharsetCallback {
|
||||
buffer[(sourceIndex + length-1) -j] = buffer[sourceIndex + j];
|
||||
buffer[sourceIndex + j] = temp;
|
||||
}
|
||||
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,14 @@ class CharsetCompoundText extends CharsetICU {
|
||||
private static final byte[] fromUSubstitution = new byte[] { (byte) 0x3F };
|
||||
private CharsetMBCS myConverterArray[];
|
||||
private byte state;
|
||||
|
||||
|
||||
private final static byte INVALID = -2;
|
||||
private final static byte DO_SEARCH = -1;
|
||||
private final static byte COMPOUND_TEXT_SINGLE_0 = 0;
|
||||
private final static byte COMPOUND_TEXT_SINGLE_1 = 1;
|
||||
private final static byte COMPOUND_TEXT_SINGLE_2 = 2;
|
||||
private final static byte COMPOUND_TEXT_SINGLE_3 = 3;
|
||||
|
||||
|
||||
/*private final static byte COMPOUND_TEXT_DOUBLE_1 = 4;
|
||||
private final static byte COMPOUND_TEXT_DOUBLE_2 = 5;
|
||||
private final static byte COMPOUND_TEXT_DOUBLE_3 = 6;
|
||||
@ -40,9 +40,9 @@ class CharsetCompoundText extends CharsetICU {
|
||||
private final static byte COMPOUND_TEXT_DOUBLE_5 = 8;
|
||||
private final static byte COMPOUND_TEXT_DOUBLE_6 = 9;
|
||||
private final static byte COMPOUND_TEXT_DOUBLE_7 = 10;
|
||||
|
||||
|
||||
private final static byte COMPOUND_TEXT_TRIPLE_DOUBLE = 11;*/
|
||||
|
||||
|
||||
private final static byte IBM_915 = 12;
|
||||
private final static byte IBM_916 = 13;
|
||||
private final static byte IBM_914 = 14;
|
||||
@ -51,18 +51,18 @@ class CharsetCompoundText extends CharsetICU {
|
||||
private final static byte IBM_913 = 17;
|
||||
private final static byte ISO_8859_14 = 18;
|
||||
private final static byte IBM_923 = 19;
|
||||
|
||||
|
||||
private final static byte NUM_OF_CONVERTERS = 20;
|
||||
|
||||
|
||||
private final static byte SEARCH_LENGTH = 12;
|
||||
|
||||
|
||||
private final static byte[][] escSeqCompoundText = {
|
||||
/* Single */
|
||||
{ 0x1B, 0x2D, 0x41 },
|
||||
{ 0x1B, 0x2D, 0x4D },
|
||||
{ 0x1B, 0x2D, 0x46 },
|
||||
{ 0x1B, 0x2D, 0x47 },
|
||||
|
||||
|
||||
/* Double */
|
||||
{ 0x1B, 0x24, 0x29, 0x41 },
|
||||
{ 0x1B, 0x24, 0x29, 0x42 },
|
||||
@ -71,10 +71,10 @@ class CharsetCompoundText extends CharsetICU {
|
||||
{ 0x1B, 0x24, 0x29, 0x47 },
|
||||
{ 0x1B, 0x24, 0x29, 0x48 },
|
||||
{ 0x1B, 0x24, 0x29, 0x49 },
|
||||
|
||||
|
||||
/* Triple/Double */
|
||||
{ 0x1B, 0x25, 0x47 },
|
||||
|
||||
|
||||
/*IBM-915*/
|
||||
{ 0x1B, 0x2D, 0x4C },
|
||||
/*IBM-916*/
|
||||
@ -92,9 +92,9 @@ class CharsetCompoundText extends CharsetICU {
|
||||
/* IBM-923 */
|
||||
{ 0x1B, 0x2D, 0x62 },
|
||||
};
|
||||
|
||||
|
||||
private final static byte ESC_START = 0x1B;
|
||||
|
||||
|
||||
private static boolean isASCIIRange(int codepoint) {
|
||||
if ((codepoint == 0x0000) || (codepoint == 0x0009) || (codepoint == 0x000A) ||
|
||||
(codepoint >= 0x0020 && codepoint <= 0x007f) || (codepoint >= 0x00A0 && codepoint <= 0x00FF)) {
|
||||
@ -102,21 +102,21 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isIBM915(int codepoint) {
|
||||
if ((codepoint >= 0x0401 && codepoint <= 0x045F) || (codepoint == 0x2116)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isIBM916(int codepoint) {
|
||||
if ((codepoint >= 0x05D0 && codepoint <= 0x05EA) || (codepoint == 0x2017) || (codepoint == 0x203E)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isCompoundS3(int codepoint) {
|
||||
if ((codepoint == 0x060C) || (codepoint == 0x061B) || (codepoint == 0x061F) || (codepoint >= 0x0621 && codepoint <= 0x063A) ||
|
||||
(codepoint >= 0x0640 && codepoint <= 0x0652) || (codepoint >= 0x0660 && codepoint <= 0x066D) || (codepoint == 0x200B) ||
|
||||
@ -125,14 +125,14 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isCompoundS2(int codepoint) {
|
||||
if ((codepoint == 0x02BC) || (codepoint == 0x02BD) || (codepoint >= 0x0384 && codepoint <= 0x03CE) || (codepoint == 0x2015)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isIBM914(int codepoint) {
|
||||
if ((codepoint == 0x0100) || (codepoint == 0x0101) || (codepoint == 0x0112) || (codepoint == 0x0113) || (codepoint == 0x0116) || (codepoint == 0x0117) ||
|
||||
(codepoint == 0x0122) || (codepoint == 0x0123) || (codepoint >= 0x0128 && codepoint <= 0x012B) || (codepoint == 0x012E) || (codepoint == 0x012F) ||
|
||||
@ -143,14 +143,14 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isIBM874(int codepoint) {
|
||||
if ((codepoint >= 0x0E01 && codepoint <= 0x0E3A) || (codepoint >= 0x0E3F && codepoint <= 0x0E5B)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isIBM912(int codepoint) {
|
||||
return ((codepoint >= 0x0102 && codepoint <= 0x0107) || (codepoint >= 0x010C && codepoint <= 0x0111) || (codepoint >= 0x0118 && codepoint <= 0x011B) ||
|
||||
(codepoint == 0x0139) || (codepoint == 0x013A) || (codepoint == 0x013D) || (codepoint == 0x013E) || (codepoint >= 0x0141 && codepoint <= 0x0144) ||
|
||||
@ -159,7 +159,7 @@ class CharsetCompoundText extends CharsetICU {
|
||||
(codepoint == 0x016E) || (codepoint == 0x016F) || (codepoint == 0x0170) || (codepoint == 0x0171) || (codepoint >= 0x0179 && codepoint <= 0x017E) ||
|
||||
(codepoint == 0x02C7) || (codepoint == 0x02D8) || (codepoint == 0x02D9) || (codepoint == 0x02DB) || (codepoint == 0x02DD));
|
||||
}
|
||||
|
||||
|
||||
private static boolean isIBM913(int codepoint) {
|
||||
if ((codepoint >= 0x0108 && codepoint <= 0x010B) || (codepoint == 0x011C) ||
|
||||
(codepoint == 0x011D) || (codepoint == 0x0120) || (codepoint == 0x0121) ||
|
||||
@ -169,7 +169,7 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isCompoundS1(int codepoint) {
|
||||
if ((codepoint == 0x011E) || (codepoint == 0x011F) || (codepoint == 0x0130) ||
|
||||
(codepoint == 0x0131) || (codepoint >= 0x0218 && codepoint <= 0x021B)) {
|
||||
@ -177,7 +177,7 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isISO8859_14(int codepoint) {
|
||||
if ((codepoint >= 0x0174 && codepoint <= 0x0177) || (codepoint == 0x1E0A) ||
|
||||
(codepoint == 0x1E0B) || (codepoint == 0x1E1E) || (codepoint == 0x1E1F) ||
|
||||
@ -189,14 +189,14 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isIBM923(int codepoint) {
|
||||
if ((codepoint == 0x0152) || (codepoint == 0x0153) || (codepoint == 0x0178) || (codepoint == 0x20AC)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static int findNextEsc(ByteBuffer source) {
|
||||
int sourceLimit = source.limit();
|
||||
for (int i = (source.position() + 1); i < sourceLimit; i++) {
|
||||
@ -206,10 +206,10 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
return sourceLimit;
|
||||
}
|
||||
|
||||
|
||||
private static byte getState(int codepoint) {
|
||||
byte state = -1;
|
||||
|
||||
|
||||
if (isASCIIRange(codepoint)) {
|
||||
state = COMPOUND_TEXT_SINGLE_0;
|
||||
} else if (isIBM912(codepoint)) {
|
||||
@ -235,10 +235,10 @@ class CharsetCompoundText extends CharsetICU {
|
||||
} else if (isCompoundS1(codepoint)) {
|
||||
state = COMPOUND_TEXT_SINGLE_1;
|
||||
}
|
||||
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
private static byte findStateFromEscSeq(ByteBuffer source, byte[] toUBytes, int toUBytesLength) {
|
||||
byte state = INVALID;
|
||||
int sourceIndex = source.position();
|
||||
@ -246,7 +246,7 @@ class CharsetCompoundText extends CharsetICU {
|
||||
byte i, n;
|
||||
int offset = toUBytesLength;
|
||||
int sourceLimit = source.limit();
|
||||
|
||||
|
||||
for (i = 0; i < escSeqCompoundText.length; i++) {
|
||||
matchFound = true;
|
||||
for (n = 0; n < escSeqCompoundText[i].length; n++) {
|
||||
@ -266,30 +266,30 @@ class CharsetCompoundText extends CharsetICU {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (matchFound) {
|
||||
state = i;
|
||||
source.position(sourceIndex + (escSeqCompoundText[i].length - offset));
|
||||
}
|
||||
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
public CharsetCompoundText(String icuCanonicalName, String javaCanonicalName, String[] aliases) {
|
||||
super(icuCanonicalName, javaCanonicalName, aliases);
|
||||
|
||||
|
||||
LoadConverters();
|
||||
|
||||
|
||||
maxBytesPerChar = 6;
|
||||
minBytesPerChar = 1;
|
||||
maxCharsPerByte = 1;
|
||||
}
|
||||
|
||||
|
||||
private void LoadConverters() {
|
||||
myConverterArray = new CharsetMBCS[NUM_OF_CONVERTERS];
|
||||
|
||||
|
||||
myConverterArray[COMPOUND_TEXT_SINGLE_0] = null;
|
||||
|
||||
|
||||
for (int i = 1; i < SEARCH_LENGTH; i++) {
|
||||
String name = "icu-internal-compound-";
|
||||
if (i <= 3) {
|
||||
@ -299,10 +299,10 @@ class CharsetCompoundText extends CharsetICU {
|
||||
} else {
|
||||
name = name + "t";
|
||||
}
|
||||
|
||||
|
||||
myConverterArray[i] = (CharsetMBCS)CharsetICU.forNameICU(name);
|
||||
}
|
||||
|
||||
|
||||
myConverterArray[IBM_915] = (CharsetMBCS)CharsetICU.forNameICU("ibm-915_P100-1995");
|
||||
myConverterArray[IBM_916] = (CharsetMBCS)CharsetICU.forNameICU("ibm-916_P100-1995");
|
||||
myConverterArray[IBM_914] = (CharsetMBCS)CharsetICU.forNameICU("ibm-914_P100-1995");
|
||||
@ -312,15 +312,15 @@ class CharsetCompoundText extends CharsetICU {
|
||||
myConverterArray[ISO_8859_14] = (CharsetMBCS)CharsetICU.forNameICU("iso-8859_14-1998");
|
||||
myConverterArray[IBM_923] = (CharsetMBCS)CharsetICU.forNameICU("ibm-923_P100-1998");
|
||||
}
|
||||
|
||||
|
||||
class CharsetEncoderCompoundText extends CharsetEncoderICU {
|
||||
CharsetEncoderMBCS gbEncoder[];
|
||||
|
||||
|
||||
public CharsetEncoderCompoundText(CharsetICU cs) {
|
||||
super(cs, fromUSubstitution);
|
||||
|
||||
|
||||
gbEncoder = new CharsetEncoderMBCS[NUM_OF_CONVERTERS];
|
||||
|
||||
|
||||
for (int i = 0; i < NUM_OF_CONVERTERS; i++) {
|
||||
if (i == 0) {
|
||||
gbEncoder[i] = null;
|
||||
@ -329,7 +329,8 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
for (int i = 0; i < NUM_OF_CONVERTERS; i++) {
|
||||
@ -338,7 +339,8 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult err = CoderResult.UNDERFLOW;
|
||||
int sourceChar;
|
||||
@ -350,35 +352,35 @@ class CharsetCompoundText extends CharsetICU {
|
||||
byte tmpState = 0;
|
||||
int i = 0;
|
||||
boolean gotoGetTrail = false;
|
||||
|
||||
|
||||
if (!source.hasRemaining())
|
||||
return CoderResult.UNDERFLOW;
|
||||
else if (!target.hasRemaining())
|
||||
return CoderResult.OVERFLOW;
|
||||
|
||||
|
||||
/* check if the last codepoint of previous buffer was a lead surrogate */
|
||||
if ((sourceChar = fromUChar32) != 0 && target.hasRemaining()) {
|
||||
// goto getTrail label
|
||||
gotoGetTrail = true;
|
||||
gotoGetTrail = true;
|
||||
}
|
||||
|
||||
|
||||
while (source.hasRemaining()) {
|
||||
if (target.hasRemaining()) {
|
||||
if (!gotoGetTrail) {
|
||||
sourceChar = source.get();
|
||||
}
|
||||
|
||||
|
||||
targetLength = 0;
|
||||
tmpTargetBuffer.position(0);
|
||||
tmpTargetBuffer.limit(3);
|
||||
|
||||
|
||||
/* check if the char is a First surrogate */
|
||||
if (UTF16.isSurrogate((char)sourceChar) || gotoGetTrail) {
|
||||
if (UTF16.isLeadSurrogate((char)sourceChar) || gotoGetTrail) {
|
||||
// getTrail label
|
||||
/* reset gotoGetTrail flag*/
|
||||
gotoGetTrail = false;
|
||||
|
||||
|
||||
/* look ahead to find the trail surrogate */
|
||||
if (source.hasRemaining()) {
|
||||
/* test the following code unit */
|
||||
@ -410,11 +412,11 @@ class CharsetCompoundText extends CharsetICU {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tmpState = getState(sourceChar);
|
||||
|
||||
|
||||
sourceCharArray[0] = (char)sourceChar;
|
||||
|
||||
|
||||
if (tmpState < 0) {
|
||||
/* Test all available converters */
|
||||
for (i = 1; i < SEARCH_LENGTH; i++) {
|
||||
@ -438,22 +440,22 @@ class CharsetCompoundText extends CharsetICU {
|
||||
if (err.isError()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (currentState != tmpState) {
|
||||
currentState = tmpState;
|
||||
|
||||
|
||||
/* Write escape sequence if necessary */
|
||||
for (i = 0; i < escSeqCompoundText[currentState].length; i++) {
|
||||
targetBytes[i] = escSeqCompoundText[currentState][i];
|
||||
}
|
||||
targetLength = i;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < tmpTargetBuffer.limit(); i++) {
|
||||
targetBytes[i+targetLength] = tmpTargetBuffer.get(i);
|
||||
}
|
||||
targetLength += i;
|
||||
|
||||
|
||||
for (i = 0; i < targetLength; i++) {
|
||||
if (target.hasRemaining()) {
|
||||
target.put(targetBytes[i]);
|
||||
@ -467,7 +469,7 @@ class CharsetCompoundText extends CharsetICU {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (err.isOverflow()) {
|
||||
int m = 0;
|
||||
for (int n = i; n < targetLength; n++) {
|
||||
@ -476,18 +478,18 @@ class CharsetCompoundText extends CharsetICU {
|
||||
this.errorBufferLength = m;
|
||||
}
|
||||
state = currentState;
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CharsetDecoderCompoundText extends CharsetDecoderICU {
|
||||
CharsetDecoderMBCS gbDecoder[];
|
||||
|
||||
|
||||
public CharsetDecoderCompoundText(CharsetICU cs) {
|
||||
super(cs);
|
||||
gbDecoder = new CharsetDecoderMBCS[NUM_OF_CONVERTERS];
|
||||
|
||||
|
||||
for (int i = 0; i < NUM_OF_CONVERTERS; i++) {
|
||||
if (i == 0) {
|
||||
gbDecoder[i] = null;
|
||||
@ -496,7 +498,8 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
for (int i = 0; i < NUM_OF_CONVERTERS; i++) {
|
||||
@ -505,7 +508,8 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult err = CoderResult.UNDERFLOW;
|
||||
byte[] sourceChar = { 0x00 };
|
||||
@ -513,12 +517,12 @@ class CharsetCompoundText extends CharsetICU {
|
||||
byte tmpState = currentState;
|
||||
CharsetDecoderMBCS decoder;
|
||||
int sourceLimit = source.limit();;
|
||||
|
||||
|
||||
if (!source.hasRemaining())
|
||||
return CoderResult.UNDERFLOW;
|
||||
else if (!target.hasRemaining())
|
||||
return CoderResult.OVERFLOW;
|
||||
|
||||
|
||||
while (source.hasRemaining()) {
|
||||
if (target.hasRemaining()) {
|
||||
if (this.toULength > 0) {
|
||||
@ -526,7 +530,7 @@ class CharsetCompoundText extends CharsetICU {
|
||||
} else {
|
||||
sourceChar[0] = source.get(source.position());
|
||||
}
|
||||
|
||||
|
||||
if (sourceChar[0] == ESC_START) {
|
||||
tmpState = findStateFromEscSeq(source, this.toUBytesArray, this.toULength);
|
||||
if (tmpState == DO_SEARCH) {
|
||||
@ -542,14 +546,14 @@ class CharsetCompoundText extends CharsetICU {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
this.toULength = 0;
|
||||
}
|
||||
|
||||
|
||||
if (tmpState != currentState) {
|
||||
currentState = tmpState;
|
||||
}
|
||||
|
||||
|
||||
if (currentState == COMPOUND_TEXT_SINGLE_0) {
|
||||
while (source.hasRemaining()) {
|
||||
if (!target.hasRemaining()) {
|
||||
@ -567,29 +571,29 @@ class CharsetCompoundText extends CharsetICU {
|
||||
source.limit(findNextEsc(source));
|
||||
|
||||
decoder = gbDecoder[currentState];
|
||||
|
||||
|
||||
decoder.toUBytesArray = this.toUBytesArray;
|
||||
decoder.toULength = this.toULength;
|
||||
|
||||
err = decoder.decodeLoop(source, target, offsets, true);
|
||||
|
||||
|
||||
this.toULength = decoder.toULength;
|
||||
decoder.toULength = 0;
|
||||
|
||||
|
||||
if (err.isError()) {
|
||||
if (err.isOverflow()) {
|
||||
this.charErrorBufferArray = decoder.charErrorBufferArray;
|
||||
this.charErrorBufferBegin = decoder.charErrorBufferBegin;
|
||||
this.charErrorBufferLength = decoder.charErrorBufferLength;
|
||||
|
||||
|
||||
decoder.charErrorBufferBegin = 0;
|
||||
decoder.charErrorBufferLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
source.limit(sourceLimit);
|
||||
}
|
||||
|
||||
|
||||
if (err.isError()) {
|
||||
break;
|
||||
}
|
||||
@ -602,15 +606,18 @@ class CharsetCompoundText extends CharsetICU {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderCompoundText(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderCompoundText(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
for (int i = 1; i < NUM_OF_CONVERTERS; i++) {
|
||||
myConverterArray[i].MBCSGetFilteredUnicodeSetForUnicode(myConverterArray[i].sharedData, setFillIn, which, CharsetMBCS.UCNV_SET_FILTER_NONE);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
*/
|
||||
|
||||
package com.ibm.icu.charset;
|
||||
|
||||
@ -22,11 +22,11 @@ import com.ibm.icu.impl.Assert;
|
||||
|
||||
/**
|
||||
* An abstract class that provides framework methods of decoding operations for concrete
|
||||
* subclasses.
|
||||
* subclasses.
|
||||
* In the future this class will contain API that will implement converter sematics of ICU4C.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
|
||||
int toUnicodeStatus;
|
||||
byte[] toUBytesArray = new byte[128];
|
||||
@ -37,7 +37,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
int charErrorBufferBegin;
|
||||
char[] invalidCharBuffer = new char[128];
|
||||
int invalidCharLength;
|
||||
|
||||
|
||||
/**
|
||||
* Maximum number of indexed bytes
|
||||
* @internal
|
||||
@ -52,11 +52,12 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
int preToULength; /* negative: replay */
|
||||
int preToUFirstLength; /* length of first character */
|
||||
int mode;
|
||||
|
||||
|
||||
Object toUContext = null;
|
||||
private CharsetCallback.Decoder onUnmappableCharacter = CharsetCallback.TO_U_CALLBACK_STOP;
|
||||
private CharsetCallback.Decoder onMalformedInput = CharsetCallback.TO_U_CALLBACK_STOP;
|
||||
CharsetCallback.Decoder toCharErrorBehaviour = new CharsetCallback.Decoder() {
|
||||
@Override
|
||||
public CoderResult call(CharsetDecoderICU decoder, Object context, ByteBuffer source,
|
||||
CharBuffer target, IntBuffer offsets, char[] buffer, int length, CoderResult cr) {
|
||||
if (cr.isUnmappable()) {
|
||||
@ -69,14 +70,14 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
// return CharsetCallback.TO_U_CALLBACK_STOP.call(decoder, context, source, target, offsets, buffer, length, cr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// exist to keep implOnMalformedInput and implOnUnmappableInput from being too recursive
|
||||
private boolean malformedInputCalled = false;
|
||||
private boolean unmappableCharacterCalled = false;
|
||||
|
||||
|
||||
/*
|
||||
* Construct a CharsetDecorderICU based on the information provided from a CharsetICU object.
|
||||
*
|
||||
*
|
||||
* @param cs The CharsetICU object containing information about how to charset to decode.
|
||||
*/
|
||||
CharsetDecoderICU(CharsetICU cs) {
|
||||
@ -93,65 +94,67 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
final boolean isFallbackUsed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fallback is currently always used by icu4j decoders.
|
||||
*/
|
||||
static final boolean isToUUseFallback() {
|
||||
return isToUUseFallback(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fallback is currently always used by icu4j decoders.
|
||||
*/
|
||||
static final boolean isToUUseFallback(boolean iUseFallback) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the action to be taken if an illegal sequence is encountered
|
||||
*
|
||||
*
|
||||
* @param newAction action to be taken
|
||||
* @exception IllegalArgumentException
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected final void implOnMalformedInput(CodingErrorAction newAction) {
|
||||
// don't run infinitely
|
||||
if (malformedInputCalled)
|
||||
return;
|
||||
|
||||
|
||||
// if we get a replace, do not let the nio replace
|
||||
if (newAction == CodingErrorAction.REPLACE) {
|
||||
malformedInputCalled = true;
|
||||
super.onMalformedInput(CodingErrorAction.IGNORE);
|
||||
malformedInputCalled = false;
|
||||
}
|
||||
|
||||
|
||||
onMalformedInput = getCallback(newAction);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the action to be taken if an illegal sequence is encountered
|
||||
*
|
||||
*
|
||||
* @param newAction action to be taken
|
||||
* @exception IllegalArgumentException
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected final void implOnUnmappableCharacter(CodingErrorAction newAction) {
|
||||
// dont run infinitely
|
||||
if (unmappableCharacterCalled)
|
||||
return;
|
||||
|
||||
|
||||
// if we get a replace, do not let the nio replace
|
||||
if (newAction == CodingErrorAction.REPLACE) {
|
||||
unmappableCharacterCalled = true;
|
||||
super.onUnmappableCharacter(CodingErrorAction.IGNORE);
|
||||
unmappableCharacterCalled = false;
|
||||
}
|
||||
|
||||
|
||||
onUnmappableCharacter = getCallback(newAction);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the callback encoder method and context to be used if an illegal sequence is encounterd.
|
||||
* You would normally call this twice to set both the malform and unmappable error. In this case,
|
||||
@ -170,12 +173,12 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
} else {
|
||||
/* Error: Only malformed and unmappable are handled. */
|
||||
}
|
||||
|
||||
|
||||
if (toUContext == null || !toUContext.equals(newContext)) {
|
||||
toUContext = newContext;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static CharsetCallback.Decoder getCallback(CodingErrorAction action){
|
||||
if(action==CodingErrorAction.REPLACE){
|
||||
return CharsetCallback.TO_U_CALLBACK_SUBSTITUTE;
|
||||
@ -190,42 +193,44 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
* 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.
|
||||
* @return result of flushing action and completes the decoding all input.
|
||||
* Returns CoderResult.UNDERFLOW if the action succeeds.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected final CoderResult implFlush(CharBuffer out) {
|
||||
return decode(EMPTY, out, null, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the to Unicode mode of converter
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected void implReset() {
|
||||
toUnicodeStatus = 0 ;
|
||||
toULength = 0;
|
||||
charErrorBufferLength = 0;
|
||||
charErrorBufferBegin = 0;
|
||||
|
||||
|
||||
/* store previous UChars/chars to continue partial matches */
|
||||
preToUBegin = 0;
|
||||
preToULength = 0; /* negative: replay */
|
||||
preToUFirstLength = 0;
|
||||
preToUFirstLength = 0;
|
||||
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decodes one or more bytes. The default behaviour of the converter
|
||||
* is stop and report if an error in input stream is encountered.
|
||||
* 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
|
||||
* 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
|
||||
@ -233,6 +238,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
* action succeeds or more input is needed for completing the decoding action.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer in,CharBuffer out){
|
||||
if(in.remaining() < toUCountPending()){
|
||||
return CoderResult.UNDERFLOW;
|
||||
@ -241,16 +247,16 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
// toULength = 0;
|
||||
// return CoderResult.UNDERFLOW;
|
||||
// }
|
||||
|
||||
|
||||
in.position(in.position() + toUCountPending());
|
||||
|
||||
|
||||
/* do the conversion */
|
||||
CoderResult ret = decode(in, out, null, false);
|
||||
|
||||
// ok was there input held in the previous invocation of decodeLoop
|
||||
// ok was there input held in the previous invocation of decodeLoop
|
||||
// that resulted in output in this invocation?
|
||||
in.position(in.position() - toUCountPending());
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -262,7 +268,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
* action succeeds or more input is needed for completing the decoding action.
|
||||
*/
|
||||
abstract CoderResult decodeLoop(ByteBuffer in, CharBuffer out, IntBuffer offsets, boolean flush);
|
||||
|
||||
|
||||
/*
|
||||
* Implements the ICU semantic for decode operation
|
||||
* @param source The input byte buffer
|
||||
@ -274,12 +280,12 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
* action succeeds or more input is needed for completing the decoding action.
|
||||
*/
|
||||
final CoderResult decode(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
|
||||
|
||||
/* check parameters */
|
||||
if (target == null || source == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Make sure that the buffer sizes do not exceed the number range for
|
||||
* int32_t because some functions use the size (in units or bytes)
|
||||
@ -301,7 +307,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/* flush the target overflow buffer */
|
||||
if (charErrorBufferLength > 0) {
|
||||
int i = 0;
|
||||
@ -328,12 +334,12 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
/* the overflow buffer is completely copied to the target */
|
||||
charErrorBufferLength = 0;
|
||||
}
|
||||
|
||||
|
||||
if (!flush && !source.hasRemaining() && toULength == 0 && preToULength >= 0) {
|
||||
/* the overflow buffer is emptied and there is no new input: we are done */
|
||||
return CoderResult.UNDERFLOW;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Do not simply return with a buffer overflow error if
|
||||
* !flush && t==targetLimit
|
||||
@ -341,7 +347,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
* For example, the skip callback may be called;
|
||||
* it does not output anything.
|
||||
*/
|
||||
|
||||
|
||||
return toUnicodeWithCallback(source, target, offsets, flush);
|
||||
}
|
||||
|
||||
@ -388,7 +394,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
}
|
||||
} */
|
||||
final CoderResult toUnicodeWithCallback(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush){
|
||||
|
||||
|
||||
int sourceIndex;
|
||||
int errorInputLength;
|
||||
boolean converterSawEndOfInput, calledCallback;
|
||||
@ -397,14 +403,14 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
/* variables for m:n conversion */
|
||||
ByteBuffer replayArray = ByteBuffer.allocate(EXT_MAX_BYTES);
|
||||
int replayArrayIndex = 0;
|
||||
|
||||
|
||||
ByteBuffer realSource=null;
|
||||
boolean realFlush=false;
|
||||
int realSourceIndex=0;
|
||||
|
||||
|
||||
|
||||
CoderResult cr = CoderResult.UNDERFLOW;
|
||||
|
||||
|
||||
/* get the converter implementation function */
|
||||
sourceIndex=0;
|
||||
|
||||
@ -428,7 +434,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
sourceIndex=-1;
|
||||
preToULength=0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* loop for conversion and error handling
|
||||
*
|
||||
@ -454,13 +460,13 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
* s<sourceLimit before converterSawEndOfInput is checked
|
||||
*/
|
||||
converterSawEndOfInput= (cr.isUnderflow() && flush && source.remaining()==0 && toULength == 0);
|
||||
|
||||
|
||||
/* no callback called yet for this iteration */
|
||||
calledCallback=false;
|
||||
|
||||
|
||||
/* no sourceIndex adjustment for conversion, only for callback output */
|
||||
errorInputLength=0;
|
||||
|
||||
|
||||
/*
|
||||
* loop for offsets and error handling
|
||||
*
|
||||
@ -477,8 +483,8 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
int length=(target.position()-t);
|
||||
if(length>0) {
|
||||
updateOffsets(offsets, length, sourceIndex, errorInputLength);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* if a converter handles offsets and updates the offsets
|
||||
* pointer at the end, then pArgs->offset should not change
|
||||
@ -488,13 +494,13 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
*/
|
||||
//TODO: pArgs->offsets=offsets+=length;
|
||||
/* }
|
||||
|
||||
|
||||
if(sourceIndex>=0) {
|
||||
sourceIndex+=(source.position()-s);
|
||||
}
|
||||
|
||||
|
||||
} */
|
||||
|
||||
|
||||
if(preToULength<0) {
|
||||
/*
|
||||
* switch the source to new replay units (cannot occur while replaying)
|
||||
@ -505,7 +511,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
realSource=source;
|
||||
realFlush=flush;
|
||||
realSourceIndex=sourceIndex;
|
||||
|
||||
|
||||
//UConverterUtility.uprv_memcpy(replayArray, replayBegin, preToUArray, preToUBegin, -preToULength);
|
||||
replayArray.put(preToUArray,0, -preToULength);
|
||||
// reset position
|
||||
@ -517,7 +523,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
if((sourceIndex+=preToULength)<0) {
|
||||
sourceIndex=-1;
|
||||
}
|
||||
|
||||
|
||||
preToULength=0;
|
||||
} else {
|
||||
/* see implementation note before _fromUnicodeWithCallback() */
|
||||
@ -525,11 +531,11 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
Assert.assrt(realSource==null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* update pointers */
|
||||
s=source.position();
|
||||
//t=target.position();
|
||||
|
||||
|
||||
if(cr.isUnderflow()) {
|
||||
if(s<source.limit())
|
||||
{
|
||||
@ -550,7 +556,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
* the entire input stream is consumed
|
||||
* and there is a partial, truncated input sequence left
|
||||
*/
|
||||
|
||||
|
||||
/* inject an error and continue with callback handling */
|
||||
cr = CoderResult.malformedForLength(toULength);
|
||||
calledCallback=false; /* new error condition */
|
||||
@ -567,19 +573,19 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
if(!converterSawEndOfInput) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* reset the converter without calling the callback function */
|
||||
implReset();
|
||||
}
|
||||
|
||||
|
||||
/* done successfully */
|
||||
return cr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* U_FAILURE(*err) */
|
||||
{
|
||||
|
||||
|
||||
if( calledCallback || cr.isOverflow() ||
|
||||
(cr.isMalformed() && cr.isUnmappable())
|
||||
) {
|
||||
@ -608,16 +614,16 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
return cr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* copy toUBytes[] to invalidCharBuffer[] */
|
||||
errorInputLength=invalidCharLength=toULength;
|
||||
if(errorInputLength>0) {
|
||||
copy(toUBytesArray, 0, invalidCharBuffer, 0, errorInputLength);
|
||||
}
|
||||
|
||||
|
||||
/* set the converter state to deal with the next character */
|
||||
toULength=0;
|
||||
|
||||
|
||||
/* call the callback function */
|
||||
cr = toCharErrorBehaviour.call(this, toUContext, source, target, offsets, invalidCharBuffer, errorInputLength, cr);
|
||||
/*
|
||||
@ -634,7 +640,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
|
||||
/*
|
||||
* Returns the number of chars held in the converter's internal state
|
||||
* because more input is needed for completing the conversion. This function is
|
||||
* because more input is needed for completing the conversion. This function is
|
||||
* useful for mapping semantics of ICU's converter interface to those of iconv,
|
||||
* and this information is not needed for normal conversion.
|
||||
* @return The number of chars in the state. -1 if an error is encountered.
|
||||
@ -650,7 +656,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void copy(byte[] src, int srcOffset, char[] dst, int dstOffset, int length) {
|
||||
for(int i=srcOffset; i<length; i++){
|
||||
@ -664,11 +670,11 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
* @return A CoderResult object that contains the error result when an error occurs.
|
||||
*/
|
||||
static final CoderResult toUWriteUChars( CharsetDecoderICU cnv,
|
||||
char[] ucharsArray, int ucharsBegin, int length,
|
||||
char[] ucharsArray, int ucharsBegin, int length,
|
||||
CharBuffer target, IntBuffer offsets, int sourceIndex) {
|
||||
|
||||
|
||||
CoderResult cr = CoderResult.UNDERFLOW;
|
||||
|
||||
|
||||
/* write UChars */
|
||||
if(offsets==null) {
|
||||
while(length>0 && target.hasRemaining()) {
|
||||
@ -685,7 +691,7 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
}
|
||||
}
|
||||
/* write overflow */
|
||||
if(length>0) {
|
||||
if(length>0) {
|
||||
cnv.charErrorBufferLength= 0;
|
||||
cr = CoderResult.OVERFLOW;
|
||||
do {
|
||||
@ -707,8 +713,8 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
/* Note: Currently, this method is not being used because the callback method calls toUWriteUChars with
|
||||
* the substitution characters. Will leave in here for the time being. To be removed later. (4.0)
|
||||
*/
|
||||
/*CoderResult cbToUWriteSub(CharsetDecoderICU decoder,
|
||||
ByteBuffer source, CharBuffer target,
|
||||
/*CoderResult cbToUWriteSub(CharsetDecoderICU decoder,
|
||||
ByteBuffer source, CharBuffer target,
|
||||
IntBuffer offsets){
|
||||
String sub = decoder.replacement();
|
||||
CharsetICU cs = (CharsetICU) decoder.charset();
|
||||
@ -719,10 +725,10 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
||||
} else {
|
||||
return CharsetDecoderICU.toUWriteUChars(decoder, sub.toCharArray(),
|
||||
0, sub.length(), target, offsets, source.position());
|
||||
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* Returns the maxBytesPerChar value for the Charset that created this decoder.
|
||||
* @return maxBytesPerChar
|
||||
|
@ -25,7 +25,7 @@ import com.ibm.icu.text.UTF16;
|
||||
|
||||
/**
|
||||
* An abstract class that provides framework methods of decoding operations for concrete
|
||||
* subclasses.
|
||||
* subclasses.
|
||||
* In the future this class will contain API that will implement converter semantics of ICU4C.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@ -70,6 +70,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
private CharsetCallback.Encoder onMalformedInput = CharsetCallback.FROM_U_CALLBACK_STOP;
|
||||
|
||||
CharsetCallback.Encoder fromCharErrorBehaviour = new CharsetCallback.Encoder() {
|
||||
@Override
|
||||
public CoderResult call(CharsetEncoderICU encoder, Object context,
|
||||
CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
char[] buffer, int length, int cp, CoderResult cr) {
|
||||
@ -87,7 +88,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
|
||||
/*
|
||||
* Construcs a new encoder for the given charset
|
||||
*
|
||||
*
|
||||
* @param cs
|
||||
* for which the decoder is created
|
||||
* @param replacement
|
||||
@ -144,28 +145,30 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
|
||||
/**
|
||||
* Sets the action to be taken if an illegal sequence is encountered
|
||||
*
|
||||
*
|
||||
* @param newAction
|
||||
* action to be taken
|
||||
* @exception IllegalArgumentException
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected void implOnMalformedInput(CodingErrorAction newAction) {
|
||||
onMalformedInput = getCallback(newAction);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the action to be taken if an illegal sequence is encountered
|
||||
*
|
||||
*
|
||||
* @param newAction
|
||||
* action to be taken
|
||||
* @exception IllegalArgumentException
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected void implOnUnmappableCharacter(CodingErrorAction newAction) {
|
||||
onUnmappableInput = getCallback(newAction);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the callback encoder method and context to be used if an illegal sequence is encountered.
|
||||
* You would normally call this twice to set both the malform and unmappable error. In this case,
|
||||
@ -184,7 +187,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
} else {
|
||||
/* Error: Only malformed and unmappable are handled. */
|
||||
}
|
||||
|
||||
|
||||
if (fromUContext == null || !fromUContext.equals(newContext)) {
|
||||
setFromUContext(newContext);
|
||||
}
|
||||
@ -192,7 +195,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
|
||||
/**
|
||||
* Sets fromUContext used in callbacks.
|
||||
*
|
||||
*
|
||||
* @param newContext Object
|
||||
* @exception IllegalArgumentException The object is an illegal argument for UContext.
|
||||
* @stable ICU 4.0
|
||||
@ -200,7 +203,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
public final void setFromUContext(Object newContext) {
|
||||
fromUContext = newContext;
|
||||
}
|
||||
|
||||
|
||||
private static CharsetCallback.Encoder getCallback(CodingErrorAction action) {
|
||||
if (action == CodingErrorAction.REPLACE) {
|
||||
return CharsetCallback.FROM_U_CALLBACK_SUBSTITUTE;
|
||||
@ -217,10 +220,11 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
* 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.
|
||||
* @return result of flushing action and completes the decoding all input.
|
||||
* Returns CoderResult.UNDERFLOW if the action succeeds.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected CoderResult implFlush(ByteBuffer out) {
|
||||
return encode(EMPTY, out, null, true);
|
||||
}
|
||||
@ -229,6 +233,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
* Resets the from Unicode mode of converter
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected void implReset() {
|
||||
errorBufferLength = 0;
|
||||
fromUnicodeStatus = 0;
|
||||
@ -252,6 +257,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
* action succeeds or more input is needed for completing the decoding action.
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
|
||||
if (!in.hasRemaining() && this.errorBufferLength == 0) { // make sure the errorBuffer is empty
|
||||
// The Java framework should have already substituted what was left.
|
||||
@ -596,7 +602,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
/* callback handling */
|
||||
{
|
||||
int codePoint;
|
||||
|
||||
|
||||
/* get and write the code point */
|
||||
codePoint = fromUChar32;
|
||||
errorInputLength = UTF16.append(invalidUCharBuffer, 0,
|
||||
@ -671,8 +677,9 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
}*/
|
||||
/**
|
||||
* Overrides super class method
|
||||
* @stable ICU 3.6
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
public boolean isLegalReplacement(byte[] repl) {
|
||||
return true;
|
||||
}
|
||||
@ -701,7 +708,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
out.put(bytesArray[bytesBegin]);
|
||||
bytesBegin++;
|
||||
}
|
||||
// success
|
||||
// success
|
||||
bytesLength = 0;
|
||||
} catch (BufferOverflowException ex) {
|
||||
cr = CoderResult.OVERFLOW;
|
||||
@ -713,7 +720,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
--obl;
|
||||
}
|
||||
}
|
||||
//write overflow
|
||||
//write overflow
|
||||
cnv.errorBufferLength = bytesLimit - bytesBegin;
|
||||
if (cnv.errorBufferLength > 0) {
|
||||
int index = 0;
|
||||
@ -727,7 +734,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
|
||||
/*
|
||||
* Returns the number of chars held in the converter's internal state
|
||||
* because more input is needed for completing the conversion. This function is
|
||||
* because more input is needed for completing the conversion. This function is
|
||||
* useful for mapping semantics of ICU's converter interface to those of iconv,
|
||||
* and this information is not needed for normal conversion.
|
||||
* @return The number of chars in the state. -1 if an error is encountered.
|
||||
@ -746,12 +753,12 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
private final void setSourcePosition(CharBuffer source) {
|
||||
|
||||
// ok was there input held in the previous invocation of encodeLoop
|
||||
// ok was there input held in the previous invocation of encodeLoop
|
||||
// that resulted in output in this invocation?
|
||||
source.position(source.position() - fromUCountPending());
|
||||
}
|
||||
@ -816,7 +823,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
*/
|
||||
if (cr.isOverflow()) {
|
||||
/* Overflowed target. Now, we'll write into the charErrorBuffer.
|
||||
* It's a fixed size. If we overflow it...Hm
|
||||
* It's a fixed size. If we overflow it...Hm
|
||||
*/
|
||||
|
||||
/* start the new target at the first free slot in the error buffer */
|
||||
@ -840,13 +847,13 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
* a lead surrogate followed by a trail surrogate. This method can change
|
||||
* the source position and will modify fromUChar32.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* If <code>null</code> is returned, then there was success in reading a
|
||||
* surrogate pair, the codepoint is stored in <code>fromUChar32</code> and
|
||||
* <code>fromUChar32</code> should be reset (to 0) after being read.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* The encoding source.
|
||||
* @param lead
|
||||
@ -886,8 +893,8 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
* requirement, the calling method must also increment the index if this method returns
|
||||
* <code>null</code>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* The encoding source.
|
||||
* @param lead
|
||||
@ -920,7 +927,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
fromUChar32 = UCharacter.getCodePoint(lead, trail);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the maxCharsPerByte value for the Charset that created this encoder.
|
||||
* @return maxCharsPerByte
|
||||
@ -929,7 +936,7 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
||||
public final float maxCharsPerByte() {
|
||||
return ((CharsetICU)(this.charset())).maxCharsPerByte;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the size of a buffer for conversion from Unicode to a charset.
|
||||
* The calculated size is guaranteed to be sufficient for this conversion.
|
||||
|
@ -42,7 +42,7 @@ class CharsetHZ extends CharsetICU {
|
||||
maxBytesPerChar = 4;
|
||||
minBytesPerChar = 1;
|
||||
maxCharsPerByte = 1;
|
||||
|
||||
|
||||
isEmptySegment = false;
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ class CharsetHZ extends CharsetICU {
|
||||
gbDecoder = (CharsetMBCS.CharsetDecoderMBCS) gbCharset.newDecoder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
gbDecoder.implReset();
|
||||
@ -63,6 +64,7 @@ class CharsetHZ extends CharsetICU {
|
||||
isEmptySegment = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult err = CoderResult.UNDERFLOW;
|
||||
byte[] tempBuf = new byte[2];
|
||||
@ -141,7 +143,7 @@ class CharsetHZ extends CharsetICU {
|
||||
* add another bit to distinguish a 0 byte from not having seen a lead byte
|
||||
*/
|
||||
toUnicodeStatus = mySourceChar | 0x100;
|
||||
isEmptySegment = false; /* the segment has something, either valid or will produce a different error, so reset this */
|
||||
isEmptySegment = false; /* the segment has something, either valid or will produce a different error, so reset this */
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
@ -154,7 +156,7 @@ class CharsetHZ extends CharsetICU {
|
||||
* - We include at least the first byte in the illegal sequence.
|
||||
* - If any of the non-initial bytes could be the start of a character,
|
||||
* we stop the illegal sequence before the first one of those
|
||||
*
|
||||
*
|
||||
* In HZ DBCS, if the second byte is in the 21..7e range,
|
||||
* we report ony the first byte as the illegal sequence.
|
||||
* Otherwise we convert of report the pair of bytes.
|
||||
@ -230,6 +232,7 @@ class CharsetHZ extends CharsetICU {
|
||||
gbEncoder = (CharsetMBCS.CharsetEncoderMBCS) gbCharset.newEncoder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
gbEncoder.implReset();
|
||||
@ -238,6 +241,7 @@ class CharsetHZ extends CharsetICU {
|
||||
isTargetUCharDBCS = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush) {
|
||||
int length = 0;
|
||||
int[] targetUniChar = new int[] { 0 };
|
||||
@ -375,14 +379,17 @@ class CharsetHZ extends CharsetICU {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderHZ(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderHZ(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
setFillIn.add(0,0x7f);
|
||||
// CharsetMBCS mbcshz = (CharsetMBCS)CharsetICU.forNameICU("icu-internal-25546");
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Copyright (C) 2006-2016, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
*/
|
||||
|
||||
package com.ibm.icu.charset;
|
||||
|
||||
@ -69,7 +69,7 @@ public abstract class CharsetICU extends Charset{
|
||||
int options;
|
||||
|
||||
float maxCharsPerByte;
|
||||
|
||||
|
||||
String name; /* +4: 60 internal name of the converter- invariant chars */
|
||||
|
||||
int codepage; /* +64: 4 codepage # (now IBM-$codepage) */
|
||||
@ -82,20 +82,20 @@ public abstract class CharsetICU extends Charset{
|
||||
|
||||
byte subChar[/*UCNV_MAX_SUBCHAR_LEN*/]; /* +72: 4 [note: 4 and 8 byte boundary] */
|
||||
byte subCharLen; /* +76: 1 */
|
||||
|
||||
|
||||
byte hasToUnicodeFallback; /* +77: 1 UBool needs to be changed to UBool to be consistent across platform */
|
||||
byte hasFromUnicodeFallback; /* +78: 1 */
|
||||
short unicodeMask; /* +79: 1 bit 0: has supplementary bit 1: has single surrogates */
|
||||
byte subChar1; /* +80: 1 single-byte substitution character for IBM MBCS (0 if none) */
|
||||
//byte reserved[/*19*/]; /* +81: 19 to round out the structure */
|
||||
|
||||
|
||||
|
||||
|
||||
// typedef enum UConverterUnicodeSet {
|
||||
/**
|
||||
* Parameter that select the set of roundtrippable Unicode code points.
|
||||
/**
|
||||
* Parameter that select the set of roundtrippable Unicode code points.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
public static final int ROUNDTRIP_SET=0;
|
||||
public static final int ROUNDTRIP_SET=0;
|
||||
/**
|
||||
* Select the set of Unicode code points with roundtrip or fallback mappings.
|
||||
* Not supported at this point.
|
||||
@ -106,9 +106,9 @@ public abstract class CharsetICU extends Charset{
|
||||
public static final int ROUNDTRIP_AND_FALLBACK_SET =1;
|
||||
|
||||
//} UConverterUnicodeSet;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param icuCanonicalName
|
||||
* @param canonicalName
|
||||
* @param aliases
|
||||
@ -121,7 +121,7 @@ public abstract class CharsetICU extends Charset{
|
||||
}
|
||||
this.icuCanonicalName = icuCanonicalName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ascertains if a charset is a sub set of this charset
|
||||
* Implements the abstract method of super class.
|
||||
@ -129,6 +129,7 @@ public abstract class CharsetICU extends Charset{
|
||||
* @return true if the given charset is a subset of this charset
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Charset cs){
|
||||
if (null == cs) {
|
||||
return false;
|
||||
@ -152,7 +153,7 @@ public abstract class CharsetICU extends Charset{
|
||||
algorithmicCharsets.put("LMBCS-18", "com.ibm.icu.charset.CharsetLMBCS");
|
||||
algorithmicCharsets.put("LMBCS-19", "com.ibm.icu.charset.CharsetLMBCS");
|
||||
algorithmicCharsets.put("BOCU-1", "com.ibm.icu.charset.CharsetBOCU1" );
|
||||
algorithmicCharsets.put("SCSU", "com.ibm.icu.charset.CharsetSCSU" );
|
||||
algorithmicCharsets.put("SCSU", "com.ibm.icu.charset.CharsetSCSU" );
|
||||
algorithmicCharsets.put("US-ASCII", "com.ibm.icu.charset.CharsetASCII" );
|
||||
algorithmicCharsets.put("ISO-8859-1", "com.ibm.icu.charset.Charset88591" );
|
||||
algorithmicCharsets.put("UTF-16", "com.ibm.icu.charset.CharsetUTF16" );
|
||||
@ -206,7 +207,7 @@ public abstract class CharsetICU extends Charset{
|
||||
Class<?>[] paramTypes = new Class<?>[]{ String.class, String.class, String[].class};
|
||||
final Constructor<? extends CharsetICU> c = cs.getConstructor(paramTypes);
|
||||
Object[] params = new Object[]{ icuCanonicalName, javaCanonicalName, aliases};
|
||||
|
||||
|
||||
// Run constructor
|
||||
try {
|
||||
conv = c.newInstance(params);
|
||||
@ -222,18 +223,18 @@ public abstract class CharsetICU extends Charset{
|
||||
}
|
||||
}catch(ClassNotFoundException ex){
|
||||
}catch(NoSuchMethodException ex){
|
||||
}catch (IllegalAccessException ex){
|
||||
}catch (InstantiationException ex){
|
||||
}catch (IllegalAccessException ex){
|
||||
}catch (InstantiationException ex){
|
||||
}
|
||||
throw new UnsupportedCharsetException( icuCanonicalName+": "+"Could not load " + className);
|
||||
throw new UnsupportedCharsetException( icuCanonicalName+": "+"Could not load " + className);
|
||||
}
|
||||
|
||||
|
||||
static final boolean isSurrogate(int c){
|
||||
return (((c)&0xfffff800)==0xd800);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the default charset name
|
||||
* Returns the default charset name
|
||||
*/
|
||||
// static final String getDefaultCharsetName(){
|
||||
// String defaultEncoding = new InputStreamReader(new ByteArrayInputStream(new byte[0])).getEncoding();
|
||||
@ -246,7 +247,7 @@ public abstract class CharsetICU extends Charset{
|
||||
* available. If the ICU charset provider does not support
|
||||
* the specified charset, then try other charset providers
|
||||
* including the standard Java charset provider.
|
||||
*
|
||||
*
|
||||
* @param charsetName The name of the requested charset,
|
||||
* may be either a canonical name or an alias
|
||||
* @return A charset object for the named charset
|
||||
@ -281,11 +282,11 @@ public abstract class CharsetICU extends Charset{
|
||||
* This follows ucnv.c method ucnv_detectUnicodeSignature() to detect the
|
||||
* start of the stream for example U+FEFF (the Unicode BOM/signature
|
||||
* character) that can be ignored.
|
||||
*
|
||||
*
|
||||
* Detects Unicode signature byte sequences at the start of the byte stream
|
||||
* and returns number of bytes of the BOM of the indicated Unicode charset.
|
||||
* 0 is returned when no Unicode signature is recognized.
|
||||
*
|
||||
*
|
||||
*/
|
||||
// TODO This should be proposed as CharsetDecoderICU API.
|
||||
// static String detectUnicodeSignature(ByteBuffer source) {
|
||||
@ -373,17 +374,17 @@ public abstract class CharsetICU extends Charset{
|
||||
// /* no known Unicode signature byte sequence recognized */
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
abstract void getUnicodeSetImpl(UnicodeSet setFillIn, int which);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the set of Unicode code points that can be converted by an ICU Converter.
|
||||
*
|
||||
* <p>The current implementation returns only one kind of set (UCNV_ROUNDTRIP_SET): The set of all Unicode code points that can be
|
||||
* roundtrip-converted (converted without any data loss) with the converter This set will not include code points that have fallback
|
||||
* roundtrip-converted (converted without any data loss) with the converter This set will not include code points that have fallback
|
||||
* mappings or are only the result of reverse fallback mappings. See UTR #22 "Character Mapping Markup Language" at <a href="http://www.unicode.org/reports/tr22/">http://www.unicode.org/reports/tr22/</a>
|
||||
*
|
||||
*
|
||||
* <p>In the future, there may be more UConverterUnicodeSet choices to select sets with different properties.
|
||||
*
|
||||
* <p>This is useful for example for
|
||||
@ -393,10 +394,10 @@ public abstract class CharsetICU extends Charset{
|
||||
* by comparing its roundtrip set with the set of ExemplarCharacters from
|
||||
* ICU's locale data or other sources</li></ul>
|
||||
*
|
||||
* @param setFillIn A valid UnicodeSet. It will be cleared by this function before
|
||||
* @param setFillIn A valid UnicodeSet. It will be cleared by this function before
|
||||
* the converter's specific set is filled in.
|
||||
* @param which A selector; currently ROUNDTRIP_SET is the only supported value.
|
||||
* @throws IllegalArgumentException if the parameters does not match.
|
||||
* @throws IllegalArgumentException if the parameters does not match.
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
public void getUnicodeSet(UnicodeSet setFillIn, int which){
|
||||
@ -406,7 +407,7 @@ public abstract class CharsetICU extends Charset{
|
||||
setFillIn.clear();
|
||||
getUnicodeSetImpl(setFillIn, which);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not the charset of the converter has a fixed number of bytes
|
||||
* per charset character.
|
||||
@ -422,21 +423,21 @@ public abstract class CharsetICU extends Charset{
|
||||
if (this instanceof CharsetASCII || this instanceof CharsetUTF32) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (this instanceof CharsetMBCS) {
|
||||
if (((CharsetMBCS)this).sharedData.staticData.maxBytesPerChar == ((CharsetMBCS)this).sharedData.staticData.minBytesPerChar) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void getNonSurrogateUnicodeSet(UnicodeSet setFillIn){
|
||||
setFillIn.add(0, 0xd7ff);
|
||||
setFillIn.add(0xe000, 0x10ffff);
|
||||
}
|
||||
|
||||
|
||||
static void getCompleteUnicodeSet(UnicodeSet setFillIn){
|
||||
setFillIn.add(0, 0x10ffff);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,31 +26,31 @@ import com.ibm.icu.util.ULocale;
|
||||
|
||||
/*
|
||||
* LMBCS
|
||||
*
|
||||
*
|
||||
* (Lotus Multi-Byte Character Set)
|
||||
*
|
||||
*
|
||||
* LMBS was invented in the alte 1980's and is primarily used in Lotus Notes
|
||||
* databases and in Lotus 1-2-3 files. Programmers who work with the APIs
|
||||
* into these products will sometimes need to deal with strings in this format.
|
||||
*
|
||||
*
|
||||
* The code in this file provides an implementation for an ICU converter of
|
||||
* LMBCS to and from Unicode.
|
||||
*
|
||||
*
|
||||
* Since the LMBCS character set is only sparsely documented in existing
|
||||
* printed or online material, we have added extensive annotation to this
|
||||
* file to serve as a guide to understanding LMBCS.
|
||||
*
|
||||
*
|
||||
* LMBCS was originally designed with these four sometimes-competing design goals:
|
||||
* -Provide encodings for characters in 12 existing national standards
|
||||
* (plus a few other characters)
|
||||
* -Minimal memory footprint
|
||||
* -Maximal speed of conversion into the existing national character sets
|
||||
* -No need to track a changing state as you interpret a string.
|
||||
*
|
||||
*
|
||||
* All of the national character sets LMBCS was trying to encode are 'ANSI'
|
||||
* based, in that the bytes from 0x20 - 0x7F are almost exactly the
|
||||
* same common Latin unaccented characters and symbols in all character sets.
|
||||
*
|
||||
*
|
||||
* So, in order to help meet the speed & memory design goals, the common ANSI
|
||||
* bytes from 0x20-0x7F are represented by the same single-byte values in LMBCS.
|
||||
*/
|
||||
@ -89,14 +89,14 @@ class CharsetLMBCS extends CharsetICU {
|
||||
private static final short ULMBCS_GRP_KO = 0x11; /* Korean :ibm-1261 */
|
||||
private static final short ULMBCS_GRP_TW = 0x12; /* Chinese SC :ibm-950 */
|
||||
private static final short ULMBCS_GRP_CN = 0x13; /* Chinese TC :ibm-1386 */
|
||||
/*
|
||||
/*
|
||||
* So, the beginnning of understanding LMBCS is that IF the first byte of a LMBCS
|
||||
* character is one of those 12 values, you can interpret the remaining bytes of
|
||||
* character is one of those 12 values, you can interpret the remaining bytes of
|
||||
* that character as coming from one of those character sets. Since the lower
|
||||
* ANSI bytes already are represented in singl bytes, using one of the chracter
|
||||
* set announcers is used to announce a character that starts with a byte of
|
||||
* 0x80 or greater.
|
||||
*
|
||||
*
|
||||
* The character sets are arranged so that the single byte sets all appear
|
||||
* before the multi-byte character sets. When we need to tell whether a
|
||||
* group byte is for a single byte char set or not we use this definition:
|
||||
@ -105,7 +105,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
/*
|
||||
* However, to fully understand LMBCS, you must also understand a series of
|
||||
* exceptions & optimizations made in service of the design goals.
|
||||
*
|
||||
*
|
||||
* First, those of you who are character set mavens may have noticed that
|
||||
* the 'double-byte' character sets are actually multi-byte chracter sets
|
||||
* that can have 1 or two bytes, even in upper-ascii range. To force
|
||||
@ -114,10 +114,10 @@ class CharsetLMBCS extends CharsetICU {
|
||||
* to introduce any single-byte character > 0x80 in an otherwise double-byte
|
||||
* character set. So, for example, the LMBCS sequence x10 x10 xAE is the
|
||||
* same as '0xAE' in the Japanese code page 943.
|
||||
*
|
||||
*
|
||||
* Next, you will notice that the list of group bytes has some gaps.
|
||||
* These are used in various ways.
|
||||
*
|
||||
*
|
||||
* We reserve a few special single byte values for common control
|
||||
* characters. These are in the same place as their ANSI equivalents for speed.
|
||||
*/
|
||||
@ -163,7 +163,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
private static final short ULMBCS_GRP_UNICODE = 0x14;
|
||||
/*
|
||||
* The two bytes appearing after a 0x14 are interpreted as UTF-16 BE
|
||||
* (Big Endian) characters. The exception comes when UTF16
|
||||
* (Big Endian) characters. The exception comes when UTF16
|
||||
* representation would have a zero as the second byte. In that case,
|
||||
* 'F6' is used in its place, and the bytes are swapped. (This prevents
|
||||
* LMBCS from encoding any Unicode values of the form U+F6xx, but that's OK:
|
||||
@ -180,7 +180,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
* translations even faster, sometimes the optimization group byte can be dropped
|
||||
* from a LMBCS character. This is decided on a process-by-process basis. The
|
||||
* group byte that is dropped is called the 'optimization group.'
|
||||
*
|
||||
*
|
||||
* For Notes, the optimization group is always 0x1.
|
||||
*/
|
||||
//private static final short ULMBCS_DEFAULTOPTGROUP = 0x01;
|
||||
@ -191,19 +191,19 @@ class CharsetLMBCS extends CharsetICU {
|
||||
* etc.). Using plain 'LMBCS' as the name of the converter will give you
|
||||
* LMBCS-1.
|
||||
*/
|
||||
|
||||
|
||||
/* Implementation strategy */
|
||||
/*
|
||||
/*
|
||||
* Because of the extensive use of other character sets, the LMBCS converter
|
||||
* keeps a mapping between optimization groups and IBM character sets, so that
|
||||
* ICU converters can be created and used as needed.
|
||||
*
|
||||
*
|
||||
* As you can see, even though any byte below 0x20 could be an optimization
|
||||
* byte, only those at 0x13 or below can map to an actual converter. To limit
|
||||
* some loops and searches, we define a value for that last group converter:
|
||||
*/
|
||||
private static final short ULMBCS_GRP_LAST = 0x13; /* last LMBCS group that has a converter */
|
||||
|
||||
|
||||
private static final String[] OptGroupByteToCPName = {
|
||||
/* 0x0000 */ "lmb-excp", /* internal home for the LOTUS exceptions list */
|
||||
/* 0x0001 */ "ibm-850",
|
||||
@ -227,14 +227,14 @@ class CharsetLMBCS extends CharsetICU {
|
||||
/* 0x0013 */ "windows-936",
|
||||
/* The rest are null, including the 0x0014 Unicode compatibility region
|
||||
* and 0x0019, the 1-2-3 system range control char */
|
||||
/* 0x0014 */ null
|
||||
/* 0x0014 */ null
|
||||
};
|
||||
|
||||
|
||||
/* That's approximately all the data that's needed for translating
|
||||
* LMBCS to Unicode.
|
||||
*
|
||||
*
|
||||
* However, to translate Unicode to LMBCS, we need some more support.
|
||||
*
|
||||
*
|
||||
* That's because there are often more than one possible mappings from a Unicode
|
||||
* code point back into LMBCS. The first thing we do is look up into a table
|
||||
* to figure out if there are more than one possible mapplings. This table,
|
||||
@ -252,7 +252,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
LMBCS mbcs native encoding
|
||||
(example: Unihan) */
|
||||
private static final short ULMBCS_AMBIGUOUS_ALL = 0x82;
|
||||
|
||||
|
||||
/* And here's a simple way to see if a group falls in an appropriate range */
|
||||
private boolean ULMBCS_AMBIGUOUS_MATCH(short agroup, short xgroup) {
|
||||
return (((agroup == ULMBCS_AMBIGUOUS_SBCS) &&
|
||||
@ -261,7 +261,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
(xgroup >= ULMBCS_DOUBLEOPTGROUP_START)) ||
|
||||
((agroup) == ULMBCS_AMBIGUOUS_ALL));
|
||||
}
|
||||
|
||||
|
||||
/* The table & some code to use it: */
|
||||
private static class _UniLMBCSGrpMap {
|
||||
int uniStartRange;
|
||||
@ -273,7 +273,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
this.GrpType = GrpType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final _UniLMBCSGrpMap[] UniLMBCSGrpMap = {
|
||||
new _UniLMBCSGrpMap(0x0001, 0x001F, ULMBCS_GRP_CTRL),
|
||||
new _UniLMBCSGrpMap(0x0080, 0x009F, ULMBCS_GRP_CTRL),
|
||||
@ -413,27 +413,27 @@ class CharsetLMBCS extends CharsetICU {
|
||||
new _UniLMBCSGrpMap(0xFF01, 0xFFEE, ULMBCS_AMBIGUOUS_MBCS),
|
||||
new _UniLMBCSGrpMap(0xFFFF, 0xFFFF, ULMBCS_GRP_UNICODE)
|
||||
};
|
||||
|
||||
|
||||
static short FindLMBCSUniRange(char uniChar) {
|
||||
int index = 0;
|
||||
|
||||
|
||||
while (uniChar > UniLMBCSGrpMap[index].uniEndRange) {
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
if (uniChar >= UniLMBCSGrpMap[index].uniStartRange) {
|
||||
return UniLMBCSGrpMap[index].GrpType;
|
||||
}
|
||||
return ULMBCS_GRP_UNICODE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* We also ask the creator of a converter to send in a preferred locale
|
||||
* that we can use in resolving ambiguous mappings. They send the locale
|
||||
* in as a string, and we map it, if possible, to one of the
|
||||
* LMBCS groups. We use this table, and the associated code, to
|
||||
* do the lookup:
|
||||
*
|
||||
*
|
||||
* This table maps locale ID's to LMBCS opt groups.
|
||||
* The default return is group 0x01. Note that for
|
||||
* performance reasons, the table is sorted in
|
||||
@ -500,11 +500,11 @@ class CharsetLMBCS extends CharsetICU {
|
||||
};
|
||||
static short FindLMBCSLocale(String LocaleID) {
|
||||
int index = 0;
|
||||
|
||||
|
||||
if (LocaleID == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
while (LocaleLMBCSGrpMap[index].LocaleID != null) {
|
||||
if (LocaleLMBCSGrpMap[index].LocaleID == LocaleID) {
|
||||
return LocaleLMBCSGrpMap[index].OptGroup;
|
||||
@ -515,7 +515,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
}
|
||||
return ULMBCS_GRP_L1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Before we get to the main body of code, here's how we hook up the rest
|
||||
* of ICU. ICU converters are required to define a structure that includes
|
||||
@ -540,67 +540,68 @@ class CharsetLMBCS extends CharsetICU {
|
||||
decoder = (CharsetDecoderMBCS)charset.newDecoder();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private UConverterDataLMBCS extraInfo; /* extraInfo in ICU4C implementation */
|
||||
|
||||
|
||||
public CharsetLMBCS(String icuCanonicalName, String javaCanonicalName, String[] aliases) {
|
||||
super(icuCanonicalName, javaCanonicalName, aliases);
|
||||
maxBytesPerChar = ULMBCS_CHARSIZE_MAX;
|
||||
maxBytesPerChar = ULMBCS_CHARSIZE_MAX;
|
||||
minBytesPerChar = 1;
|
||||
maxCharsPerByte = 1;
|
||||
|
||||
|
||||
extraInfo = new UConverterDataLMBCS();
|
||||
|
||||
|
||||
for (int i = 0; i <= ULMBCS_GRP_LAST; i++) {
|
||||
if (OptGroupByteToCPName[i] != null) {
|
||||
extraInfo.OptGrpConverter[i] = ((CharsetMBCS)CharsetICU.forNameICU(OptGroupByteToCPName[i])).sharedData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//get the Opt Group number for the LMBCS converter
|
||||
int option = Integer.parseInt(icuCanonicalName.substring(6));
|
||||
extraInfo.OptGroup = (short)option;
|
||||
extraInfo.localeConverterIndex = FindLMBCSLocale(ULocale.getDefault().getBaseName());
|
||||
}
|
||||
|
||||
|
||||
class CharsetDecoderLMBCS extends CharsetDecoderICU {
|
||||
public CharsetDecoderLMBCS(CharsetICU cs) {
|
||||
super(cs);
|
||||
implReset();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
}
|
||||
|
||||
|
||||
/* A function to call when we are looking at the Unicode group byte in LMBCS */
|
||||
private char GetUniFromLMBCSUni(ByteBuffer ppLMBCSin) {
|
||||
short HighCh = (short)(ppLMBCSin.get() & UConverterConstants.UNSIGNED_BYTE_MASK);
|
||||
short LowCh = (short)(ppLMBCSin.get() & UConverterConstants.UNSIGNED_BYTE_MASK);
|
||||
|
||||
|
||||
if (HighCh == ULMBCS_UNICOMPATZERO) {
|
||||
HighCh = LowCh;
|
||||
LowCh = 0; /* zero-byte in LSB special character */
|
||||
}
|
||||
|
||||
|
||||
return (char)((HighCh << 8) | LowCh);
|
||||
}
|
||||
|
||||
|
||||
private int LMBCS_SimpleGetNextUChar(UConverterSharedData cnv, ByteBuffer source, int positionOffset, int length) {
|
||||
int uniChar;
|
||||
int oldSourceLimit;
|
||||
int oldSourcePos;
|
||||
|
||||
|
||||
extraInfo.charset.sharedData = cnv;
|
||||
|
||||
|
||||
oldSourceLimit = source.limit();
|
||||
oldSourcePos = source.position();
|
||||
|
||||
|
||||
source.position(oldSourcePos + positionOffset);
|
||||
source.limit(source.position() + length);
|
||||
|
||||
|
||||
uniChar = extraInfo.decoder.simpleGetNextUChar(source, false);
|
||||
|
||||
|
||||
source.limit(oldSourceLimit);
|
||||
source.position(oldSourcePos);
|
||||
|
||||
@ -615,7 +616,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
private int LMBCSGetNextUCharWorker(ByteBuffer source, CoderResult[] err) {
|
||||
int uniChar = 0; /* an output Unicode char */
|
||||
short CurByte; /* A byte from the input stream */
|
||||
|
||||
|
||||
/* error check */
|
||||
if (!source.hasRemaining()) {
|
||||
err[0] = CoderResult.malformedForLength(0);
|
||||
@ -623,12 +624,12 @@ class CharsetLMBCS extends CharsetICU {
|
||||
}
|
||||
/* Grab first byte & save address for error recovery */
|
||||
CurByte = (short)(source.get() & UConverterConstants.UNSIGNED_BYTE_MASK);
|
||||
|
||||
|
||||
/*
|
||||
* at entry of each if clause:
|
||||
* 1. 'CurByte' points at the first byte of a LMBCS character
|
||||
* 2. 'source' points to the next byte of the source stream after 'CurByte'
|
||||
*
|
||||
*
|
||||
* the job of each if clause is:
|
||||
* 1. set 'source' to the point at the beginning of the next char (not if LMBCS char is only 1 byte)
|
||||
* 2. set 'uniChar' up with the right Unicode value, or set 'err' appropriately
|
||||
@ -637,12 +638,12 @@ class CharsetLMBCS extends CharsetICU {
|
||||
if ((CurByte > ULMBCS_C0END && CurByte < ULMBCS_C1START) /* ascii range */ ||
|
||||
CurByte == 0 || CurByte == ULMBCS_HT || CurByte == ULMBCS_CR || CurByte == ULMBCS_LF ||
|
||||
CurByte == ULMBCS_123SYSTEMRANGE) {
|
||||
|
||||
|
||||
uniChar = CurByte;
|
||||
} else {
|
||||
short group;
|
||||
UConverterSharedData cnv;
|
||||
|
||||
|
||||
if (CurByte == ULMBCS_GRP_CTRL) { /* Control character group - no opt group update */
|
||||
short C0C1byte;
|
||||
/* CHECK_SOURCE_LIMIT(1) */
|
||||
@ -660,7 +661,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
source.position(source.limit());
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
|
||||
/* don't check for error indicators fffe/ffff below */
|
||||
return GetUniFromLMBCSUni(source);
|
||||
} else if (CurByte <= ULMBCS_CTRLOFFSET) {
|
||||
@ -675,7 +676,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
source.position(source.limit());
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
|
||||
/* check for LMBCS doubled-group-byte case */
|
||||
if (source.get(source.position()) == group) {
|
||||
/* single byte */
|
||||
@ -696,7 +697,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
return 0xFFFF;
|
||||
}
|
||||
CurByte = (short)(source.get() & UConverterConstants.UNSIGNED_BYTE_MASK);
|
||||
|
||||
|
||||
if (CurByte >= ULMBCS_C1START) {
|
||||
uniChar = CharsetMBCS.MBCS_SINGLE_SIMPLE_GET_NEXT_BMP(cnv.mbcs, CurByte);
|
||||
} else {
|
||||
@ -705,16 +706,16 @@ class CharsetLMBCS extends CharsetICU {
|
||||
* AND the second byte is not in the upper ascii range
|
||||
*/
|
||||
byte[] bytes = new byte[2];
|
||||
|
||||
|
||||
cnv = extraInfo.OptGrpConverter[ULMBCS_GRP_EXCEPT];
|
||||
|
||||
|
||||
/* Lookup value must include opt group */
|
||||
bytes[0] = (byte)group;
|
||||
bytes[1] = (byte)CurByte;
|
||||
uniChar = LMBCS_SimpleGetNextUChar(cnv, ByteBuffer.wrap(bytes), 0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else if (CurByte >= ULMBCS_C1START) { /* group byte is implicit */
|
||||
group = extraInfo.OptGroup;
|
||||
cnv = extraInfo.OptGrpConverter[group];
|
||||
@ -726,7 +727,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
source.position(source.limit());
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
|
||||
/* let the MBCS conversion consume CurByte again */
|
||||
uniChar = LMBCS_SimpleGetNextUChar(cnv, source, -1, 1);
|
||||
} else {
|
||||
@ -736,7 +737,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
source.position(source.limit());
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
|
||||
/* let the MBCS conversion consume CurByte again */
|
||||
uniChar = LMBCS_SimpleGetNextUChar(cnv, source, -1, 2);
|
||||
source.get();
|
||||
@ -746,11 +747,12 @@ class CharsetLMBCS extends CharsetICU {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return uniChar;
|
||||
}
|
||||
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult[] err = new CoderResult[1];
|
||||
err[0] = CoderResult.UNDERFLOW;
|
||||
byte[] LMBCS = new byte[ULMBCS_CHARSIZE_MAX * 2]; /* Increase the size for proper handling in subsequent calls to MBCS functions */
|
||||
@ -758,14 +760,14 @@ class CharsetLMBCS extends CharsetICU {
|
||||
int saveSource; /* beginning of current code point */
|
||||
int errSource = 0; /* index to actual input in case an error occurs */
|
||||
byte savebytes = 0;
|
||||
|
||||
|
||||
/* Process from source to limit, or until error */
|
||||
while (err[0].isUnderflow() && source.hasRemaining() && target.hasRemaining()) {
|
||||
saveSource = source.position(); /* beginning of current code point */
|
||||
if (toULength > 0) { /* reassemble char from previous call */
|
||||
int size_old = toULength;
|
||||
ByteBuffer tmpSourceBuffer;
|
||||
|
||||
|
||||
/* limit from source is either remainder of temp buffer, or user limit on source */
|
||||
int size_new_maybe_1 = ULMBCS_CHARSIZE_MAX - size_old;
|
||||
int size_new_maybe_2 = source.remaining();
|
||||
@ -783,8 +785,8 @@ class CharsetLMBCS extends CharsetICU {
|
||||
uniChar = (char)LMBCSGetNextUCharWorker(tmpSourceBuffer, err);
|
||||
source.position(saveSource + tmpSourceBuffer.position() - size_old);
|
||||
errSource = saveSource - size_old;
|
||||
|
||||
if (err[0].isOverflow()) { /* err == U_TRUNCATED_CHAR_FOUND */
|
||||
|
||||
if (err[0].isOverflow()) { /* err == U_TRUNCATED_CHAR_FOUND */
|
||||
/* evil special case: source buffers so small a char spans more than 2 buffers */
|
||||
toULength = savebytes;
|
||||
for (int i = 0; i < savebytes; i++) {
|
||||
@ -802,7 +804,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
uniChar = (char)LMBCSGetNextUCharWorker(source, err);
|
||||
savebytes = (byte)(source.position() - saveSource);
|
||||
}
|
||||
|
||||
|
||||
if (err[0].isUnderflow()) {
|
||||
if (uniChar < 0x0fffe) {
|
||||
target.put(uniChar);
|
||||
@ -834,13 +836,14 @@ class CharsetLMBCS extends CharsetICU {
|
||||
return err[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CharsetEncoderLMBCS extends CharsetEncoderICU {
|
||||
public CharsetEncoderLMBCS(CharsetICU cs) {
|
||||
super(cs, fromUSubstitution);
|
||||
implReset();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
}
|
||||
@ -854,14 +857,14 @@ class CharsetLMBCS extends CharsetICU {
|
||||
private int LMBCSConversionWorker(short group, byte[] LMBCS, char pUniChar, short[] lastConverterIndex, boolean[] groups_tried) {
|
||||
byte pLMBCS = 0;
|
||||
UConverterSharedData xcnv = extraInfo.OptGrpConverter[group];
|
||||
|
||||
|
||||
int bytesConverted;
|
||||
int[] value = new int[1];
|
||||
short firstByte;
|
||||
|
||||
|
||||
extraInfo.charset.sharedData = xcnv;
|
||||
bytesConverted = extraInfo.encoder.fromUChar32(pUniChar, value, false);
|
||||
|
||||
|
||||
/* get the first result byte */
|
||||
if (bytesConverted > 0) {
|
||||
firstByte = (short)((value[0] >> ((bytesConverted - 1) * 8)) & UConverterConstants.UNSIGNED_BYTE_MASK);
|
||||
@ -870,14 +873,14 @@ class CharsetLMBCS extends CharsetICU {
|
||||
groups_tried[group] = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
lastConverterIndex[0] = group;
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* All initial byte values in lower ascii range should have been caught by now,
|
||||
* except with the exception group.
|
||||
*/
|
||||
|
||||
|
||||
/* use converted data: first write 0, 1 or two group bytes */
|
||||
if (group != ULMBCS_GRP_EXCEPT && extraInfo.OptGroup != group) {
|
||||
LMBCS[pLMBCS++] = (byte)group;
|
||||
@ -885,12 +888,12 @@ class CharsetLMBCS extends CharsetICU {
|
||||
LMBCS[pLMBCS++] = (byte)group;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* don't emit control chars */
|
||||
if (bytesConverted == 1 && firstByte < 0x20) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* then move over the converted data */
|
||||
switch (bytesConverted) {
|
||||
case 4:
|
||||
@ -905,7 +908,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
/* will never occur */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return pLMBCS;
|
||||
}
|
||||
/*
|
||||
@ -916,9 +919,9 @@ class CharsetLMBCS extends CharsetICU {
|
||||
int index = 0;
|
||||
short LowCh = (short)(uniChar & UConverterConstants.UNSIGNED_BYTE_MASK);
|
||||
short HighCh = (short)((uniChar >> 8) & UConverterConstants.UNSIGNED_BYTE_MASK);
|
||||
|
||||
|
||||
LMBCS[index++] = (byte)ULMBCS_GRP_UNICODE;
|
||||
|
||||
|
||||
if (LowCh == 0) {
|
||||
LMBCS[index++] = (byte)ULMBCS_UNICOMPATZERO;
|
||||
LMBCS[index++] = (byte)HighCh;
|
||||
@ -929,6 +932,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
return ULMBCS_UNICODE_SIZE;
|
||||
}
|
||||
/* The main Unicode to LMBCS conversion function */
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult err = CoderResult.UNDERFLOW;
|
||||
short[] lastConverterIndex = new short[1];
|
||||
@ -938,12 +942,12 @@ class CharsetLMBCS extends CharsetICU {
|
||||
int bytes_written;
|
||||
boolean[] groups_tried = new boolean[ULMBCS_GRP_LAST+1];
|
||||
int sourceIndex = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Basic strategy: attempt to fill in local LMBCS 1-char buffer.(LMBCS)
|
||||
* If that succeeds, see if it will all fit into the target & copy it over
|
||||
* if it does.
|
||||
*
|
||||
*
|
||||
* We try conversions in the following order:
|
||||
* 1. Single-byte ascii & special fixed control chars (&null)
|
||||
* 2. Look up group in table & try that (could b
|
||||
@ -959,23 +963,23 @@ class CharsetLMBCS extends CharsetICU {
|
||||
* E) If its single-byte ambiguous, try the exceptions group
|
||||
* 4. And as a grand fallback: Unicode
|
||||
*/
|
||||
|
||||
|
||||
short OldConverterIndex = 0;
|
||||
|
||||
|
||||
while (source.hasRemaining() && err.isUnderflow()) {
|
||||
OldConverterIndex = extraInfo.localeConverterIndex;
|
||||
|
||||
|
||||
if (!target.hasRemaining()) {
|
||||
err = CoderResult.OVERFLOW;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
uniChar = source.get(source.position());
|
||||
bytes_written = 0;
|
||||
pLMBCS = 0;
|
||||
|
||||
|
||||
/* check cases in rough order of how common they are, for speed */
|
||||
|
||||
|
||||
/* single-byte matches: strategy 1 */
|
||||
if((uniChar>=0x80) && (uniChar<=0xff) && (uniChar!=0xB1) && (uniChar!=0xD7) && (uniChar!=0xF7) &&
|
||||
(uniChar!=0xB0) && (uniChar!=0xB4) && (uniChar!=0xB6) && (uniChar!=0xA7) && (uniChar!=0xA8)) {
|
||||
@ -987,7 +991,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
LMBCS[pLMBCS++] = (byte)uniChar;
|
||||
bytes_written = 1;
|
||||
}
|
||||
|
||||
|
||||
if (bytes_written == 0) {
|
||||
/* Check by Unicode rage (Strategy 2) */
|
||||
short group = FindLMBCSUniRange(uniChar);
|
||||
@ -1009,12 +1013,12 @@ class CharsetLMBCS extends CharsetICU {
|
||||
}
|
||||
if (bytes_written == 0) { /* the ambiguous group cases (Strategy 3) */
|
||||
groups_tried = new boolean[ULMBCS_GRP_LAST+1];
|
||||
|
||||
|
||||
/* check for non-default optimization group (Strategy 3A) */
|
||||
if (extraInfo.OptGroup != 1 && ULMBCS_AMBIGUOUS_MATCH(group, extraInfo.OptGroup)) {
|
||||
if(extraInfo.localeConverterIndex < ULMBCS_DOUBLEOPTGROUP_START) {
|
||||
bytes_written = LMBCSConversionWorker (ULMBCS_GRP_L1, LMBCS, uniChar, lastConverterIndex, groups_tried);
|
||||
|
||||
|
||||
if(bytes_written == 0) {
|
||||
bytes_written = LMBCSConversionWorker (ULMBCS_GRP_EXCEPT, LMBCS, uniChar, lastConverterIndex, groups_tried);
|
||||
}
|
||||
@ -1027,7 +1031,7 @@ class CharsetLMBCS extends CharsetICU {
|
||||
}
|
||||
/* check for locale optimization group (Strategy 3B) */
|
||||
if (bytes_written == 0 && extraInfo.localeConverterIndex > 0 && ULMBCS_AMBIGUOUS_MATCH(group, extraInfo.localeConverterIndex)) {
|
||||
|
||||
|
||||
bytes_written = LMBCSConversionWorker(extraInfo.localeConverterIndex, LMBCS, uniChar, lastConverterIndex, groups_tried);
|
||||
}
|
||||
/* check for last optimization group used for this string (Strategy 3C) */
|
||||
@ -1039,23 +1043,23 @@ class CharsetLMBCS extends CharsetICU {
|
||||
short grp_start;
|
||||
short grp_end;
|
||||
short grp_ix;
|
||||
|
||||
|
||||
grp_start = (group == ULMBCS_AMBIGUOUS_MBCS) ? ULMBCS_DOUBLEOPTGROUP_START : ULMBCS_GRP_L1;
|
||||
grp_end = (group == ULMBCS_AMBIGUOUS_MBCS) ? ULMBCS_GRP_LAST : ULMBCS_GRP_TH;
|
||||
|
||||
|
||||
if(group == ULMBCS_AMBIGUOUS_ALL) {
|
||||
grp_start = ULMBCS_GRP_L1;
|
||||
grp_end = ULMBCS_GRP_LAST;
|
||||
}
|
||||
|
||||
|
||||
for (grp_ix = grp_start; grp_ix <= grp_end && bytes_written == 0; grp_ix++) {
|
||||
if (extraInfo.OptGrpConverter[grp_ix] != null && !groups_tried[grp_ix]) {
|
||||
bytes_written = LMBCSConversionWorker(grp_ix, LMBCS, uniChar, lastConverterIndex, groups_tried);
|
||||
}
|
||||
}
|
||||
/*
|
||||
/*
|
||||
* a final conversion fallback to the exceptions group if its likely
|
||||
* to be single byte (Strategy 3E)
|
||||
* to be single byte (Strategy 3E)
|
||||
*/
|
||||
if (bytes_written == 0 && grp_start == ULMBCS_GRP_L1) {
|
||||
bytes_written = LMBCSConversionWorker(ULMBCS_GRP_EXCEPT, LMBCS, uniChar, lastConverterIndex, groups_tried);
|
||||
@ -1092,18 +1096,21 @@ class CharsetLMBCS extends CharsetICU {
|
||||
}
|
||||
extraInfo.localeConverterIndex = OldConverterIndex;
|
||||
}
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderLMBCS(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderLMBCS(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl(UnicodeSet setFillIn, int which){
|
||||
getCompleteUnicodeSet(setFillIn);
|
||||
}
|
||||
|
@ -35,19 +35,20 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
private static List<Charset> icuCharsets = Collections.<Charset>emptyList();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
* Default constructor
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
public CharsetProviderICU() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Charset for the given charset name.
|
||||
* Constructs a Charset for the given charset name.
|
||||
* Implements the abstract method of super class.
|
||||
* @param charsetName charset name
|
||||
* @return Charset object for the given charset name, null if unsupported
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
public final Charset charsetForName(String charsetName){
|
||||
try{
|
||||
// extract the options from the charset name
|
||||
@ -58,11 +59,11 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
charsetName = charsetName.substring(0, charsetName.length() - optionsString.length());
|
||||
}
|
||||
// get the canonical name
|
||||
String icuCanonicalName = getICUCanonicalName(charsetName);
|
||||
String icuCanonicalName = getICUCanonicalName(charsetName);
|
||||
|
||||
// create the converter object and return it
|
||||
if(icuCanonicalName==null || icuCanonicalName.length()==0){
|
||||
// Try the original name, may be something added and not in the alias table.
|
||||
// Try the original name, may be something added and not in the alias table.
|
||||
// Will get an unsupported encoding exception if it doesn't work.
|
||||
icuCanonicalName = charsetName;
|
||||
}
|
||||
@ -72,7 +73,7 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a charset for the given ICU conversion table from the specified class path.
|
||||
* Example use: <code>cnv = CharsetProviderICU.charsetForName("myConverter", "com/myCompany/myDataPackage");</code>.
|
||||
@ -88,7 +89,7 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
public final Charset charsetForName(String charsetName, String classPath) {
|
||||
return charsetForName(charsetName, classPath, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a charset for the given ICU conversion table from the specified class path.
|
||||
* This function is similar to {@link #charsetForName(String, String)}.
|
||||
@ -107,7 +108,7 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the canonical name of the converter as defined by Java
|
||||
* @param enc converter name
|
||||
@ -143,7 +144,7 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
} else {
|
||||
ret = "";
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
/* unsupported encoding */
|
||||
ret = "";
|
||||
@ -152,7 +153,7 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
return ret;
|
||||
}catch(IOException ex){
|
||||
throw new UnsupportedCharsetException(enc);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final Charset getCharset(String icuCanonicalName, String optionsString)
|
||||
throws IOException {
|
||||
@ -174,17 +175,17 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
@Deprecated
|
||||
public static String getJavaCanonicalName(String charsetName){
|
||||
/*
|
||||
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
|
||||
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-".
|
||||
*/
|
||||
if(charsetName==null ){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try{
|
||||
String cName = null;
|
||||
/* find out the alias with MIME tag */
|
||||
@ -192,8 +193,8 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
/* find out the alias with IANA tag */
|
||||
}else if((cName=UConverterAlias.getStandardName(charsetName, "IANA"))!=null){
|
||||
}else {
|
||||
/*
|
||||
check to see if an alias already exists with x- prefix, if yes then
|
||||
/*
|
||||
check to see if an alias already exists with x- prefix, if yes then
|
||||
make that the canonical name
|
||||
*/
|
||||
int aliasNum = UConverterAlias.countAliases(charsetName);
|
||||
@ -205,7 +206,7 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* last resort just append x- to any of the alias and
|
||||
/* last resort just append x- to any of the alias and
|
||||
make it the canonical name */
|
||||
if((cName==null || cName.length()==0)){
|
||||
name = UConverterAlias.getStandardName(charsetName, "UTR22");
|
||||
@ -221,12 +222,12 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
}
|
||||
return cName;
|
||||
}catch (IOException ex){
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets the aliases associated with the converter name
|
||||
* @param encName converter name
|
||||
* @return converter names as elements in an object array
|
||||
@ -240,7 +241,7 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
int i=0;
|
||||
int j=0;
|
||||
String aliasArray[/*50*/] = new String[50];
|
||||
|
||||
|
||||
if(encName != null){
|
||||
aliasNum = UConverterAlias.countAliases(encName);
|
||||
for(i=0,j=0;i<aliasNum;i++){
|
||||
@ -253,10 +254,10 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
for(;--j>=0;) {
|
||||
ret[j] = aliasArray[j];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return (ret);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,13 +291,14 @@ public final class CharsetProviderICU extends CharsetProvider{
|
||||
* @return the Charset iterator
|
||||
* @stable ICU 3.6
|
||||
*/
|
||||
@Override
|
||||
public final Iterator<Charset> charsets() {
|
||||
loadAvailableICUCharsets();
|
||||
return icuCharsets.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the canonical names of available ICU converters
|
||||
* Gets the canonical names of available ICU converters
|
||||
* @return array of available converter names
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
|
@ -38,7 +38,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
private static final short SC7=0x17; /* Select window 7 */
|
||||
private static final short SD0=0x18; /* Define and select window 0 */
|
||||
//private static final short SD7=0x1F; /* Define and select window 7 */
|
||||
|
||||
|
||||
private static final short UC0=0xE0; /* Select window 0 */
|
||||
private static final short UC7=0xE7; /* Select window 7 */
|
||||
private static final short UD0=0xE8; /* Define and select window 0 */
|
||||
@ -47,7 +47,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
private static final short UDX=0xF1; /* Define a Window as extended */
|
||||
private static final short Urs=0xF2; /* reserved */
|
||||
// };
|
||||
|
||||
|
||||
// enum {
|
||||
/*
|
||||
* Unicode code points from 3400 to E000 are not adressible by
|
||||
@ -61,9 +61,9 @@ class CharsetSCSU extends CharsetICU{
|
||||
/* use table of predefined fixed offsets for values from fixedThreshold */
|
||||
private static final int fixedThreshold=0xF9;
|
||||
//};
|
||||
|
||||
|
||||
protected byte[] fromUSubstitution = new byte[]{(byte)0x0E,(byte)0xFF, (byte)0xFD};
|
||||
|
||||
|
||||
/* constant offsets for the 8 static windows */
|
||||
private static final int staticOffsets[]={
|
||||
0x0000, /* ASCII for quoted tags */
|
||||
@ -109,11 +109,11 @@ class CharsetSCSU extends CharsetICU{
|
||||
private static final int definePairTwo=5;
|
||||
private static final int defineOne=6;
|
||||
// };
|
||||
|
||||
|
||||
private final static class SCSUData {
|
||||
/* dynamic window offsets, intitialize to default values from initialDynamicOffsets */
|
||||
int toUDynamicOffsets[] = new int[8] ;
|
||||
int fromUDynamicOffsets[] = new int[8] ;
|
||||
int fromUDynamicOffsets[] = new int[8] ;
|
||||
|
||||
/* state machine state - toUnicode */
|
||||
boolean toUIsSingleByteMode;
|
||||
@ -135,11 +135,11 @@ class CharsetSCSU extends CharsetICU{
|
||||
byte locale;
|
||||
byte nextWindowUseIndex;
|
||||
byte windowUse[] = new byte[8];
|
||||
|
||||
|
||||
SCSUData(){
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
void initialize(){
|
||||
for(int i=0;i<8;i++){
|
||||
this.toUDynamicOffsets[i] = initialDynamicOffsets[i];
|
||||
@ -154,7 +154,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
for(int i=0;i<8;i++){
|
||||
this.fromUDynamicOffsets[i] = initialDynamicOffsets[i];
|
||||
}
|
||||
this.nextWindowUseIndex = 0;
|
||||
this.nextWindowUseIndex = 0;
|
||||
switch(this.locale){
|
||||
/* Note being used right now because "SCSU,locale=ja" does not work in ICU4J. */
|
||||
/* case l_ja:
|
||||
@ -166,11 +166,11 @@ class CharsetSCSU extends CharsetICU{
|
||||
for(int i=0;i<8;i++){
|
||||
this.windowUse[i] = initialWindowUse[i];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static final byte initialWindowUse[]={ 7, 0, 3, 2, 4, 5, 6, 1 };
|
||||
/* Note being used right now because "SCSU,locale=ja" does not work in ICU4J. */
|
||||
// static final byte initialWindowUse_ja[]={ 3, 2, 4, 1, 0, 7, 5, 6 };
|
||||
@ -180,74 +180,76 @@ class CharsetSCSU extends CharsetICU{
|
||||
/* Note being used right now because "SCSU,locale=ja" does not work in ICU4J. */
|
||||
// private static final int l_ja = 1;
|
||||
//};
|
||||
|
||||
private SCSUData extraInfo = null;
|
||||
|
||||
|
||||
private SCSUData extraInfo = null;
|
||||
|
||||
public CharsetSCSU(String icuCanonicalName, String javaCanonicalName, String[] aliases){
|
||||
super(icuCanonicalName, javaCanonicalName, aliases);
|
||||
maxBytesPerChar = 3;
|
||||
maxBytesPerChar = 3;
|
||||
minBytesPerChar = 1;
|
||||
maxCharsPerByte = 1;
|
||||
extraInfo = new SCSUData();
|
||||
}
|
||||
|
||||
class CharsetDecoderSCSU extends CharsetDecoderICU {
|
||||
|
||||
class CharsetDecoderSCSU extends CharsetDecoderICU {
|
||||
/* label values for supporting behavior similar to goto in C */
|
||||
private static final int FastSingle=0;
|
||||
private static final int SingleByteMode=1;
|
||||
private static final int EndLoop=2;
|
||||
|
||||
|
||||
/* Mode Type */
|
||||
private static final int ByteMode = 0;
|
||||
private static final int UnicodeMode =1;
|
||||
|
||||
private static final int UnicodeMode =1;
|
||||
|
||||
public CharsetDecoderSCSU(CharsetICU cs) {
|
||||
super(cs);
|
||||
implReset();
|
||||
}
|
||||
|
||||
|
||||
//private SCSUData data ;
|
||||
@Override
|
||||
protected void implReset(){
|
||||
super.implReset();
|
||||
toULength = 0;
|
||||
extraInfo.initialize();
|
||||
}
|
||||
|
||||
|
||||
short b;
|
||||
|
||||
//Get the state machine state
|
||||
|
||||
//Get the state machine state
|
||||
private boolean isSingleByteMode ;
|
||||
private short state ;
|
||||
private byte quoteWindow ;
|
||||
private byte dynamicWindow ;
|
||||
private short byteOne;
|
||||
|
||||
|
||||
|
||||
|
||||
//sourceIndex=-1 if the current character began in the previous buffer
|
||||
private int sourceIndex ;
|
||||
private int nextSourceIndex ;
|
||||
|
||||
|
||||
CoderResult cr;
|
||||
SCSUData data ;
|
||||
private boolean LabelLoop;// used to break the while loop
|
||||
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
boolean flush){
|
||||
data = extraInfo;
|
||||
|
||||
//Get the state machine state
|
||||
|
||||
//Get the state machine state
|
||||
isSingleByteMode = data.toUIsSingleByteMode;
|
||||
state = data.toUState;
|
||||
quoteWindow = data.toUQuoteWindow;
|
||||
dynamicWindow = data.toUDynamicWindow;
|
||||
byteOne = data.toUByteOne;
|
||||
|
||||
|
||||
LabelLoop = true;
|
||||
|
||||
|
||||
//sourceIndex=-1 if the current character began in the previous buffer
|
||||
sourceIndex = data.toUState == readCommand ? 0: -1 ;
|
||||
nextSourceIndex = 0;
|
||||
|
||||
|
||||
cr = CoderResult.UNDERFLOW;
|
||||
int labelType = 0;
|
||||
while(LabelLoop){
|
||||
@ -284,11 +286,11 @@ class CharsetSCSU extends CharsetICU{
|
||||
}
|
||||
return cr;
|
||||
}
|
||||
|
||||
|
||||
private int fastSingle(ByteBuffer source, CharBuffer target, IntBuffer offsets, int modeType){
|
||||
int label = 0;
|
||||
if(modeType==ByteMode){
|
||||
|
||||
|
||||
if(state==readCommand){
|
||||
while(source.hasRemaining() && target.hasRemaining() && (b=(short)(source.get(source.position()) & UConverterConstants.UNSIGNED_BYTE_MASK)) >= 0x20){
|
||||
source.position(source.position()+1);
|
||||
@ -350,7 +352,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
label = SingleByteMode;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
private int singleByteMode(ByteBuffer source, CharBuffer target, IntBuffer offsets, int modeType){
|
||||
int label = SingleByteMode;
|
||||
if(modeType == ByteMode){
|
||||
@ -403,7 +405,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
label = EndLoop;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
/* Store the first byte of a multibyte sequence in toUByte[] */
|
||||
toUBytesArray[0] = (byte)b;
|
||||
toULength = 1;
|
||||
@ -504,7 +506,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}else if(modeType==UnicodeMode){
|
||||
while(source.hasRemaining()){
|
||||
if(!target.hasRemaining()){
|
||||
@ -576,7 +578,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
label = EndLoop;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
private void endLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets){
|
||||
if(cr==CoderResult.OVERFLOW){
|
||||
state = readCommand;
|
||||
@ -591,78 +593,80 @@ class CharsetSCSU extends CharsetICU{
|
||||
LabelLoop = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CharsetEncoderSCSU extends CharsetEncoderICU{
|
||||
public CharsetEncoderSCSU(CharsetICU cs) {
|
||||
super(cs, fromUSubstitution);
|
||||
implReset();
|
||||
}
|
||||
|
||||
|
||||
//private SCSUData data;
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
extraInfo.initialize();
|
||||
}
|
||||
|
||||
|
||||
/* label values for supporting behavior similar to goto in C */
|
||||
private static final int Loop=0;
|
||||
private static final int Loop=0;
|
||||
private static final int GetTrailUnicode=1;
|
||||
private static final int OutputBytes=2;
|
||||
private static final int EndLoop =3;
|
||||
|
||||
|
||||
private int delta;
|
||||
private int length;
|
||||
|
||||
|
||||
///variables of compression heuristics
|
||||
private int offset;
|
||||
private char lead, trail;
|
||||
private int code;
|
||||
private byte window;
|
||||
|
||||
//Get the state machine state
|
||||
|
||||
//Get the state machine state
|
||||
private boolean isSingleByteMode;
|
||||
private byte dynamicWindow ;
|
||||
private int currentOffset;
|
||||
int c;
|
||||
|
||||
|
||||
SCSUData data ;
|
||||
|
||||
|
||||
//sourceIndex=-1 if the current character began in the previous buffer
|
||||
private int sourceIndex ;
|
||||
private int nextSourceIndex;
|
||||
private int targetCapacity;
|
||||
|
||||
|
||||
private boolean LabelLoop;//used to break the while loop
|
||||
private boolean AfterGetTrail;// its value is set to true in order to ignore the code before getTrailSingle:
|
||||
private boolean AfterGetTrailUnicode;// is value is set to true in order to ignore the code before getTrailUnicode:
|
||||
|
||||
|
||||
CoderResult cr;
|
||||
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush) {
|
||||
data = extraInfo;
|
||||
cr = CoderResult.UNDERFLOW;
|
||||
|
||||
//Get the state machine state
|
||||
|
||||
//Get the state machine state
|
||||
isSingleByteMode = data.fromUIsSingleByteMode;
|
||||
dynamicWindow = data.fromUDynamicWindow;
|
||||
currentOffset = data.fromUDynamicOffsets[dynamicWindow];
|
||||
c = fromUChar32;
|
||||
|
||||
|
||||
sourceIndex = c== 0 ? 0: -1 ;
|
||||
nextSourceIndex = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
targetCapacity = target.limit()-target.position();
|
||||
|
||||
|
||||
//sourceIndex=-1 if the current character began in the previous buffer
|
||||
sourceIndex = c== 0 ? 0: -1 ;
|
||||
nextSourceIndex = 0;
|
||||
|
||||
|
||||
int labelType = Loop; // set to Loop so that the code starts from loop:
|
||||
LabelLoop = true;
|
||||
AfterGetTrail = false;
|
||||
AfterGetTrailUnicode = false;
|
||||
|
||||
LabelLoop = true;
|
||||
AfterGetTrail = false;
|
||||
AfterGetTrailUnicode = false;
|
||||
|
||||
while(LabelLoop){
|
||||
switch(labelType){
|
||||
case Loop:
|
||||
@ -681,7 +685,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
}
|
||||
return cr;
|
||||
}
|
||||
|
||||
|
||||
private byte getWindow(int[] offsets){
|
||||
int i;
|
||||
for (i=0;i<8;i++){
|
||||
@ -691,14 +695,14 @@ class CharsetSCSU extends CharsetICU{
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
private boolean isInOffsetWindowOrDirect(int offsetValue, int a){
|
||||
return (a & UConverterConstants.UNSIGNED_INT_MASK)<=(offsetValue & UConverterConstants.UNSIGNED_INT_MASK)+0x7f &
|
||||
((a & UConverterConstants.UNSIGNED_INT_MASK)>=(offsetValue & UConverterConstants.UNSIGNED_INT_MASK) ||
|
||||
((a & UConverterConstants.UNSIGNED_INT_MASK)<=0x7f && ((a & UConverterConstants.UNSIGNED_INT_MASK)>=0x20
|
||||
return (a & UConverterConstants.UNSIGNED_INT_MASK)<=(offsetValue & UConverterConstants.UNSIGNED_INT_MASK)+0x7f &
|
||||
((a & UConverterConstants.UNSIGNED_INT_MASK)>=(offsetValue & UConverterConstants.UNSIGNED_INT_MASK) ||
|
||||
((a & UConverterConstants.UNSIGNED_INT_MASK)<=0x7f && ((a & UConverterConstants.UNSIGNED_INT_MASK)>=0x20
|
||||
|| ((1L<<(a & UConverterConstants.UNSIGNED_INT_MASK))&0x2601)!=0)));
|
||||
}
|
||||
|
||||
|
||||
private byte getNextDynamicWindow(){
|
||||
byte windowValue = data.windowUse[data.nextWindowUseIndex];
|
||||
if(++data.nextWindowUseIndex==8){
|
||||
@ -706,7 +710,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
}
|
||||
return windowValue;
|
||||
}
|
||||
|
||||
|
||||
private void useDynamicWindow(byte windowValue){
|
||||
/*first find the index of the window*/
|
||||
int i,j;
|
||||
@ -716,7 +720,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
i=7;
|
||||
}
|
||||
}while(data.windowUse[i]!=windowValue);
|
||||
|
||||
|
||||
/*now copy each window[i+1] to [i]*/
|
||||
j= i+1;
|
||||
if(j==8){
|
||||
@ -729,12 +733,12 @@ class CharsetSCSU extends CharsetICU{
|
||||
j=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*finally, set the window into the most recently used index*/
|
||||
data.windowUse[i]= windowValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private int getDynamicOffset(){
|
||||
int i;
|
||||
for(i=0;i<7;++i){
|
||||
@ -746,7 +750,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
if((c&UConverterConstants.UNSIGNED_INT_MASK)<0x80){
|
||||
/*No dynamic window for US-ASCII*/
|
||||
return -1;
|
||||
}else if((c&UConverterConstants.UNSIGNED_INT_MASK)<0x3400 || ((c-0x10000)&UConverterConstants.UNSIGNED_INT_MASK)<(0x14000-0x10000) ||
|
||||
}else if((c&UConverterConstants.UNSIGNED_INT_MASK)<0x3400 || ((c-0x10000)&UConverterConstants.UNSIGNED_INT_MASK)<(0x14000-0x10000) ||
|
||||
((c-0x1d000)&UConverterConstants.UNSIGNED_INT_MASK)<=(0x1ffff-0x1d000)){
|
||||
/*This character is in the code range for a "small", i.e, reasonably windowable, script*/
|
||||
offset = c&0x7fffff80;
|
||||
@ -759,7 +763,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int loop(CharBuffer source, ByteBuffer target, IntBuffer offsets){
|
||||
int label = 0;
|
||||
if(isSingleByteMode){
|
||||
@ -778,7 +782,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
if(!AfterGetTrail){
|
||||
c = source.get();
|
||||
++nextSourceIndex;
|
||||
|
||||
|
||||
}
|
||||
if(((c -0x20)&UConverterConstants.UNSIGNED_INT_MASK)<=0x5f && !AfterGetTrail){
|
||||
/*pass US-ASCII graphic character through*/
|
||||
@ -824,12 +828,12 @@ class CharsetSCSU extends CharsetICU{
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(AfterGetTrail){
|
||||
AfterGetTrail = false;
|
||||
}
|
||||
|
||||
|
||||
/*Compress supplementary character U+10000...U+10ffff */
|
||||
if(((delta=(c-currentOffset))&UConverterConstants.UNSIGNED_INT_MASK)<=0x7f){
|
||||
/*use the current dynamic window*/
|
||||
@ -923,9 +927,9 @@ class CharsetSCSU extends CharsetICU{
|
||||
length = 3;
|
||||
label = OutputBytes;
|
||||
return label;
|
||||
} else if(((int)((c-0x3400)&UConverterConstants.UNSIGNED_INT_MASK))<(0xd800-0x3400) && (source.position()>=source.limit() ||
|
||||
} else if(((int)((c-0x3400)&UConverterConstants.UNSIGNED_INT_MASK))<(0xd800-0x3400) && (source.position()>=source.limit() ||
|
||||
((int)((source.get(source.position())-0x3400)&UConverterConstants.UNSIGNED_INT_MASK))< (0xd800 - 0x3400))){
|
||||
|
||||
|
||||
/*
|
||||
* this character is not compressible (a BMP ideograph of similar)
|
||||
* switch to Unicode mode if this is the last character in the block
|
||||
@ -953,7 +957,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
label = GetTrailUnicode;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
/*state machine for Unicode*/
|
||||
/*unicodeByteMode*/
|
||||
while(AfterGetTrailUnicode || source.hasRemaining()){
|
||||
@ -967,7 +971,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
c = source.get();
|
||||
++nextSourceIndex;
|
||||
}
|
||||
|
||||
|
||||
if((((c-0x3400)& UConverterConstants.UNSIGNED_INT_MASK))<(0xd800-0x3400) && !AfterGetTrailUnicode){
|
||||
/*not compressible, write character directly */
|
||||
if(targetCapacity>=2){
|
||||
@ -986,7 +990,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
} else if((((c-0x3400)& UConverterConstants.UNSIGNED_INT_MASK))>=(0xf300-0x3400) /* c<0x3400 || c>=0xf300*/&& !AfterGetTrailUnicode){
|
||||
/*compress BMP character if the following one is not an uncompressible ideograph*/
|
||||
if(!(source.hasRemaining() && (((source.get(source.position())-0x3400)& UConverterConstants.UNSIGNED_INT_MASK))<(0xd800-0x3400))){
|
||||
if(((((c-0x30)&UConverterConstants.UNSIGNED_INT_MASK))<10 || (((c-0x61)&UConverterConstants.UNSIGNED_INT_MASK))<26
|
||||
if(((((c-0x30)&UConverterConstants.UNSIGNED_INT_MASK))<10 || (((c-0x61)&UConverterConstants.UNSIGNED_INT_MASK))<26
|
||||
|| (((c-0x41)&UConverterConstants.UNSIGNED_INT_MASK))<26)){
|
||||
/*ASCII digit or letter*/
|
||||
isSingleByteMode = true;
|
||||
@ -1010,14 +1014,14 @@ class CharsetSCSU extends CharsetICU{
|
||||
dynamicWindow = getNextDynamicWindow();
|
||||
currentOffset = data.fromUDynamicOffsets[dynamicWindow]=offset;
|
||||
useDynamicWindow(dynamicWindow);
|
||||
c = ((UD0+dynamicWindow)<<16) | (code<<8)
|
||||
c = ((UD0+dynamicWindow)<<16) | (code<<8)
|
||||
|(c - currentOffset) | 0x80;
|
||||
length = 3;
|
||||
label = OutputBytes;
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*don't know how to compress these character, just write it directly*/
|
||||
length = 2;
|
||||
label = OutputBytes;
|
||||
@ -1032,7 +1036,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
label = OutputBytes;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
if(AfterGetTrailUnicode){
|
||||
AfterGetTrailUnicode = false;
|
||||
}
|
||||
@ -1044,7 +1048,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
label = EndLoop;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
private int getTrail(CharBuffer source, ByteBuffer target, IntBuffer offsets){
|
||||
lead = (char)c;
|
||||
int label = Loop;
|
||||
@ -1069,13 +1073,13 @@ class CharsetSCSU extends CharsetICU{
|
||||
AfterGetTrail = true;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
private int getTrailUnicode(CharBuffer source, ByteBuffer target, IntBuffer offsets){
|
||||
int label = EndLoop;
|
||||
AfterGetTrailUnicode = true;
|
||||
/*c is surrogate*/
|
||||
if(UTF16.isLeadSurrogate((char)c)){
|
||||
// getTrailUnicode:
|
||||
// getTrailUnicode:
|
||||
lead = (char)c;
|
||||
if(source.hasRemaining()){
|
||||
/*test the following code unit*/
|
||||
@ -1105,10 +1109,10 @@ class CharsetSCSU extends CharsetICU{
|
||||
label = EndLoop;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
/*compress supplementary character*/
|
||||
if((window=getWindow(data.fromUDynamicOffsets))>=0 &&
|
||||
!(source.hasRemaining() && ((source.get(source.position())-0x3400)&UConverterConstants.UNSIGNED_INT_MASK) <
|
||||
if((window=getWindow(data.fromUDynamicOffsets))>=0 &&
|
||||
!(source.hasRemaining() && ((source.get(source.position())-0x3400)&UConverterConstants.UNSIGNED_INT_MASK) <
|
||||
(0xd800 - 0x3400))){
|
||||
/*
|
||||
* this is the dynamic window that contains this character and the following
|
||||
@ -1140,9 +1144,9 @@ class CharsetSCSU extends CharsetICU{
|
||||
label = OutputBytes;
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void endLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets){
|
||||
/*set the converter state back to UConverter*/
|
||||
data.fromUIsSingleByteMode = isSingleByteMode;
|
||||
@ -1185,7 +1189,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
break;
|
||||
}
|
||||
targetCapacity-=length;
|
||||
|
||||
|
||||
/*normal end of conversion: prepare for a new character*/
|
||||
c = 0;
|
||||
sourceIndex = nextSourceIndex;
|
||||
@ -1196,7 +1200,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
/*
|
||||
* We actually do this backwards here:
|
||||
* In order to save an intermediate variable, we output
|
||||
* first to the overflow buffer what does not fit into the
|
||||
* first to the overflow buffer what does not fit into the
|
||||
* regular target
|
||||
*/
|
||||
/* we know that 0<=targetCapacity<length<=4 */
|
||||
@ -1217,7 +1221,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
break;
|
||||
}
|
||||
errorBufferLength = length;
|
||||
|
||||
|
||||
/*now output what fits into the regular target*/
|
||||
c>>=8*length; //length was reduced by targetCapacity
|
||||
switch(targetCapacity){
|
||||
@ -1240,7 +1244,7 @@ class CharsetSCSU extends CharsetICU{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/*target overflow*/
|
||||
targetCapacity = 0;
|
||||
cr = CoderResult.OVERFLOW;
|
||||
@ -1249,19 +1253,22 @@ class CharsetSCSU extends CharsetICU{
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderSCSU(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderSCSU(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
CharsetICU.getCompleteUnicodeSet(setFillIn);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class CharsetUTF16 extends CharsetICU {
|
||||
private int endianXOR;
|
||||
private byte[] bom;
|
||||
private byte[] fromUSubstitution;
|
||||
|
||||
|
||||
private int version;
|
||||
|
||||
public CharsetUTF16(String icuCanonicalName, String javaCanonicalName, String[] aliases) {
|
||||
@ -51,7 +51,7 @@ class CharsetUTF16 extends CharsetICU {
|
||||
} else {
|
||||
version = 0;
|
||||
}
|
||||
|
||||
|
||||
this.isEndianSpecified = (this instanceof CharsetUTF16BE || this instanceof CharsetUTF16LE);
|
||||
this.isBigEndian = !(this instanceof CharsetUTF16LE);
|
||||
|
||||
@ -64,21 +64,21 @@ class CharsetUTF16 extends CharsetICU {
|
||||
this.fromUSubstitution = fromUSubstitution_LE;
|
||||
this.endianXOR = ENDIAN_XOR_LE;
|
||||
}
|
||||
|
||||
|
||||
/* UnicodeBig and UnicodeLittle requires maxBytesPerChar set to 4 in Java 5 or less */
|
||||
if ((VersionInfo.javaVersion().getMajor() == 1 && VersionInfo.javaVersion().getMinor() <= 5)
|
||||
&& (isEndianSpecified && version == 1)) {
|
||||
maxBytesPerChar = 4;
|
||||
} else {
|
||||
maxBytesPerChar = 2;
|
||||
}
|
||||
&& (isEndianSpecified && version == 1)) {
|
||||
maxBytesPerChar = 4;
|
||||
} else {
|
||||
maxBytesPerChar = 2;
|
||||
}
|
||||
|
||||
minBytesPerChar = 2;
|
||||
maxCharsPerByte = 1;
|
||||
}
|
||||
|
||||
class CharsetDecoderUTF16 extends CharsetDecoderICU {
|
||||
|
||||
|
||||
private boolean isBOMReadYet;
|
||||
private int actualEndianXOR;
|
||||
private byte[] actualBOM;
|
||||
@ -87,12 +87,14 @@ class CharsetUTF16 extends CharsetICU {
|
||||
super(cs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
isBOMReadYet = false;
|
||||
actualBOM = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
/*
|
||||
* If we detect a BOM in this buffer, then we must add the BOM size to the offsets because the actual
|
||||
@ -167,7 +169,7 @@ class CharsetUTF16 extends CharsetICU {
|
||||
return CoderResult.UNDERFLOW;
|
||||
toUBytesArray[toULength++] = source.get();
|
||||
}
|
||||
|
||||
|
||||
if (isEndianSpecified && version == 1 && (toUBytesArray[toULength - 1] == actualBOM[toULength - 2] && toUBytesArray[toULength - 2] == actualBOM[toULength - 1])) {
|
||||
return CoderResult.malformedForLength(2);
|
||||
} else if (isEndianSpecified && version == 1 && (toUBytesArray[toULength - 1] == actualBOM[toULength - 1] && toUBytesArray[toULength - 2] == actualBOM[toULength - 2])) {
|
||||
@ -246,11 +248,13 @@ class CharsetUTF16 extends CharsetICU {
|
||||
fromUnicodeStatus = (isEndianSpecified && version != 1) ? 0 : NEED_TO_WRITE_BOM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
fromUnicodeStatus = (isEndianSpecified && version != 1) ? 0 : NEED_TO_WRITE_BOM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult cr;
|
||||
|
||||
@ -315,15 +319,18 @@ class CharsetUTF16 extends CharsetICU {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderUTF16(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderUTF16(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
getNonSurrogateUnicodeSet(setFillIn);
|
||||
getNonSurrogateUnicodeSet(setFillIn);
|
||||
}
|
||||
}
|
||||
|
@ -69,12 +69,14 @@ class CharsetUTF32 extends CharsetICU {
|
||||
super(cs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
isBOMReadYet = false;
|
||||
actualBOM = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
/*
|
||||
* If we detect a BOM in this buffer, then we must add the BOM size to the offsets because the actual
|
||||
@ -171,11 +173,13 @@ class CharsetUTF32 extends CharsetICU {
|
||||
fromUnicodeStatus = isEndianSpecified ? 0 : NEED_TO_WRITE_BOM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
fromUnicodeStatus = isEndianSpecified ? 0 : NEED_TO_WRITE_BOM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult cr;
|
||||
|
||||
@ -238,16 +242,19 @@ class CharsetUTF32 extends CharsetICU {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderUTF32(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderUTF32(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
getNonSurrogateUnicodeSet(setFillIn);
|
||||
getNonSurrogateUnicodeSet(setFillIn);
|
||||
}
|
||||
}
|
||||
|
@ -25,20 +25,20 @@ class CharsetUTF7 extends CharsetICU {
|
||||
private final static String IMAP_NAME="IMAP-mailbox-name";
|
||||
private boolean useIMAP;
|
||||
protected byte[] fromUSubstitution=new byte[]{0x3F};
|
||||
|
||||
|
||||
public CharsetUTF7(String icuCanonicalName, String javaCanonicalName, String[] aliases) {
|
||||
super(icuCanonicalName, javaCanonicalName, aliases);
|
||||
maxBytesPerChar=4; /* max 3 bytes per code unit from UTF-7 (base64) */
|
||||
minBytesPerChar=1;
|
||||
maxCharsPerByte=1;
|
||||
|
||||
|
||||
useIMAP=false;
|
||||
|
||||
|
||||
if (icuCanonicalName.equals(IMAP_NAME)) {
|
||||
useIMAP=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//private static boolean inSetD(char c) {
|
||||
// return (
|
||||
// (char)(c - 97) < 26 || (char)(c - 65) < 26 || /* letters */
|
||||
@ -48,7 +48,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
// (c==58) || (c==63) /* :? */
|
||||
// );
|
||||
//}
|
||||
|
||||
|
||||
//private static boolean inSetO(char c) {
|
||||
// return (
|
||||
// (char)(c - 33) < 6 || /* !"#$%& */
|
||||
@ -58,19 +58,19 @@ class CharsetUTF7 extends CharsetICU {
|
||||
// (c==58) || (c==63) /* *@[ */
|
||||
// );
|
||||
//}
|
||||
|
||||
|
||||
private static boolean isCRLFTAB(char c) {
|
||||
return (
|
||||
(c==13) || (c==10) || (c==9)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//private static boolean isCRLFSPTAB(char c) {
|
||||
// return (
|
||||
// (c==32) || (c==13) || (c==10) || (c==9)
|
||||
// );
|
||||
//}
|
||||
|
||||
|
||||
private static final byte PLUS=43;
|
||||
private static final byte MINUS=45;
|
||||
private static final byte BACKSLASH=92;
|
||||
@ -78,7 +78,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
private static final byte AMPERSAND=0x26;
|
||||
private static final byte COMMA=0x2c;
|
||||
private static final byte SLASH=0x2f;
|
||||
|
||||
|
||||
// legal byte values: all US-ASCII graphic characters 0x20..0x7e
|
||||
private static boolean isLegal(char c, boolean useIMAP) {
|
||||
if (useIMAP) {
|
||||
@ -91,56 +91,56 @@ class CharsetUTF7 extends CharsetICU {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// directly encode all of printable ASCII 0x20..0x7e except '&' 0x26
|
||||
private static boolean inSetDIMAP(char c) {
|
||||
return (
|
||||
(isLegal(c, true) && c != AMPERSAND)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private static byte TO_BASE64_IMAP(int n) {
|
||||
return (n < 63 ? TO_BASE_64[n] : COMMA);
|
||||
}
|
||||
|
||||
|
||||
private static byte FROM_BASE64_IMAP(char c) {
|
||||
return (c==COMMA ? 63 : c==SLASH ? -1 : FROM_BASE_64[c]);
|
||||
}
|
||||
|
||||
|
||||
/* encode directly sets D and O and CR LF SP TAB */
|
||||
private static final byte ENCODE_DIRECTLY_MAXIMUM[] =
|
||||
{
|
||||
/*0 1 2 3 4 5 6 7 8 9 a b c d e f*/
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
|
||||
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
|
||||
|
||||
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0
|
||||
};
|
||||
|
||||
|
||||
/* encode directly set D and CR LF SP TAB but not set O */
|
||||
private static final byte ENCODE_DIRECTLY_RESTRICTED[] =
|
||||
{
|
||||
/*0 1 2 3 4 5 6 7 8 9 a b c d e f*/
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
|
||||
1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
|
||||
|
||||
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
|
||||
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
|
||||
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
|
||||
private static final byte TO_BASE_64[] =
|
||||
{
|
||||
/* A-Z */
|
||||
@ -154,7 +154,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
/* +/ */
|
||||
43, 47
|
||||
};
|
||||
|
||||
|
||||
private static final byte FROM_BASE_64[] =
|
||||
{
|
||||
/* C0 controls, -1 for legal ones (CR LF TAB), -3 for illegal ones */
|
||||
@ -166,24 +166,26 @@ class CharsetUTF7 extends CharsetICU {
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
|
||||
/* A-Z */
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -3, -1, -1, -1,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -3, -1, -1, -1,
|
||||
/* a-z*/
|
||||
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -3, -3
|
||||
};
|
||||
|
||||
|
||||
class CharsetDecoderUTF7 extends CharsetDecoderICU {
|
||||
public CharsetDecoderUTF7(CharsetICU cs) {
|
||||
super(cs);
|
||||
implReset();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
toUnicodeStatus=(toUnicodeStatus & 0xf0000000) | 0x1000000;
|
||||
}
|
||||
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult cr=CoderResult.UNDERFLOW;
|
||||
byte base64Value;
|
||||
byte base64Counter;
|
||||
@ -191,14 +193,14 @@ class CharsetUTF7 extends CharsetICU {
|
||||
char bits;
|
||||
int byteIndex;
|
||||
int sourceIndex, nextSourceIndex;
|
||||
|
||||
|
||||
int length;
|
||||
|
||||
|
||||
char b;
|
||||
char c;
|
||||
|
||||
|
||||
int sourceArrayIndex=source.position();
|
||||
|
||||
|
||||
//get the state of the machine state
|
||||
{
|
||||
int status=toUnicodeStatus;
|
||||
@ -209,23 +211,23 @@ class CharsetUTF7 extends CharsetICU {
|
||||
byteIndex=toULength;
|
||||
/* sourceIndex=-1 if the current character began in the previous buffer */
|
||||
sourceIndex=byteIndex==0 ? 0 : -1;
|
||||
nextSourceIndex=0;
|
||||
|
||||
nextSourceIndex=0;
|
||||
|
||||
directMode: while (true) {
|
||||
if (inDirectMode==1) {
|
||||
/*
|
||||
/*
|
||||
* In Direct Mode, most US-ASCII characters are encoded directly, i.e.,
|
||||
* with their US-ASCII byte values.
|
||||
* Backslash and Tilde and most control characters are not alled in UTF-7.
|
||||
* A plus sign starts Unicode (or "escape") Mode.
|
||||
* An ampersand starts Unicode Mode for IMAP.
|
||||
*
|
||||
*
|
||||
* In Direct Mode, only the sourceIndex is used.
|
||||
*/
|
||||
byteIndex=0;
|
||||
length=source.remaining();
|
||||
//targetCapacity=target.remaining();
|
||||
//Commented out because length of source may be larger than target when it comes to bytes
|
||||
//Commented out because length of source may be larger than target when it comes to bytes
|
||||
/*if (useIMAP && length > targetCapacity) {
|
||||
length=targetCapacity;
|
||||
}*/
|
||||
@ -266,11 +268,11 @@ class CharsetUTF7 extends CharsetICU {
|
||||
}
|
||||
break directMode;
|
||||
} else { /* Unicode Mode*/
|
||||
/*
|
||||
/*
|
||||
* In Unicode Mode, UTF-16BE is base64-encoded.
|
||||
* The base64 sequence ends with any character that is not in the base64 alphabet.
|
||||
* A terminating minus sign is consumed.
|
||||
*
|
||||
*
|
||||
* In Unicode Mode, the sourceIndex has the index to the start of the current
|
||||
* base64 bytes, while nextSourceIndex is precisely parallel to source,
|
||||
* keeping the index to the following byte.
|
||||
@ -296,7 +298,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
* 2.2.2. Else if the current char is illegal, we might as well deal with it here.
|
||||
*/
|
||||
inDirectMode=1;
|
||||
|
||||
|
||||
if(base64Counter==-1) {
|
||||
/* illegal: + immediately followed by something other than base64 or minus sign */
|
||||
/* include the plus sign in the reported sequence, but not the subsequent char */
|
||||
@ -396,9 +398,9 @@ class CharsetUTF7 extends CharsetICU {
|
||||
bits=0;
|
||||
base64Counter=0;
|
||||
break;
|
||||
//default:
|
||||
//default:
|
||||
/* will never occur */
|
||||
//break;
|
||||
//break;
|
||||
}//end of switch
|
||||
} else if (!useIMAP || (useIMAP && base64Value==-2)) {
|
||||
/* minus sign terminates the base64 sequence */
|
||||
@ -419,7 +421,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
}
|
||||
sourceIndex=nextSourceIndex;
|
||||
continue directMode;
|
||||
} else if (useIMAP) {
|
||||
} else if (useIMAP) {
|
||||
if (base64Counter==-1) {
|
||||
// illegal: & immediately followed by something other than base64 or minus sign
|
||||
// include the ampersand in the reported sequence
|
||||
@ -455,13 +457,13 @@ class CharsetUTF7 extends CharsetICU {
|
||||
inDirectMode=1;
|
||||
cr=CoderResult.malformedForLength(sourceIndex);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
if (!cr.isError() && flush && !source.hasRemaining() && bits ==0) {
|
||||
/*
|
||||
* if we are in Unicode Mode, then the byteIndex might not be 0,
|
||||
* but that is ok if bits -- 0
|
||||
* -> we set byteIndex=0 at the end of the stream to avoid a truncated error
|
||||
* -> we set byteIndex=0 at the end of the stream to avoid a truncated error
|
||||
* (not true for IMAP-mailbox-name where we must end in direct mode)
|
||||
*/
|
||||
if (!cr.isOverflow()) {
|
||||
@ -470,32 +472,34 @@ class CharsetUTF7 extends CharsetICU {
|
||||
}
|
||||
}
|
||||
/* set the converter state */
|
||||
toUnicodeStatus=(inDirectMode<<24 | (((short)base64Counter & UConverterConstants.UNSIGNED_BYTE_MASK)<<16) | (int)bits);
|
||||
toUnicodeStatus=(inDirectMode<<24 | ((base64Counter & UConverterConstants.UNSIGNED_BYTE_MASK)<<16) | bits);
|
||||
toULength=byteIndex;
|
||||
|
||||
|
||||
return cr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CharsetEncoderUTF7 extends CharsetEncoderICU {
|
||||
public CharsetEncoderUTF7(CharsetICU cs) {
|
||||
super(cs, fromUSubstitution);
|
||||
implReset();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
fromUnicodeStatus=(fromUnicodeStatus & 0xf0000000) | 0x1000000;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets, boolean flush) {
|
||||
CoderResult cr=CoderResult.UNDERFLOW;
|
||||
byte inDirectMode;
|
||||
byte encodeDirectly[];
|
||||
int status;
|
||||
|
||||
|
||||
int length, targetCapacity, sourceIndex;
|
||||
|
||||
|
||||
byte base64Counter;
|
||||
char bits;
|
||||
char c;
|
||||
@ -510,7 +514,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
}
|
||||
/* UTF-7 always encodes UTF-16 code units, therefore we need only a simple sourceIndex */
|
||||
sourceIndex=0;
|
||||
|
||||
|
||||
directMode: while(true) {
|
||||
if(inDirectMode==1) {
|
||||
length=source.remaining();
|
||||
@ -567,7 +571,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
cr=CoderResult.OVERFLOW;
|
||||
}
|
||||
break directMode;
|
||||
} else {
|
||||
} else {
|
||||
/* Unicode Mode */
|
||||
while (source.hasRemaining()) {
|
||||
if (target.hasRemaining()) {
|
||||
@ -575,10 +579,10 @@ class CharsetUTF7 extends CharsetICU {
|
||||
if ((!useIMAP && c<=127 && encodeDirectly[c]==1) || (useIMAP && isLegal(c, useIMAP))) {
|
||||
/* encode directly */
|
||||
inDirectMode=1;
|
||||
|
||||
|
||||
/* trick: back out this character to make this easier */
|
||||
source.position(source.position() - 1);
|
||||
|
||||
|
||||
/* terminate the base64 sequence */
|
||||
if (base64Counter!=0) {
|
||||
/* write remaining bits for the previous character */
|
||||
@ -607,7 +611,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
* base64 this character:
|
||||
* Output 2 or 3 base64 bytres for the remaining bits of the previous character
|
||||
* and the bits of this character, each implicitly in UTF-16BE.
|
||||
*
|
||||
*
|
||||
* Here, bits is an 8-bit variable because only 6 bits need to be kept from one
|
||||
* character to the next. The actual 2 or 4 bits are shifted to the left edge
|
||||
* of the 6-bits filed 5..0 to make the termination of the base64 sequence easier.
|
||||
@ -714,8 +718,8 @@ class CharsetUTF7 extends CharsetICU {
|
||||
//default:
|
||||
/* will never occur */
|
||||
//break;
|
||||
} //end of switch
|
||||
}
|
||||
} //end of switch
|
||||
}
|
||||
} else {
|
||||
/* target is full */
|
||||
cr=CoderResult.OVERFLOW;
|
||||
@ -725,7 +729,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
break directMode;
|
||||
}
|
||||
} //end of directMode label
|
||||
|
||||
|
||||
if (flush && !source.hasRemaining()) {
|
||||
/* flush remaining bits to the target */
|
||||
if (inDirectMode==0) {
|
||||
@ -740,7 +744,7 @@ class CharsetUTF7 extends CharsetICU {
|
||||
cr=CoderResult.OVERFLOW;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* need to terminate with a minus */
|
||||
if (target.hasRemaining()) {
|
||||
target.put(MINUS);
|
||||
@ -756,21 +760,24 @@ class CharsetUTF7 extends CharsetICU {
|
||||
fromUnicodeStatus=((status&0xf0000000) | 0x1000000); /* keep version, inDirectMode=TRUE */
|
||||
} else {
|
||||
/* set the converter state back */
|
||||
fromUnicodeStatus=((status&0xf0000000) | (inDirectMode<<24) | (((short)base64Counter & UConverterConstants.UNSIGNED_BYTE_MASK)<<16) | ((int)bits));
|
||||
fromUnicodeStatus=((status&0xf0000000) | (inDirectMode<<24) | ((base64Counter & UConverterConstants.UNSIGNED_BYTE_MASK)<<16) | (bits));
|
||||
}
|
||||
|
||||
|
||||
return cr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderUTF7(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderUTF7(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
getCompleteUnicodeSet(setFillIn);
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ class CharsetUTF8 extends CharsetICU {
|
||||
super(cs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target, IntBuffer offsets,
|
||||
boolean flush) {
|
||||
if (!source.hasRemaining()) {
|
||||
@ -346,10 +347,12 @@ class CharsetUTF8 extends CharsetICU {
|
||||
implReset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implReset() {
|
||||
super.implReset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CoderResult encodeLoop(CharBuffer source, ByteBuffer target, IntBuffer offsets,
|
||||
boolean flush) {
|
||||
if (!source.hasRemaining()) {
|
||||
@ -548,7 +551,7 @@ class CharsetUTF8 extends CharsetICU {
|
||||
CoderResult cr = handleSurrogates(sourceArray, sourceIndex, sourceLimit, (char)char32);
|
||||
if (cr != null)
|
||||
return cr;
|
||||
|
||||
|
||||
sourceIndex++;
|
||||
char32 = fromUChar32;
|
||||
fromUChar32 = 0;
|
||||
@ -588,10 +591,10 @@ class CharsetUTF8 extends CharsetICU {
|
||||
CoderResult cr = handleSurrogates(source, (char)char32);
|
||||
if (cr != null)
|
||||
return cr;
|
||||
|
||||
|
||||
char32 = fromUChar32;
|
||||
fromUChar32 = 0;
|
||||
|
||||
|
||||
/* the rest is routine -- encode four bytes, stopping on overflow */
|
||||
|
||||
target.put(encodeHeadOf4(char32));
|
||||
@ -672,7 +675,7 @@ class CharsetUTF8 extends CharsetICU {
|
||||
// UConverterConstants.UNSIGNED_BYTE_MASK)<0x3e);}
|
||||
/*
|
||||
* Is this code unit (byte) a UTF-8 trail byte?
|
||||
*
|
||||
*
|
||||
* @param c
|
||||
* 8-bit code unit (byte)
|
||||
* @return TRUE or FALSE
|
||||
@ -681,15 +684,18 @@ class CharsetUTF8 extends CharsetICU {
|
||||
return (((c) & 0xc0) == 0x80);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new CharsetDecoderUTF8(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new CharsetEncoderUTF8(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
|
||||
getNonSurrogateUnicodeSet(setFillIn);
|
||||
}
|
||||
|
@ -150,6 +150,7 @@ final class UConverterAliasDataReader implements ICUBinary.Authenticate {
|
||||
return ICUBinary.getInts(byteBuffer, n, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[])
|
||||
{
|
||||
return version.length >= DATA_FORMAT_VERSION.length
|
||||
@ -157,9 +158,9 @@ final class UConverterAliasDataReader implements ICUBinary.Authenticate {
|
||||
&& version[1] == DATA_FORMAT_VERSION[1]
|
||||
&& version[2] == DATA_FORMAT_VERSION[2];
|
||||
}
|
||||
|
||||
|
||||
/*byte[] getUnicodeVersion(){
|
||||
return ICUBinary.getVersionByteArrayFromCompactInt(unicodeVersion);
|
||||
return ICUBinary.getVersionByteArrayFromCompactInt(unicodeVersion);
|
||||
}*/
|
||||
// private data members -------------------------------------------------
|
||||
|
||||
|
@ -81,15 +81,15 @@ import com.ibm.icu.impl.InvalidFormatException;
|
||||
* -- normal base table with optional extension
|
||||
*
|
||||
* int32_t stateTable[countStates][256];
|
||||
*
|
||||
*
|
||||
* struct _MBCSToUFallback { (fallbacks are sorted by offset)
|
||||
* uint32_t offset;
|
||||
* UChar32 codePoint;
|
||||
* } toUFallbacks[countToUFallbacks];
|
||||
*
|
||||
*
|
||||
* uint16_t unicodeCodeUnits[(offsetFromUTable-offsetToUCodeUnits)/2];
|
||||
* (padded to an even number of units)
|
||||
*
|
||||
*
|
||||
* -- stage 1 tables
|
||||
* if(staticData.unicodeMask&UCNV_HAS_SUPPLEMENTARY) {
|
||||
* -- stage 1 table for all of Unicode
|
||||
@ -98,7 +98,7 @@ import com.ibm.icu.impl.InvalidFormatException;
|
||||
* -- BMP-only tables have a smaller stage 1 table
|
||||
* uint16_t fromUTable[0x40]; (32-bit-aligned)
|
||||
* }
|
||||
*
|
||||
*
|
||||
* -- stage 2 tables
|
||||
* length determined by top of stage 1 and bottom of stage 3 tables
|
||||
* if(outputType==MBCS_OUTPUT_1) {
|
||||
@ -108,7 +108,7 @@ import com.ibm.icu.impl.InvalidFormatException;
|
||||
* -- DBCS, MBCS, EBCDIC_STATEFUL, ...: roundtrip flags and indexes
|
||||
* uint32_t stage 2 flags and indexes[?];
|
||||
* }
|
||||
*
|
||||
*
|
||||
* -- stage 3 tables with byte results
|
||||
* if(outputType==MBCS_OUTPUT_1) {
|
||||
* -- SBCS: each 16-bit result contains flags and the result byte, see ucnvmbcs.c
|
||||
@ -342,7 +342,7 @@ import com.ibm.icu.impl.InvalidFormatException;
|
||||
* the result bytes in fromUBytes[]; (0 indexes fromUBytes[0])
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*
|
||||
* The first pair in a section contains the number of following pairs in the
|
||||
* UChar position (16 bits, number=1..0xffff).
|
||||
* The value of the initial pair is used when the current UChar is not found
|
||||
@ -408,6 +408,7 @@ final class UConverterDataReader {
|
||||
|
||||
private static final class IsAcceptable implements ICUBinary.Authenticate {
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte formatVersion[]) {
|
||||
return formatVersion[0] == 6;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public final class CollationBuilder extends CollationRuleParser.Sink {
|
||||
private static final boolean DEBUG = false;
|
||||
private static final class BundleImporter implements CollationRuleParser.Importer {
|
||||
BundleImporter() {}
|
||||
@Override
|
||||
public String getRules(String localeID, String collationType) {
|
||||
return CollationLoader.loadRules(new ULocale(localeID), collationType);
|
||||
}
|
||||
@ -433,7 +434,7 @@ public final class CollationBuilder extends CollationRuleParser.Sink {
|
||||
}
|
||||
|
||||
/** Implements CollationRuleParser.Sink. */
|
||||
// Java 6: @Override
|
||||
@Override
|
||||
void addRelation(int strength, CharSequence prefix, CharSequence str, CharSequence extension) {
|
||||
String nfdPrefix;
|
||||
if(prefix.length() == 0) {
|
||||
@ -1322,6 +1323,7 @@ public final class CollationBuilder extends CollationRuleParser.Sink {
|
||||
CEFinalizer(long[] ces) {
|
||||
finalCEs = ces;
|
||||
}
|
||||
@Override
|
||||
public long modifyCE32(int ce32) {
|
||||
assert(!Collation.isSpecialCE32(ce32));
|
||||
if(CollationBuilder.isTempCE32(ce32)) {
|
||||
@ -1331,6 +1333,7 @@ public final class CollationBuilder extends CollationRuleParser.Sink {
|
||||
return Collation.NO_CE;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public long modifyCE(long ce) {
|
||||
if(CollationBuilder.isTempCE(ce)) {
|
||||
// retain case bits
|
||||
|
@ -491,7 +491,7 @@ final class CollationDataReader /* all static */ {
|
||||
}
|
||||
|
||||
private static final class IsAcceptable implements ICUBinary.Authenticate {
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[]) {
|
||||
return version[0] == 5;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// © 2016 and later: Unicode, Inc. and others.
|
||||
// License & terms of use: http://www.unicode.org/copyright.html#License
|
||||
/*
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2015, International Business Machines
|
||||
@ -160,7 +160,7 @@ public final class CollationWeights {
|
||||
long start, end;
|
||||
int length, count;
|
||||
|
||||
// Java 6: @Override
|
||||
@Override
|
||||
public int compareTo(WeightRange other) {
|
||||
long l=start;
|
||||
long r=other.start;
|
||||
|
@ -57,18 +57,18 @@ import com.ibm.icu.util.ULocale;
|
||||
* <h2>Direct Use</h2>
|
||||
* <p>The following shows an example of building an index directly.
|
||||
* The "show..." methods below are just to illustrate usage.
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* // Create a simple index where the values for the strings are Integers, and add the strings
|
||||
*
|
||||
*
|
||||
* AlphabeticIndex<Integer> index = new AlphabeticIndex<Integer>(desiredLocale).addLabels(additionalLocale);
|
||||
* int counter = 0;
|
||||
* for (String item : test) {
|
||||
* index.addRecord(item, counter++);
|
||||
* index.addRecord(item, counter++);
|
||||
* }
|
||||
* ...
|
||||
* // Show index at top. We could skip or gray out empty buckets
|
||||
*
|
||||
*
|
||||
* for (AlphabeticIndex.Bucket<Integer> bucket : index) {
|
||||
* if (showAll || bucket.size() != 0) {
|
||||
* showLabelAtTop(UI, bucket.getLabel());
|
||||
@ -76,7 +76,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* }
|
||||
* ...
|
||||
* // Show the buckets with their contents, skipping empty buckets
|
||||
*
|
||||
*
|
||||
* for (AlphabeticIndex.Bucket<Integer> bucket : index) {
|
||||
* if (bucket.size() != 0) {
|
||||
* showLabelInList(UI, bucket.getLabel());
|
||||
@ -140,6 +140,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
// Comparator for records, so that the Record class can be static.
|
||||
private final Comparator<Record<V>> recordComparator = new Comparator<Record<V>>() {
|
||||
@Override
|
||||
public int compare(Record<V> o1, Record<V> o2) {
|
||||
return collatorOriginal.compare(o1.name, o2.name);
|
||||
}
|
||||
@ -218,6 +219,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
* {@inheritDoc}
|
||||
* @stable ICU 51
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Bucket<V>> iterator() {
|
||||
return buckets.iterator();
|
||||
}
|
||||
@ -225,7 +227,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Create the index object.
|
||||
*
|
||||
*
|
||||
* @param locale
|
||||
* The locale for the index.
|
||||
* @stable ICU 4.8
|
||||
@ -236,7 +238,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Create the index object.
|
||||
*
|
||||
*
|
||||
* @param locale
|
||||
* The locale for the index.
|
||||
* @stable ICU 4.8
|
||||
@ -245,16 +247,16 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
this(ULocale.forLocale(locale), null);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create an AlphabeticIndex that uses a specific collator.
|
||||
*
|
||||
*
|
||||
* <p>The index will be created with no labels; the addLabels() function must be called
|
||||
* after creation to add the desired labels to the index.
|
||||
*
|
||||
* <p>The index will work directly with the supplied collator. If the caller will need to
|
||||
*
|
||||
* <p>The index will work directly with the supplied collator. If the caller will need to
|
||||
* continue working with the collator it should be cloned first, so that the
|
||||
* collator provided to the AlphabeticIndex remains unchanged after creation of the index.
|
||||
*
|
||||
*
|
||||
* @param collator The collator to use to order the contents of this index.
|
||||
* @stable ICU 51
|
||||
*/
|
||||
@ -353,7 +355,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Get the default label used in the IndexCharacters' locale for underflow, eg the last item in: X Y Z ...
|
||||
*
|
||||
*
|
||||
* @return underflow label
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -376,7 +378,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Get the default label used in the IndexCharacters' locale for overflow, eg the first item in: ... A B C
|
||||
*
|
||||
*
|
||||
* @return overflow label
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -400,7 +402,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
/**
|
||||
* Get the default label used for abbreviated buckets <i>between</i> other labels. For example, consider the labels
|
||||
* for Latin and Greek are used: X Y Z ... Α Β Γ.
|
||||
*
|
||||
*
|
||||
* @return inflow label
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -411,7 +413,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Get the limit on the number of labels in the index. The number of buckets can be slightly larger: see getBucketCount().
|
||||
*
|
||||
*
|
||||
* @return maxLabelCount maximum number of labels.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -632,7 +634,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Get the labels.
|
||||
*
|
||||
*
|
||||
* @return The list of bucket labels, after processing.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -651,7 +653,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
* <p>
|
||||
* <b><i>Don't use this method across threads if you are changing the settings on the collator, at least not without
|
||||
* synchronizing.</i></b>
|
||||
*
|
||||
*
|
||||
* @return a clone of the collator used internally
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -671,7 +673,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
* Add a record (name and data) to the index. The name will be used to sort the items into buckets, and to sort
|
||||
* within the bucket. Two records may have the same name. When they do, the sort order is according to the order added:
|
||||
* the first added comes first.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* Name, such as a name
|
||||
* @param data
|
||||
@ -698,7 +700,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
* <p>
|
||||
* Note that the bucket number (and sort key) are only valid for the settings of the current AlphabeticIndex; if
|
||||
* those are changed, then the bucket number and sort key must be regenerated.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* Name, such as a name
|
||||
* @return the bucket index for the name
|
||||
@ -711,7 +713,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Clear the index.
|
||||
*
|
||||
*
|
||||
* @return this, for chaining
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -725,7 +727,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Return the number of buckets in the index. This will be the same as the number of labels, plus buckets for the underflow, overflow, and inflow(s).
|
||||
*
|
||||
*
|
||||
* @return number of buckets
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -736,7 +738,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Return the number of records in the index: that is, the total number of distinct <name,data> pairs added with addRecord(...), over all the buckets.
|
||||
*
|
||||
*
|
||||
* @return total number of records in buckets
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -746,10 +748,11 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Return an iterator over the buckets.
|
||||
*
|
||||
*
|
||||
* @return iterator over buckets.
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Bucket<V>> iterator() {
|
||||
initBuckets();
|
||||
return buckets.iterator();
|
||||
@ -839,7 +842,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
/**
|
||||
* A (name, data) pair, to be sorted by name into one of the index buckets.
|
||||
* The user data is not used by the index implementation.
|
||||
*
|
||||
*
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
public static class Record<V> {
|
||||
@ -853,7 +856,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Get the name
|
||||
*
|
||||
*
|
||||
* @return the name
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -863,7 +866,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Get the data
|
||||
*
|
||||
*
|
||||
* @return the data
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -875,6 +878,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
* Standard toString()
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + "=" + data;
|
||||
}
|
||||
@ -887,7 +891,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
* returned by {@link AlphabeticIndex.ImmutableIndex#getBucket(int)},
|
||||
* and {@link AlphabeticIndex#addRecord(CharSequence, Object)} adds a record
|
||||
* into a bucket according to the record's name.
|
||||
*
|
||||
*
|
||||
* @param <V>
|
||||
* Data type
|
||||
* @stable ICU 4.8
|
||||
@ -902,7 +906,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Type of the label
|
||||
*
|
||||
*
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
public enum LabelType {
|
||||
@ -930,7 +934,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Set up the bucket.
|
||||
*
|
||||
*
|
||||
* @param label
|
||||
* label for the bucket
|
||||
* @param labelType
|
||||
@ -945,7 +949,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Get the label
|
||||
*
|
||||
*
|
||||
* @return label for the bucket
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -955,7 +959,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Is a normal, underflow, overflow, or inflow bucket
|
||||
*
|
||||
*
|
||||
* @return is an underflow, overflow, or inflow bucket
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -965,7 +969,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
|
||||
/**
|
||||
* Get the number of records in the bucket.
|
||||
*
|
||||
*
|
||||
* @return number of records in bucket
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@ -977,6 +981,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
* Iterator over the records in the bucket
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Record<V>> iterator() {
|
||||
if (records == null) {
|
||||
return Collections.<Record<V>>emptyList().iterator();
|
||||
@ -1188,6 +1193,7 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
/**
|
||||
* Iterator over just the visible buckets.
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Bucket<V>> iterator() {
|
||||
return immutableVisibleList.iterator(); // use immutable list to prevent remove().
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import com.ibm.icu.util.ULocale;
|
||||
|
||||
final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
|
||||
@Override
|
||||
Collator getInstance(ULocale locale) {
|
||||
// use service cache, it's faster than instantiation
|
||||
// if (service.isDefault()) {
|
||||
@ -51,6 +52,7 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Object registerInstance(Collator collator, ULocale locale) {
|
||||
// Set the collator locales while registering so that getInstance()
|
||||
// need not guess whether the collator's locales are already set properly
|
||||
@ -59,6 +61,7 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
return service.registerObject(collator, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
Object registerFactory(CollatorFactory f) {
|
||||
class CFactory extends LocaleKeyFactory {
|
||||
CollatorFactory delegate;
|
||||
@ -68,16 +71,19 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
this.delegate = fctry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object handleCreate(ULocale loc, int kind, ICUService srvc) {
|
||||
Object coll = delegate.createCollator(loc);
|
||||
return coll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(String id, ULocale displayLocale) {
|
||||
ULocale objectLocale = new ULocale(id);
|
||||
return delegate.getDisplayName(objectLocale, displayLocale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedIDs() {
|
||||
return delegate.getSupportedLocaleIDs();
|
||||
}
|
||||
@ -86,10 +92,12 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
return service.registerFactory(new CFactory(f));
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean unregister(Object registryKey) {
|
||||
return service.unregisterFactory((Factory)registryKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
Locale[] getAvailableLocales() {
|
||||
// TODO rewrite this to just wrap getAvailableULocales later
|
||||
Locale[] result;
|
||||
@ -102,6 +110,7 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
ULocale[] getAvailableULocales() {
|
||||
ULocale[] result;
|
||||
if (service.isDefault()) {
|
||||
@ -113,6 +122,7 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getDisplayName(ULocale objectLocale, ULocale displayLocale) {
|
||||
String id = objectLocale.getName();
|
||||
return service.getDisplayName(id, displayLocale);
|
||||
@ -152,6 +162,7 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
|
||||
///CLOVER:OFF
|
||||
// The following method can not be reached by testing
|
||||
@Override
|
||||
protected Object handleDefault(Key key, String[] actualIDReturn) {
|
||||
if (actualIDReturn != null) {
|
||||
actualIDReturn[0] = "root";
|
||||
|
@ -86,7 +86,7 @@ import com.ibm.icu.text.SimpleDateFormat;
|
||||
// - Other utilities?
|
||||
|
||||
public class GlobalizationPreferences implements Freezable<GlobalizationPreferences> {
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
* @draft ICU 3.6
|
||||
@ -98,7 +98,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public static final int
|
||||
public static final int
|
||||
NF_NUMBER = 0, // NumberFormat.NUMBERSTYLE
|
||||
NF_CURRENCY = 1, // NumberFormat.CURRENCYSTYLE
|
||||
NF_PERCENT = 2, // NumberFormat.PERCENTSTYLE
|
||||
@ -131,7 +131,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
ID_LANGUAGE = 1,
|
||||
ID_SCRIPT = 2,
|
||||
ID_TERRITORY = 3,
|
||||
ID_VARIANT = 4,
|
||||
ID_VARIANT = 4,
|
||||
ID_KEYWORD = 5,
|
||||
ID_KEYWORD_VALUE = 6,
|
||||
ID_CURRENCY = 7,
|
||||
@ -160,8 +160,8 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* for the appropriate territory, currency, timezone, etc. The
|
||||
* user should be given the opportunity to correct those defaults
|
||||
* in case they are incorrect.
|
||||
*
|
||||
* @param inputLocales list of locales in priority order, eg {"be", "fr"}
|
||||
*
|
||||
* @param inputLocales list of locales in priority order, eg {"be", "fr"}
|
||||
* for Breton first, then French if that fails.
|
||||
* @return this, for chaining
|
||||
* @draft ICU 3.6
|
||||
@ -177,7 +177,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* Get a copy of the language/locale priority list
|
||||
*
|
||||
*
|
||||
* @return a copy of the language/locale priority list.
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -187,7 +187,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
if (locales == null) {
|
||||
result = guessLocales();
|
||||
} else {
|
||||
result = new ArrayList<ULocale>();
|
||||
result = new ArrayList<ULocale>();
|
||||
result.addAll(locales);
|
||||
}
|
||||
return result;
|
||||
@ -214,7 +214,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
/**
|
||||
* Convenience routine for setting the language/locale priority
|
||||
* list from an array.
|
||||
*
|
||||
*
|
||||
* @see #setLocales(List locales)
|
||||
* @param uLocales list of locales in an array
|
||||
* @return this, for chaining
|
||||
@ -231,7 +231,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
/**
|
||||
* Convenience routine for setting the language/locale priority
|
||||
* list from a single locale/language.
|
||||
*
|
||||
*
|
||||
* @see #setLocales(List locales)
|
||||
* @param uLocale single locale
|
||||
* @return this, for chaining
|
||||
@ -249,7 +249,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* Convenience routine for setting the locale priority list from
|
||||
* an Accept-Language string.
|
||||
* @see #setLocales(List locales)
|
||||
* @param acceptLanguageString Accept-Language list, as defined by
|
||||
* @param acceptLanguageString Accept-Language list, as defined by
|
||||
* Section 14.4 of the RFC 2616 (HTTP 1.1)
|
||||
* @return this, for chaining
|
||||
* @draft ICU 3.6
|
||||
@ -273,7 +273,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* Convenience function to get a ResourceBundle instance using
|
||||
* the specified base name based on the language/locale priority list
|
||||
* stored in this object.
|
||||
*
|
||||
*
|
||||
* @param baseName the base name of the resource bundle, a fully qualified
|
||||
* class name
|
||||
* @return a resource bundle for the given base name and locale based on the
|
||||
@ -289,7 +289,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* Convenience function to get a ResourceBundle instance using
|
||||
* the specified base name and class loader based on the language/locale
|
||||
* priority list stored in this object.
|
||||
*
|
||||
*
|
||||
* @param baseName the base name of the resource bundle, a fully qualified
|
||||
* class name
|
||||
* @param loader the class object from which to load the resource bundle
|
||||
@ -340,14 +340,14 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
}
|
||||
return urb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the territory, which is a valid territory according to for
|
||||
* RFC 3066 (or successor). If not otherwise set, default
|
||||
* currency and timezone values will be set from this. The user
|
||||
* should be given the opportunity to correct those defaults in
|
||||
* case they are incorrect.
|
||||
*
|
||||
*
|
||||
* @param territory code
|
||||
* @return this, for chaining
|
||||
* @draft ICU 3.6
|
||||
@ -364,7 +364,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
/**
|
||||
* Gets the territory setting. If it wasn't explicitly set, it is
|
||||
* computed from the general locale setting.
|
||||
*
|
||||
*
|
||||
* @return territory code, explicit or implicit.
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -378,7 +378,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* Sets the currency code. If this has not been set, uses default for territory.
|
||||
*
|
||||
*
|
||||
* @param currency Valid ISO 4217 currency code.
|
||||
* @return this, for chaining
|
||||
* @draft ICU 3.6
|
||||
@ -394,7 +394,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* Get a copy of the currency computed according to the settings.
|
||||
*
|
||||
*
|
||||
* @return currency code, explicit or implicit.
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -408,7 +408,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* Sets the calendar. If this has not been set, uses default for territory.
|
||||
*
|
||||
*
|
||||
* @param calendar arbitrary calendar
|
||||
* @return this, for chaining
|
||||
* @draft ICU 3.6
|
||||
@ -423,8 +423,8 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a copy of the calendar according to the settings.
|
||||
*
|
||||
* Get a copy of the calendar according to the settings.
|
||||
*
|
||||
* @return calendar explicit or implicit.
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -441,7 +441,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* Sets the timezone ID. If this has not been set, uses default for territory.
|
||||
*
|
||||
*
|
||||
* @param timezone a valid TZID (see UTS#35).
|
||||
* @return this, for chaining
|
||||
* @draft ICU 3.6
|
||||
@ -458,7 +458,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
/**
|
||||
* Get the timezone. It was either explicitly set, or is
|
||||
* heuristically computed from other settings.
|
||||
*
|
||||
*
|
||||
* @return timezone, either implicitly or explicitly set
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -471,8 +471,8 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a copy of the collator according to the settings.
|
||||
*
|
||||
* Get a copy of the collator according to the settings.
|
||||
*
|
||||
* @return collator explicit or implicit.
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -500,7 +500,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
throw new UnsupportedOperationException("Attempt to modify immutable object");
|
||||
}
|
||||
try {
|
||||
this.collator = (Collator) collator.clone(); // clone for safety
|
||||
this.collator = (Collator) collator.clone(); // clone for safety
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new ICUCloneNotSupportedException("Error in cloning collator", e);
|
||||
}
|
||||
@ -510,7 +510,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
/**
|
||||
* Get a copy of the break iterator for the specified type according to the
|
||||
* settings.
|
||||
*
|
||||
*
|
||||
* @param type break type - BI_CHARACTER or BI_WORD, BI_LINE, BI_SENTENCE, BI_TITLE
|
||||
* @return break iterator explicit or implicit
|
||||
* @draft ICU 3.6
|
||||
@ -528,7 +528,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* Explicitly set the break iterator for this object.
|
||||
*
|
||||
*
|
||||
* @param type break type - BI_CHARACTER or BI_WORD, BI_LINE, BI_SENTENCE, BI_TITLE
|
||||
* @param iterator a break iterator
|
||||
* @return this, for chaining
|
||||
@ -551,7 +551,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
/**
|
||||
* Get the display name for an ID: language, script, territory, currency, timezone...
|
||||
* Uses the language priority list to do so.
|
||||
*
|
||||
*
|
||||
* @param id language code, script code, ...
|
||||
* @param type specifies the type of the ID: ID_LANGUAGE, etc.
|
||||
* @return the display name
|
||||
@ -566,23 +566,23 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
}
|
||||
switch (type) {
|
||||
case ID_LOCALE:
|
||||
result = ULocale.getDisplayName(id, locale);
|
||||
result = ULocale.getDisplayName(id, locale);
|
||||
break;
|
||||
case ID_LANGUAGE:
|
||||
result = ULocale.getDisplayLanguage(id, locale);
|
||||
result = ULocale.getDisplayLanguage(id, locale);
|
||||
break;
|
||||
case ID_SCRIPT:
|
||||
result = ULocale.getDisplayScript("und-" + id, locale);
|
||||
result = ULocale.getDisplayScript("und-" + id, locale);
|
||||
break;
|
||||
case ID_TERRITORY:
|
||||
result = ULocale.getDisplayCountry("und-" + id, locale);
|
||||
result = ULocale.getDisplayCountry("und-" + id, locale);
|
||||
break;
|
||||
case ID_VARIANT:
|
||||
// TODO fix variant parsing
|
||||
result = ULocale.getDisplayVariant("und-QQ-" + id, locale);
|
||||
result = ULocale.getDisplayVariant("und-QQ-" + id, locale);
|
||||
break;
|
||||
case ID_KEYWORD:
|
||||
result = ULocale.getDisplayKeyword(id, locale);
|
||||
result = ULocale.getDisplayKeyword(id, locale);
|
||||
break;
|
||||
case ID_KEYWORD_VALUE:
|
||||
String[] parts = new String[2];
|
||||
@ -596,12 +596,12 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
case ID_CURRENCY_SYMBOL:
|
||||
case ID_CURRENCY:
|
||||
Currency temp = new Currency(id);
|
||||
result =temp.getName(locale, type==ID_CURRENCY
|
||||
? Currency.LONG_NAME
|
||||
result =temp.getName(locale, type==ID_CURRENCY
|
||||
? Currency.LONG_NAME
|
||||
: Currency.SYMBOL_NAME, new boolean[1]);
|
||||
// TODO: have method that doesn't take parameter. Add
|
||||
// function to determine whether string is choice
|
||||
// format.
|
||||
// format.
|
||||
// TODO: have method that doesn't require us
|
||||
// to create a currency
|
||||
break;
|
||||
@ -612,7 +612,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
// TODO, have method that doesn't require us to create a timezone
|
||||
// fix other hacks
|
||||
// hack for couldn't match
|
||||
|
||||
|
||||
boolean isBadStr = false;
|
||||
// Matcher badTimeZone = Pattern.compile("[A-Z]{2}|.*\\s\\([A-Z]{2}\\)").matcher("");
|
||||
// badtzstr = badTimeZone.reset(result).matches();
|
||||
@ -654,7 +654,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* a particular combination of dateStyle and timeStyle. DF_NONE should
|
||||
* be used if for the style, where only the date or time format individually
|
||||
* is being set.
|
||||
*
|
||||
*
|
||||
* @param dateStyle DF_FULL, DF_LONG, DF_MEDIUM, DF_SHORT or DF_NONE
|
||||
* @param timeStyle DF_FULL, DF_LONG, DF_MEDIUM, DF_SHORT or DF_NONE
|
||||
* @param format The date format
|
||||
@ -679,7 +679,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* is returned. Otherwise, the language priority list is used.
|
||||
* DF_NONE should be used for the style, where only the date or
|
||||
* time format individually is being gotten.
|
||||
*
|
||||
*
|
||||
* @param dateStyle DF_FULL, DF_LONG, DF_MEDIUM, DF_SHORT or DF_NONE
|
||||
* @param timeStyle DF_FULL, DF_LONG, DF_MEDIUM, DF_SHORT or DF_NONE
|
||||
* @return a DateFormat, according to the above description
|
||||
@ -711,7 +711,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* there is an explicit (non-null) number format set, a copy of
|
||||
* that is returned. Otherwise, the language priority list is
|
||||
* used.
|
||||
*
|
||||
*
|
||||
* @param style NF_NUMBER, NF_CURRENCY, NF_PERCENT, NF_SCIENTIFIC, NF_INTEGER
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -734,7 +734,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* Sets a number format explicitly. Overrides the general locale settings.
|
||||
*
|
||||
*
|
||||
* @param style NF_NUMBER, NF_CURRENCY, NF_PERCENT, NF_SCIENTIFIC, NF_INTEGER
|
||||
* @param format The number format
|
||||
* @return this, for chaining
|
||||
@ -754,7 +754,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* Restore the object to the initial state.
|
||||
*
|
||||
*
|
||||
* @return this, for chaining
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -803,13 +803,13 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* Before: en_US, en, en_GB, en, en, fr_FR, fr
|
||||
* <br>
|
||||
* After: en_US, en_GB, en, fr_FR, fr
|
||||
* <br>
|
||||
* <br>
|
||||
* <br>
|
||||
* The final locale list is used to produce a default value for the appropriate territory,
|
||||
* currency, timezone, etc. The list also represents the lookup order used in
|
||||
* <code>getResourceBundle</code> for this object. A subclass may override this method
|
||||
* to customize the algorithm used for populating the locale list.
|
||||
*
|
||||
*
|
||||
* @param inputLocales The list of input locales
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -853,7 +853,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
// We want to see zh_Hant_HK before zh_HK
|
||||
result.add(j, uloc);
|
||||
bInserted = true;
|
||||
break;
|
||||
break;
|
||||
} else if (script.length() == 0 && country.length() > 0 && c.length() == 0) {
|
||||
// We want to see zh_HK before zh_Hant
|
||||
result.add(j, uloc);
|
||||
@ -907,7 +907,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/*
|
||||
* Step 3: Remove earlier occurrence of duplicated locales
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
* Before - en_US_Boston, en_US, en, en_US, en, fr_FR, fr,
|
||||
* zh_TW, zn, zh_Hant, zh, zh, fr_CA, fr
|
||||
@ -933,12 +933,12 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This function can be overridden by subclasses to use different heuristics.
|
||||
* <b>It MUST return a 'safe' value,
|
||||
* one whose modification will not affect this object.</b>
|
||||
*
|
||||
*
|
||||
* @param dateStyle
|
||||
* @param timeStyle
|
||||
* @draft ICU 3.6
|
||||
@ -964,7 +964,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* This function can be overridden by subclasses to use different heuristics.
|
||||
* <b>It MUST return a 'safe' value,
|
||||
* one whose modification will not affect this object.</b>
|
||||
*
|
||||
*
|
||||
* @param style
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -1000,7 +1000,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* This function can be overridden by subclasses to use different heuristics.
|
||||
*
|
||||
*
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@ -1035,7 +1035,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
|
||||
/**
|
||||
* This function can be overridden by subclasses to use different heuristics
|
||||
*
|
||||
*
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@ -1047,7 +1047,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* This function can be overridden by subclasses to use different heuristics
|
||||
* <b>It MUST return a 'safe' value,
|
||||
* one whose modification will not affect this object.</b>
|
||||
*
|
||||
*
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@ -1064,7 +1064,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* This function can be overridden by subclasses to use different heuristics.
|
||||
* <b>It MUST return a 'safe' value,
|
||||
* one whose modification will not affect this object.</b>
|
||||
*
|
||||
*
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@ -1080,7 +1080,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* This function can be overridden by subclasses to use different heuristics.
|
||||
* <b>It MUST return a 'safe' value,
|
||||
* one whose modification will not affect this object.</b>
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
@ -1117,7 +1117,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* This function can be overridden by subclasses to use different heuristics.
|
||||
* <b>It MUST return a 'safe' value,
|
||||
* one whose modification will not affect this object.</b>
|
||||
*
|
||||
*
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@ -1126,7 +1126,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
// for single-zone countries, pick that zone
|
||||
// for others, pick the most populous zone
|
||||
// for now, just use fixed value
|
||||
// NOTE: in a few cases can do better by looking at language.
|
||||
// NOTE: in a few cases can do better by looking at language.
|
||||
// Eg haw+US should go to Pacific/Honolulu
|
||||
// fr+CA should go to America/Montreal
|
||||
String timezoneString = territory_tzid_hack_map.get(getTerritory());
|
||||
@ -1151,7 +1151,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* This function can be overridden by subclasses to use different heuristics.
|
||||
* <b>It MUST return a 'safe' value,
|
||||
* one whose modification will not affect this object.</b>
|
||||
*
|
||||
*
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@ -1162,9 +1162,9 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
}
|
||||
return Calendar.getInstance(getTimeZone(), calLocale);
|
||||
}
|
||||
|
||||
|
||||
// PRIVATES
|
||||
|
||||
|
||||
private List<ULocale> locales;
|
||||
private String territory;
|
||||
private Currency currency;
|
||||
@ -1175,7 +1175,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
private DateFormat[][] dateFormats;
|
||||
private NumberFormat[] numberFormats;
|
||||
private List<ULocale> implicitLocales;
|
||||
|
||||
|
||||
{
|
||||
reset();
|
||||
}
|
||||
@ -1199,9 +1199,9 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
if (bits != null && bits.get(type)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Available locales for service types
|
||||
*/
|
||||
@ -1272,7 +1272,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
}
|
||||
|
||||
/** WARNING: All of this data is temporary, until we start importing from CLDR!!!
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final Map<String, String> language_territory_hack_map = new HashMap<String, String>();
|
||||
private static final String[][] language_territory_hack = {
|
||||
@ -1467,7 +1467,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
{"MH", "Pacific/Majuro"},
|
||||
{"MN", "Asia/Ulaanbaatar"},
|
||||
{"SJ", "Arctic/Longyearbyen"},
|
||||
{"UM", "Pacific/Midway"},
|
||||
{"UM", "Pacific/Midway"},
|
||||
};
|
||||
static {
|
||||
for (int i = 0; i < territory_tzid_hack.length; ++i) {
|
||||
@ -1476,13 +1476,14 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
}
|
||||
|
||||
// Freezable implementation
|
||||
|
||||
|
||||
private volatile boolean frozen;
|
||||
|
||||
/**
|
||||
* @draft ICU 3.6
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
}
|
||||
@ -1491,6 +1492,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@Override
|
||||
public GlobalizationPreferences freeze() {
|
||||
frozen = true;
|
||||
return this;
|
||||
@ -1500,6 +1502,7 @@ public class GlobalizationPreferences implements Freezable<GlobalizationPreferen
|
||||
* @draft ICU 4.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
@Override
|
||||
public GlobalizationPreferences cloneAsThawed() {
|
||||
try {
|
||||
GlobalizationPreferences result = (GlobalizationPreferences) clone();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -103,7 +103,7 @@ public class CharTrie extends Trie
|
||||
}
|
||||
|
||||
// public methods --------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value associated with the codepoint.
|
||||
* If no value is associated with the codepoint, a default value will be
|
||||
@ -118,14 +118,14 @@ public class CharTrie extends Trie
|
||||
// fastpath for U+0000..U+D7FF
|
||||
if(0 <= ch && ch < UTF16.LEAD_SURROGATE_MIN_VALUE) {
|
||||
// copy of getRawOffset()
|
||||
offset = (m_index_[ch >> INDEX_STAGE_1_SHIFT_] << INDEX_STAGE_2_SHIFT_)
|
||||
offset = (m_index_[ch >> INDEX_STAGE_1_SHIFT_] << INDEX_STAGE_2_SHIFT_)
|
||||
+ (ch & INDEX_STAGE_3_MASK_);
|
||||
return m_data_[offset];
|
||||
}
|
||||
|
||||
// handle U+D800..U+10FFFF
|
||||
offset = getCodePointOffset(ch);
|
||||
|
||||
|
||||
// return -1 if there is an error, in this case we return the default
|
||||
// value: m_initialValue_
|
||||
return (offset >= 0) ? m_data_[offset] : m_initialValue_;
|
||||
@ -174,7 +174,7 @@ public class CharTrie extends Trie
|
||||
/**
|
||||
* <p>Get a value from a folding offset (from the value of a lead surrogate)
|
||||
* and a trail surrogate.</p>
|
||||
* <p>If the
|
||||
* <p>If the
|
||||
* @param leadvalue value associated with the lead surrogate which contains
|
||||
* the folding offset
|
||||
* @param trail surrogate
|
||||
@ -188,24 +188,24 @@ public class CharTrie extends Trie
|
||||
}
|
||||
int offset = m_dataManipulate_.getFoldingOffset(leadvalue);
|
||||
if (offset > 0) {
|
||||
return m_data_[getRawOffset(offset,
|
||||
return m_data_[getRawOffset(offset,
|
||||
(char)(trail & SURROGATE_MASK_))];
|
||||
}
|
||||
return m_initialValue_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Gets the latin 1 fast path value.</p>
|
||||
* <p>Note this only works if latin 1 characters have their own linear
|
||||
* <p>Note this only works if latin 1 characters have their own linear
|
||||
* array.</p>
|
||||
* @param ch latin 1 characters
|
||||
* @return value associated with latin character
|
||||
*/
|
||||
public final char getLatin1LinearValue(char ch)
|
||||
public final char getLatin1LinearValue(char ch)
|
||||
{
|
||||
return m_data_[INDEX_STAGE_3_MASK_ + 1 + m_dataOffset_ + ch];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the argument Trie has the same data as this Trie
|
||||
* @param other Trie to check
|
||||
@ -213,7 +213,8 @@ public class CharTrie extends Trie
|
||||
* otherwise
|
||||
*/
|
||||
///CLOVER:OFF
|
||||
public boolean equals(Object other)
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
boolean result = super.equals(other);
|
||||
if (result && other instanceof CharTrie) {
|
||||
@ -222,7 +223,8 @@ public class CharTrie extends Trie
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
assert false : "hashCode not designed";
|
||||
return 42;
|
||||
@ -236,6 +238,7 @@ public class CharTrie extends Trie
|
||||
* data array</p>
|
||||
* @param bytes buffer containing trie data
|
||||
*/
|
||||
@Override
|
||||
protected final void unserialize(ByteBuffer bytes)
|
||||
{
|
||||
int indexDataLength = m_dataOffset_ + m_dataLength_;
|
||||
@ -250,13 +253,14 @@ public class CharTrie extends Trie
|
||||
* @param trail trailing surrogate
|
||||
* @return offset to data
|
||||
*/
|
||||
@Override
|
||||
protected final int getSurrogateOffset(char lead, char trail)
|
||||
{
|
||||
if (m_dataManipulate_ == null) {
|
||||
throw new NullPointerException(
|
||||
"The field DataManipulate in this Trie is null");
|
||||
}
|
||||
|
||||
|
||||
// get fold position for the next trail surrogate
|
||||
int offset = m_dataManipulate_.getFoldingOffset(getLeadValue(lead));
|
||||
|
||||
@ -269,7 +273,7 @@ public class CharTrie extends Trie
|
||||
// value: m_initialValue_
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value at the argument index.
|
||||
* For use internally in TrieIterator.
|
||||
@ -277,6 +281,7 @@ public class CharTrie extends Trie
|
||||
* @return 32 bit value
|
||||
* @see com.ibm.icu.impl.TrieIterator
|
||||
*/
|
||||
@Override
|
||||
protected final int getValue(int index)
|
||||
{
|
||||
return m_data_[index];
|
||||
@ -284,13 +289,14 @@ public class CharTrie extends Trie
|
||||
|
||||
/**
|
||||
* Gets the default initial value
|
||||
* @return 32 bit value
|
||||
* @return 32 bit value
|
||||
*/
|
||||
@Override
|
||||
protected final int getInitialValue()
|
||||
{
|
||||
return m_initialValue_;
|
||||
}
|
||||
|
||||
|
||||
// private data members --------------------------------------------
|
||||
|
||||
/**
|
||||
|
@ -13,26 +13,27 @@ import java.text.CharacterIterator;
|
||||
import com.ibm.icu.text.UCharacterIterator;
|
||||
|
||||
/**
|
||||
* This class is a wrapper around CharacterIterator and implements the
|
||||
* This class is a wrapper around CharacterIterator and implements the
|
||||
* UCharacterIterator protocol
|
||||
* @author ram
|
||||
*/
|
||||
|
||||
public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
|
||||
|
||||
private CharacterIterator iterator;
|
||||
|
||||
|
||||
|
||||
|
||||
public CharacterIteratorWrapper(CharacterIterator iter){
|
||||
if(iter==null){
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
iterator = iter;
|
||||
iterator = iter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UCharacterIterator#current()
|
||||
*/
|
||||
@Override
|
||||
public int current() {
|
||||
int c = iterator.current();
|
||||
if(c==CharacterIterator.DONE){
|
||||
@ -44,6 +45,7 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
/**
|
||||
* @see UCharacterIterator#getLength()
|
||||
*/
|
||||
@Override
|
||||
public int getLength() {
|
||||
return (iterator.getEndIndex() - iterator.getBeginIndex());
|
||||
}
|
||||
@ -51,6 +53,7 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
/**
|
||||
* @see UCharacterIterator#getIndex()
|
||||
*/
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return iterator.getIndex();
|
||||
}
|
||||
@ -58,10 +61,11 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
/**
|
||||
* @see UCharacterIterator#next()
|
||||
*/
|
||||
@Override
|
||||
public int next() {
|
||||
int i = iterator.current();
|
||||
iterator.next();
|
||||
if(i==CharacterIterator.DONE){
|
||||
if(i==CharacterIterator.DONE){
|
||||
return DONE;
|
||||
}
|
||||
return i;
|
||||
@ -70,6 +74,7 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
/**
|
||||
* @see UCharacterIterator#previous()
|
||||
*/
|
||||
@Override
|
||||
public int previous() {
|
||||
int i = iterator.previous();
|
||||
if(i==CharacterIterator.DONE){
|
||||
@ -81,6 +86,7 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
/**
|
||||
* @see UCharacterIterator#setIndex(int)
|
||||
*/
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
try{
|
||||
iterator.setIndex(index);
|
||||
@ -92,6 +98,7 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
/**
|
||||
* @see UCharacterIterator#setToLimit()
|
||||
*/
|
||||
@Override
|
||||
public void setToLimit() {
|
||||
iterator.setIndex(iterator.getEndIndex());
|
||||
}
|
||||
@ -99,13 +106,14 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
/**
|
||||
* @see UCharacterIterator#getText(char[])
|
||||
*/
|
||||
@Override
|
||||
public int getText(char[] fillIn, int offset){
|
||||
int length =iterator.getEndIndex() - iterator.getBeginIndex();
|
||||
int length =iterator.getEndIndex() - iterator.getBeginIndex();
|
||||
int currentIndex = iterator.getIndex();
|
||||
if(offset < 0 || offset + length > fillIn.length){
|
||||
throw new IndexOutOfBoundsException(Integer.toString(length));
|
||||
}
|
||||
|
||||
|
||||
for (char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) {
|
||||
fillIn[offset++] = ch;
|
||||
}
|
||||
@ -118,21 +126,23 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
* Creates a clone of this iterator. Clones the underlying character iterator.
|
||||
* @see UCharacterIterator#clone()
|
||||
*/
|
||||
@Override
|
||||
public Object clone(){
|
||||
try {
|
||||
CharacterIteratorWrapper result = (CharacterIteratorWrapper) super.clone();
|
||||
result.iterator = (CharacterIterator)this.iterator.clone();
|
||||
return result;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null; // only invoked if bad underlying character iterator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int moveIndex(int delta){
|
||||
int length = iterator.getEndIndex() - iterator.getBeginIndex();
|
||||
int length = iterator.getEndIndex() - iterator.getBeginIndex();
|
||||
int idx = iterator.getIndex()+delta;
|
||||
|
||||
|
||||
if(idx < 0) {
|
||||
idx = 0;
|
||||
} else if(idx > length) {
|
||||
@ -140,11 +150,12 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
}
|
||||
return iterator.setIndex(idx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see UCharacterIterator#getCharacterIterator()
|
||||
*/
|
||||
@Override
|
||||
public CharacterIterator getCharacterIterator(){
|
||||
return (CharacterIterator)iterator.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ClassLoaderUtil {
|
||||
// this constructor on Android, because ClassLoaderUtil.getClassLoader()
|
||||
// should get non-null ClassLoader before calling
|
||||
// ClassLoaderUtil.getBootstrapClassLoader().
|
||||
//
|
||||
//
|
||||
// On other common JREs (such as Oracle, OpenJDK),
|
||||
// Object.class.getClassLoader() returns null, but
|
||||
// super(null) is commonly used for accessing the bootstrap
|
||||
@ -44,7 +44,7 @@ public class ClassLoaderUtil {
|
||||
* Lazily create a singleton BootstrapClassLoader.
|
||||
* This class loader might be necessary when ICU4J classes are
|
||||
* initialized by bootstrap class loader.
|
||||
*
|
||||
*
|
||||
* @return The BootStrapClassLoader singleton instance
|
||||
*/
|
||||
private static ClassLoader getBootstrapClassLoader() {
|
||||
@ -54,10 +54,11 @@ public class ClassLoaderUtil {
|
||||
ClassLoader cl = null;
|
||||
if (System.getSecurityManager() != null) {
|
||||
cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
|
||||
public BootstrapClassLoader run() {
|
||||
return new BootstrapClassLoader();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public BootstrapClassLoader run() {
|
||||
return new BootstrapClassLoader();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
cl = new BootstrapClassLoader();
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public final class DateNumberFormat extends NumberFormat {
|
||||
} catch (MissingResourceException ex) {
|
||||
if ( !nsName.equals("latn") ) {
|
||||
try {
|
||||
minusString = rb.getStringWithFallback("NumberElements/latn/symbols/minusSign");
|
||||
minusString = rb.getStringWithFallback("NumberElements/latn/symbols/minusSign");
|
||||
} catch (MissingResourceException ex1) {
|
||||
minusString = "-";
|
||||
}
|
||||
@ -90,18 +90,22 @@ public final class DateNumberFormat extends NumberFormat {
|
||||
minusSign = elems[10];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaximumIntegerDigits(int newValue) {
|
||||
maxIntDigits = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumIntegerDigits() {
|
||||
return maxIntDigits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMinimumIntegerDigits(int newValue) {
|
||||
minIntDigits = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumIntegerDigits() {
|
||||
return minIntDigits;
|
||||
}
|
||||
@ -130,11 +134,13 @@ public final class DateNumberFormat extends NumberFormat {
|
||||
return digits.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuffer format(double number, StringBuffer toAppendTo,
|
||||
FieldPosition pos) {
|
||||
throw new UnsupportedOperationException("StringBuffer format(double, StringBuffer, FieldPostion) is not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuffer format(long numberL, StringBuffer toAppendTo,
|
||||
FieldPosition pos) {
|
||||
|
||||
@ -173,17 +179,20 @@ public final class DateNumberFormat extends NumberFormat {
|
||||
}
|
||||
return toAppendTo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StringBuffer format(BigInteger number, StringBuffer toAppendTo,
|
||||
FieldPosition pos) {
|
||||
throw new UnsupportedOperationException("StringBuffer format(BigInteger, StringBuffer, FieldPostion) is not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo,
|
||||
FieldPosition pos) {
|
||||
throw new UnsupportedOperationException("StringBuffer format(BigDecimal, StringBuffer, FieldPostion) is not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuffer format(BigDecimal number,
|
||||
StringBuffer toAppendTo, FieldPosition pos) {
|
||||
throw new UnsupportedOperationException("StringBuffer format(BigDecimal, StringBuffer, FieldPostion) is not implemented");
|
||||
@ -194,6 +203,7 @@ public final class DateNumberFormat extends NumberFormat {
|
||||
*/
|
||||
private static final long PARSE_THRESHOLD = 922337203685477579L; // (Long.MAX_VALUE / 10) - 1
|
||||
|
||||
@Override
|
||||
public Number parse(String text, ParsePosition parsePosition) {
|
||||
long num = 0;
|
||||
boolean sawNumber = false;
|
||||
@ -236,6 +246,7 @@ public final class DateNumberFormat extends NumberFormat {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || !super.equals(obj) || !(obj instanceof DateNumberFormat)) {
|
||||
return false;
|
||||
@ -247,7 +258,8 @@ public final class DateNumberFormat extends NumberFormat {
|
||||
&& this.positiveOnly == other.positiveOnly
|
||||
&& Arrays.equals(this.digits, other.digits));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public final class ICUBinary {
|
||||
private static final int DATA_FORMAT = 0x436d6e44;
|
||||
|
||||
private static final class IsAcceptable implements Authenticate {
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[]) {
|
||||
return version[0] == 1;
|
||||
}
|
||||
@ -367,7 +367,7 @@ public final class ICUBinary {
|
||||
} else if (i == key.length()) {
|
||||
return -1; // key < table key because key is shorter.
|
||||
}
|
||||
int diff = (int)key.charAt(i) - c2;
|
||||
int diff = key.charAt(i) - c2;
|
||||
if (diff != 0) {
|
||||
return diff;
|
||||
}
|
||||
@ -386,7 +386,7 @@ public final class ICUBinary {
|
||||
} else if (i == key.length()) {
|
||||
return -1; // key < table key because key is shorter.
|
||||
}
|
||||
int diff = (int)key.charAt(i) - c2;
|
||||
int diff = key.charAt(i) - c2;
|
||||
if (diff != 0) {
|
||||
return diff;
|
||||
}
|
||||
@ -402,13 +402,13 @@ public final class ICUBinary {
|
||||
{
|
||||
/**
|
||||
* Method used in ICUBinary.readHeader() to provide data format
|
||||
* authentication.
|
||||
* authentication.
|
||||
* @param version version of the current data
|
||||
* @return true if dataformat is an acceptable version, false otherwise
|
||||
*/
|
||||
public boolean isDataVersionAcceptable(byte version[]);
|
||||
}
|
||||
|
||||
|
||||
// public methods --------------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -610,7 +610,7 @@ public final class ICUBinary {
|
||||
|
||||
bytes.position(headerSize);
|
||||
return // dataVersion
|
||||
((int)bytes.get(20) << 24) |
|
||||
(bytes.get(20) << 24) |
|
||||
((bytes.get(21) & 0xff) << 16) |
|
||||
((bytes.get(22) & 0xff) << 8) |
|
||||
(bytes.get(23) & 0xff);
|
||||
@ -767,23 +767,23 @@ public final class ICUBinary {
|
||||
}
|
||||
|
||||
// private variables -------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Magic numbers to authenticate the data file
|
||||
*/
|
||||
private static final byte MAGIC1 = (byte)0xda;
|
||||
private static final byte MAGIC2 = (byte)0x27;
|
||||
|
||||
|
||||
/**
|
||||
* File format authentication values
|
||||
*/
|
||||
private static final byte CHAR_SET_ = 0;
|
||||
private static final byte CHAR_SIZE_ = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Error messages
|
||||
*/
|
||||
private static final String MAGIC_NUMBER_AUTHENTICATION_FAILED_ =
|
||||
private static final String MAGIC_NUMBER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Not an ICU data file";
|
||||
private static final String HEADER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Header authentication failed, please check if you have a valid ICU data file";
|
||||
|
@ -63,6 +63,7 @@ public class ICUConfig {
|
||||
if (System.getSecurityManager() != null) {
|
||||
try {
|
||||
val = AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getProperty(fname);
|
||||
}
|
||||
|
@ -93,6 +93,7 @@ public final class ICUData {
|
||||
URL i = null;
|
||||
if (System.getSecurityManager() != null) {
|
||||
i = AccessController.doPrivileged(new PrivilegedAction<URL>() {
|
||||
@Override
|
||||
public URL run() {
|
||||
return ICUData.class.getResource(resourceName);
|
||||
}
|
||||
@ -107,6 +108,7 @@ public final class ICUData {
|
||||
InputStream i = null;
|
||||
if (System.getSecurityManager() != null) {
|
||||
i = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
||||
@Override
|
||||
public InputStream run() {
|
||||
return root.getResourceAsStream(resourceName);
|
||||
}
|
||||
@ -129,6 +131,7 @@ public final class ICUData {
|
||||
InputStream i = null;
|
||||
if (System.getSecurityManager() != null) {
|
||||
i = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
||||
@Override
|
||||
public InputStream run() {
|
||||
return loader.getResourceAsStream(resourceName);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class ICULocaleService extends ICUService {
|
||||
* Convenience override for callers using locales. This uses
|
||||
* createKey(ULocale.toString(), kind) to create a key, calls getKey, and then
|
||||
* if actualReturn is not null, returns the actualResult from
|
||||
* getKey (stripping any prefix) into a ULocale.
|
||||
* getKey (stripping any prefix) into a ULocale.
|
||||
*/
|
||||
public Object get(ULocale locale, int kind, ULocale[] actualReturn) {
|
||||
Key key = createKey(locale, kind);
|
||||
@ -146,7 +146,7 @@ public class ICULocaleService extends ICUService {
|
||||
}
|
||||
return locales;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A subclass of Key that implements a locale fallback mechanism.
|
||||
* The first locale to search for is the locale provided by the
|
||||
@ -157,7 +157,7 @@ public class ICULocaleService extends ICUService {
|
||||
*
|
||||
* <p>Canonicalization adjusts the locale string so that the
|
||||
* section before the first understore is in lower case, and the rest
|
||||
* is in upper case, with no trailing underscores.</p>
|
||||
* is in upper case, with no trailing underscores.</p>
|
||||
*/
|
||||
public static class LocaleKey extends ICUService.Key {
|
||||
private int kind;
|
||||
@ -174,7 +174,7 @@ public class ICULocaleService extends ICUService {
|
||||
public static LocaleKey createWithCanonicalFallback(String primaryID, String canonicalFallbackID) {
|
||||
return createWithCanonicalFallback(primaryID, canonicalFallbackID, KIND_ANY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a LocaleKey with canonical primary and fallback IDs.
|
||||
*/
|
||||
@ -185,7 +185,7 @@ public class ICULocaleService extends ICUService {
|
||||
String canonicalPrimaryID = ULocale.getName(primaryID);
|
||||
return new LocaleKey(primaryID, canonicalPrimaryID, canonicalFallbackID, kind);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a LocaleKey with canonical primary and fallback IDs.
|
||||
*/
|
||||
@ -196,7 +196,7 @@ public class ICULocaleService extends ICUService {
|
||||
String canonicalPrimaryID = locale.getName();
|
||||
return new LocaleKey(canonicalPrimaryID, canonicalPrimaryID, canonicalFallbackID, kind);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PrimaryID is the user's requested locale string,
|
||||
* canonicalPrimaryID is this string in canonical form,
|
||||
@ -248,6 +248,7 @@ public class ICULocaleService extends ICUService {
|
||||
/**
|
||||
* Return the (canonical) original ID.
|
||||
*/
|
||||
@Override
|
||||
public String canonicalID() {
|
||||
return primaryID;
|
||||
}
|
||||
@ -255,6 +256,7 @@ public class ICULocaleService extends ICUService {
|
||||
/**
|
||||
* Return the (canonical) current ID, or null if no current id.
|
||||
*/
|
||||
@Override
|
||||
public String currentID() {
|
||||
return currentID;
|
||||
}
|
||||
@ -263,6 +265,7 @@ public class ICULocaleService extends ICUService {
|
||||
* Return the (canonical) current descriptor, or null if no current id.
|
||||
* Includes the keywords, whereas the ID does not include keywords.
|
||||
*/
|
||||
@Override
|
||||
public String currentDescriptor() {
|
||||
String result = currentID();
|
||||
if (result != null) {
|
||||
@ -305,8 +308,9 @@ public class ICULocaleService extends ICUService {
|
||||
* <p>First falls back through the primary ID, then through
|
||||
* the fallbackID. The final fallback is "" (root)
|
||||
* unless the primary id was "" (root), in which case
|
||||
* there is no fallback.
|
||||
* there is no fallback.
|
||||
*/
|
||||
@Override
|
||||
public boolean fallback() {
|
||||
int x = currentID.lastIndexOf('_');
|
||||
if (x != -1) {
|
||||
@ -329,9 +333,10 @@ public class ICULocaleService extends ICUService {
|
||||
}
|
||||
|
||||
/**
|
||||
* If a key created from id would eventually fallback to match the
|
||||
* If a key created from id would eventually fallback to match the
|
||||
* canonical ID of this key, return true.
|
||||
*/
|
||||
@Override
|
||||
public boolean isFallbackOf(String id) {
|
||||
return LocaleUtility.isFallbackOf(canonicalID(), id);
|
||||
}
|
||||
@ -369,11 +374,12 @@ public class ICULocaleService extends ICUService {
|
||||
* the key against the supported IDs, and passes the canonicalLocale and
|
||||
* kind off to handleCreate (which subclasses must implement).
|
||||
*/
|
||||
@Override
|
||||
public Object create(Key key, ICUService service) {
|
||||
if (handlesKey(key)) {
|
||||
LocaleKey lkey = (LocaleKey)key;
|
||||
int kind = lkey.kind();
|
||||
|
||||
|
||||
ULocale uloc = lkey.currentLocale();
|
||||
return handleCreate(uloc, kind, service);
|
||||
} else {
|
||||
@ -395,6 +401,7 @@ public class ICULocaleService extends ICUService {
|
||||
/**
|
||||
* Override of superclass method.
|
||||
*/
|
||||
@Override
|
||||
public void updateVisibleIDs(Map<String, Factory> result) {
|
||||
Set<String> cache = getSupportedIDs();
|
||||
for (String id : cache) {
|
||||
@ -409,6 +416,7 @@ public class ICULocaleService extends ICUService {
|
||||
/**
|
||||
* Return a localized name for the locale represented by id.
|
||||
*/
|
||||
@Override
|
||||
public String getDisplayName(String id, ULocale locale) {
|
||||
// assume if the user called this on us, we must have handled some fallback of this id
|
||||
// if (isSupportedID(id)) {
|
||||
@ -432,15 +440,15 @@ public class ICULocaleService extends ICUService {
|
||||
///CLOVER:ON
|
||||
|
||||
/**
|
||||
* Return true if this id is one the factory supports (visible or
|
||||
* Return true if this id is one the factory supports (visible or
|
||||
* otherwise).
|
||||
*/
|
||||
protected boolean isSupportedID(String id) {
|
||||
return getSupportedIDs().contains(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the set of ids that this factory supports (visible or
|
||||
* Return the set of ids that this factory supports (visible or
|
||||
* otherwise). This can be called often and might need to be
|
||||
* cached if it is expensive to create.
|
||||
*/
|
||||
@ -451,6 +459,7 @@ public class ICULocaleService extends ICUService {
|
||||
/**
|
||||
* For debugging.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder(super.toString());
|
||||
if (name != null) {
|
||||
@ -478,7 +487,7 @@ public class ICULocaleService extends ICUService {
|
||||
|
||||
public SimpleLocaleKeyFactory(Object obj, ULocale locale, int kind, boolean visible, String name) {
|
||||
super(visible, name);
|
||||
|
||||
|
||||
this.obj = obj;
|
||||
this.id = locale.getBaseName();
|
||||
this.kind = kind;
|
||||
@ -487,11 +496,12 @@ public class ICULocaleService extends ICUService {
|
||||
/**
|
||||
* Returns the service object if kind/locale match. Service is not used.
|
||||
*/
|
||||
@Override
|
||||
public Object create(Key key, ICUService service) {
|
||||
if (!(key instanceof LocaleKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
LocaleKey lkey = (LocaleKey)key;
|
||||
if (kind != LocaleKey.KIND_ANY && kind != lkey.kind()) {
|
||||
return null;
|
||||
@ -499,14 +509,16 @@ public class ICULocaleService extends ICUService {
|
||||
if (!id.equals(lkey.currentID())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSupportedID(String idToCheck) {
|
||||
return this.id.equals(idToCheck);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateVisibleIDs(Map<String, Factory> result) {
|
||||
if (visible) {
|
||||
result.put(id, this);
|
||||
@ -515,6 +527,7 @@ public class ICULocaleService extends ICUService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder(super.toString());
|
||||
buf.append(", id: ");
|
||||
@ -555,13 +568,15 @@ public class ICULocaleService extends ICUService {
|
||||
/**
|
||||
* Return the supported IDs. This is the set of all locale names for the bundleName.
|
||||
*/
|
||||
@Override
|
||||
protected Set<String> getSupportedIDs() {
|
||||
return ICUResourceBundle.getFullLocaleNameSet(bundleName, loader());
|
||||
return ICUResourceBundle.getFullLocaleNameSet(bundleName, loader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of superclass method.
|
||||
*/
|
||||
@Override
|
||||
public void updateVisibleIDs(Map<String, Factory> result) {
|
||||
Set<String> visibleIDs = ICUResourceBundle.getAvailableLocaleNameSet(bundleName, loader()); // only visible ids
|
||||
for (String id : visibleIDs) {
|
||||
@ -573,6 +588,7 @@ public class ICULocaleService extends ICUService {
|
||||
* Create the service. The default implementation returns the resource bundle
|
||||
* for the locale, ignoring kind, and service.
|
||||
*/
|
||||
@Override
|
||||
protected Object handleCreate(ULocale loc, int kind, ICUService service) {
|
||||
return ICUResourceBundle.getBundleInstance(bundleName, loc, loader());
|
||||
}
|
||||
@ -581,6 +597,7 @@ public class ICULocaleService extends ICUService {
|
||||
return ClassLoaderUtil.getClassLoader(getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + ", bundle: " + bundleName;
|
||||
}
|
||||
@ -604,6 +621,7 @@ public class ICULocaleService extends ICUService {
|
||||
return fallbackLocaleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key createKey(String id) {
|
||||
return LocaleKey.createWithCanonicalFallback(id, validateFallbackLocale());
|
||||
}
|
||||
|
@ -21,12 +21,12 @@ import java.util.List;
|
||||
* eventually dequeues the list and calls notifyListener on each
|
||||
* listener in the list.</p>
|
||||
*
|
||||
* <p>Subclasses override acceptsListener and notifyListener
|
||||
* <p>Subclasses override acceptsListener and notifyListener
|
||||
* to add type-safe notification. AcceptsListener should return
|
||||
* true if the listener is of the appropriate type; ICUNotifier
|
||||
* itself will ensure the listener is non-null and that the
|
||||
* identical listener is not already registered with the Notifier.
|
||||
* NotifyListener should cast the listener to the appropriate
|
||||
* NotifyListener should cast the listener to the appropriate
|
||||
* type and call the appropriate method on the listener.
|
||||
*/
|
||||
public abstract class ICUNotifier {
|
||||
@ -39,7 +39,7 @@ public abstract class ICUNotifier {
|
||||
* The listener must not be null. AcceptsListener must return
|
||||
* true for the listener. Attempts to concurrently
|
||||
* register the identical listener more than once will be
|
||||
* silently ignored.
|
||||
* silently ignored.
|
||||
*/
|
||||
public void addListener(EventListener l) {
|
||||
if (l == null) {
|
||||
@ -137,6 +137,7 @@ public abstract class ICUNotifier {
|
||||
* Wait for a notification to be queued, then notify all
|
||||
* listeners listed in the notification.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
EventListener[] list;
|
||||
while (true) {
|
||||
|
@ -88,9 +88,10 @@ public class ICURWLock {
|
||||
/**
|
||||
* Return a string listing all the stats.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return " rc: " + _rc +
|
||||
" mrc: " + _mrc +
|
||||
" mrc: " + _mrc +
|
||||
" wrc: " + _wrc +
|
||||
" wc: " + _wc +
|
||||
" wwc: " + _wwc;
|
||||
@ -114,7 +115,7 @@ public class ICURWLock {
|
||||
stats = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a snapshot of the current stats. This does not reset the stats.
|
||||
*/
|
||||
@ -130,7 +131,7 @@ public class ICURWLock {
|
||||
* <p>If there's a writer, or a waiting writer, increment the
|
||||
* waiting reader count and block on this. Otherwise
|
||||
* increment the active reader count and return. Caller must call
|
||||
* releaseRead when done (for example, in a finally block).</p>
|
||||
* releaseRead when done (for example, in a finally block).</p>
|
||||
*/
|
||||
public void acquireRead() {
|
||||
if (stats != null) { // stats is null by default
|
||||
@ -168,7 +169,7 @@ public class ICURWLock {
|
||||
* having an active writer and return. Otherwise, add a lock to the
|
||||
* end of the waiting writer list, and block on it. Caller
|
||||
* must call releaseWrite when done (for example, in a finally
|
||||
* block).<p>
|
||||
* block).<p>
|
||||
*/
|
||||
public void acquireWrite() {
|
||||
if (stats != null) { // stats is null by default
|
||||
@ -189,7 +190,7 @@ public class ICURWLock {
|
||||
* <p>If there are waiting readers, make them all active and
|
||||
* notify all of them. Otherwise, notify the oldest waiting
|
||||
* writer, if any. Call when finished with work controlled by
|
||||
* acquireWrite.</p>
|
||||
* acquireWrite.</p>
|
||||
*/
|
||||
public void releaseWrite() {
|
||||
rwl.writeLock().unlock();
|
||||
|
@ -297,6 +297,7 @@ public class ICUService extends ICUNotifier {
|
||||
* Return the service instance if the factory's id is equal to
|
||||
* the key's currentID. Service is ignored.
|
||||
*/
|
||||
@Override
|
||||
public Object create(Key key, ICUService service) {
|
||||
if (id.equals(key.currentID())) {
|
||||
return instance;
|
||||
@ -308,6 +309,7 @@ public class ICUService extends ICUNotifier {
|
||||
* If visible, adds a mapping from id -> this to the result,
|
||||
* otherwise removes id from result.
|
||||
*/
|
||||
@Override
|
||||
public void updateVisibleIDs(Map<String, Factory> result) {
|
||||
if (visible) {
|
||||
result.put(id, this);
|
||||
@ -321,6 +323,7 @@ public class ICUService extends ICUNotifier {
|
||||
* otherwise returns null. (This default implementation has
|
||||
* no localized id information.)
|
||||
*/
|
||||
@Override
|
||||
public String getDisplayName(String identifier, ULocale locale) {
|
||||
return (visible && id.equals(identifier)) ? identifier : null;
|
||||
}
|
||||
@ -328,6 +331,7 @@ public class ICUService extends ICUNotifier {
|
||||
/**
|
||||
* For debugging.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder(super.toString());
|
||||
buf.append(", id: ");
|
||||
@ -625,12 +629,12 @@ public class ICUService extends ICUNotifier {
|
||||
return f.getDisplayName(id, locale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience override of getDisplayNames(ULocale, Comparator, String) that
|
||||
* Convenience override of getDisplayNames(ULocale, Comparator, String) that
|
||||
* uses the current default Locale as the locale, null as
|
||||
* the comparator, and null for the matchID.
|
||||
*/
|
||||
@ -685,7 +689,7 @@ public class ICUService extends ICUNotifier {
|
||||
synchronized (this) {
|
||||
if (ref == dnref || dnref == null) {
|
||||
dncache = new TreeMap<String, String>(com); // sorted
|
||||
|
||||
|
||||
Map<String, Factory> m = getVisibleIDMap();
|
||||
Iterator<Entry<String, Factory>> ei = m.entrySet().iterator();
|
||||
while (ei.hasNext()) {
|
||||
@ -923,6 +927,7 @@ public class ICUService extends ICUNotifier {
|
||||
* requires a ServiceListener. Subclasses can override to accept
|
||||
* different listeners.
|
||||
*/
|
||||
@Override
|
||||
protected boolean acceptsListener(EventListener l) {
|
||||
return l instanceof ServiceListener;
|
||||
}
|
||||
@ -931,6 +936,7 @@ public class ICUService extends ICUNotifier {
|
||||
* Notify the listener, which by default is a ServiceListener.
|
||||
* Subclasses can override to use a different listener.
|
||||
*/
|
||||
@Override
|
||||
protected void notifyListener(EventListener l) {
|
||||
((ServiceListener)l).serviceChanged(this);
|
||||
}
|
||||
@ -959,6 +965,7 @@ public class ICUService extends ICUNotifier {
|
||||
/**
|
||||
* Returns the result of super.toString, appending the name in curly braces.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + "{" + name + "}";
|
||||
}
|
||||
|
@ -18,17 +18,18 @@ public class IllegalIcuArgumentException extends IllegalArgumentException {
|
||||
public IllegalIcuArgumentException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
|
||||
public IllegalIcuArgumentException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
|
||||
public IllegalIcuArgumentException(String errorMessage, Throwable cause) {
|
||||
super(errorMessage, cause);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized IllegalIcuArgumentException initCause(Throwable cause) {
|
||||
return (IllegalIcuArgumentException) super.initCause(cause);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ public class IntTrie extends Trie
|
||||
|
||||
/**
|
||||
* <p>Creates a new Trie with the settings for the trie data.</p>
|
||||
* <p>Unserialize the 32-bit-aligned input stream and use the data for the
|
||||
* <p>Unserialize the 32-bit-aligned input stream and use the data for the
|
||||
* trie.</p>
|
||||
* @param bytes file buffer to a ICU data file, containing the trie
|
||||
* @param dataManipulate object which provides methods to parse the char
|
||||
* @param dataManipulate object which provides methods to parse the char
|
||||
* data
|
||||
* @throws IOException thrown when data reading fails
|
||||
*/
|
||||
@ -122,7 +122,7 @@ public class IntTrie extends Trie
|
||||
// fastpath for U+0000..U+D7FF
|
||||
if(0 <= ch && ch < UTF16.LEAD_SURROGATE_MIN_VALUE) {
|
||||
// copy of getRawOffset()
|
||||
offset = (m_index_[ch >> INDEX_STAGE_1_SHIFT_] << INDEX_STAGE_2_SHIFT_)
|
||||
offset = (m_index_[ch >> INDEX_STAGE_1_SHIFT_] << INDEX_STAGE_2_SHIFT_)
|
||||
+ (ch & INDEX_STAGE_3_MASK_);
|
||||
return m_data_[offset];
|
||||
}
|
||||
@ -202,15 +202,15 @@ public class IntTrie extends Trie
|
||||
}
|
||||
return m_initialValue_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Gets the latin 1 fast path value.</p>
|
||||
* <p>Note this only works if latin 1 characters have their own linear
|
||||
* <p>Note this only works if latin 1 characters have their own linear
|
||||
* array.</p>
|
||||
* @param ch latin 1 characters
|
||||
* @return value associated with latin character
|
||||
*/
|
||||
public final int getLatin1LinearValue(char ch)
|
||||
public final int getLatin1LinearValue(char ch)
|
||||
{
|
||||
return m_data_[INDEX_STAGE_3_MASK_ + 1 + ch];
|
||||
}
|
||||
@ -222,7 +222,8 @@ public class IntTrie extends Trie
|
||||
* otherwise
|
||||
*/
|
||||
///CLOVER:OFF
|
||||
public boolean equals(Object other)
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
boolean result = super.equals(other);
|
||||
if (result && other instanceof IntTrie) {
|
||||
@ -235,13 +236,14 @@ public class IntTrie extends Trie
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
assert false : "hashCode not designed";
|
||||
return 42;
|
||||
}
|
||||
///CLOVER:ON
|
||||
|
||||
|
||||
// protected methods -----------------------------------------------
|
||||
|
||||
/**
|
||||
@ -249,6 +251,7 @@ public class IntTrie extends Trie
|
||||
* data array</p>
|
||||
* @param bytes data buffer containing trie data
|
||||
*/
|
||||
@Override
|
||||
protected final void unserialize(ByteBuffer bytes)
|
||||
{
|
||||
super.unserialize(bytes);
|
||||
@ -263,6 +266,7 @@ public class IntTrie extends Trie
|
||||
* @param trail trailing surrogate
|
||||
* @return offset to data
|
||||
*/
|
||||
@Override
|
||||
protected final int getSurrogateOffset(char lead, char trail)
|
||||
{
|
||||
if (m_dataManipulate_ == null) {
|
||||
@ -281,7 +285,7 @@ public class IntTrie extends Trie
|
||||
// value: m_initialValue_
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value at the argument index.
|
||||
* For use internally in TrieIterator
|
||||
@ -289,22 +293,24 @@ public class IntTrie extends Trie
|
||||
* @return 32 bit value
|
||||
* @see com.ibm.icu.impl.TrieIterator
|
||||
*/
|
||||
@Override
|
||||
protected final int getValue(int index)
|
||||
{
|
||||
return m_data_[index];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the default initial value
|
||||
* @return 32 bit value
|
||||
* @return 32 bit value
|
||||
*/
|
||||
@Override
|
||||
protected final int getInitialValue()
|
||||
{
|
||||
return m_initialValue_;
|
||||
}
|
||||
|
||||
// package private methods -----------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Internal constructor for builder use
|
||||
* @param index the index array to be slotted into this trie
|
||||
@ -321,7 +327,7 @@ public class IntTrie extends Trie
|
||||
m_dataLength_ = m_data_.length;
|
||||
m_initialValue_ = initialvalue;
|
||||
}
|
||||
|
||||
|
||||
// private data members --------------------------------------------
|
||||
|
||||
/**
|
||||
|
@ -32,6 +32,7 @@ public class IterableComparator<T> implements Comparator<Iterable<T>> {
|
||||
this.shorterFirst = shorterFirst ? 1 : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Iterable<T> a, Iterable<T> b) {
|
||||
if (a == null) {
|
||||
return b == null ? 0 : -shorterFirst;
|
||||
|
@ -637,10 +637,12 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
|
||||
path, locale.getBaseName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ULocale getLocale() {
|
||||
return bundle.getULocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String tableName, String subTableName, String code) {
|
||||
return ICUResourceTableAccess.getTableString(bundle, tableName, subTableName,
|
||||
code, nullIfNotFound ? null : code);
|
||||
@ -654,6 +656,7 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames {
|
||||
return (DataTables) Class.forName(className).newInstance();
|
||||
} catch (Throwable t) {
|
||||
return new DataTables() {
|
||||
@Override
|
||||
public DataTable get(ULocale locale, boolean nullIfNotFound) {
|
||||
return new DataTable(nullIfNotFound);
|
||||
}
|
||||
|
@ -21,22 +21,22 @@ import com.ibm.icu.impl.locale.AsciiUtil;
|
||||
* Utility class to parse and normalize locale ids (including POSIX style)
|
||||
*/
|
||||
public final class LocaleIDParser {
|
||||
|
||||
|
||||
/**
|
||||
* Char array representing the locale ID.
|
||||
*/
|
||||
private char[] id;
|
||||
|
||||
|
||||
/**
|
||||
* Current position in {@link #id} (while parsing).
|
||||
*/
|
||||
private int index;
|
||||
|
||||
|
||||
/**
|
||||
* Temporary buffer for parsed sections of data.
|
||||
*/
|
||||
private StringBuilder buffer;
|
||||
|
||||
|
||||
// um, don't handle POSIX ids unless we request it. why not? well... because.
|
||||
private boolean canonicalize;
|
||||
private boolean hadCountry;
|
||||
@ -73,14 +73,14 @@ public final class LocaleIDParser {
|
||||
}
|
||||
|
||||
// utilities for working on text in the buffer
|
||||
|
||||
|
||||
/**
|
||||
* Append c to the buffer.
|
||||
*/
|
||||
private void append(char c) {
|
||||
buffer.append(c);
|
||||
}
|
||||
|
||||
|
||||
private void addSeparator() {
|
||||
append(UNDERSCORE);
|
||||
}
|
||||
@ -194,7 +194,7 @@ public final class LocaleIDParser {
|
||||
*/
|
||||
private int parseLanguage() {
|
||||
int startLength = buffer.length();
|
||||
|
||||
|
||||
if (haveExperimentalLanguagePrefix()) {
|
||||
append(AsciiUtil.toLower(id[0]));
|
||||
append(HYPHEN);
|
||||
@ -280,7 +280,7 @@ public final class LocaleIDParser {
|
||||
if (!atTerminator()) {
|
||||
int oldIndex = index;
|
||||
++index;
|
||||
|
||||
|
||||
char c;
|
||||
while (!isTerminatorOrIDSeparator(c = next()) && AsciiUtil.isAlpha(c));
|
||||
--index;
|
||||
@ -397,7 +397,7 @@ public final class LocaleIDParser {
|
||||
boolean skipping = false;
|
||||
char c;
|
||||
boolean firstPass = true;
|
||||
|
||||
|
||||
while ((c = next()) != DONE) {
|
||||
if (c == DOT) {
|
||||
start = false;
|
||||
@ -591,6 +591,7 @@ public final class LocaleIDParser {
|
||||
|
||||
private Comparator<String> getKeyComparator() {
|
||||
final Comparator<String> comp = new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String lhs, String rhs) {
|
||||
return lhs.compareTo(rhs);
|
||||
}
|
||||
|
@ -342,6 +342,7 @@ public final class Norm2AllModes {
|
||||
}
|
||||
private static CacheBase<String, Norm2AllModes, ByteBuffer> cache =
|
||||
new SoftCache<String, Norm2AllModes, ByteBuffer>() {
|
||||
@Override
|
||||
protected Norm2AllModes createInstance(String key, ByteBuffer bytes) {
|
||||
Normalizer2Impl impl;
|
||||
if(bytes==null) {
|
||||
|
@ -206,6 +206,7 @@ public final class Normalizer2Impl {
|
||||
// They assume that the cc or trailCC of their input is 0.
|
||||
// Most of them implement Appendable interface methods.
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public ReorderingBuffer append(char c) {
|
||||
str.append(c);
|
||||
lastCC=0;
|
||||
@ -218,6 +219,7 @@ public final class Normalizer2Impl {
|
||||
reorderStart=str.length();
|
||||
}
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public ReorderingBuffer append(CharSequence s) {
|
||||
if(s.length()!=0) {
|
||||
str.append(s);
|
||||
@ -227,6 +229,7 @@ public final class Normalizer2Impl {
|
||||
return this;
|
||||
}
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public ReorderingBuffer append(CharSequence s, int start, int limit) {
|
||||
if(start!=limit) {
|
||||
str.append(s, start, limit);
|
||||
@ -413,6 +416,7 @@ public final class Normalizer2Impl {
|
||||
|
||||
private static final class IsAcceptable implements ICUBinary.Authenticate {
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[]) {
|
||||
return version[0]==2;
|
||||
}
|
||||
@ -560,6 +564,7 @@ public final class Normalizer2Impl {
|
||||
}
|
||||
}
|
||||
private static final Trie2.ValueMapper segmentStarterMapper=new Trie2.ValueMapper() {
|
||||
@Override
|
||||
public int map(int in) {
|
||||
return in&CANON_NOT_SEGMENT_STARTER;
|
||||
}
|
||||
@ -1829,7 +1834,7 @@ public final class Normalizer2Impl {
|
||||
}
|
||||
if(key1==(firstUnit&COMP_1_TRAIL_MASK)) {
|
||||
if((firstUnit&COMP_1_TRIPLE)!=0) {
|
||||
return ((int)compositions.charAt(list+1)<<16)|compositions.charAt(list+2);
|
||||
return (compositions.charAt(list+1)<<16)|compositions.charAt(list+2);
|
||||
} else {
|
||||
return compositions.charAt(list+1);
|
||||
}
|
||||
@ -1874,7 +1879,7 @@ public final class Normalizer2Impl {
|
||||
compositeAndFwd=maybeYesCompositions.charAt(list+1);
|
||||
list+=2;
|
||||
} else {
|
||||
compositeAndFwd=(((int)maybeYesCompositions.charAt(list+1)&~COMP_2_TRAIL_MASK)<<16)|
|
||||
compositeAndFwd=((maybeYesCompositions.charAt(list+1)&~COMP_2_TRAIL_MASK)<<16)|
|
||||
maybeYesCompositions.charAt(list+2);
|
||||
list+=3;
|
||||
}
|
||||
|
@ -45,52 +45,52 @@ import com.ibm.icu.util.UResourceBundle;
|
||||
*
|
||||
* a. Zone (table). A zone is a table resource contains several
|
||||
* type of resources below:
|
||||
*
|
||||
*
|
||||
* - typeOffsets:intvector (Required)
|
||||
*
|
||||
*
|
||||
* Sets of UTC raw/dst offset pairs in seconds. Entries at
|
||||
* 2n represents raw offset and 2n+1 represents dst offset
|
||||
* paired with the raw offset at 2n. The very first pair represents
|
||||
* the initial zone offset (before the first transition) always.
|
||||
*
|
||||
* - trans:intvector (Optional)
|
||||
*
|
||||
* - trans:intvector (Optional)
|
||||
*
|
||||
* List of transition times represented by 32bit seconds from the
|
||||
* epoch (1970-01-01T00:00Z) in ascending order.
|
||||
*
|
||||
*
|
||||
* - transPre32/transPost32:intvector (Optional)
|
||||
*
|
||||
*
|
||||
* List of transition times before/after 32bit minimum seconds.
|
||||
* Each time is represented by a pair of 32bit integer.
|
||||
*
|
||||
*
|
||||
* - typeMap:bin (Optional)
|
||||
*
|
||||
*
|
||||
* Array of bytes representing the mapping between each transition
|
||||
* time (transPre32/trans/transPost32) and its corresponding offset
|
||||
* data (typeOffsets).
|
||||
*
|
||||
*
|
||||
* - finalRule:string (Optional)
|
||||
*
|
||||
*
|
||||
* If a recurrent transition rule is applicable to a zone forever
|
||||
* after the final transition time, finalRule represents the rule
|
||||
* in Rules data.
|
||||
*
|
||||
*
|
||||
* - finalRaw:int (Optional)
|
||||
*
|
||||
*
|
||||
* When finalRule is available, finalRaw is required and specifies
|
||||
* the raw (base) offset of the rule.
|
||||
*
|
||||
*
|
||||
* - finalYear:int (Optional)
|
||||
*
|
||||
*
|
||||
* When finalRule is available, finalYear is required and specifies
|
||||
* the start year of the rule.
|
||||
*
|
||||
*
|
||||
* - links:intvector (Optional)
|
||||
*
|
||||
*
|
||||
* When this zone data is shared with other zones, links specifies
|
||||
* all zones including the zone itself. Each zone is referenced by
|
||||
* integer index.
|
||||
*
|
||||
*
|
||||
* b. Link (int, length 1). A link zone is an int resource. The
|
||||
* integer is the zone number of the target zone. The key of this
|
||||
* resource is an alternate name for the target zone. This data
|
||||
@ -317,8 +317,8 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
int[] fields = Grego.timeToFields(current, null);
|
||||
|
||||
// Find start of this year, and start of next year
|
||||
long start = Grego.fieldsToDay(fields[0], 0, 1) * SECONDS_PER_DAY;
|
||||
long limit = Grego.fieldsToDay(fields[0] + 1, 0, 1) * SECONDS_PER_DAY;
|
||||
long start = Grego.fieldsToDay(fields[0], 0, 1) * SECONDS_PER_DAY;
|
||||
long limit = Grego.fieldsToDay(fields[0] + 1, 0, 1) * SECONDS_PER_DAY;
|
||||
|
||||
// Return TRUE if DST is observed at any time during the current
|
||||
// year.
|
||||
@ -485,7 +485,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
}
|
||||
|
||||
private void construct(UResourceBundle top, UResourceBundle res){
|
||||
|
||||
|
||||
if ((top == null || res == null)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
@ -537,21 +537,21 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
int idx = 0;
|
||||
if (transPre32 != null) {
|
||||
for (int i = 0; i < transPre32.length / 2; i++, idx++) {
|
||||
transitionTimes64[idx] =
|
||||
(((long)transPre32[i * 2]) & 0x00000000FFFFFFFFL) << 32
|
||||
| (((long)transPre32[i * 2 + 1]) & 0x00000000FFFFFFFFL);
|
||||
transitionTimes64[idx] =
|
||||
((transPre32[i * 2]) & 0x00000000FFFFFFFFL) << 32
|
||||
| ((transPre32[i * 2 + 1]) & 0x00000000FFFFFFFFL);
|
||||
}
|
||||
}
|
||||
if (trans32 != null) {
|
||||
for (int i = 0; i < trans32.length; i++, idx++) {
|
||||
transitionTimes64[idx] = (long)trans32[i];
|
||||
transitionTimes64[idx] = trans32[i];
|
||||
}
|
||||
}
|
||||
if (transPost32 != null) {
|
||||
for (int i = 0; i < transPost32.length / 2; i++, idx++) {
|
||||
transitionTimes64[idx] =
|
||||
(((long)transPost32[i * 2]) & 0x00000000FFFFFFFFL) << 32
|
||||
| (((long)transPost32[i * 2 + 1]) & 0x00000000FFFFFFFFL);
|
||||
transitionTimes64[idx] =
|
||||
((transPost32[i * 2]) & 0x00000000FFFFFFFFL) << 32
|
||||
| ((transPost32[i * 2 + 1]) & 0x00000000FFFFFFFFL);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -607,7 +607,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
finalStartYear = r.getInt();
|
||||
|
||||
// Note: Setting finalStartYear to the finalZone is problematic. When a date is around
|
||||
// year boundary, SimpleTimeZone may return false result when DST is observed at the
|
||||
// year boundary, SimpleTimeZone may return false result when DST is observed at the
|
||||
// beginning of year. We could apply safe margin (day or two), but when one of recurrent
|
||||
// rules falls around year boundary, it could return false result. Without setting the
|
||||
// start year, finalZone works fine around the year boundary of the start year.
|
||||
@ -747,7 +747,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
}
|
||||
|
||||
private int getInt(byte val){
|
||||
return val & 0xFF;
|
||||
return val & 0xFF;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -827,7 +827,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
buf.append(",finalStartMillis=" + finalStartMillis);
|
||||
buf.append(",finalZone=" + finalZone);
|
||||
buf.append(']');
|
||||
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@ -874,7 +874,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
* If and only if finalYear == INT32_MAX then finalZone == 0.
|
||||
*/
|
||||
private SimpleTimeZone finalZone = null; // owned, may be NULL
|
||||
|
||||
|
||||
/**
|
||||
* The canonical ID of this zone. Initialized when {@link #getCanonicalID()}
|
||||
* is invoked first time, or {@link #setID(String)} is called.
|
||||
@ -885,7 +885,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
|
||||
private static final boolean DEBUG = ICUDebug.enabled("olson");
|
||||
private static final int SECONDS_PER_DAY = 24*60*60;
|
||||
|
||||
|
||||
private static UResourceBundle loadRule(UResourceBundle top, String ruleid) {
|
||||
UResourceBundle r = top.get("Rules");
|
||||
r = r.get(ruleid);
|
||||
@ -919,9 +919,9 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
public int hashCode(){
|
||||
int ret = (int) (finalStartYear ^ (finalStartYear>>>4) +
|
||||
transitionCount ^ (transitionCount>>>6) +
|
||||
typeCount ^ (typeCount>>>8) +
|
||||
typeCount ^ (typeCount>>>8) +
|
||||
Double.doubleToLongBits(finalStartMillis)+
|
||||
(finalZone == null ? 0 : finalZone.hashCode()) +
|
||||
(finalZone == null ? 0 : finalZone.hashCode()) +
|
||||
super.hashCode());
|
||||
if (transitionTimes64 != null) {
|
||||
for(int i=0; i<transitionTimes64.length; i++){
|
||||
@ -934,7 +934,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
if (typeMapData != null) {
|
||||
for(int i=0; i<typeMapData.length; i++){
|
||||
ret+=typeMapData[i] & 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -1010,7 +1010,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
return finalZoneWithStartYear.getPreviousTransition(base, inclusive);
|
||||
} else {
|
||||
return firstFinalTZTransition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1091,7 +1091,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
} else {
|
||||
// Create a TimeArrayTimeZoneRule at finalMillis
|
||||
rules[idx++] = new TimeArrayTimeZoneRule(getID() + "(STD)", finalZone.getRawOffset(), 0,
|
||||
new long[] {(long)finalStartMillis}, DateTimeRule.UTC_TIME);
|
||||
new long[] {(long)finalStartMillis}, DateTimeRule.UTC_TIME);
|
||||
}
|
||||
}
|
||||
return rules;
|
||||
@ -1175,7 +1175,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
typeIdx = getInt(typeMapData[firstTZTransitionIdx]);
|
||||
firstTZTransition = new TimeZoneTransition(transitionTimes64[firstTZTransitionIdx] * Grego.MILLIS_PER_SECOND,
|
||||
initialRule, historicRules[typeIdx]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1268,6 +1268,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.icu.util.TimeZone#isFrozen()
|
||||
*/
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
return isFrozen;
|
||||
}
|
||||
@ -1275,6 +1276,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.icu.util.TimeZone#freeze()
|
||||
*/
|
||||
@Override
|
||||
public TimeZone freeze() {
|
||||
isFrozen = true;
|
||||
return this;
|
||||
@ -1283,6 +1285,7 @@ public class OlsonTimeZone extends BasicTimeZone {
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.icu.util.TimeZone#cloneAsThawed()
|
||||
*/
|
||||
@Override
|
||||
public TimeZone cloneAsThawed() {
|
||||
OlsonTimeZone tz = (OlsonTimeZone)super.cloneAsThawed();
|
||||
if (finalZone != null) {
|
||||
|
@ -19,17 +19,21 @@ public class PVecToTrieCompactHandler implements CompactHandler {
|
||||
public IntTrieBuilder builder;
|
||||
public int initialValue;
|
||||
|
||||
@Override
|
||||
public void setRowIndexForErrorValue(int rowIndex) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRowIndexForInitialValue(int rowIndex) {
|
||||
initialValue = rowIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRowIndexForRange(int start, int end, int rowIndex) {
|
||||
builder.setRange(start, end + 1, rowIndex, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startRealValues(int rowIndex) {
|
||||
if (rowIndex > 0xffff) {
|
||||
// too many rows for a 16-bit trie
|
||||
@ -37,6 +41,6 @@ public class PVecToTrieCompactHandler implements CompactHandler {
|
||||
} else {
|
||||
builder = new IntTrieBuilder(null, 100000, initialValue,
|
||||
initialValue, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@
|
||||
|
||||
/**
|
||||
* Store bits (Unicode character properties) in bit set vectors.
|
||||
*
|
||||
*
|
||||
* This is a port of the C++ class UPropsVectors from ICU4C
|
||||
*
|
||||
*
|
||||
* @author Shaopeng Jia
|
||||
* @internal
|
||||
*/
|
||||
@ -23,15 +23,15 @@ import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Unicode Properties Vectors associated with code point ranges.
|
||||
*
|
||||
*
|
||||
* Rows of primitive integers in a contiguous array store the range limits and
|
||||
* the properties vectors.
|
||||
*
|
||||
*
|
||||
* In each row, row[0] contains the start code point and row[1] contains the
|
||||
* limit code point, which is the start of the next range.
|
||||
*
|
||||
*
|
||||
* Initially, there is only one range [0..0x110000] with values 0.
|
||||
*
|
||||
*
|
||||
* It would be possible to store only one range boundary per row, but
|
||||
* self-contained rows allow to later sort them by contents.
|
||||
*/
|
||||
@ -45,10 +45,10 @@ public class PropsVectors {
|
||||
private boolean isCompacted;
|
||||
|
||||
// internal function to compare elements in v and target. Return true iff
|
||||
// elements in v starting from index1 to index1 + length - 1
|
||||
// elements in v starting from index1 to index1 + length - 1
|
||||
// are exactly the same as elements in target
|
||||
// starting from index2 to index2 + length - 1
|
||||
private boolean areElementsSame(int index1, int[] target, int index2,
|
||||
private boolean areElementsSame(int index1, int[] target, int index2,
|
||||
int length) {
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if (v[index1 + i] != target[index2 + i]) {
|
||||
@ -57,7 +57,7 @@ public class PropsVectors {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// internal function which given rangeStart, returns
|
||||
// index where v[index]<=rangeStart<v[index+1].
|
||||
// The returned index is a multiple of columns, and therefore
|
||||
@ -165,11 +165,11 @@ public class PropsVectors {
|
||||
/*
|
||||
* In rows for code points [start..end], select the column, reset the mask
|
||||
* bits and set the value bits (ANDed with the mask).
|
||||
*
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
*
|
||||
*
|
||||
* @throws IndexOutOfBoundsException
|
||||
*/
|
||||
public void setValue(int start, int end, int column, int value, int mask) {
|
||||
@ -290,7 +290,7 @@ public class PropsVectors {
|
||||
|
||||
/*
|
||||
* Returns an array which contains value elements
|
||||
* in row rowIndex.
|
||||
* in row rowIndex.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* @throws IllegalArgumentException
|
||||
@ -312,9 +312,9 @@ public class PropsVectors {
|
||||
/*
|
||||
* Returns an int which is the start codepoint
|
||||
* in row rowIndex.
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
*
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public int getRowStart(int rowIndex) {
|
||||
@ -329,11 +329,11 @@ public class PropsVectors {
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns an int which is the limit codepoint
|
||||
* Returns an int which is the limit codepoint
|
||||
* minus 1 in row rowIndex.
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
*
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public int getRowEnd(int rowIndex) {
|
||||
@ -346,23 +346,23 @@ public class PropsVectors {
|
||||
}
|
||||
return v[rowIndex * columns + 1] - 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Compact the vectors:
|
||||
* - modify the memory
|
||||
* - keep only unique vectors
|
||||
* - store them contiguously from the beginning of the memory
|
||||
* - for each (non-unique) row, call the respective function in
|
||||
* - for each (non-unique) row, call the respective function in
|
||||
* CompactHandler
|
||||
*
|
||||
* The handler's rowIndex is the index of the row in the compacted
|
||||
* memory block. Therefore, it starts at 0 increases in increments of the
|
||||
* memory block. Therefore, it starts at 0 increases in increments of the
|
||||
* columns value.
|
||||
*
|
||||
* In a first phase, only special values are delivered (each exactly once).
|
||||
* Then CompactHandler::startRealValues() is called
|
||||
* where rowIndex is the length of the compacted array.
|
||||
* Then, in the second phase, the CompactHandler::setRowIndexForRange() is
|
||||
* Then, in the second phase, the CompactHandler::setRowIndexForRange() is
|
||||
* called for each row of real values.
|
||||
*/
|
||||
public void compact(CompactHandler compactor) {
|
||||
@ -382,6 +382,7 @@ public class PropsVectors {
|
||||
}
|
||||
|
||||
Arrays.sort(indexArray, new Comparator<Integer>() {
|
||||
@Override
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
int indexOfRow1 = o1.intValue();
|
||||
int indexOfRow2 = o2.intValue();
|
||||
@ -436,10 +437,10 @@ public class PropsVectors {
|
||||
compactor.startRealValues(count);
|
||||
|
||||
/*
|
||||
* Move vector contents up to a contiguous array with only unique
|
||||
* Move vector contents up to a contiguous array with only unique
|
||||
* vector values, and call the handler function for each vector.
|
||||
*
|
||||
* This destroys the Properties Vector structure and replaces it
|
||||
*
|
||||
* This destroys the Properties Vector structure and replaces it
|
||||
* with an array of just vector values.
|
||||
*/
|
||||
int[] temp = new int[count];
|
||||
@ -450,7 +451,7 @@ public class PropsVectors {
|
||||
|
||||
// count a new values vector if it is different
|
||||
// from the current one
|
||||
if (count < 0 || !areElementsSame(indexArray[i].intValue() + 2,
|
||||
if (count < 0 || !areElementsSame(indexArray[i].intValue() + 2,
|
||||
temp, count, valueColumns)) {
|
||||
count += valueColumns;
|
||||
System.arraycopy(v, indexArray[i].intValue() + 2, temp, count,
|
||||
@ -462,7 +463,7 @@ public class PropsVectors {
|
||||
}
|
||||
}
|
||||
v = temp;
|
||||
|
||||
|
||||
// count is at the beginning of the last vector,
|
||||
// add one to include that last vector
|
||||
rows = count / valueColumns + 1;
|
||||
@ -470,7 +471,7 @@ public class PropsVectors {
|
||||
|
||||
/*
|
||||
* Get the vectors array after calling compact().
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public int[] getCompactedArray() {
|
||||
@ -483,7 +484,7 @@ public class PropsVectors {
|
||||
|
||||
/*
|
||||
* Get the number of rows for the compacted array.
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public int getCompactedRows() {
|
||||
@ -496,7 +497,7 @@ public class PropsVectors {
|
||||
|
||||
/*
|
||||
* Get the number of columns for the compacted array.
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public int getCompactedColumns() {
|
||||
@ -520,6 +521,7 @@ public class PropsVectors {
|
||||
|
||||
// inner class implementation of Trie.DataManipulate
|
||||
private static class DefaultGetFoldingOffset implements Trie.DataManipulate {
|
||||
@Override
|
||||
public int getFoldingOffset(int value) {
|
||||
return value;
|
||||
}
|
||||
@ -534,8 +536,9 @@ public class PropsVectors {
|
||||
builder = inBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFoldedValue(int start, int offset) {
|
||||
int initialValue = builder.m_initialValue_;
|
||||
int initialValue = builder.m_initialValue_;
|
||||
int limit = start + 0x400;
|
||||
while (start < limit) {
|
||||
boolean[] inBlockZero = new boolean[1];
|
||||
@ -551,7 +554,7 @@ public class PropsVectors {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static interface CompactHandler {
|
||||
public void setRowIndexForRange(int start, int end, int rowIndex);
|
||||
public void setRowIndexForInitialValue(int rowIndex);
|
||||
|
@ -57,7 +57,7 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
this.setCreator.newInstance(setComparatorParam); // check to make sure compiles
|
||||
} else {
|
||||
this.setCreator = ((Class<? extends Set<V>>)setCreator).getConstructor(Comparator.class);
|
||||
this.setCreator.newInstance(setComparatorParam); // check to make sure compiles
|
||||
this.setCreator.newInstance(setComparatorParam); // check to make sure compiles
|
||||
}
|
||||
data = map == null ? new HashMap<K, Set<V>>() : map;
|
||||
} catch (Exception e) {
|
||||
@ -85,11 +85,11 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
public final Set<Entry<K, V>> entrySet() {
|
||||
return keyValueSet();
|
||||
}
|
||||
|
||||
|
||||
public Set<Entry<K, Set<V>>> keyValuesSet() {
|
||||
return data.entrySet();
|
||||
}
|
||||
|
||||
|
||||
public Set<Entry<K, V>> keyValueSet() {
|
||||
Set<Entry<K, V>> result = new LinkedHashSet<Entry<K, V>>();
|
||||
for (K key : data.keySet()) {
|
||||
@ -100,6 +100,7 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null)
|
||||
return false;
|
||||
@ -123,6 +124,7 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
return data.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return data.hashCode();
|
||||
}
|
||||
@ -163,7 +165,7 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
|
||||
private Set<V> newSet() {
|
||||
try {
|
||||
return (Set<V>) setCreator.newInstance(setComparatorParam);
|
||||
return setCreator.newInstance(setComparatorParam);
|
||||
} catch (Exception e) {
|
||||
throw (RuntimeException) new IllegalArgumentException("Can't create new set").initCause(e);
|
||||
}
|
||||
@ -222,6 +224,7 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return data.toString();
|
||||
}
|
||||
@ -241,14 +244,17 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
this.value = e.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
V oldValue = this.value;
|
||||
this.value = value;
|
||||
@ -274,10 +280,12 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
|
||||
volatile boolean frozen = false;
|
||||
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Relation<K, V> freeze() {
|
||||
if (!frozen) {
|
||||
// does not handle one level down, so we do that on a case-by-case basis
|
||||
@ -291,6 +299,7 @@ public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add ,
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Relation<K, V> cloneAsThawed() {
|
||||
// TODO do later
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -26,7 +26,7 @@ import com.ibm.icu.text.UTF16;
|
||||
public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
|
||||
// public constructor ------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Public constructor
|
||||
* @param replaceable text which the iterator will be based on
|
||||
@ -38,7 +38,7 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
this.replaceable = replaceable;
|
||||
this.currentIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Public constructor
|
||||
* @param str text which the iterator will be based on
|
||||
@ -50,7 +50,7 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
this.replaceable = new ReplaceableString(str);
|
||||
this.currentIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Public constructor
|
||||
* @param buf buffer of text on which the iterator will be based
|
||||
@ -62,14 +62,15 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
this.replaceable = new ReplaceableString(buf);
|
||||
this.currentIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
// public methods ----------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Creates a copy of this iterator, does not clone the underlying
|
||||
* Creates a copy of this iterator, does not clone the underlying
|
||||
* <code>Replaceable</code>object
|
||||
* @return copy of this iterator
|
||||
*/
|
||||
@Override
|
||||
public Object clone(){
|
||||
try {
|
||||
return super.clone();
|
||||
@ -77,37 +78,39 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
return null; // never invoked
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current UTF16 character.
|
||||
* @return current UTF16 character
|
||||
*/
|
||||
@Override
|
||||
public int current(){
|
||||
if (currentIndex < replaceable.length()) {
|
||||
return replaceable.charAt(currentIndex);
|
||||
}
|
||||
return DONE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current codepoint
|
||||
* @return current codepoint
|
||||
*/
|
||||
@Override
|
||||
public int currentCodePoint(){
|
||||
// cannot use charAt due to it different
|
||||
// cannot use charAt due to it different
|
||||
// behaviour when index is pointing at a
|
||||
// trail surrogate, check for surrogates
|
||||
|
||||
|
||||
int ch = current();
|
||||
if(UTF16.isLeadSurrogate((char)ch)){
|
||||
// advance the index to get the next code point
|
||||
next();
|
||||
// due to post increment semantics current() after next()
|
||||
// due to post increment semantics current() after next()
|
||||
// actually returns the next char which is what we want
|
||||
int ch2 = current();
|
||||
// current should never change the current index so back off
|
||||
previous();
|
||||
|
||||
|
||||
if(UTF16.isTrailSurrogate((char)ch2)){
|
||||
// we found a surrogate pair
|
||||
return Character.toCodePoint((char)ch, (char)ch2);
|
||||
@ -115,47 +118,51 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the length of the text
|
||||
* @return length of the text
|
||||
*/
|
||||
@Override
|
||||
public int getLength(){
|
||||
return replaceable.length();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the current currentIndex in text.
|
||||
* @return current currentIndex in text.
|
||||
*/
|
||||
@Override
|
||||
public int getIndex(){
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns next UTF16 character and increments the iterator's currentIndex by 1.
|
||||
* If the resulting currentIndex is greater or equal to the text length, the
|
||||
* currentIndex is reset to the text length and a value of DONECODEPOINT is
|
||||
* returned.
|
||||
* @return next UTF16 character in text or DONE if the new currentIndex is off the
|
||||
* Returns next UTF16 character and increments the iterator's currentIndex by 1.
|
||||
* If the resulting currentIndex is greater or equal to the text length, the
|
||||
* currentIndex is reset to the text length and a value of DONECODEPOINT is
|
||||
* returned.
|
||||
* @return next UTF16 character in text or DONE if the new currentIndex is off the
|
||||
* end of the text range.
|
||||
*/
|
||||
@Override
|
||||
public int next(){
|
||||
if (currentIndex < replaceable.length()) {
|
||||
return replaceable.charAt(currentIndex++);
|
||||
}
|
||||
return DONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns previous UTF16 character and decrements the iterator's currentIndex by
|
||||
* 1.
|
||||
* If the resulting currentIndex is less than 0, the currentIndex is reset to 0 and a
|
||||
* value of DONECODEPOINT is returned.
|
||||
* @return next UTF16 character in text or DONE if the new currentIndex is off the
|
||||
* Returns previous UTF16 character and decrements the iterator's currentIndex by
|
||||
* 1.
|
||||
* If the resulting currentIndex is less than 0, the currentIndex is reset to 0 and a
|
||||
* value of DONECODEPOINT is returned.
|
||||
* @return next UTF16 character in text or DONE if the new currentIndex is off the
|
||||
* start of the text range.
|
||||
*/
|
||||
@Override
|
||||
public int previous(){
|
||||
if (currentIndex > 0) {
|
||||
return replaceable.charAt(--currentIndex);
|
||||
@ -164,22 +171,24 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Sets the currentIndex to the specified currentIndex in the text and returns that
|
||||
* single UTF16 character at currentIndex.
|
||||
* <p>Sets the currentIndex to the specified currentIndex in the text and returns that
|
||||
* single UTF16 character at currentIndex.
|
||||
* This assumes the text is stored as 16-bit code units.</p>
|
||||
* @param currentIndex the currentIndex within the text.
|
||||
* @exception IllegalArgumentException is thrown if an invalid currentIndex is
|
||||
* @param currentIndex the currentIndex within the text.
|
||||
* @exception IllegalArgumentException is thrown if an invalid currentIndex is
|
||||
* supplied. i.e. currentIndex is out of bounds.
|
||||
* @returns the character at the specified currentIndex or DONE if the specified
|
||||
* @returns the character at the specified currentIndex or DONE if the specified
|
||||
* currentIndex is equal to the end of the text.
|
||||
*/
|
||||
@Override
|
||||
public void setIndex(int currentIndex) throws IndexOutOfBoundsException{
|
||||
if (currentIndex < 0 || currentIndex > replaceable.length()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
this.currentIndex = currentIndex;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getText(char[] fillIn, int offset){
|
||||
int length = replaceable.length();
|
||||
if(offset < 0 || offset + length > fillIn.length){
|
||||
@ -187,10 +196,10 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
}
|
||||
replaceable.getChars(0,length,fillIn,offset);
|
||||
return length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// private data members ----------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Replacable object
|
||||
*/
|
||||
|
@ -22,7 +22,7 @@ import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
/**
|
||||
* just a wrapper for Java ListResourceBundles and
|
||||
* just a wrapper for Java ListResourceBundles and
|
||||
* @author ram
|
||||
*
|
||||
*/
|
||||
@ -49,6 +49,7 @@ public final class ResourceBundleWrapper extends UResourceBundle {
|
||||
this.bundle=bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object handleGetObject(String aKey){
|
||||
ResourceBundleWrapper current = this;
|
||||
Object obj = null;
|
||||
@ -69,11 +70,12 @@ public final class ResourceBundleWrapper extends UResourceBundle {
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys(){
|
||||
return Collections.enumeration(keys);
|
||||
}
|
||||
|
||||
|
||||
private void initKeysVector(){
|
||||
ResourceBundleWrapper current = this;
|
||||
keys = new ArrayList<String>();
|
||||
@ -88,25 +90,29 @@ public final class ResourceBundleWrapper extends UResourceBundle {
|
||||
current = (ResourceBundleWrapper)current.getParent();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
return localeID;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getBaseName(){
|
||||
return bundle.getClass().getName().replace('.','/');
|
||||
return bundle.getClass().getName().replace('.','/');
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ULocale getULocale(){
|
||||
return new ULocale(localeID);
|
||||
return new ULocale(localeID);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UResourceBundle getParent(){
|
||||
return (UResourceBundle)parent;
|
||||
return (UResourceBundle)parent;
|
||||
}
|
||||
|
||||
// Flag for enabling/disabling debugging code
|
||||
private static final boolean DEBUG = ICUDebug.enabled("resourceBundleWrapper");
|
||||
|
||||
|
||||
// This method is for super class's instantiateBundle method
|
||||
public static ResourceBundleWrapper getBundleInstance(String baseName, String localeID,
|
||||
ClassLoader root, boolean disableFallback) {
|
||||
@ -182,6 +188,7 @@ public final class ResourceBundleWrapper extends UResourceBundle {
|
||||
final String resName = name.replace('.', '/') + ".properties";
|
||||
InputStream stream = java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<InputStream>() {
|
||||
@Override
|
||||
public InputStream run() {
|
||||
return root.getResourceAsStream(resName);
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int sum = items.length;
|
||||
for (Object item : items) {
|
||||
@ -103,6 +104,7 @@ public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
|
||||
return sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
@ -127,6 +129,7 @@ public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object other) {
|
||||
int result;
|
||||
Row<C0, C1, C2, C3, C4> that = (Row<C0, C1, C2, C3, C4>)other;
|
||||
@ -144,6 +147,7 @@ public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder("[");
|
||||
boolean first = true;
|
||||
@ -158,15 +162,18 @@ public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
|
||||
return result.append("]").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Row<C0, C1, C2, C3, C4> freeze() {
|
||||
frozen = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
if (frozen) return this;
|
||||
try {
|
||||
@ -178,6 +185,7 @@ public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Row<C0, C1, C2, C3, C4> cloneAsThawed() {
|
||||
try {
|
||||
Row<C0, C1, C2, C3, C4> result = (Row<C0, C1, C2, C3, C4>) super.clone();
|
||||
|
@ -36,7 +36,7 @@ public class RuleCharacterIterator {
|
||||
|
||||
/**
|
||||
* Text being iterated.
|
||||
*/
|
||||
*/
|
||||
private String text;
|
||||
|
||||
/**
|
||||
@ -81,7 +81,7 @@ public class RuleCharacterIterator {
|
||||
* PARSE_ESCAPES) != 0, then an embedded escape sequence will be expanded
|
||||
* to its value. Escapes are parsed using Utility.unescapeAt().
|
||||
*/
|
||||
public static final int PARSE_ESCAPES = 2;
|
||||
public static final int PARSE_ESCAPES = 2;
|
||||
|
||||
/**
|
||||
* Bitmask option to enable skipping of whitespace. If (options &
|
||||
@ -111,7 +111,7 @@ public class RuleCharacterIterator {
|
||||
this.pos = pos;
|
||||
buf = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this iterator has no more characters to return.
|
||||
*/
|
||||
@ -308,6 +308,7 @@ public class RuleCharacterIterator {
|
||||
* Position within an expanded variable is <em>not</em> indicated.
|
||||
* @return a string representation of this object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
int b = pos.getIndex();
|
||||
return text.substring(0, b) + '|' + text.substring(b);
|
||||
@ -326,7 +327,7 @@ public class RuleCharacterIterator {
|
||||
return (i < text.length()) ? UTF16.charAt(text, i) : DONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Advances the position by the given amount.
|
||||
* @param count the number of 16-bit code units to advance past
|
||||
|
@ -39,6 +39,7 @@ public class SimpleCache<K, V> implements ICUCache<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
Reference<Map<K, V>> ref = cacheRef;
|
||||
if (ref != null) {
|
||||
@ -50,6 +51,7 @@ public class SimpleCache<K, V> implements ICUCache<K, V> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
Reference<Map<K, V>> ref = cacheRef;
|
||||
Map<K, V> map = null;
|
||||
@ -68,6 +70,7 @@ public class SimpleCache<K, V> implements ICUCache<K, V> {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
cacheRef = null;
|
||||
}
|
||||
|
@ -47,9 +47,10 @@ public final class StringPrepDataReader implements ICUBinary.Authenticate {
|
||||
return ICUBinary.getChars(byteBuffer, length, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[]){
|
||||
return version[0] == DATA_FORMAT_VERSION[0]
|
||||
&& version[2] == DATA_FORMAT_VERSION[2]
|
||||
return version[0] == DATA_FORMAT_VERSION[0]
|
||||
&& version[2] == DATA_FORMAT_VERSION[2]
|
||||
&& version[3] == DATA_FORMAT_VERSION[3];
|
||||
}
|
||||
public int[] readIndexes(int length)throws IOException{
|
||||
@ -59,7 +60,7 @@ public final class StringPrepDataReader implements ICUBinary.Authenticate {
|
||||
indexes[i] = byteBuffer.getInt();
|
||||
}
|
||||
return indexes;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getUnicodeVersion(){
|
||||
return ICUBinary.getVersionByteArrayFromCompactInt(unicodeVersion);
|
||||
|
@ -33,6 +33,7 @@ public class StringRange {
|
||||
}
|
||||
|
||||
public static final Comparator<int[]> COMPARE_INT_ARRAYS = new Comparator<int[]>() {
|
||||
@Override
|
||||
public int compare(int[] o1, int[] o2) {
|
||||
int minIndex = Math.min(o1.length, o2.length);
|
||||
for (int i = 0; i < minIndex; ++i) {
|
||||
@ -69,8 +70,8 @@ public class StringRange {
|
||||
}
|
||||
}
|
||||
// We failed to find continuation. Add what we have and restart
|
||||
adder.add(start, end == null ? null
|
||||
: !shorterPairs ? end
|
||||
adder.add(start, end == null ? null
|
||||
: !shorterPairs ? end
|
||||
: end.substring(prefixLen, end.length()));
|
||||
}
|
||||
// new possible range
|
||||
@ -79,8 +80,8 @@ public class StringRange {
|
||||
lastCp = s.codePointBefore(s.length());
|
||||
prefixLen = s.length() - Character.charCount(lastCp);
|
||||
}
|
||||
adder.add(start, end == null ? null
|
||||
: !shorterPairs ? end
|
||||
adder.add(start, end == null ? null
|
||||
: !shorterPairs ? end
|
||||
: end.substring(prefixLen, end.length()));
|
||||
} else {
|
||||
// not a fast algorithm, but ok for now
|
||||
@ -88,19 +89,19 @@ public class StringRange {
|
||||
// first sort by lengths
|
||||
Relation<Integer,Ranges> lengthToArrays = Relation.of(new TreeMap<Integer,Set<Ranges>>(), TreeSet.class);
|
||||
for (String s : source) {
|
||||
Ranges item = new Ranges(s);
|
||||
Ranges item = new Ranges(s);
|
||||
lengthToArrays.put(item.size(), item);
|
||||
}
|
||||
// then compact items of each length and emit compacted sets
|
||||
for (Entry<Integer, Set<Ranges>> entry : lengthToArrays.keyValuesSet()) {
|
||||
LinkedList<Ranges> compacted = compact(entry.getKey(), entry.getValue());
|
||||
for (Ranges ranges : compacted) {
|
||||
for (Ranges ranges : compacted) {
|
||||
adder.add(ranges.start(), ranges.end(shorterPairs));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Faster but not as good compaction. Only looks at final codepoint.
|
||||
* @param source set of strings
|
||||
@ -140,6 +141,7 @@ public class StringRange {
|
||||
public boolean equals(Object obj) {
|
||||
return this == obj || (obj != null && obj instanceof Range && compareTo((Range)obj) == 0);
|
||||
}
|
||||
@Override
|
||||
public int compareTo(Range that) {
|
||||
int diff = min - that.min;
|
||||
if (diff != 0) {
|
||||
@ -185,7 +187,7 @@ public class StringRange {
|
||||
if (DEBUG) System.out.println(" => " + this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public String start() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < ranges.length; ++i) {
|
||||
@ -215,6 +217,7 @@ public class StringRange {
|
||||
public Integer size() {
|
||||
return ranges.length;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(Ranges other) {
|
||||
int diff = ranges.length - other.ranges.length;
|
||||
if (diff != 0) {
|
||||
@ -259,7 +262,7 @@ public class StringRange {
|
||||
add(0, startOffset, startCps, endCps, builder, output);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
private static void add(int endIndex, int startOffset, int[] starts, int[] ends, StringBuilder builder, Collection<String> output) {
|
||||
int start = starts[endIndex+startOffset];
|
||||
int end = ends[endIndex];
|
||||
|
@ -26,10 +26,10 @@ import com.ibm.icu.util.UResourceBundle;
|
||||
* Yet another TimeZoneNames implementation based on the tz database.
|
||||
* This implementation contains only tz abbreviations (short standard
|
||||
* and daylight names) for each metazone.
|
||||
*
|
||||
*
|
||||
* The data file $ICU4C_ROOT/source/data/zone/tzdbNames.txt contains
|
||||
* the metazone - abbreviations mapping data (manually edited).
|
||||
*
|
||||
*
|
||||
* Note: The abbreviations in the tz database are not necessarily
|
||||
* unique. For example, parsing abbreviation "IST" is ambiguous
|
||||
* (can be parsed as India Standard Time or Israel Standard Time).
|
||||
@ -40,7 +40,7 @@ import com.ibm.icu.util.UResourceBundle;
|
||||
public class TZDBTimeZoneNames extends TimeZoneNames {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final ConcurrentHashMap<String, TZDBNames> TZDB_NAMES_MAP =
|
||||
private static final ConcurrentHashMap<String, TZDBNames> TZDB_NAMES_MAP =
|
||||
new ConcurrentHashMap<String, TZDBNames>();
|
||||
|
||||
private static volatile TextTrieMap<TZDBNameInfo> TZDB_NAMES_TRIE = null;
|
||||
@ -97,7 +97,7 @@ public class TZDBTimeZoneNames extends TimeZoneNames {
|
||||
*/
|
||||
@Override
|
||||
public String getMetaZoneDisplayName(String mzID, NameType type) {
|
||||
if (mzID == null || mzID.length() == 0 ||
|
||||
if (mzID == null || mzID.length() == 0 ||
|
||||
(type != NameType.SHORT_STANDARD && type != NameType.SHORT_DAYLIGHT)) {
|
||||
return null;
|
||||
}
|
||||
@ -242,6 +242,7 @@ public class TZDBTimeZoneNames extends TimeZoneNames {
|
||||
* @see com.ibm.icu.impl.TextTrieMap.ResultHandler#handlePrefixMatch(int,
|
||||
* java.util.Iterator)
|
||||
*/
|
||||
@Override
|
||||
public boolean handlePrefixMatch(int matchLength, Iterator<TZDBNameInfo> values) {
|
||||
TZDBNameInfo match = null;
|
||||
TZDBNameInfo defaultRegionMatch = null;
|
||||
|
@ -26,7 +26,7 @@ public class TextTrieMap<V> {
|
||||
|
||||
/**
|
||||
* Constructs a TextTrieMap object.
|
||||
*
|
||||
*
|
||||
* @param ignoreCase true to use simple case insensitive match
|
||||
*/
|
||||
public TextTrieMap(boolean ignoreCase) {
|
||||
@ -35,7 +35,7 @@ public class TextTrieMap<V> {
|
||||
|
||||
/**
|
||||
* Adds the text key and its associated object in this object.
|
||||
*
|
||||
*
|
||||
* @param text The text.
|
||||
* @param val The value object associated with the text.
|
||||
*/
|
||||
@ -48,7 +48,7 @@ public class TextTrieMap<V> {
|
||||
/**
|
||||
* Gets an iterator of the objects associated with the
|
||||
* longest prefix matching string key.
|
||||
*
|
||||
*
|
||||
* @param text The text to be matched with prefixes.
|
||||
* @return An iterator of the objects associated with
|
||||
* the longest prefix matching matching key, or null
|
||||
@ -60,13 +60,13 @@ public class TextTrieMap<V> {
|
||||
|
||||
/**
|
||||
* Gets an iterator of the objects associated with the
|
||||
* longest prefix matching string key starting at the
|
||||
* longest prefix matching string key starting at the
|
||||
* specified position.
|
||||
*
|
||||
*
|
||||
* @param text The text to be matched with prefixes.
|
||||
* @param start The start index of of the text
|
||||
* @return An iterator of the objects associated with the
|
||||
* longest prefix matching matching key, or null if no
|
||||
* longest prefix matching matching key, or null if no
|
||||
* matching entry is found.
|
||||
*/
|
||||
public Iterator<V> get(CharSequence text, int start) {
|
||||
@ -122,6 +122,7 @@ public class TextTrieMap<V> {
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (_nextIdx == _text.length() && _remainingChar == null) {
|
||||
return false;
|
||||
@ -132,6 +133,7 @@ public class TextTrieMap<V> {
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
@Override
|
||||
public Character next() {
|
||||
if (_nextIdx == _text.length() && _remainingChar == null) {
|
||||
return null;
|
||||
@ -161,6 +163,7 @@ public class TextTrieMap<V> {
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("remove() not supproted");
|
||||
}
|
||||
@ -184,7 +187,7 @@ public class TextTrieMap<V> {
|
||||
public interface ResultHandler<V> {
|
||||
/**
|
||||
* Handles a prefix key match
|
||||
*
|
||||
*
|
||||
* @param matchLength Matched key's length
|
||||
* @param values An iterator of the objects associated with the matched key
|
||||
* @return Return true to continue the search in the trie, false to quit.
|
||||
@ -196,6 +199,7 @@ public class TextTrieMap<V> {
|
||||
private Iterator<V> matches = null;
|
||||
private int length = 0;
|
||||
|
||||
@Override
|
||||
public boolean handlePrefixMatch(int matchLength, Iterator<V> values) {
|
||||
if (matchLength > length) {
|
||||
length = matchLength;
|
||||
|
@ -30,16 +30,16 @@ import com.ibm.icu.util.TimeZone;
|
||||
* @since ICU 2.8
|
||||
*/
|
||||
public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
|
||||
|
||||
// Generated by serialver from JDK 1.4.1_01
|
||||
static final long serialVersionUID = -2040072218820018557L;
|
||||
|
||||
|
||||
/**
|
||||
* The contained com.ibm.icu.util.TimeZone object. Must not be null.
|
||||
* We delegate all methods to this object.
|
||||
*/
|
||||
private TimeZone zone;
|
||||
|
||||
|
||||
/**
|
||||
* Given a java.util.TimeZone, wrap it in the appropriate adapter
|
||||
* subclass of com.ibm.icu.util.TimeZone and return the adapter.
|
||||
@ -66,14 +66,16 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
@Override
|
||||
public void setID(String ID) {
|
||||
super.setID(ID);
|
||||
zone.setID(ID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasSameRules(java.util.TimeZone other) {
|
||||
return other instanceof TimeZoneAdapter &&
|
||||
zone.hasSameRules(((TimeZoneAdapter)other).zone);
|
||||
@ -82,6 +84,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
@Override
|
||||
public int getOffset(int era, int year, int month, int day, int dayOfWeek,
|
||||
int millis) {
|
||||
return zone.getOffset(era, year, month, day, dayOfWeek, millis);
|
||||
@ -90,6 +93,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
@Override
|
||||
public int getRawOffset() {
|
||||
return zone.getRawOffset();
|
||||
}
|
||||
@ -97,6 +101,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
@Override
|
||||
public void setRawOffset(int offsetMillis) {
|
||||
zone.setRawOffset(offsetMillis);
|
||||
}
|
||||
@ -104,6 +109,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
@Override
|
||||
public boolean useDaylightTime() {
|
||||
return zone.useDaylightTime();
|
||||
}
|
||||
@ -111,6 +117,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* TimeZone API; calls through to wrapped time zone.
|
||||
*/
|
||||
@Override
|
||||
public boolean inDaylightTime(Date date) {
|
||||
return zone.inDaylightTime(date);
|
||||
}
|
||||
@ -118,6 +125,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* Boilerplate API; calls through to wrapped object.
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
return new TimeZoneAdapter((TimeZone)zone.clone());
|
||||
}
|
||||
@ -125,6 +133,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* Boilerplate API; calls through to wrapped object.
|
||||
*/
|
||||
@Override
|
||||
public synchronized int hashCode() {
|
||||
return zone.hashCode();
|
||||
}
|
||||
@ -132,6 +141,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
/**
|
||||
* Boilerplate API; calls through to wrapped object.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TimeZoneAdapter) {
|
||||
obj = ((TimeZoneAdapter) obj).zone;
|
||||
@ -143,6 +153,7 @@ public class TimeZoneAdapter extends java.util.TimeZone {
|
||||
* Returns a string representation of this object.
|
||||
* @return a string representation of this object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TimeZoneAdapter: " + zone.toString();
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
* Format pattern enum used for composing location and partial location names
|
||||
*/
|
||||
public enum Pattern {
|
||||
// The format pattern such as "{0} Time", where {0} is the country or city.
|
||||
// The format pattern such as "{0} Time", where {0} is the country or city.
|
||||
REGION_FORMAT("regionFormat", "({0})"),
|
||||
|
||||
// Note: FALLBACK_REGION_FORMAT is no longer used since ICU 50/CLDR 22.1
|
||||
@ -185,7 +185,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
/**
|
||||
* Returns the display name of the time zone for the given name type
|
||||
* at the given date, or null if the display name is not available.
|
||||
*
|
||||
*
|
||||
* @param tz the time zone
|
||||
* @param type the generic name type - see {@link GenericNameType}
|
||||
* @param date the date
|
||||
@ -218,7 +218,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
|
||||
/**
|
||||
* Returns the generic location name for the given canonical time zone ID.
|
||||
*
|
||||
*
|
||||
* @param canonicalTzID the canonical time zone ID
|
||||
* @return the generic location name for the given canonical time zone ID.
|
||||
*/
|
||||
@ -303,9 +303,9 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
/**
|
||||
* Private method to get a generic string, with fallback logics involved,
|
||||
* that is,
|
||||
*
|
||||
*
|
||||
* 1. If a generic non-location string is available for the zone, return it.
|
||||
* 2. If a generic non-location string is associated with a meta zone and
|
||||
* 2. If a generic non-location string is associated with a meta zone and
|
||||
* the zone never use daylight time around the given date, use the standard
|
||||
* string (if available).
|
||||
* 3. If a generic non-location string is associated with a meta zone and
|
||||
@ -313,7 +313,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
* current locale, then return the generic partial location string (if available)
|
||||
* 4. If a generic non-location string is not available, use generic location
|
||||
* string.
|
||||
*
|
||||
*
|
||||
* @param tz the requested time zone
|
||||
* @param date the date
|
||||
* @param type the generic name type, either LONG or SHORT
|
||||
@ -433,7 +433,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
* Private simple pattern formatter used for formatting generic location names
|
||||
* and partial location names. We intentionally use JDK MessageFormat
|
||||
* for performance reason.
|
||||
*
|
||||
*
|
||||
* @param pat the message pattern enum
|
||||
* @param args the format argument(s)
|
||||
* @return the formatted string
|
||||
@ -464,7 +464,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
* instance. Because LocaleDisplayNames is only used for generic
|
||||
* location formant and partial location format, the LocaleDisplayNames
|
||||
* is instantiated lazily.
|
||||
*
|
||||
*
|
||||
* @return the instance of LocaleDisplayNames for the locale of this object.
|
||||
*/
|
||||
private synchronized LocaleDisplayNames getLocaleDisplayNames() {
|
||||
@ -484,7 +484,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
return;
|
||||
}
|
||||
// getGenericLocationName() formats a name and put it into the trie
|
||||
getGenericLocationName(tzCanonicalID);
|
||||
getGenericLocationName(tzCanonicalID);
|
||||
|
||||
// Generic partial location format
|
||||
Set<String> mzIDs = _tznames.getAvailableMetaZoneIDs(tzCanonicalID);
|
||||
@ -510,7 +510,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
* the locale of this instance. When a generic name is coming from
|
||||
* a meta zone, this region is used for checking if the time zone
|
||||
* is a reference zone of the meta zone.
|
||||
*
|
||||
*
|
||||
* @return the target region
|
||||
*/
|
||||
private synchronized String getTargetRegion() {
|
||||
@ -531,7 +531,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
* Private method for formatting partial location names. This format
|
||||
* is used when a generic name of a meta zone is available, but the given
|
||||
* time zone is not a reference zone (golden zone) of the meta zone.
|
||||
*
|
||||
*
|
||||
* @param tzID the canonical time zone ID
|
||||
* @param mzID the meta zone ID
|
||||
* @param isLong true when long generic name
|
||||
@ -647,6 +647,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.icu.impl.TextTrieMap.ResultHandler#handlePrefixMatch(int, java.util.Iterator)
|
||||
*/
|
||||
@Override
|
||||
public boolean handlePrefixMatch(int matchLength, Iterator<NameInfo> values) {
|
||||
while (values.hasNext()) {
|
||||
NameInfo info = values.next();
|
||||
@ -847,7 +848,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
nameTypes.add(NameType.SHORT_GENERIC);
|
||||
nameTypes.add(NameType.SHORT_STANDARD);
|
||||
}
|
||||
|
||||
|
||||
if (!nameTypes.isEmpty()) {
|
||||
// Find matches in the TimeZoneNames
|
||||
tznamesMatches = _tznames.find(text, start, nameTypes);
|
||||
@ -900,7 +901,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
protected TimeZoneGenericNames createInstance(String key, ULocale data) {
|
||||
return new TimeZoneGenericNames(data).freeze();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -915,6 +916,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
return _frozen;
|
||||
}
|
||||
@ -922,6 +924,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TimeZoneGenericNames freeze() {
|
||||
_frozen = true;
|
||||
return this;
|
||||
@ -930,6 +933,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TimeZoneGenericNames cloneAsThawed() {
|
||||
TimeZoneGenericNames copy = null;
|
||||
try {
|
||||
|
@ -16,9 +16,9 @@ import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
|
||||
/**
|
||||
* <p>A trie is a kind of compressed, serializable table of values
|
||||
* <p>A trie is a kind of compressed, serializable table of values
|
||||
* associated with Unicode code points (0..0x10ffff).</p>
|
||||
* <p>This class defines the basic structure of a trie and provides methods
|
||||
* <p>This class defines the basic structure of a trie and provides methods
|
||||
* to <b>retrieve the offsets to the actual data</b>.</p>
|
||||
* <p>Data will be the form of an array of basic types, char or int.</p>
|
||||
* <p>The actual data format will have to be specified by the user in the
|
||||
@ -35,9 +35,9 @@ import com.ibm.icu.text.UTF16;
|
||||
* to the fromOffsetTrail() methods.
|
||||
* To handle such supplementary codepoints, some offset information are kept
|
||||
* in the data.</p>
|
||||
* <p>Methods in com.ibm.icu.impl.Trie.DataManipulate are called to retrieve
|
||||
* <p>Methods in com.ibm.icu.impl.Trie.DataManipulate are called to retrieve
|
||||
* that offset from the folded value for the lead surrogate unit.</p>
|
||||
* <p>For examples of use, see com.ibm.icu.impl.CharTrie or
|
||||
* <p>For examples of use, see com.ibm.icu.impl.CharTrie or
|
||||
* com.ibm.icu.impl.IntTrie.</p>
|
||||
* @author synwee
|
||||
* @see com.ibm.icu.impl.CharTrie
|
||||
@ -47,36 +47,37 @@ import com.ibm.icu.text.UTF16;
|
||||
public abstract class Trie
|
||||
{
|
||||
// public class declaration ----------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Character data in com.ibm.impl.Trie have different user-specified format
|
||||
* for different purposes.
|
||||
* This interface specifies methods to be implemented in order for
|
||||
* com.ibm.impl.Trie, to surrogate offset information encapsulated within
|
||||
* com.ibm.impl.Trie, to surrogate offset information encapsulated within
|
||||
* the data.
|
||||
*/
|
||||
public static interface DataManipulate
|
||||
{
|
||||
/**
|
||||
* Called by com.ibm.icu.impl.Trie to extract from a lead surrogate's
|
||||
* Called by com.ibm.icu.impl.Trie to extract from a lead surrogate's
|
||||
* data
|
||||
* the index array offset of the indexes for that lead surrogate.
|
||||
* @param value data value for a surrogate from the trie, including the
|
||||
* folding offset
|
||||
* @return data offset or 0 if there is no data for the lead surrogate
|
||||
*/
|
||||
public int getFoldingOffset(int value);
|
||||
public int getFoldingOffset(int value);
|
||||
}
|
||||
|
||||
// default implementation
|
||||
private static class DefaultGetFoldingOffset implements DataManipulate {
|
||||
@Override
|
||||
public int getFoldingOffset(int value) {
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// public methods --------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Determines if this trie has a linear latin 1 array
|
||||
* @return true if this trie has a linear latin 1 array, false otherwise
|
||||
@ -85,7 +86,7 @@ public abstract class Trie
|
||||
{
|
||||
return m_isLatin1Linear_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the argument Trie has the same data as this Trie.
|
||||
* Attributes are checked but not the index data.
|
||||
@ -94,7 +95,8 @@ public abstract class Trie
|
||||
* otherwise
|
||||
*/
|
||||
///CLOVER:OFF
|
||||
public boolean equals(Object other)
|
||||
@Override
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if (other == this) {
|
||||
return true;
|
||||
@ -108,16 +110,17 @@ public abstract class Trie
|
||||
&& m_dataLength_ == othertrie.m_dataLength_
|
||||
&& Arrays.equals(m_index_, othertrie.m_index_);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
assert false : "hashCode not designed";
|
||||
return 42;
|
||||
}
|
||||
///CLOVER:ON
|
||||
|
||||
|
||||
/**
|
||||
* Gets the serialized data file size of the Trie. This is used during
|
||||
* trie data reading for size checking purposes.
|
||||
* Gets the serialized data file size of the Trie. This is used during
|
||||
* trie data reading for size checking purposes.
|
||||
* @return size size of serialized trie data file in terms of the number
|
||||
* of bytes
|
||||
*/
|
||||
@ -169,7 +172,7 @@ public abstract class Trie
|
||||
* Trie constructor
|
||||
* @param index array to be used for index
|
||||
* @param options used by the trie
|
||||
* @param dataManipulate object containing the information to parse the
|
||||
* @param dataManipulate object containing the information to parse the
|
||||
* trie data
|
||||
*/
|
||||
protected Trie(char index[], int options, DataManipulate dataManipulate)
|
||||
@ -231,7 +234,7 @@ public abstract class Trie
|
||||
* Surrogate mask to use when shifting offset to retrieve supplementary
|
||||
* values
|
||||
*/
|
||||
protected static final int SURROGATE_MASK_ = 0x3FF;
|
||||
protected static final int SURROGATE_MASK_ = 0x3FF;
|
||||
/**
|
||||
* Index or UTF16 characters
|
||||
*/
|
||||
@ -242,17 +245,17 @@ public abstract class Trie
|
||||
*/
|
||||
protected DataManipulate m_dataManipulate_;
|
||||
/**
|
||||
* Start index of the data portion of the trie. CharTrie combines
|
||||
* index and data into a char array, so this is used to indicate the
|
||||
* Start index of the data portion of the trie. CharTrie combines
|
||||
* index and data into a char array, so this is used to indicate the
|
||||
* initial offset to the data portion.
|
||||
* Note this index always points to the initial value.
|
||||
*/
|
||||
protected int m_dataOffset_;
|
||||
/**
|
||||
* Length of the data array
|
||||
* Length of the data array
|
||||
*/
|
||||
protected int m_dataLength_;
|
||||
|
||||
|
||||
// protected methods -----------------------------------------------
|
||||
|
||||
/**
|
||||
@ -262,20 +265,20 @@ public abstract class Trie
|
||||
* @return offset to data
|
||||
*/
|
||||
protected abstract int getSurrogateOffset(char lead, char trail);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value at the argument index
|
||||
* @param index value at index will be retrieved
|
||||
* @return 32 bit value
|
||||
* @return 32 bit value
|
||||
*/
|
||||
protected abstract int getValue(int index);
|
||||
|
||||
/**
|
||||
* Gets the default initial value
|
||||
* @return 32 bit value
|
||||
* @return 32 bit value
|
||||
*/
|
||||
protected abstract int getInitialValue();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the offset to the data which the index ch after variable offset
|
||||
* points to.
|
||||
@ -292,11 +295,11 @@ public abstract class Trie
|
||||
*/
|
||||
protected final int getRawOffset(int offset, char ch)
|
||||
{
|
||||
return (m_index_[offset + (ch >> INDEX_STAGE_1_SHIFT_)]
|
||||
<< INDEX_STAGE_2_SHIFT_)
|
||||
return (m_index_[offset + (ch >> INDEX_STAGE_1_SHIFT_)]
|
||||
<< INDEX_STAGE_2_SHIFT_)
|
||||
+ (ch & INDEX_STAGE_3_MASK_);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the offset to data which the BMP character points to
|
||||
* Treats a lead surrogate as a normal code point.
|
||||
@ -305,10 +308,10 @@ public abstract class Trie
|
||||
*/
|
||||
protected final int getBMPOffset(char ch)
|
||||
{
|
||||
return (ch >= UTF16.LEAD_SURROGATE_MIN_VALUE
|
||||
&& ch <= UTF16.LEAD_SURROGATE_MAX_VALUE)
|
||||
return (ch >= UTF16.LEAD_SURROGATE_MIN_VALUE
|
||||
&& ch <= UTF16.LEAD_SURROGATE_MAX_VALUE)
|
||||
? getRawOffset(LEAD_INDEX_OFFSET_, ch)
|
||||
: getRawOffset(0, ch);
|
||||
: getRawOffset(0, ch);
|
||||
// using a getRawOffset(ch) makes no diff
|
||||
}
|
||||
|
||||
@ -343,14 +346,14 @@ public abstract class Trie
|
||||
return getRawOffset(0, (char)ch);
|
||||
} else if (ch < UTF16.SUPPLEMENTARY_MIN_VALUE) {
|
||||
// BMP codepoint
|
||||
return getBMPOffset((char)ch);
|
||||
return getBMPOffset((char)ch);
|
||||
} else if (ch <= UCharacter.MAX_VALUE) {
|
||||
// look at the construction of supplementary characters
|
||||
// trail forms the ends of it.
|
||||
return getSurrogateOffset(UTF16.getLeadSurrogate(ch),
|
||||
return getSurrogateOffset(UTF16.getLeadSurrogate(ch),
|
||||
(char)(ch & SURROGATE_MASK_));
|
||||
} else {
|
||||
// return -1 if there is an error, in this case we return
|
||||
// return -1 if there is an error, in this case we return
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -410,12 +413,12 @@ public abstract class Trie
|
||||
private static final int HEADER_OPTIONS_SHIFT_MASK_ = 0xF;
|
||||
protected static final int HEADER_OPTIONS_INDEX_SHIFT_ = 4;
|
||||
protected static final int HEADER_OPTIONS_DATA_IS_32_BIT_ = 0x100;
|
||||
|
||||
|
||||
/**
|
||||
* Flag indicator for Latin quick access data block
|
||||
*/
|
||||
private boolean m_isLatin1Linear_;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Trie options field.</p>
|
||||
* <p>options bit field:<br>
|
||||
@ -425,9 +428,9 @@ public abstract class Trie
|
||||
* 3..0 INDEX_STAGE_2_SHIFT // 1..9<br>
|
||||
*/
|
||||
private int m_options_;
|
||||
|
||||
|
||||
// private methods ---------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Authenticates raw data header.
|
||||
* Checking the header information, signature and options.
|
||||
@ -443,7 +446,7 @@ public abstract class Trie
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((m_options_ & HEADER_OPTIONS_SHIFT_MASK_) !=
|
||||
if ((m_options_ & HEADER_OPTIONS_SHIFT_MASK_) !=
|
||||
INDEX_STAGE_1_SHIFT_ ||
|
||||
((m_options_ >> HEADER_OPTIONS_INDEX_SHIFT_) &
|
||||
HEADER_OPTIONS_SHIFT_MASK_)
|
||||
|
@ -26,7 +26,7 @@ import java.util.NoSuchElementException;
|
||||
* character properties.
|
||||
*
|
||||
* This is the second common version of a Unicode trie (hence the name Trie2).
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
|
||||
@ -208,11 +208,11 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
byte sig[] = new byte[4];
|
||||
int read = is.read(sig);
|
||||
is.reset();
|
||||
|
||||
|
||||
if (read != sig.length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (sig[0]=='T' && sig[1]=='r' && sig[2]=='i' && sig[3]=='e') {
|
||||
return 1;
|
||||
}
|
||||
@ -238,7 +238,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
*/
|
||||
abstract public int get(int codePoint);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the trie value for a UTF-16 code unit.
|
||||
*
|
||||
@ -246,15 +246,15 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
* range, one for lead surrogates, which is the value that will be
|
||||
* returned by this function, and a second value that is returned
|
||||
* by Trie2.get().
|
||||
*
|
||||
*
|
||||
* For code units outside of the lead surrogate range, this function
|
||||
* returns the same result as Trie2.get().
|
||||
*
|
||||
*
|
||||
* This function, together with the alternate value for lead surrogates,
|
||||
* makes possible very efficient processing of UTF-16 strings without
|
||||
* first converting surrogate pairs to their corresponding 32 bit code point
|
||||
* values.
|
||||
*
|
||||
*
|
||||
* At build-time, enumerate the contents of the Trie2 to see if there
|
||||
* is non-trivial (non-initialValue) data for any of the supplementary
|
||||
* code points associated with a lead surrogate.
|
||||
@ -263,33 +263,34 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
*
|
||||
* At runtime, use Trie2.getFromU16SingleLead(). If there is non-trivial
|
||||
* data and the code unit is a lead surrogate, then check if a trail surrogate
|
||||
* follows. If so, assemble the supplementary code point and look up its value
|
||||
* follows. If so, assemble the supplementary code point and look up its value
|
||||
* with Trie2.get(); otherwise reset the lead
|
||||
* surrogate's value or do a code point lookup for it.
|
||||
*
|
||||
* If there is only trivial data for lead and trail surrogates, then processing
|
||||
* can often skip them. For example, in normalization or case mapping
|
||||
* all characters that do not have any mappings are simply copied as is.
|
||||
*
|
||||
*
|
||||
* @param c the code point or lead surrogate value.
|
||||
* @return the value
|
||||
*/
|
||||
abstract public int getFromU16SingleLead(char c);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Equals function. Two Tries are equal if their contents are equal.
|
||||
* The type need not be the same, so a Trie2Writable will be equal to
|
||||
* The type need not be the same, so a Trie2Writable will be equal to
|
||||
* (read-only) Trie2_16 or Trie2_32 so long as they are storing the same values.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public final boolean equals(Object other) {
|
||||
if(!(other instanceof Trie2)) {
|
||||
return false;
|
||||
}
|
||||
Trie2 OtherTrie = (Trie2)other;
|
||||
Range rangeFromOther;
|
||||
|
||||
|
||||
Iterator<Trie2.Range> otherIter = OtherTrie.iterator();
|
||||
for (Trie2.Range rangeFromThis: this) {
|
||||
if (otherIter.hasNext() == false) {
|
||||
@ -303,16 +304,17 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
if (otherIter.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (errorValue != OtherTrie.errorValue ||
|
||||
initialValue != OtherTrie.initialValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (fHash == 0) {
|
||||
int hash = initHash();
|
||||
@ -326,11 +328,11 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
}
|
||||
return fHash;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When iterating over the contents of a Trie2, Elements of this type are produced.
|
||||
* The iterator will return one item for each contiguous range of codepoints having the same value.
|
||||
*
|
||||
* The iterator will return one item for each contiguous range of codepoints having the same value.
|
||||
*
|
||||
* When iterating, the same Trie2EnumRange object will be reused and returned for each range.
|
||||
* If you need to retain complete iteration results, clone each returned Trie2EnumRange,
|
||||
* or save the range in some other way, before advancing to the next iteration step.
|
||||
@ -340,7 +342,8 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
public int endCodePoint; // Inclusive.
|
||||
public int value;
|
||||
public boolean leadSurrogate;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other.getClass().equals(getClass()))) {
|
||||
return false;
|
||||
@ -348,11 +351,12 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
Range tother = (Range)other;
|
||||
return this.startCodePoint == tother.startCodePoint &&
|
||||
this.endCodePoint == tother.endCodePoint &&
|
||||
this.value == tother.value &&
|
||||
this.value == tother.value &&
|
||||
this.leadSurrogate == tother.leadSurrogate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int h = initHash();
|
||||
h = hashUChar32(h, startCodePoint);
|
||||
@ -362,32 +366,34 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create an iterator over the value ranges in this Trie2.
|
||||
* Values from the Trie2 are not remapped or filtered, but are returned as they
|
||||
* are stored in the Trie2.
|
||||
*
|
||||
*
|
||||
* @return an Iterator
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Range> iterator() {
|
||||
return iterator(defaultValueMapper);
|
||||
}
|
||||
|
||||
|
||||
private static ValueMapper defaultValueMapper = new ValueMapper() {
|
||||
public int map(int in) {
|
||||
@Override
|
||||
public int map(int in) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create an iterator over the value ranges from this Trie2.
|
||||
* Values from the Trie2 are passed through a caller-supplied remapping function,
|
||||
* and it is the remapped values that determine the ranges that
|
||||
* will be produced by the iterator.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param mapper provides a function to remap values obtained from the Trie2.
|
||||
* @return an Iterator
|
||||
*/
|
||||
@ -395,7 +401,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
return new Trie2Iterator(mapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create an iterator over the Trie2 values for the 1024=0x400 code points
|
||||
* corresponding to a given lead surrogate.
|
||||
@ -435,10 +441,10 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
* be used to remap the values from the Trie2. The remapped values will be used
|
||||
* both in determining the ranges of codepoints and as the value to be returned
|
||||
* for each range.
|
||||
*
|
||||
*
|
||||
* Example of use, with an anonymous subclass of TrieValueMapper:
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* ValueMapper m = new ValueMapper() {
|
||||
* int map(int in) {return in & 0x1f;};
|
||||
* }
|
||||
@ -446,12 +452,12 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
* Trie2EnumRange r = i.next();
|
||||
* ... // Do something with the range r.
|
||||
* }
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface ValueMapper {
|
||||
public int map(int originalVal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Serialize a trie2 Header and Index onto an OutputStream. This is
|
||||
@ -459,12 +465,12 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
* @param dos the stream to which the serialized Trie2 data will be written.
|
||||
* @return the number of bytes written.
|
||||
*/
|
||||
protected int serializeHeader(DataOutputStream dos) throws IOException {
|
||||
protected int serializeHeader(DataOutputStream dos) throws IOException {
|
||||
// Write the header. It is already set and ready to use, having been
|
||||
// created when the Trie2 was unserialized or when it was frozen.
|
||||
int bytesWritten = 0;
|
||||
|
||||
dos.writeInt(header.signature);
|
||||
|
||||
dos.writeInt(header.signature);
|
||||
dos.writeShort(header.options);
|
||||
dos.writeShort(header.indexLength);
|
||||
dos.writeShort(header.shiftedDataLength);
|
||||
@ -472,36 +478,36 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
dos.writeShort(header.dataNullOffset);
|
||||
dos.writeShort(header.shiftedHighStart);
|
||||
bytesWritten += 16;
|
||||
|
||||
|
||||
// Write the index
|
||||
int i;
|
||||
for (i=0; i< header.indexLength; i++) {
|
||||
dos.writeChar(index[i]);
|
||||
}
|
||||
bytesWritten += header.indexLength;
|
||||
return bytesWritten;
|
||||
bytesWritten += header.indexLength;
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Struct-like class for holding the results returned by a UTrie2 CharSequence iterator.
|
||||
* The iteration walks over a CharSequence, and for each Unicode code point therein
|
||||
* returns the character and its associated Trie2 value.
|
||||
*/
|
||||
public static class CharSequenceValues {
|
||||
public static class CharSequenceValues {
|
||||
/** string index of the current code point. */
|
||||
public int index;
|
||||
public int index;
|
||||
/** The code point at index. */
|
||||
public int codePoint;
|
||||
public int codePoint;
|
||||
/** The Trie2 value for the current code point */
|
||||
public int value;
|
||||
public int value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create an iterator that will produce the values from the Trie2 for
|
||||
* the sequence of code points in an input text.
|
||||
*
|
||||
*
|
||||
* @param text A text string to be iterated over.
|
||||
* @param index The starting iteration position within the input text.
|
||||
* @return the CharSequenceIterator
|
||||
@ -509,17 +515,17 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
public CharSequenceIterator charSequenceIterator(CharSequence text, int index) {
|
||||
return new CharSequenceIterator(text, index);
|
||||
}
|
||||
|
||||
|
||||
// TODO: Survey usage of the equivalent of CharSequenceIterator in ICU4C
|
||||
// and if there is none, remove it from here.
|
||||
// Don't waste time testing and maintaining unused code.
|
||||
|
||||
|
||||
/**
|
||||
* An iterator that operates over an input CharSequence, and for each Unicode code point
|
||||
* in the input returns the associated value from the Trie2.
|
||||
*
|
||||
*
|
||||
* The iterator can move forwards or backwards, and can be reset to an arbitrary index.
|
||||
*
|
||||
*
|
||||
* Note that Trie2_16 and Trie2_32 subclass Trie2.CharSequenceIterator. This is done
|
||||
* only for performance reasons. It does require that any changes made here be propagated
|
||||
* into the corresponding code in the subclasses.
|
||||
@ -528,36 +534,38 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
/**
|
||||
* Internal constructor.
|
||||
*/
|
||||
CharSequenceIterator(CharSequence t, int index) {
|
||||
CharSequenceIterator(CharSequence t, int index) {
|
||||
text = t;
|
||||
textLength = text.length();
|
||||
set(index);
|
||||
}
|
||||
|
||||
|
||||
private CharSequence text;
|
||||
private int textLength;
|
||||
private int index;
|
||||
private Trie2.CharSequenceValues fResults = new Trie2.CharSequenceValues();
|
||||
|
||||
|
||||
|
||||
|
||||
public void set(int i) {
|
||||
if (i < 0 || i > textLength) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
index = i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean hasNext() {
|
||||
return index<textLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public final boolean hasPrevious() {
|
||||
return index>0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Trie2.CharSequenceValues next() {
|
||||
int c = Character.codePointAt(text, index);
|
||||
int val = get(c);
|
||||
@ -568,11 +576,11 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
index++;
|
||||
if (c >= 0x10000) {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return fResults;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Trie2.CharSequenceValues previous() {
|
||||
int c = Character.codePointBefore(text, index);
|
||||
int val = get(c);
|
||||
@ -585,49 +593,50 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
fResults.value = val;
|
||||
return fResults;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Iterator.remove() is not supported by Trie2.CharSequenceIterator.
|
||||
* @throws UnsupportedOperationException Always thrown because this operation is not supported
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Trie2.CharSequenceIterator does not support remove().");
|
||||
throw new UnsupportedOperationException("Trie2.CharSequenceIterator does not support remove().");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
//
|
||||
// Below this point are internal implementation items. No further public API.
|
||||
//
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Selectors for the width of a UTrie2 data value.
|
||||
*/
|
||||
*/
|
||||
enum ValueWidth {
|
||||
BITS_16,
|
||||
BITS_32
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trie2 data structure in serialized form:
|
||||
*
|
||||
* UTrie2Header header;
|
||||
* uint16_t index[header.index2Length];
|
||||
* uint16_t data[header.shiftedDataLength<<2]; -- or uint32_t data[...]
|
||||
*
|
||||
*
|
||||
* For Java, this is read from the stream into an instance of UTrie2Header.
|
||||
* (The C version just places a struct over the raw serialized data.)
|
||||
*
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
static class UTrie2Header {
|
||||
/** "Tri2" in big-endian US-ASCII (0x54726932) */
|
||||
int signature;
|
||||
|
||||
|
||||
/**
|
||||
* options bit field (uint16_t):
|
||||
* 15.. 4 reserved (0)
|
||||
@ -637,7 +646,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
|
||||
/** UTRIE2_INDEX_1_OFFSET..UTRIE2_MAX_INDEX_LENGTH (uint16_t) */
|
||||
int indexLength;
|
||||
|
||||
|
||||
/** (UTRIE2_DATA_START_OFFSET..UTRIE2_MAX_DATA_LENGTH)>>UTRIE2_INDEX_SHIFT (uint16_t) */
|
||||
int shiftedDataLength;
|
||||
|
||||
@ -650,7 +659,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
*/
|
||||
int shiftedHighStart;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Data members of UTrie2.
|
||||
//
|
||||
@ -658,7 +667,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
char index[]; // Index array. Includes data for 16 bit Tries.
|
||||
int data16; // Offset to data portion of the index array, if 16 bit data.
|
||||
// zero if 32 bit data.
|
||||
int data32[]; // NULL if 16b data is used via index
|
||||
int data32[]; // NULL if 16b data is used via index
|
||||
|
||||
int indexLength;
|
||||
int dataLength;
|
||||
@ -671,25 +680,25 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
/* Start of the last range which ends at U+10ffff, and its value. */
|
||||
int highStart;
|
||||
int highValueIndex;
|
||||
|
||||
|
||||
int dataNullOffset;
|
||||
|
||||
|
||||
int fHash; // Zero if not yet computed.
|
||||
// Shared by Trie2Writable, Trie2_16, Trie2_32.
|
||||
// Thread safety: if two racing threads compute
|
||||
// the same hash on a frozen Trie2, no damage is done.
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Trie2 constants, defining shift widths, index array lengths, etc.
|
||||
*
|
||||
* These are needed for the runtime macros but users can treat these as
|
||||
* implementation details and skip to the actual public API further below.
|
||||
*/
|
||||
|
||||
|
||||
static final int UTRIE2_OPTIONS_VALUE_BITS_MASK=0x000f;
|
||||
|
||||
|
||||
|
||||
|
||||
/** Shift size for getting the index-1 table offset. */
|
||||
static final int UTRIE2_SHIFT_1=6+5;
|
||||
|
||||
@ -710,19 +719,19 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
|
||||
/** Number of code points per index-1 table entry. 2048=0x800 */
|
||||
static final int UTRIE2_CP_PER_INDEX_1_ENTRY=1<<UTRIE2_SHIFT_1;
|
||||
|
||||
|
||||
/** Number of entries in an index-2 block. 64=0x40 */
|
||||
static final int UTRIE2_INDEX_2_BLOCK_LENGTH=1<<UTRIE2_SHIFT_1_2;
|
||||
|
||||
|
||||
/** Mask for getting the lower bits for the in-index-2-block offset. */
|
||||
static final int UTRIE2_INDEX_2_MASK=UTRIE2_INDEX_2_BLOCK_LENGTH-1;
|
||||
|
||||
|
||||
/** Number of entries in a data block. 32=0x20 */
|
||||
static final int UTRIE2_DATA_BLOCK_LENGTH=1<<UTRIE2_SHIFT_2;
|
||||
|
||||
|
||||
/** Mask for getting the lower bits for the in-data-block offset. */
|
||||
static final int UTRIE2_DATA_MASK=UTRIE2_DATA_BLOCK_LENGTH-1;
|
||||
|
||||
|
||||
/**
|
||||
* Shift size for shifting left the index array values.
|
||||
* Increases possible data size with 16-bit index values at the cost
|
||||
@ -730,18 +739,18 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
* This requires data blocks to be aligned by UTRIE2_DATA_GRANULARITY.
|
||||
*/
|
||||
static final int UTRIE2_INDEX_SHIFT=2;
|
||||
|
||||
|
||||
/** The alignment size of a data block. Also the granularity for compaction. */
|
||||
static final int UTRIE2_DATA_GRANULARITY=1<<UTRIE2_INDEX_SHIFT;
|
||||
|
||||
|
||||
/* Fixed layout of the first part of the index array. ------------------- */
|
||||
|
||||
|
||||
/**
|
||||
* The BMP part of the index-2 table is fixed and linear and starts at offset 0.
|
||||
* Length=2048=0x800=0x10000>>UTRIE2_SHIFT_2.
|
||||
*/
|
||||
static final int UTRIE2_INDEX_2_OFFSET=0;
|
||||
|
||||
|
||||
/**
|
||||
* The part of the index-2 table for U+D800..U+DBFF stores values for
|
||||
* lead surrogate code _units_ not code _points_.
|
||||
@ -750,17 +759,17 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
*/
|
||||
static final int UTRIE2_LSCP_INDEX_2_OFFSET=0x10000>>UTRIE2_SHIFT_2;
|
||||
static final int UTRIE2_LSCP_INDEX_2_LENGTH=0x400>>UTRIE2_SHIFT_2;
|
||||
|
||||
|
||||
/** Count the lengths of both BMP pieces. 2080=0x820 */
|
||||
static final int UTRIE2_INDEX_2_BMP_LENGTH=UTRIE2_LSCP_INDEX_2_OFFSET+UTRIE2_LSCP_INDEX_2_LENGTH;
|
||||
|
||||
|
||||
/**
|
||||
* The 2-byte UTF-8 version of the index-2 table follows at offset 2080=0x820.
|
||||
* Length 32=0x20 for lead bytes C0..DF, regardless of UTRIE2_SHIFT_2.
|
||||
*/
|
||||
static final int UTRIE2_UTF8_2B_INDEX_2_OFFSET=UTRIE2_INDEX_2_BMP_LENGTH;
|
||||
static final int UTRIE2_UTF8_2B_INDEX_2_LENGTH=0x800>>6; /* U+0800 is the first code point after 2-byte UTF-8 */
|
||||
|
||||
|
||||
/**
|
||||
* The index-1 table, only used for supplementary code points, at offset 2112=0x840.
|
||||
* Variable length, for code points up to highStart, where the last single-value range starts.
|
||||
@ -775,22 +784,22 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
*/
|
||||
static final int UTRIE2_INDEX_1_OFFSET=UTRIE2_UTF8_2B_INDEX_2_OFFSET+UTRIE2_UTF8_2B_INDEX_2_LENGTH;
|
||||
static final int UTRIE2_MAX_INDEX_1_LENGTH=0x100000>>UTRIE2_SHIFT_1;
|
||||
|
||||
|
||||
/*
|
||||
* Fixed layout of the first part of the data array. -----------------------
|
||||
* Starts with 4 blocks (128=0x80 entries) for ASCII.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The illegal-UTF-8 data block follows the ASCII block, at offset 128=0x80.
|
||||
* Used with linear access for single bytes 0..0xbf for simple error handling.
|
||||
* Length 64=0x40, not UTRIE2_DATA_BLOCK_LENGTH.
|
||||
*/
|
||||
static final int UTRIE2_BAD_UTF8_DATA_OFFSET=0x80;
|
||||
|
||||
|
||||
/** The start of non-linear-ASCII data blocks, at offset 192=0xc0. */
|
||||
static final int UTRIE2_DATA_START_OFFSET=0xc0;
|
||||
|
||||
|
||||
/* Building a Trie2 ---------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
@ -831,14 +840,14 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
*/
|
||||
static final int UNEWTRIE2_MAX_DATA_LENGTH = (0x110000+0x40+0x40+0x400);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
|
||||
/**
|
||||
* Implementation class for an iterator over a Trie2.
|
||||
*
|
||||
*
|
||||
* Iteration over a Trie2 first returns all of the ranges that are indexed by code points,
|
||||
* then returns the special alternate values for the lead surrogates
|
||||
*
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class Trie2Iterator implements Iterator<Range> {
|
||||
@ -850,7 +859,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
limitCP = 0x110000;
|
||||
doLeadSurrogates = true;
|
||||
}
|
||||
|
||||
|
||||
// An alternate constructor that configures the iterator to cover only the
|
||||
// code points corresponding to a particular Lead Surrogate value.
|
||||
Trie2Iterator(char leadSurrogate, ValueMapper vm) {
|
||||
@ -863,11 +872,12 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
doLeadSurrogates = false; // Do not iterate over lead the special lead surrogate
|
||||
// values after completing iteration over code points.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main next() function for Trie2 iterators
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Range next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
@ -881,7 +891,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
int endOfRange = 0;
|
||||
int val = 0;
|
||||
int mappedVal = 0;
|
||||
|
||||
|
||||
if (doingCodePoints) {
|
||||
// Iteration over code point values.
|
||||
val = get(nextStart);
|
||||
@ -901,7 +911,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
}
|
||||
} else {
|
||||
// Iteration over the alternate lead surrogate values.
|
||||
val = getFromU16SingleLead((char)nextStart);
|
||||
val = getFromU16SingleLead((char)nextStart);
|
||||
mappedVal = mapper.map(val);
|
||||
endOfRange = rangeEndLS((char)nextStart);
|
||||
// Loop once for each range in the Trie2 with the same raw (unmapped) value.
|
||||
@ -921,34 +931,36 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
returnValue.endCodePoint = endOfRange;
|
||||
returnValue.value = mappedVal;
|
||||
returnValue.leadSurrogate = !doingCodePoints;
|
||||
nextStart = endOfRange+1;
|
||||
nextStart = endOfRange+1;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return doingCodePoints && (doLeadSurrogates || nextStart < limitCP) || nextStart < 0xdc00;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Find the last lead surrogate in a contiguous range with the
|
||||
* same Trie2 value as the input character.
|
||||
*
|
||||
*
|
||||
* Use the alternate Lead Surrogate values from the Trie2,
|
||||
* not the code-point values.
|
||||
*
|
||||
*
|
||||
* Note: Trie2_16 and Trie2_32 override this implementation with optimized versions,
|
||||
* meaning that the implementation here is only being used with
|
||||
* Trie2Writable. The code here is logically correct with any type
|
||||
* of Trie2, however.
|
||||
*
|
||||
*
|
||||
* @param c The character to begin with.
|
||||
* @return The last contiguous character with the same value.
|
||||
*/
|
||||
@ -956,7 +968,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
if (startingLS >= 0xdbff) {
|
||||
return 0xdbff;
|
||||
}
|
||||
|
||||
|
||||
int c;
|
||||
int val = getFromU16SingleLead(startingLS);
|
||||
for (c = startingLS+1; c <= 0x0dbff; c++) {
|
||||
@ -966,7 +978,7 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
}
|
||||
return c-1;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Iteration State Variables
|
||||
//
|
||||
@ -977,27 +989,27 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
// The upper limit for the last normal range to be returned. Normally 0x110000, but
|
||||
// may be lower when iterating over the code points for a single lead surrogate.
|
||||
private int limitCP;
|
||||
|
||||
|
||||
// True while iterating over the the Trie2 values for code points.
|
||||
// False while iterating over the alternate values for lead surrogates.
|
||||
private boolean doingCodePoints = true;
|
||||
|
||||
|
||||
// True if the iterator should iterate the special values for lead surrogates in
|
||||
// addition to the normal values for code points.
|
||||
private boolean doLeadSurrogates = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the last character in a contiguous range of characters with the
|
||||
* same Trie2 value as the input character.
|
||||
*
|
||||
*
|
||||
* @param c The character to begin with.
|
||||
* @return The last contiguous character with the same value.
|
||||
*/
|
||||
int rangeEnd(int start, int limitp, int val) {
|
||||
int c;
|
||||
int limit = Math.min(highStart, limitp);
|
||||
|
||||
|
||||
for (c = start+1; c < limit; c++) {
|
||||
if (get(c) != val) {
|
||||
break;
|
||||
@ -1008,28 +1020,28 @@ public abstract class Trie2 implements Iterable<Trie2.Range> {
|
||||
}
|
||||
return c - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Hashing implementation functions. FNV hash. Respected public domain algorithm.
|
||||
//
|
||||
private static int initHash() {
|
||||
return 0x811c9DC5; // unsigned 2166136261
|
||||
}
|
||||
|
||||
|
||||
private static int hashByte(int h, int b) {
|
||||
h = h * 16777619;
|
||||
h = h ^ b;
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
private static int hashUChar32(int h, int c) {
|
||||
h = Trie2.hashByte(h, c & 255);
|
||||
h = Trie2.hashByte(h, (c>>8) & 255);
|
||||
h = Trie2.hashByte(h, c>>16);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
private static int hashInt(int h, int i) {
|
||||
h = Trie2.hashByte(h, i & 255);
|
||||
h = Trie2.hashByte(h, (i>>8) & 255);
|
||||
|
@ -23,38 +23,38 @@ import com.ibm.icu.util.RangeValueIterator;
|
||||
* <p>Result of each iteration contains the interval of codepoints that have
|
||||
* the same value type and the value type itself.</p>
|
||||
* <p>The comparison of each codepoint value is done via extract(), which the
|
||||
* default implementation is to return the value as it is.</p>
|
||||
* <p>Method extract() can be overwritten to perform manipulations on
|
||||
* default implementation is to return the value as it is.</p>
|
||||
* <p>Method extract() can be overwritten to perform manipulations on
|
||||
* codepoint values in order to perform specialized comparison.</p>
|
||||
* <p>TrieIterator is designed to be a generic iterator for the CharTrie
|
||||
* and the IntTrie, hence to accommodate both types of data, the return
|
||||
* and the IntTrie, hence to accommodate both types of data, the return
|
||||
* result will be in terms of int (32 bit) values.</p>
|
||||
* <p>See com.ibm.icu.text.UCharacterTypeIterator for examples of use.</p>
|
||||
* <p>Notes for porting utrie_enum from icu4c to icu4j:<br>
|
||||
* Internally, icu4c's utrie_enum performs all iterations in its body. In Java
|
||||
* sense, the caller will have to pass a object with a callback function
|
||||
* UTrieEnumRange(const void *context, UChar32 start, UChar32 limit,
|
||||
* uint32_t value) into utrie_enum. utrie_enum will then find ranges of
|
||||
* codepoints with the same value as determined by
|
||||
* UTrieEnumValue(const void *context, uint32_t value). for each range,
|
||||
* sense, the caller will have to pass a object with a callback function
|
||||
* UTrieEnumRange(const void *context, UChar32 start, UChar32 limit,
|
||||
* uint32_t value) into utrie_enum. utrie_enum will then find ranges of
|
||||
* codepoints with the same value as determined by
|
||||
* UTrieEnumValue(const void *context, uint32_t value). for each range,
|
||||
* utrie_enum calls the callback function to perform a task. In this way,
|
||||
* icu4c performs the iteration within utrie_enum.
|
||||
* To follow the JDK model, icu4j is slightly different from icu4c.
|
||||
* Instead of requesting the caller to implement an object for a callback.
|
||||
* The caller will have to implement a subclass of TrieIterator, fleshing out
|
||||
* the method extract(int) (equivalent to UTrieEnumValue). Independent of icu4j,
|
||||
* the caller will have to code his own iteration and flesh out the task
|
||||
* the method extract(int) (equivalent to UTrieEnumValue). Independent of icu4j,
|
||||
* the caller will have to code his own iteration and flesh out the task
|
||||
* (equivalent to UTrieEnumRange) to be performed in the iteration loop.
|
||||
* </p>
|
||||
* <p>There are basically 3 usage scenarios for porting:</p>
|
||||
* <p>1) UTrieEnumValue is the only implemented callback then just implement a
|
||||
* subclass of TrieIterator and override the extract(int) method. The
|
||||
* <p>1) UTrieEnumValue is the only implemented callback then just implement a
|
||||
* subclass of TrieIterator and override the extract(int) method. The
|
||||
* extract(int) method is analogus to UTrieEnumValue callback.
|
||||
* </p>
|
||||
* <p>2) UTrieEnumValue and UTrieEnumRange both are implemented then implement
|
||||
* <p>2) UTrieEnumValue and UTrieEnumRange both are implemented then implement
|
||||
* a subclass of TrieIterator, override the extract method and iterate, e.g
|
||||
* </p>
|
||||
* <p>utrie_enum(&normTrie, _enumPropertyStartsValue, _enumPropertyStartsRange,
|
||||
* <p>utrie_enum(&normTrie, _enumPropertyStartsValue, _enumPropertyStartsRange,
|
||||
* set);<br>
|
||||
* In Java :<br>
|
||||
* <pre>
|
||||
@ -66,14 +66,14 @@ import com.ibm.icu.util.RangeValueIterator;
|
||||
* // port the implementation of _enumPropertyStartsValue here
|
||||
* }
|
||||
* }
|
||||
* ....
|
||||
* ....
|
||||
* TrieIterator fcdIter = new TrieIteratorImpl(fcdTrieImpl.fcdTrie);
|
||||
* while(fcdIter.next(result)) {
|
||||
* // port the implementation of _enumPropertyStartsRange
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
* <p>3) UTrieEnumRange is the only implemented callback then just implement
|
||||
* <p>3) UTrieEnumRange is the only implemented callback then just implement
|
||||
* the while loop, when utrie_enum is called
|
||||
* <pre>
|
||||
* // utrie_enum(&fcdTrie, NULL, _enumPropertyStartsRange, set);
|
||||
@ -90,7 +90,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
|
||||
{
|
||||
// public constructor ---------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* TrieEnumeration constructor
|
||||
* @param trie to be used
|
||||
@ -107,19 +107,20 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_initialValue_ = extract(m_trie_.getInitialValue());
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
// public methods -------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* <p>Returns true if we are not at the end of the iteration, false
|
||||
* <p>Returns true if we are not at the end of the iteration, false
|
||||
* otherwise.</p>
|
||||
* <p>The next set of codepoints with the same value type will be
|
||||
* <p>The next set of codepoints with the same value type will be
|
||||
* calculated during this call and returned in the arguement element.</p>
|
||||
* @param element return result
|
||||
* @param element return result
|
||||
* @return true if we are not at the end of the iteration, false otherwise.
|
||||
* @exception NoSuchElementException - if no more elements exist.
|
||||
* @see com.ibm.icu.util.RangeValueIterator.Element
|
||||
*/
|
||||
@Override
|
||||
public final boolean next(Element element)
|
||||
{
|
||||
if (m_nextCodepoint_ > UCharacter.MAX_VALUE) {
|
||||
@ -128,14 +129,15 @@ public class TrieIterator implements RangeValueIterator
|
||||
if (m_nextCodepoint_ < UCharacter.SUPPLEMENTARY_MIN_VALUE &&
|
||||
calculateNextBMPElement(element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
calculateNextSupplementaryElement(element);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the iterator to the beginning of the iteration
|
||||
*/
|
||||
@Override
|
||||
public final void reset()
|
||||
{
|
||||
m_currentCodepoint_ = 0;
|
||||
@ -151,9 +153,9 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextBlockIndex_ = 0;
|
||||
m_nextTrailIndexOffset_ = TRAIL_SURROGATE_INDEX_BLOCK_LENGTH_;
|
||||
}
|
||||
|
||||
|
||||
// protected methods ----------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Called by next() to extracts a 32 bit value from a trie value
|
||||
* used for comparison.
|
||||
@ -167,30 +169,30 @@ public class TrieIterator implements RangeValueIterator
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// private methods ------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Set the result values
|
||||
* @param element return result object
|
||||
* @param start codepoint of range
|
||||
* @param start codepoint of range
|
||||
* @param limit (end + 1) codepoint of range
|
||||
* @param value common value of range
|
||||
*/
|
||||
private final void setResult(Element element, int start, int limit,
|
||||
private final void setResult(Element element, int start, int limit,
|
||||
int value)
|
||||
{
|
||||
element.start = start;
|
||||
element.limit = limit;
|
||||
element.value = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finding the next element.
|
||||
* This method is called just before returning the result of
|
||||
* This method is called just before returning the result of
|
||||
* next().
|
||||
* We always store the next element before it is requested.
|
||||
* In the case that we have to continue calculations into the
|
||||
* In the case that we have to continue calculations into the
|
||||
* supplementary planes, a false will be returned.
|
||||
* @param element return result object
|
||||
* @return true if the next range is found, false if we have to proceed to
|
||||
@ -203,11 +205,11 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextCodepoint_ ++;
|
||||
m_nextBlockIndex_ ++;
|
||||
if (!checkBlockDetail(currentValue)) {
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
return true;
|
||||
}
|
||||
// synwee check that next block index == 0 here
|
||||
// synwee check that next block index == 0 here
|
||||
// enumerate BMP - the main loop enumerates data blocks
|
||||
while (m_nextCodepoint_ < UCharacter.SUPPLEMENTARY_MIN_VALUE) {
|
||||
// because of the way the character is split to form the index
|
||||
@ -224,10 +226,10 @@ public class TrieIterator implements RangeValueIterator
|
||||
} else {
|
||||
m_nextIndex_ ++;
|
||||
}
|
||||
|
||||
|
||||
m_nextBlockIndex_ = 0;
|
||||
if (!checkBlock(currentValue)) {
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
return true;
|
||||
}
|
||||
@ -248,9 +250,9 @@ public class TrieIterator implements RangeValueIterator
|
||||
* lower bound of the next element, in calculateNextBMP() it gets set
|
||||
* at the start of any loop, where-else, in calculateNextSupplementary()
|
||||
* since m_currentCodepoint_ already contains the lower bound of the
|
||||
* next element (passed down from calculateNextBMP()), we keep it till
|
||||
* next element (passed down from calculateNextBMP()), we keep it till
|
||||
* the end before resetting it to the new value.
|
||||
* Note, if there are no more iterations, it will never get to here.
|
||||
* Note, if there are no more iterations, it will never get to here.
|
||||
* Blocked out by next().
|
||||
* @param element return result object
|
||||
*/
|
||||
@ -259,13 +261,13 @@ public class TrieIterator implements RangeValueIterator
|
||||
int currentValue = m_nextValue_;
|
||||
m_nextCodepoint_ ++;
|
||||
m_nextBlockIndex_ ++;
|
||||
|
||||
if (UTF16.getTrailSurrogate(m_nextCodepoint_)
|
||||
!= UTF16.TRAIL_SURROGATE_MIN_VALUE) {
|
||||
|
||||
if (UTF16.getTrailSurrogate(m_nextCodepoint_)
|
||||
!= UTF16.TRAIL_SURROGATE_MIN_VALUE) {
|
||||
// this piece is only called when we are in the middle of a lead
|
||||
// surrogate block
|
||||
if (!checkNullNextTrailIndex() && !checkBlockDetail(currentValue)) {
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
@ -274,7 +276,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextIndex_ ++;
|
||||
m_nextTrailIndexOffset_ ++;
|
||||
if (!checkTrailBlock(currentValue)) {
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
@ -284,8 +286,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
// enumerate supplementary code points
|
||||
while (nextLead < TRAIL_SURROGATE_MIN_VALUE_) {
|
||||
// lead surrogate access
|
||||
final int leadBlock =
|
||||
m_trie_.m_index_[nextLead >> Trie.INDEX_STAGE_1_SHIFT_] <<
|
||||
final int leadBlock =
|
||||
m_trie_.m_index_[nextLead >> Trie.INDEX_STAGE_1_SHIFT_] <<
|
||||
Trie.INDEX_STAGE_2_SHIFT_;
|
||||
if (leadBlock == m_trie_.m_dataOffset_) {
|
||||
// no entries for a whole block of lead surrogates
|
||||
@ -293,7 +295,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextValue_ = m_initialValue_;
|
||||
m_nextBlock_ = leadBlock; // == m_trie_.m_dataOffset_
|
||||
m_nextBlockIndex_ = 0;
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
@ -302,7 +304,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
nextLead += DATA_BLOCK_LENGTH_;
|
||||
// number of total affected supplementary codepoints in one
|
||||
// block
|
||||
// this is not a simple addition of
|
||||
// this is not a simple addition of
|
||||
// DATA_BLOCK_SUPPLEMENTARY_LENGTH since we need to consider
|
||||
// that we might have moved some of the codepoints
|
||||
m_nextCodepoint_ = Character.toCodePoint((char)nextLead, (char)UTF16.TRAIL_SURROGATE_MIN_VALUE);
|
||||
@ -314,7 +316,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
}
|
||||
// enumerate trail surrogates for this lead surrogate
|
||||
m_nextIndex_ = m_trie_.m_dataManipulate_.getFoldingOffset(
|
||||
m_trie_.getValue(leadBlock +
|
||||
m_trie_.getValue(leadBlock +
|
||||
(nextLead & Trie.INDEX_STAGE_3_MASK_)));
|
||||
if (m_nextIndex_ <= 0) {
|
||||
// no data for this lead surrogate
|
||||
@ -322,7 +324,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextValue_ = m_initialValue_;
|
||||
m_nextBlock_ = m_trie_.m_dataOffset_;
|
||||
m_nextBlockIndex_ = 0;
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
@ -331,20 +333,20 @@ public class TrieIterator implements RangeValueIterator
|
||||
} else {
|
||||
m_nextTrailIndexOffset_ = 0;
|
||||
if (!checkTrailBlock(currentValue)) {
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
nextLead ++;
|
||||
}
|
||||
|
||||
// deliver last range
|
||||
setResult(element, m_currentCodepoint_, UCharacter.MAX_VALUE + 1,
|
||||
setResult(element, m_currentCodepoint_, UCharacter.MAX_VALUE + 1,
|
||||
currentValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal block value calculations
|
||||
* Performs calculations on a data block to find codepoints in m_nextBlock_
|
||||
@ -360,7 +362,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
private final boolean checkBlockDetail(int currentValue)
|
||||
{
|
||||
while (m_nextBlockIndex_ < DATA_BLOCK_LENGTH_) {
|
||||
m_nextValue_ = extract(m_trie_.getValue(m_nextBlock_ +
|
||||
m_nextValue_ = extract(m_trie_.getValue(m_nextBlock_ +
|
||||
m_nextBlockIndex_));
|
||||
if (m_nextValue_ != currentValue) {
|
||||
return false;
|
||||
@ -370,11 +372,11 @@ public class TrieIterator implements RangeValueIterator
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal block value calculations
|
||||
* Performs calculations on a data block to find codepoints in m_nextBlock_
|
||||
* that has the same value.
|
||||
* that has the same value.
|
||||
* Will call checkBlockDetail() if highlevel check fails.
|
||||
* Note m_*_ variables at this point is the next codepoint whose value
|
||||
* has not been calculated.
|
||||
@ -383,14 +385,14 @@ public class TrieIterator implements RangeValueIterator
|
||||
* @return true if the whole block has the same value as currentValue or if
|
||||
* the whole block has been calculated, false otherwise.
|
||||
*/
|
||||
private final boolean checkBlock(int currentValue)
|
||||
private final boolean checkBlock(int currentValue)
|
||||
{
|
||||
int currentBlock = m_nextBlock_;
|
||||
m_nextBlock_ = m_trie_.m_index_[m_nextIndex_] <<
|
||||
m_nextBlock_ = m_trie_.m_index_[m_nextIndex_] <<
|
||||
Trie.INDEX_STAGE_2_SHIFT_;
|
||||
if (m_nextBlock_ == currentBlock &&
|
||||
(m_nextCodepoint_ - m_currentCodepoint_) >= DATA_BLOCK_LENGTH_) {
|
||||
// the block is the same as the previous one, filled with
|
||||
// the block is the same as the previous one, filled with
|
||||
// currentValue
|
||||
m_nextCodepoint_ += DATA_BLOCK_LENGTH_;
|
||||
}
|
||||
@ -410,11 +412,11 @@ public class TrieIterator implements RangeValueIterator
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal block value calculations
|
||||
* Performs calculations on multiple data blocks for a set of trail
|
||||
* surrogates to find codepoints in m_nextBlock_ that has the same value.
|
||||
* Performs calculations on multiple data blocks for a set of trail
|
||||
* surrogates to find codepoints in m_nextBlock_ that has the same value.
|
||||
* Will call checkBlock() for internal block checks.
|
||||
* Note m_*_ variables at this point is the next codepoint whose value
|
||||
* has not been calculated.
|
||||
@ -425,7 +427,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
private final boolean checkTrailBlock(int currentValue)
|
||||
{
|
||||
// enumerate code points for this lead surrogate
|
||||
while (m_nextTrailIndexOffset_ < TRAIL_SURROGATE_INDEX_BLOCK_LENGTH_)
|
||||
while (m_nextTrailIndexOffset_ < TRAIL_SURROGATE_INDEX_BLOCK_LENGTH_)
|
||||
{
|
||||
// if we ever reach here, we are at the start of a new block
|
||||
m_nextBlockIndex_ = 0;
|
||||
@ -438,7 +440,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if we are beginning at the start of a initial block.
|
||||
* If we are then the rest of the codepoints in this initial block
|
||||
@ -453,15 +455,15 @@ public class TrieIterator implements RangeValueIterator
|
||||
if (m_nextIndex_ <= 0) {
|
||||
m_nextCodepoint_ += TRAIL_SURROGATE_COUNT_ - 1;
|
||||
int nextLead = UTF16.getLeadSurrogate(m_nextCodepoint_);
|
||||
int leadBlock =
|
||||
m_trie_.m_index_[nextLead >> Trie.INDEX_STAGE_1_SHIFT_] <<
|
||||
int leadBlock =
|
||||
m_trie_.m_index_[nextLead >> Trie.INDEX_STAGE_1_SHIFT_] <<
|
||||
Trie.INDEX_STAGE_2_SHIFT_;
|
||||
if (m_trie_.m_dataManipulate_ == null) {
|
||||
throw new NullPointerException(
|
||||
"The field DataManipulate in this Trie is null");
|
||||
}
|
||||
m_nextIndex_ = m_trie_.m_dataManipulate_.getFoldingOffset(
|
||||
m_trie_.getValue(leadBlock +
|
||||
m_trie_.getValue(leadBlock +
|
||||
(nextLead & Trie.INDEX_STAGE_3_MASK_)));
|
||||
m_nextIndex_ --;
|
||||
m_nextBlockIndex_ = DATA_BLOCK_LENGTH_;
|
||||
@ -505,7 +507,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
/**
|
||||
* Number of data values in a stage 2 (data array) block.
|
||||
*/
|
||||
private static final int DATA_BLOCK_LENGTH_ =
|
||||
private static final int DATA_BLOCK_LENGTH_ =
|
||||
1 << Trie.INDEX_STAGE_1_SHIFT_;
|
||||
// /**
|
||||
// * Number of codepoints in a stage 2 block
|
||||
|
@ -85,6 +85,7 @@ public final class UBiDiProps {
|
||||
|
||||
// implement ICUBinary.Authenticate
|
||||
private final static class IsAcceptable implements ICUBinary.Authenticate {
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[]) {
|
||||
return version[0]==2;
|
||||
}
|
||||
@ -226,12 +227,12 @@ public final class UBiDiProps {
|
||||
start=indexes[IX_JG_START];
|
||||
limit=indexes[IX_JG_LIMIT];
|
||||
if(start<=c && c<limit) {
|
||||
return (int)jgArray[c-start]&0xff;
|
||||
return jgArray[c-start]&0xff;
|
||||
}
|
||||
start=indexes[IX_JG_START2];
|
||||
limit=indexes[IX_JG_LIMIT2];
|
||||
if(start<=c && c<limit) {
|
||||
return (int)jgArray2[c-start]&0xff;
|
||||
return jgArray2[c-start]&0xff;
|
||||
}
|
||||
return UCharacter.JoiningGroup.NO_JOINING_GROUP;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public final class UCharArrayIterator extends UCharacterIterator {
|
||||
public UCharArrayIterator(char[] text, int start, int limit) {
|
||||
if (start < 0 || limit > text.length || start > limit) {
|
||||
throw new IllegalArgumentException("start: " + start + " or limit: "
|
||||
+ limit + " out of range [0, "
|
||||
+ limit + " out of range [0, "
|
||||
+ text.length + ")");
|
||||
}
|
||||
this.text = text;
|
||||
@ -36,35 +36,42 @@ public final class UCharArrayIterator extends UCharacterIterator {
|
||||
this.pos = start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int current() {
|
||||
return pos < limit ? text[pos] : DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return limit - start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return pos - start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int next() {
|
||||
return pos < limit ? text[pos++] : DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previous() {
|
||||
return pos > start ? text[--pos] : DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
if (index < 0 || index > limit - start) {
|
||||
throw new IndexOutOfBoundsException("index: " + index +
|
||||
" out of range [0, "
|
||||
throw new IndexOutOfBoundsException("index: " + index +
|
||||
" out of range [0, "
|
||||
+ (limit - start) + ")");
|
||||
}
|
||||
pos = start + index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getText(char[] fillIn, int offset) {
|
||||
int len = limit - start;
|
||||
System.arraycopy(text, start, fillIn, offset, len);
|
||||
@ -72,10 +79,11 @@ public final class UCharArrayIterator extends UCharacterIterator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of this iterator, does not clone the underlying
|
||||
* Creates a copy of this iterator, does not clone the underlying
|
||||
* <code>Replaceable</code>object
|
||||
* @return copy of this iterator
|
||||
*/
|
||||
@Override
|
||||
public Object clone(){
|
||||
try {
|
||||
return super.clone();
|
||||
|
@ -6,7 +6,7 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
package com.ibm.icu.impl;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
@ -14,16 +14,16 @@ import java.text.CharacterIterator;
|
||||
import com.ibm.icu.text.UCharacterIterator;
|
||||
|
||||
/**
|
||||
* This class is a wrapper around UCharacterIterator and implements the
|
||||
* This class is a wrapper around UCharacterIterator and implements the
|
||||
* CharacterIterator protocol
|
||||
* @author ram
|
||||
*/
|
||||
public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
|
||||
|
||||
public UCharacterIteratorWrapper(UCharacterIterator iter){
|
||||
this.iterator = iter;
|
||||
}
|
||||
|
||||
|
||||
private UCharacterIterator iterator;
|
||||
|
||||
|
||||
@ -33,6 +33,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @return the first character in the text, or DONE if the text is empty
|
||||
* @see #getBeginIndex()
|
||||
*/
|
||||
@Override
|
||||
public char first(){
|
||||
//UCharacterIterator always iterates from 0 to length
|
||||
iterator.setToStart();
|
||||
@ -45,6 +46,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @return the last character in the text, or DONE if the text is empty
|
||||
* @see #getEndIndex()
|
||||
*/
|
||||
@Override
|
||||
public char last(){
|
||||
iterator.setToLimit();
|
||||
return (char)iterator.previous();
|
||||
@ -56,6 +58,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* position is off the end of the text.
|
||||
* @see #getIndex()
|
||||
*/
|
||||
@Override
|
||||
public char current(){
|
||||
return (char) iterator.current();
|
||||
}
|
||||
@ -68,6 +71,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @return the character at the new position or DONE if the new
|
||||
* position is off the end of the text range.
|
||||
*/
|
||||
@Override
|
||||
public char next(){
|
||||
//pre-increment
|
||||
iterator.next();
|
||||
@ -81,6 +85,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @return the character at the new position or DONE if the current
|
||||
* position is equal to getBeginIndex().
|
||||
*/
|
||||
@Override
|
||||
public char previous(){
|
||||
//pre-decrement
|
||||
return (char) iterator.previous();
|
||||
@ -94,6 +99,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* if an invalid value is supplied.
|
||||
* @return the character at the specified position or DONE if the specified position is equal to getEndIndex()
|
||||
*/
|
||||
@Override
|
||||
public char setIndex(int position){
|
||||
iterator.setIndex(position);
|
||||
return (char) iterator.current();
|
||||
@ -103,6 +109,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* Returns the start index of the text.
|
||||
* @return the index at which the text begins.
|
||||
*/
|
||||
@Override
|
||||
public int getBeginIndex(){
|
||||
//UCharacterIterator always starts from 0
|
||||
return 0;
|
||||
@ -113,6 +120,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* character following the end of the text.
|
||||
* @return the index after the last character in the text
|
||||
*/
|
||||
@Override
|
||||
public int getEndIndex(){
|
||||
return iterator.getLength();
|
||||
}
|
||||
@ -121,6 +129,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* Returns the current index.
|
||||
* @return the current index.
|
||||
*/
|
||||
@Override
|
||||
public int getIndex(){
|
||||
return iterator.getIndex();
|
||||
}
|
||||
@ -129,15 +138,16 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* Create a copy of this iterator
|
||||
* @return A copy of this
|
||||
*/
|
||||
@Override
|
||||
public Object clone(){
|
||||
try {
|
||||
UCharacterIteratorWrapper result = (UCharacterIteratorWrapper) super.clone();
|
||||
result.iterator = (UCharacterIterator)this.iterator.clone();
|
||||
return result;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null; // only invoked if bad underlying character iterator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,22 +14,23 @@ import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* <p>Internal reader class for ICU data file uname.dat containing
|
||||
* Unicode codepoint name data.</p>
|
||||
* <p>Internal reader class for ICU data file uname.dat containing
|
||||
* Unicode codepoint name data.</p>
|
||||
* <p>This class simply reads unames.icu, authenticates that it is a valid
|
||||
* ICU data file and split its contents up into blocks of data for use in
|
||||
* <a href=UCharacterName.html>com.ibm.icu.impl.UCharacterName</a>.
|
||||
* </p>
|
||||
* <p>unames.icu which is in big-endian format is jared together with this
|
||||
* </p>
|
||||
* <p>unames.icu which is in big-endian format is jared together with this
|
||||
* package.</p>
|
||||
* @author Syn Wee Quek
|
||||
* @since release 2.1, February 1st 2002
|
||||
*/
|
||||
|
||||
final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
{
|
||||
{
|
||||
// public methods ----------------------------------------------------
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[])
|
||||
{
|
||||
return version[0] == 1;
|
||||
@ -64,7 +65,7 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
m_groupindex_ = m_byteBuffer_.getInt();
|
||||
m_groupstringindex_ = m_byteBuffer_.getInt();
|
||||
m_algnamesindex_ = m_byteBuffer_.getInt();
|
||||
|
||||
|
||||
// reading tokens
|
||||
int count = m_byteBuffer_.getChar();
|
||||
char token[] = ICUBinary.getChars(m_byteBuffer_, count, 0);
|
||||
@ -72,7 +73,7 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
byte tokenstr[] = new byte[size];
|
||||
m_byteBuffer_.get(tokenstr);
|
||||
data.setToken(token, tokenstr);
|
||||
|
||||
|
||||
// reading the group information records
|
||||
count = m_byteBuffer_.getChar();
|
||||
data.setGroupCountSize(count, GROUP_INFO_SIZE_);
|
||||
@ -82,13 +83,13 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
size = m_algnamesindex_ - m_groupstringindex_;
|
||||
byte groupstring[] = new byte[size];
|
||||
m_byteBuffer_.get(groupstring);
|
||||
|
||||
|
||||
data.setGroup(group, groupstring);
|
||||
|
||||
|
||||
count = m_byteBuffer_.getInt();
|
||||
UCharacterName.AlgorithmName alg[] =
|
||||
UCharacterName.AlgorithmName alg[] =
|
||||
new UCharacterName.AlgorithmName[count];
|
||||
|
||||
|
||||
for (int i = 0; i < count; i ++)
|
||||
{
|
||||
UCharacterName.AlgorithmName an = readAlg();
|
||||
@ -99,7 +100,7 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
}
|
||||
data.setAlgorithm(alg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Checking the file for the correct format.</p>
|
||||
* @param dataformatid
|
||||
@ -116,7 +117,7 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
isDataVersionAcceptable(dataformatversion);
|
||||
}
|
||||
///CLOVER:ON
|
||||
|
||||
|
||||
// private variables -------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -135,10 +136,10 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
private int m_groupindex_;
|
||||
private int m_groupstringindex_;
|
||||
private int m_algnamesindex_;
|
||||
|
||||
|
||||
/**
|
||||
* Size of an algorithmic name information group
|
||||
* start code point size + end code point size + type size + variant size +
|
||||
* start code point size + end code point size + type size + variant size +
|
||||
* size of data size
|
||||
*/
|
||||
private static final int ALG_INFO_SIZE_ = 12;
|
||||
@ -149,7 +150,7 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
private static final int DATA_FORMAT_ID_ = 0x756E616D;
|
||||
|
||||
// private methods ---------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Reads an individual record of AlgorithmNames
|
||||
* @return an instance of AlgorithNames if read is successful otherwise null
|
||||
@ -157,7 +158,7 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
*/
|
||||
private UCharacterName.AlgorithmName readAlg() throws IOException
|
||||
{
|
||||
UCharacterName.AlgorithmName result =
|
||||
UCharacterName.AlgorithmName result =
|
||||
new UCharacterName.AlgorithmName();
|
||||
int rangestart = m_byteBuffer_.getInt();
|
||||
int rangeend = m_byteBuffer_.getInt();
|
||||
@ -166,7 +167,7 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
if (!result.setInfo(rangestart, rangeend, type, variant)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
int size = m_byteBuffer_.getChar();
|
||||
if (type == UCharacterName.AlgorithmName.TYPE_1_)
|
||||
{
|
||||
@ -175,7 +176,7 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
result.setFactor(factor);
|
||||
size -= (variant << 1);
|
||||
}
|
||||
|
||||
|
||||
StringBuilder prefix = new StringBuilder();
|
||||
char c = (char)(m_byteBuffer_.get() & 0x00FF);
|
||||
while (c != 0)
|
||||
@ -183,11 +184,11 @@ final class UCharacterNameReader implements ICUBinary.Authenticate
|
||||
prefix.append(c);
|
||||
c = (char)(m_byteBuffer_.get() & 0x00FF);
|
||||
}
|
||||
|
||||
|
||||
result.setPrefix(prefix.toString());
|
||||
|
||||
|
||||
size -= (ALG_INFO_SIZE_ + prefix.length() + 1);
|
||||
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
byte string[] = new byte[size];
|
||||
|
@ -212,6 +212,7 @@ public final class UCharacterProperty
|
||||
super(SRC_CASE);
|
||||
this.which=which;
|
||||
}
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
return UCaseProps.INSTANCE.hasBinaryProperty(c, which);
|
||||
}
|
||||
@ -223,6 +224,7 @@ public final class UCharacterProperty
|
||||
super(source);
|
||||
this.which=which;
|
||||
}
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
return Norm2AllModes.getN2WithImpl(which-UProperty.NFD_INERT).isInert(c);
|
||||
}
|
||||
@ -236,11 +238,13 @@ public final class UCharacterProperty
|
||||
new BinaryProperty(1, (1<<ALPHABETIC_PROPERTY_)),
|
||||
new BinaryProperty(1, (1<<ASCII_HEX_DIGIT_PROPERTY_)),
|
||||
new BinaryProperty(SRC_BIDI) { // UCHAR_BIDI_CONTROL
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
return UBiDiProps.INSTANCE.isBidiControl(c);
|
||||
}
|
||||
},
|
||||
new BinaryProperty(SRC_BIDI) { // UCHAR_BIDI_MIRRORED
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
return UBiDiProps.INSTANCE.isMirrored(c);
|
||||
}
|
||||
@ -251,6 +255,7 @@ public final class UCharacterProperty
|
||||
new BinaryProperty(1, (1<<DIACRITIC_PROPERTY_)),
|
||||
new BinaryProperty(1, (1<<EXTENDER_PROPERTY_)),
|
||||
new BinaryProperty(SRC_NFC) { // UCHAR_FULL_COMPOSITION_EXCLUSION
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
// By definition, Full_Composition_Exclusion is the same as NFC_QC=No.
|
||||
Normalizer2Impl impl=Norm2AllModes.getNFCInstance().impl;
|
||||
@ -268,6 +273,7 @@ public final class UCharacterProperty
|
||||
new BinaryProperty(1, (1<<IDS_BINARY_OPERATOR_PROPERTY_)),
|
||||
new BinaryProperty(1, (1<<IDS_TRINARY_OPERATOR_PROPERTY_)),
|
||||
new BinaryProperty(SRC_BIDI) { // UCHAR_JOIN_CONTROL
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
return UBiDiProps.INSTANCE.isJoinControl(c);
|
||||
}
|
||||
@ -293,6 +299,7 @@ public final class UCharacterProperty
|
||||
new NormInertBinaryProperty(SRC_NFC, UProperty.NFC_INERT),
|
||||
new NormInertBinaryProperty(SRC_NFKC, UProperty.NFKC_INERT),
|
||||
new BinaryProperty(SRC_NFC_CANON_ITER) { // UCHAR_SEGMENT_STARTER
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
return Norm2AllModes.getNFCInstance().impl.
|
||||
ensureCanonIterData().isCanonSegmentStarter(c);
|
||||
@ -301,11 +308,13 @@ public final class UCharacterProperty
|
||||
new BinaryProperty(1, (1<<PATTERN_SYNTAX)),
|
||||
new BinaryProperty(1, (1<<PATTERN_WHITE_SPACE)),
|
||||
new BinaryProperty(SRC_CHAR_AND_PROPSVEC) { // UCHAR_POSIX_ALNUM
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
return UCharacter.isUAlphabetic(c) || UCharacter.isDigit(c);
|
||||
}
|
||||
},
|
||||
new BinaryProperty(SRC_CHAR) { // UCHAR_POSIX_BLANK
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
// "horizontal space"
|
||||
if(c<=0x9f) {
|
||||
@ -317,11 +326,13 @@ public final class UCharacterProperty
|
||||
}
|
||||
},
|
||||
new BinaryProperty(SRC_CHAR) { // UCHAR_POSIX_GRAPH
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
return isgraphPOSIX(c);
|
||||
}
|
||||
},
|
||||
new BinaryProperty(SRC_CHAR) { // UCHAR_POSIX_PRINT
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
/*
|
||||
* Checks if codepoint is in \p{graph}\p{blank} - \p{cntrl}.
|
||||
@ -333,6 +344,7 @@ public final class UCharacterProperty
|
||||
}
|
||||
},
|
||||
new BinaryProperty(SRC_CHAR) { // UCHAR_POSIX_XDIGIT
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
/* check ASCII and Fullwidth ASCII a-fA-F */
|
||||
if(
|
||||
@ -350,6 +362,7 @@ public final class UCharacterProperty
|
||||
new CaseBinaryProperty(UProperty.CHANGES_WHEN_UPPERCASED),
|
||||
new CaseBinaryProperty(UProperty.CHANGES_WHEN_TITLECASED),
|
||||
new BinaryProperty(SRC_CASE_AND_NORM) { // UCHAR_CHANGES_WHEN_CASEFOLDED
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
String nfd=Norm2AllModes.getNFCInstance().impl.getDecomposition(c);
|
||||
if(nfd!=null) {
|
||||
@ -376,6 +389,7 @@ public final class UCharacterProperty
|
||||
},
|
||||
new CaseBinaryProperty(UProperty.CHANGES_WHEN_CASEMAPPED),
|
||||
new BinaryProperty(SRC_NFKC_CF) { // UCHAR_CHANGES_WHEN_NFKC_CASEFOLDED
|
||||
@Override
|
||||
boolean contains(int c) {
|
||||
Normalizer2Impl kcf=Norm2AllModes.getNFKC_CFInstance().impl;
|
||||
String src=UTF16.valueOf(c);
|
||||
@ -457,6 +471,7 @@ public final class UCharacterProperty
|
||||
BiDiIntProperty() {
|
||||
super(SRC_BIDI);
|
||||
}
|
||||
@Override
|
||||
int getMaxValue(int which) {
|
||||
return UBiDiProps.INSTANCE.getMaxValue(which);
|
||||
}
|
||||
@ -466,6 +481,7 @@ public final class UCharacterProperty
|
||||
CombiningClassIntProperty(int source) {
|
||||
super(source);
|
||||
}
|
||||
@Override
|
||||
int getMaxValue(int which) {
|
||||
return 0xff;
|
||||
}
|
||||
@ -479,9 +495,11 @@ public final class UCharacterProperty
|
||||
this.which=which;
|
||||
this.max=max;
|
||||
}
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return Norm2AllModes.getN2WithImpl(which-UProperty.NFD_QUICK_CHECK).getQuickCheck(c);
|
||||
}
|
||||
@Override
|
||||
int getMaxValue(int which) {
|
||||
return max;
|
||||
}
|
||||
@ -489,12 +507,14 @@ public final class UCharacterProperty
|
||||
|
||||
IntProperty intProps[]={
|
||||
new BiDiIntProperty() { // BIDI_CLASS
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return UBiDiProps.INSTANCE.getClass(c);
|
||||
}
|
||||
},
|
||||
new IntProperty(0, BLOCK_MASK_, BLOCK_SHIFT_),
|
||||
new CombiningClassIntProperty(SRC_NFC) { // CANONICAL_COMBINING_CLASS
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return Normalizer2.getNFDInstance().getCombiningClass(c);
|
||||
}
|
||||
@ -502,38 +522,46 @@ public final class UCharacterProperty
|
||||
new IntProperty(2, DECOMPOSITION_TYPE_MASK_, 0),
|
||||
new IntProperty(0, EAST_ASIAN_MASK_, EAST_ASIAN_SHIFT_),
|
||||
new IntProperty(SRC_CHAR) { // GENERAL_CATEGORY
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return getType(c);
|
||||
}
|
||||
@Override
|
||||
int getMaxValue(int which) {
|
||||
return UCharacterCategory.CHAR_CATEGORY_COUNT-1;
|
||||
}
|
||||
},
|
||||
new BiDiIntProperty() { // JOINING_GROUP
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return UBiDiProps.INSTANCE.getJoiningGroup(c);
|
||||
}
|
||||
},
|
||||
new BiDiIntProperty() { // JOINING_TYPE
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return UBiDiProps.INSTANCE.getJoiningType(c);
|
||||
}
|
||||
},
|
||||
new IntProperty(2, LB_MASK, LB_SHIFT), // LINE_BREAK
|
||||
new IntProperty(SRC_CHAR) { // NUMERIC_TYPE
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return ntvGetType(getNumericTypeValue(getProperty(c)));
|
||||
}
|
||||
@Override
|
||||
int getMaxValue(int which) {
|
||||
return NumericType.COUNT-1;
|
||||
}
|
||||
},
|
||||
new IntProperty(0, SCRIPT_MASK_, 0) {
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return UScript.getScript(c);
|
||||
}
|
||||
},
|
||||
new IntProperty(SRC_PROPSVEC) { // HANGUL_SYLLABLE_TYPE
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
/* see comments on gcbToHst[] above */
|
||||
int gcb=(getAdditional(c, 2)&GCB_MASK)>>>GCB_SHIFT;
|
||||
@ -543,6 +571,7 @@ public final class UCharacterProperty
|
||||
return HangulSyllableType.NOT_APPLICABLE;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
int getMaxValue(int which) {
|
||||
return HangulSyllableType.COUNT-1;
|
||||
}
|
||||
@ -554,11 +583,13 @@ public final class UCharacterProperty
|
||||
new NormQuickCheckIntProperty(SRC_NFC, UProperty.NFC_QUICK_CHECK, 2),
|
||||
new NormQuickCheckIntProperty(SRC_NFKC, UProperty.NFKC_QUICK_CHECK, 2),
|
||||
new CombiningClassIntProperty(SRC_NFC) { // LEAD_CANONICAL_COMBINING_CLASS
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return Norm2AllModes.getNFCInstance().impl.getFCD16(c)>>8;
|
||||
}
|
||||
},
|
||||
new CombiningClassIntProperty(SRC_NFC) { // TRAIL_CANONICAL_COMBINING_CLASS
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return Norm2AllModes.getNFCInstance().impl.getFCD16(c)&0xff;
|
||||
}
|
||||
@ -567,6 +598,7 @@ public final class UCharacterProperty
|
||||
new IntProperty(2, SB_MASK, SB_SHIFT), // SENTENCE_BREAK
|
||||
new IntProperty(2, WB_MASK, WB_SHIFT), // WORD_BREAK
|
||||
new BiDiIntProperty() { // BIDI_PAIRED_BRACKET_TYPE
|
||||
@Override
|
||||
int getValue(int c) {
|
||||
return UBiDiProps.INSTANCE.getPairedBracketType(c);
|
||||
}
|
||||
@ -1240,6 +1272,7 @@ public final class UCharacterProperty
|
||||
|
||||
private static final class IsAcceptable implements ICUBinary.Authenticate {
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[]) {
|
||||
return version[0] == 7;
|
||||
}
|
||||
@ -1332,7 +1365,7 @@ public final class UCharacterProperty
|
||||
|
||||
/* add for u_charDigitValue() */
|
||||
// TODO remove when UCharacter.getHanNumericValue() is changed to just return
|
||||
// Unicode numeric values
|
||||
// Unicode numeric values
|
||||
set.add(0x3007);
|
||||
set.add(0x3008);
|
||||
set.add(0x4e00);
|
||||
|
@ -69,6 +69,7 @@ public final class UPropertyAliases {
|
||||
|
||||
private static final class IsAcceptable implements ICUBinary.Authenticate {
|
||||
// @Override when we switch to Java 6
|
||||
@Override
|
||||
public boolean isDataVersionAcceptable(byte version[]) {
|
||||
return version[0]==2;
|
||||
}
|
||||
@ -186,7 +187,7 @@ public final class UPropertyAliases {
|
||||
// Find the end of this name.
|
||||
int nameStart=nameGroupsIndex;
|
||||
while(0!=nameGroups.charAt(nameGroupsIndex)) {
|
||||
++nameGroupsIndex;
|
||||
++nameGroupsIndex;
|
||||
}
|
||||
if(nameStart==nameGroupsIndex) {
|
||||
return null; // no name (Property[Value]Aliases.txt has "n/a")
|
||||
|
@ -27,14 +27,14 @@ import java.util.jar.JarFile;
|
||||
|
||||
public abstract class URLHandler {
|
||||
public static final String PROPNAME = "urlhandler.props";
|
||||
|
||||
|
||||
private static final Map<String, Method> handlers;
|
||||
|
||||
|
||||
private static final boolean DEBUG = ICUDebug.enabled("URLHandler");
|
||||
|
||||
|
||||
static {
|
||||
Map<String, Method> h = null;
|
||||
|
||||
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
@SuppressWarnings("resource") // Closed by BufferedReader.
|
||||
@ -44,32 +44,32 @@ public abstract class URLHandler {
|
||||
if (is != null) {
|
||||
Class<?>[] params = { URL.class };
|
||||
br = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
|
||||
for (String line = br.readLine(); line != null; line = br.readLine()) {
|
||||
line = line.trim();
|
||||
|
||||
|
||||
if (line.length() == 0 || line.charAt(0) == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
int ix = line.indexOf('=');
|
||||
|
||||
|
||||
if (ix == -1) {
|
||||
if (DEBUG) System.err.println("bad urlhandler line: '" + line + "'");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
String key = line.substring(0, ix).trim();
|
||||
String value = line.substring(ix+1).trim();
|
||||
|
||||
|
||||
try {
|
||||
Class<?> cl = Class.forName(value);
|
||||
Method m = cl.getDeclaredMethod("get", params);
|
||||
|
||||
|
||||
if (h == null) {
|
||||
h = new HashMap<String, Method>();
|
||||
}
|
||||
|
||||
|
||||
h.put(key, m);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
@ -102,16 +102,16 @@ public abstract class URLHandler {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
String protocol = url.getProtocol();
|
||||
|
||||
|
||||
if (handlers != null) {
|
||||
Method m = handlers.get(protocol);
|
||||
|
||||
|
||||
if (m != null) {
|
||||
try {
|
||||
URLHandler handler = (URLHandler)m.invoke(null, new Object[] { url });
|
||||
|
||||
|
||||
if (handler != null) {
|
||||
return handler;
|
||||
}
|
||||
@ -127,10 +127,10 @@ public abstract class URLHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return getDefault(url);
|
||||
}
|
||||
|
||||
|
||||
protected static URLHandler getDefault(URL url) {
|
||||
URLHandler handler = null;
|
||||
|
||||
@ -146,7 +146,7 @@ public abstract class URLHandler {
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
||||
private static class FileURLHandler extends URLHandler {
|
||||
File file;
|
||||
|
||||
@ -161,7 +161,8 @@ public abstract class URLHandler {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void guide(URLVisitor v, boolean recurse, boolean strip) {
|
||||
if (file.isDirectory()) {
|
||||
process(v, recurse, strip, "/", file.listFiles());
|
||||
@ -169,12 +170,12 @@ public abstract class URLHandler {
|
||||
v.visit(file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void process(URLVisitor v, boolean recurse, boolean strip, String path, File[] files) {
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
File f = files[i];
|
||||
|
||||
|
||||
if (f.isDirectory()) {
|
||||
if (recurse) {
|
||||
process(v, recurse, strip, path + f.getName()+ '/', f.listFiles());
|
||||
@ -186,7 +187,7 @@ public abstract class URLHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class JarURLHandler extends URLHandler {
|
||||
JarFile jarFile;
|
||||
String prefix;
|
||||
@ -194,9 +195,9 @@ public abstract class URLHandler {
|
||||
JarURLHandler(URL url) {
|
||||
try {
|
||||
prefix = url.getPath();
|
||||
|
||||
|
||||
int ix = prefix.lastIndexOf("!/");
|
||||
|
||||
|
||||
if (ix >= 0) {
|
||||
prefix = prefix.substring(ix + 2); // truncate after "!/"
|
||||
}
|
||||
@ -220,17 +221,18 @@ public abstract class URLHandler {
|
||||
throw new IllegalArgumentException("jar error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void guide(URLVisitor v, boolean recurse, boolean strip) {
|
||||
try {
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
|
||||
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
|
||||
|
||||
if (!entry.isDirectory()) { // skip just directory paths
|
||||
String name = entry.getName();
|
||||
|
||||
|
||||
if (name.startsWith(prefix)) {
|
||||
name = name.substring(prefix.length());
|
||||
int ix = name.lastIndexOf('/');
|
||||
@ -255,9 +257,9 @@ public abstract class URLHandler {
|
||||
{
|
||||
guide(visitor, recurse, true);
|
||||
}
|
||||
|
||||
|
||||
public abstract void guide(URLVisitor visitor, boolean recurse, boolean strip);
|
||||
|
||||
|
||||
public interface URLVisitor {
|
||||
void visit(String str);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
* consistent with Java regex, so be careful of the differences.
|
||||
* <p>Not thread-safe; create a separate copy for different threads.
|
||||
* <p>In the future, we may extend this to support other regex packages.
|
||||
*
|
||||
*
|
||||
* @regex A modified Java regex pattern, as in the input to
|
||||
* Pattern.compile(), except that all "character classes" are
|
||||
* processed as if they were UnicodeSet patterns. Example:
|
||||
@ -82,6 +82,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
* @return A processed Java regex pattern, suitable for input to
|
||||
* Pattern.compile().
|
||||
*/
|
||||
@Override
|
||||
public String transform(String regex) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
UnicodeSet temp = new UnicodeSet();
|
||||
@ -150,7 +151,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
|
||||
/**
|
||||
* Compile a regex string, after processing by fix(...).
|
||||
*
|
||||
*
|
||||
* @param regex Raw regex pattern, as in fix(...).
|
||||
* @return Pattern
|
||||
*/
|
||||
@ -160,7 +161,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
|
||||
/**
|
||||
* Compile a regex string, after processing by fix(...).
|
||||
*
|
||||
*
|
||||
* @param regex Raw regex pattern, as in fix(...).
|
||||
* @return Pattern
|
||||
*/
|
||||
@ -170,7 +171,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
|
||||
/**
|
||||
* Compile a composed string from a set of BNF lines; see the List version for more information.
|
||||
*
|
||||
*
|
||||
* @param bnfLines Series of BNF lines.
|
||||
* @return Pattern
|
||||
*/
|
||||
@ -194,10 +195,10 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
* </pre>
|
||||
* <p>
|
||||
* Caveats: at this point the parsing is simple; for example, # cannot be
|
||||
* quoted (use \\u0023); you can set it to null to disable.
|
||||
* quoted (use \\u0023); you can set it to null to disable.
|
||||
* The equality sign and a few others can be reset with
|
||||
* setBnfX().
|
||||
*
|
||||
*
|
||||
* @param lines Series of lines that represent a BNF expression. The lines contain
|
||||
* a series of statements that of the form x=y;. A statement can take
|
||||
* multiple lines, but there can't be multiple statements on a line.
|
||||
@ -213,7 +214,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
for (Entry<String, String> entry : variables.entrySet()) {
|
||||
String variable = entry.getKey(),
|
||||
definition = entry.getValue();
|
||||
|
||||
|
||||
for (Entry<String, String> entry2 : variables.entrySet()) {
|
||||
String variable2 = entry2.getKey(),
|
||||
definition2 = entry2.getValue();
|
||||
@ -300,12 +301,13 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.icu.util.Freezable#cloneAsThawed()
|
||||
*/
|
||||
@Override
|
||||
public UnicodeRegex cloneAsThawed() {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
@ -318,6 +320,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.icu.util.Freezable#freeze()
|
||||
*/
|
||||
@Override
|
||||
public UnicodeRegex freeze() {
|
||||
// no action needed now.
|
||||
return this;
|
||||
@ -326,6 +329,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
/* (non-Javadoc)
|
||||
* @see com.ibm.icu.util.Freezable#isFrozen()
|
||||
*/
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
// at this point, always true
|
||||
return true;
|
||||
@ -353,6 +357,7 @@ public class UnicodeRegex implements Cloneable, Freezable<UnicodeRegex>, StringT
|
||||
// private Appendable log = null;
|
||||
|
||||
private Comparator<Object> LongestFirst = new Comparator<Object>() {
|
||||
@Override
|
||||
public int compare(Object obj0, Object obj1) {
|
||||
String arg0 = obj0.toString();
|
||||
String arg1 = obj1.toString();
|
||||
|
@ -14,17 +14,19 @@ import java.util.ListResourceBundle;
|
||||
public class HolidayBundle extends ListResourceBundle {
|
||||
|
||||
// Normally, each HolidayBundle uses the holiday's US English name
|
||||
// as the string key for looking up the localized name. This means
|
||||
// as the string key for looking up the localized name. This means
|
||||
// that the key itself can be used if no name is found for the requested
|
||||
// locale.
|
||||
//
|
||||
// For holidays where the key is _not_ the English name, e.g. in the
|
||||
// case of conflicts, the English name must be given here.
|
||||
//
|
||||
static private final Object[][] fContents = {
|
||||
{ "", "" }, // Can't be empty!
|
||||
static private final Object[][] fContents = { { "", "" }, // Can't be empty!
|
||||
};
|
||||
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
@Override
|
||||
public synchronized Object[][] getContents() {
|
||||
return fContents;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,5 +28,6 @@ public class HolidayBundle_da extends ListResourceBundle
|
||||
{ "Pentecost", "pinse" },
|
||||
{ "Shrove Tuesday", "hvidetirsdag" },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -16,28 +16,20 @@ import com.ibm.icu.util.EasterHoliday;
|
||||
import com.ibm.icu.util.Holiday;
|
||||
import com.ibm.icu.util.SimpleHoliday;
|
||||
|
||||
public class HolidayBundle_da_DK extends ListResourceBundle
|
||||
{
|
||||
static private final Holiday[] fHolidays = {
|
||||
SimpleHoliday.NEW_YEARS_DAY,
|
||||
new SimpleHoliday(Calendar.APRIL, 30, -Calendar.FRIDAY, "General Prayer Day"),
|
||||
new SimpleHoliday(Calendar.JUNE, 5, "Constitution Day"),
|
||||
SimpleHoliday.CHRISTMAS_EVE,
|
||||
SimpleHoliday.CHRISTMAS,
|
||||
SimpleHoliday.BOXING_DAY,
|
||||
SimpleHoliday.NEW_YEARS_EVE,
|
||||
public class HolidayBundle_da_DK extends ListResourceBundle {
|
||||
static private final Holiday[] fHolidays = { SimpleHoliday.NEW_YEARS_DAY,
|
||||
new SimpleHoliday(Calendar.APRIL, 30, -Calendar.FRIDAY, "General Prayer Day"),
|
||||
new SimpleHoliday(Calendar.JUNE, 5, "Constitution Day"), SimpleHoliday.CHRISTMAS_EVE,
|
||||
SimpleHoliday.CHRISTMAS, SimpleHoliday.BOXING_DAY, SimpleHoliday.NEW_YEARS_EVE,
|
||||
|
||||
// Easter and related holidays
|
||||
EasterHoliday.MAUNDY_THURSDAY,
|
||||
EasterHoliday.GOOD_FRIDAY,
|
||||
EasterHoliday.EASTER_SUNDAY,
|
||||
EasterHoliday.EASTER_MONDAY,
|
||||
EasterHoliday.ASCENSION,
|
||||
EasterHoliday.WHIT_MONDAY,
|
||||
};
|
||||
// Easter and related holidays
|
||||
EasterHoliday.MAUNDY_THURSDAY, EasterHoliday.GOOD_FRIDAY, EasterHoliday.EASTER_SUNDAY,
|
||||
EasterHoliday.EASTER_MONDAY, EasterHoliday.ASCENSION, EasterHoliday.WHIT_MONDAY, };
|
||||
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
static private final Object[][] fContents = { { "holidays", fHolidays }, };
|
||||
|
||||
@Override
|
||||
public synchronized Object[][] getContents() {
|
||||
return fContents;
|
||||
}
|
||||
}
|
||||
|
@ -65,5 +65,6 @@ public class HolidayBundle_de extends ListResourceBundle {
|
||||
{ "Whit Sunday", "Pfingstsonntag" },
|
||||
};
|
||||
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -44,5 +44,6 @@ public class HolidayBundle_de_AT extends ListResourceBundle {
|
||||
{ "Christmas", "Christtag" },
|
||||
{ "New Year's Day", "Neujahrstag" },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -39,5 +39,6 @@ public class HolidayBundle_de_DE extends ListResourceBundle {
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -27,5 +27,6 @@ public class HolidayBundle_el extends ListResourceBundle {
|
||||
{ "Whit Monday", "\u0394\u03b5\u03cd\u03c4\u03b5\u03c1\u03b7 \u03bc\u03ad\u03c1\u03b1 \u03c4\u03bf\u03cd \u03a0\u03b5\u03bd\u03c4\u03b7\u03ba\u03bf\u03c3\u03c4\u03ae" },
|
||||
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -40,5 +40,6 @@ public class HolidayBundle_el_GR extends ListResourceBundle {
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public class HolidayBundle_en extends ListResourceBundle {
|
||||
{ "", "" }, // Can't be empty!
|
||||
};
|
||||
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
|
||||
}
|
||||
|
@ -40,5 +40,6 @@ public class HolidayBundle_en_CA extends ListResourceBundle {
|
||||
|
||||
{ "Labor Day", "Labour Day" },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -37,5 +37,6 @@ public class HolidayBundle_en_GB extends ListResourceBundle
|
||||
|
||||
{ "Labor Day", "Labour Day" },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -47,5 +47,6 @@ public class HolidayBundle_en_US extends ListResourceBundle
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -48,5 +48,6 @@ public class HolidayBundle_es extends ListResourceBundle {
|
||||
{ "Whit Sunday", "Pentecost\u00e9s" },
|
||||
};
|
||||
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -34,5 +34,6 @@ public class HolidayBundle_es_MX extends ListResourceBundle {
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -41,5 +41,6 @@ public class HolidayBundle_fr extends ListResourceBundle {
|
||||
{ "Victory Day", "F\u00EAte de la Victoire" },
|
||||
};
|
||||
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -38,5 +38,6 @@ public class HolidayBundle_fr_CA extends ListResourceBundle {
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -37,5 +37,6 @@ public class HolidayBundle_fr_FR extends ListResourceBundle {
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -33,5 +33,6 @@ public class HolidayBundle_it extends ListResourceBundle {
|
||||
{ "Thanksgiving", "Giorno del Ringraziamento" },
|
||||
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -36,5 +36,6 @@ public class HolidayBundle_it_IT extends ListResourceBundle {
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public class HolidayBundle_iw extends ListResourceBundle {
|
||||
{ "", "" }, // Can't be empty!
|
||||
};
|
||||
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
|
||||
}
|
||||
|
@ -28,5 +28,6 @@ public class HolidayBundle_iw_IL extends ListResourceBundle {
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -22,5 +22,6 @@ public class HolidayBundle_ja_JP extends ListResourceBundle {
|
||||
static private final Object[][] fContents = {
|
||||
{ "holidays", fHolidays },
|
||||
};
|
||||
@Override
|
||||
public synchronized Object[][] getContents() { return fContents; }
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class ResourceReader implements Closeable {
|
||||
private String resourceName;
|
||||
private String encoding; // null for default encoding
|
||||
private Class<?> root;
|
||||
|
||||
|
||||
/**
|
||||
* The one-based line number. Has the special value -1 before the
|
||||
* object is initialized. Has the special value 0 after initialization
|
||||
@ -103,7 +103,7 @@ public class ResourceReader implements Closeable {
|
||||
|
||||
this.lineNo = -1;
|
||||
try {
|
||||
InputStreamReader isr = (encoding == null)
|
||||
InputStreamReader isr = (encoding == null)
|
||||
? new InputStreamReader(is)
|
||||
: new InputStreamReader(is, encoding);
|
||||
|
||||
@ -200,7 +200,7 @@ public class ResourceReader implements Closeable {
|
||||
public int getLineNumber() {
|
||||
return lineNo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a string description of the position of the last line
|
||||
* returned by readLine() or readLineSkippingComments().
|
||||
@ -208,7 +208,7 @@ public class ResourceReader implements Closeable {
|
||||
public String describePosition() {
|
||||
return resourceName + ':' + lineNo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset this reader so that the next call to
|
||||
* <code>readLine()</code> returns the first line of the file
|
||||
@ -244,7 +244,7 @@ public class ResourceReader implements Closeable {
|
||||
if (is == null) {
|
||||
throw new IllegalArgumentException("Can't open " + resourceName);
|
||||
}
|
||||
|
||||
|
||||
InputStreamReader isr =
|
||||
(encoding == null) ? new InputStreamReader(is) :
|
||||
new InputStreamReader(is, encoding);
|
||||
@ -257,6 +257,7 @@ public class ResourceReader implements Closeable {
|
||||
* associated with it. If the stream is already closed then invoking
|
||||
* this method has no effect.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
|
@ -29,7 +29,7 @@ class BasicDurationFormatter implements DurationFormatter {
|
||||
* the locales and timezones of these are in sync.
|
||||
*/
|
||||
public BasicDurationFormatter(PeriodFormatter formatter,
|
||||
PeriodBuilder builder,
|
||||
PeriodBuilder builder,
|
||||
DateFormatter fallback,
|
||||
long fallbackLimit) {
|
||||
this.formatter = formatter;
|
||||
@ -39,7 +39,7 @@ class BasicDurationFormatter implements DurationFormatter {
|
||||
}
|
||||
|
||||
protected BasicDurationFormatter(PeriodFormatter formatter,
|
||||
PeriodBuilder builder,
|
||||
PeriodBuilder builder,
|
||||
DateFormatter fallback,
|
||||
long fallbackLimit,
|
||||
String localeName,
|
||||
@ -52,17 +52,20 @@ class BasicDurationFormatter implements DurationFormatter {
|
||||
this.timeZone = timeZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatDurationFromNowTo(Date targetDate) {
|
||||
long now = System.currentTimeMillis();
|
||||
long duration = targetDate.getTime() - now;
|
||||
return formatDurationFrom(duration, now);
|
||||
}
|
||||
|
||||
public String formatDurationFromNow(long duration) {
|
||||
@Override
|
||||
public String formatDurationFromNow(long duration) {
|
||||
return formatDurationFrom(duration, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public String formatDurationFrom(long duration, long referenceDate) {
|
||||
@Override
|
||||
public String formatDurationFrom(long duration, long referenceDate) {
|
||||
String s = doFallback(duration, referenceDate);
|
||||
if (s == null) {
|
||||
Period p = doBuild(duration, referenceDate);
|
||||
@ -71,12 +74,13 @@ class BasicDurationFormatter implements DurationFormatter {
|
||||
return s;
|
||||
}
|
||||
|
||||
public DurationFormatter withLocale(String locName) {
|
||||
@Override
|
||||
public DurationFormatter withLocale(String locName) {
|
||||
if (!locName.equals(localeName)) {
|
||||
PeriodFormatter newFormatter = formatter.withLocale(locName);
|
||||
PeriodBuilder newBuilder = builder.withLocale(locName);
|
||||
DateFormatter newFallback = fallback == null
|
||||
? null
|
||||
DateFormatter newFallback = fallback == null
|
||||
? null
|
||||
: fallback.withLocale(locName);
|
||||
return new BasicDurationFormatter(newFormatter, newBuilder,
|
||||
newFallback, fallbackLimit,
|
||||
@ -85,11 +89,12 @@ class BasicDurationFormatter implements DurationFormatter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DurationFormatter withTimeZone(TimeZone tz) {
|
||||
@Override
|
||||
public DurationFormatter withTimeZone(TimeZone tz) {
|
||||
if (!tz.equals(timeZone)) {
|
||||
PeriodBuilder newBuilder = builder.withTimeZone(tz);
|
||||
DateFormatter newFallback = fallback == null
|
||||
? null
|
||||
DateFormatter newFallback = fallback == null
|
||||
? null
|
||||
: fallback.withTimeZone(tz);
|
||||
return new BasicDurationFormatter(formatter, newBuilder,
|
||||
newFallback, fallbackLimit,
|
||||
@ -99,7 +104,7 @@ class BasicDurationFormatter implements DurationFormatter {
|
||||
}
|
||||
|
||||
protected String doFallback(long duration, long referenceDate) {
|
||||
if (fallback != null
|
||||
if (fallback != null
|
||||
&& fallbackLimit > 0
|
||||
&& Math.abs(duration) >= fallbackLimit) {
|
||||
return fallback.format(referenceDate + duration);
|
||||
|
@ -47,6 +47,7 @@ class BasicDurationFormatterFactory implements DurationFormatterFactory {
|
||||
*
|
||||
* @return this BasicDurationFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public DurationFormatterFactory setPeriodFormatter(
|
||||
PeriodFormatter formatter) {
|
||||
if (formatter != this.formatter) {
|
||||
@ -63,6 +64,7 @@ class BasicDurationFormatterFactory implements DurationFormatterFactory {
|
||||
* @param builder the builder to use
|
||||
* @return this BasicDurationFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public DurationFormatterFactory setPeriodBuilder(PeriodBuilder builder) {
|
||||
if (builder != this.builder) {
|
||||
this.builder = builder;
|
||||
@ -77,6 +79,7 @@ class BasicDurationFormatterFactory implements DurationFormatterFactory {
|
||||
* @param fallback the fallback formatter to use, or null
|
||||
* @return this BasicDurationFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public DurationFormatterFactory setFallback(DateFormatter fallback) {
|
||||
boolean doReset = fallback == null
|
||||
? this.fallback != null
|
||||
@ -94,6 +97,7 @@ class BasicDurationFormatterFactory implements DurationFormatterFactory {
|
||||
* @param fallbackLimit the fallback limit to use, or 0 if none is desired.
|
||||
* @return this BasicDurationFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public DurationFormatterFactory setFallbackLimit(long fallbackLimit) {
|
||||
if (fallbackLimit < 0) {
|
||||
fallbackLimit = 0;
|
||||
@ -106,12 +110,13 @@ class BasicDurationFormatterFactory implements DurationFormatterFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the locale that will be used when
|
||||
* Set the name of the locale that will be used when
|
||||
* creating new formatters.
|
||||
*
|
||||
* @param localeName the name of the Locale
|
||||
* @return this BasicDurationFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public DurationFormatterFactory setLocale(String localeName) {
|
||||
if (!localeName.equals(this.localeName)) {
|
||||
this.localeName = localeName;
|
||||
@ -127,12 +132,13 @@ class BasicDurationFormatterFactory implements DurationFormatterFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the locale that will be used when
|
||||
* Set the name of the locale that will be used when
|
||||
* creating new formatters.
|
||||
*
|
||||
* @param timeZone The time zone to use.
|
||||
* @return this BasicDurationFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public DurationFormatterFactory setTimeZone(TimeZone timeZone) {
|
||||
if (!timeZone.equals(this.timeZone)) {
|
||||
this.timeZone = timeZone;
|
||||
@ -149,6 +155,7 @@ class BasicDurationFormatterFactory implements DurationFormatterFactory {
|
||||
*
|
||||
* @return a BasicDurationFormatter
|
||||
*/
|
||||
@Override
|
||||
public DurationFormatter getFormatter() {
|
||||
if (f == null) {
|
||||
if (fallback != null) {
|
||||
@ -232,7 +239,7 @@ class BasicDurationFormatterFactory implements DurationFormatterFactory {
|
||||
* Create the formatter. All local fields are already initialized.
|
||||
*/
|
||||
protected BasicDurationFormatter createFormatter() {
|
||||
return new BasicDurationFormatter(formatter, builder, fallback,
|
||||
return new BasicDurationFormatter(formatter, builder, fallback,
|
||||
fallbackLimit, localeName,
|
||||
timeZone);
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ import com.ibm.icu.impl.duration.impl.PeriodFormatterDataService;
|
||||
class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
private PeriodFormatterDataService ds;
|
||||
private Settings settings;
|
||||
|
||||
|
||||
private static final short allBits = 0xff;
|
||||
|
||||
|
||||
BasicPeriodBuilderFactory(PeriodFormatterDataService ds) {
|
||||
this.ds = ds;
|
||||
this.settings = new Settings();
|
||||
@ -50,7 +50,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
return this;
|
||||
}
|
||||
Settings result = inUse ? copy() : this;
|
||||
|
||||
|
||||
result.uset = (short)uset;
|
||||
|
||||
if ((uset & allBits) == allBits) {
|
||||
@ -67,7 +67,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
lastUnit = i;
|
||||
}
|
||||
}
|
||||
if (lastUnit == -1) {
|
||||
if (lastUnit == -1) {
|
||||
// currently empty, but this might be transient so no fail
|
||||
result.minUnit = result.maxUnit = null;
|
||||
} else {
|
||||
@ -84,7 +84,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
}
|
||||
return (short)(uset & ~(1 << TimeUnit.MILLISECOND.ordinal));
|
||||
}
|
||||
|
||||
|
||||
TimeUnit effectiveMinUnit() {
|
||||
if (allowMillis || minUnit != TimeUnit.MILLISECOND) {
|
||||
return minUnit;
|
||||
@ -97,7 +97,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
}
|
||||
return TimeUnit.SECOND; // default for pathological case
|
||||
}
|
||||
|
||||
|
||||
Settings setMaxLimit(float maxLimit) {
|
||||
int val = maxLimit <= 0 ? 0 : (int)(maxLimit*1000);
|
||||
if (maxLimit == val) {
|
||||
@ -150,7 +150,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
return this
|
||||
.setAllowZero(data.allowZero())
|
||||
.setWeeksAloneOnly(data.weeksAloneOnly())
|
||||
.setAllowMilliseconds(data.useMilliseconds() != DataRecord.EMilliSupport.NO);
|
||||
.setAllowMilliseconds(data.useMilliseconds() != DataRecord.EMilliSupport.NO);
|
||||
}
|
||||
|
||||
Settings setInUse() {
|
||||
@ -165,7 +165,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
return Period.moreThan(maxLimit/1000f, maxUnit).inPast(inPast);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (minLimit > 0) {
|
||||
TimeUnit emu = effectiveMinUnit();
|
||||
long emud = approximateDurationOf(emu);
|
||||
@ -193,6 +193,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory setAvailableUnitRange(TimeUnit minUnit,
|
||||
TimeUnit maxUnit) {
|
||||
int uset = 0;
|
||||
@ -206,7 +207,8 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PeriodBuilderFactory setUnitIsAvailable(TimeUnit unit,
|
||||
@Override
|
||||
public PeriodBuilderFactory setUnitIsAvailable(TimeUnit unit,
|
||||
boolean available) {
|
||||
int uset = settings.uset;
|
||||
if (available) {
|
||||
@ -218,36 +220,43 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory setMaxLimit(float maxLimit) {
|
||||
settings = settings.setMaxLimit(maxLimit);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory setMinLimit(float minLimit) {
|
||||
settings = settings.setMinLimit(minLimit);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory setAllowZero(boolean allow) {
|
||||
settings = settings.setAllowZero(allow);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory setWeeksAloneOnly(boolean aloneOnly) {
|
||||
settings = settings.setWeeksAloneOnly(aloneOnly);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory setAllowMilliseconds(boolean allow) {
|
||||
settings = settings.setAllowMilliseconds(allow);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory setLocale(String localeName) {
|
||||
settings = settings.setLocale(localeName);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory setTimeZone(TimeZone timeZone) {
|
||||
// ignore this
|
||||
return this;
|
||||
@ -267,6 +276,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
* @param unit the single TimeUnit with which to represent times
|
||||
* @return a builder
|
||||
*/
|
||||
@Override
|
||||
public PeriodBuilder getFixedUnitBuilder(TimeUnit unit) {
|
||||
return FixedUnitBuilder.get(unit, getSettings());
|
||||
}
|
||||
@ -277,6 +287,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
*
|
||||
* @return a builder
|
||||
*/
|
||||
@Override
|
||||
public PeriodBuilder getSingleUnitBuilder() {
|
||||
return SingleUnitBuilder.get(getSettings());
|
||||
}
|
||||
@ -289,6 +300,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
*
|
||||
* @return a builder
|
||||
*/
|
||||
@Override
|
||||
public PeriodBuilder getOneOrTwoUnitBuilder() {
|
||||
return OneOrTwoUnitBuilder.get(getSettings());
|
||||
}
|
||||
@ -300,6 +312,7 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
*
|
||||
* @return a builder
|
||||
*/
|
||||
@Override
|
||||
public PeriodBuilder getMultiUnitBuilder(int periodCount) {
|
||||
return MultiUnitBuilder.get(periodCount, getSettings());
|
||||
}
|
||||
@ -308,7 +321,8 @@ class BasicPeriodBuilderFactory implements PeriodBuilderFactory {
|
||||
abstract class PeriodBuilderImpl implements PeriodBuilder {
|
||||
|
||||
protected BasicPeriodBuilderFactory.Settings settings;
|
||||
|
||||
|
||||
@Override
|
||||
public Period create(long duration) {
|
||||
return createWithReferenceDate(duration, System.currentTimeMillis());
|
||||
}
|
||||
@ -317,6 +331,7 @@ abstract class PeriodBuilderImpl implements PeriodBuilder {
|
||||
return BasicPeriodBuilderFactory.approximateDurationOf(unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Period createWithReferenceDate(long duration, long referenceDate) {
|
||||
boolean inPast = duration < 0;
|
||||
if (inPast) {
|
||||
@ -332,11 +347,13 @@ abstract class PeriodBuilderImpl implements PeriodBuilder {
|
||||
return ts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilder withTimeZone(TimeZone timeZone) {
|
||||
// ignore the time zone
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilder withLocale(String localeName) {
|
||||
BasicPeriodBuilderFactory.Settings newSettings = settings.setLocale(localeName);
|
||||
if (newSettings != settings) {
|
||||
@ -347,7 +364,7 @@ abstract class PeriodBuilderImpl implements PeriodBuilder {
|
||||
|
||||
protected abstract PeriodBuilder withSettings(BasicPeriodBuilderFactory.Settings settingsToUse);
|
||||
|
||||
protected abstract Period handleCreate(long duration, long referenceDate,
|
||||
protected abstract Period handleCreate(long duration, long referenceDate,
|
||||
boolean inPast);
|
||||
|
||||
protected PeriodBuilderImpl(BasicPeriodBuilderFactory.Settings settings) {
|
||||
@ -357,7 +374,7 @@ abstract class PeriodBuilderImpl implements PeriodBuilder {
|
||||
|
||||
class FixedUnitBuilder extends PeriodBuilderImpl {
|
||||
private TimeUnit unit;
|
||||
|
||||
|
||||
public static FixedUnitBuilder get(TimeUnit unit, BasicPeriodBuilderFactory.Settings settingsToUse) {
|
||||
if (settingsToUse != null && (settingsToUse.effectiveSet() & (1 << unit.ordinal)) != 0) {
|
||||
return new FixedUnitBuilder(unit, settingsToUse);
|
||||
@ -370,11 +387,13 @@ class FixedUnitBuilder extends PeriodBuilderImpl {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PeriodBuilder withSettings(BasicPeriodBuilderFactory.Settings settingsToUse) {
|
||||
return get(unit, settingsToUse);
|
||||
}
|
||||
|
||||
protected Period handleCreate(long duration, long referenceDate,
|
||||
@Override
|
||||
protected Period handleCreate(long duration, long referenceDate,
|
||||
boolean inPast) {
|
||||
if (unit == null) {
|
||||
return null;
|
||||
@ -397,11 +416,13 @@ class SingleUnitBuilder extends PeriodBuilderImpl {
|
||||
return new SingleUnitBuilder(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PeriodBuilder withSettings(BasicPeriodBuilderFactory.Settings settingsToUse) {
|
||||
return SingleUnitBuilder.get(settingsToUse);
|
||||
}
|
||||
|
||||
protected Period handleCreate(long duration, long referenceDate,
|
||||
@Override
|
||||
protected Period handleCreate(long duration, long referenceDate,
|
||||
boolean inPast) {
|
||||
short uset = settings.effectiveSet();
|
||||
for (int i = 0; i < TimeUnit.units.length; ++i) {
|
||||
@ -430,11 +451,13 @@ class OneOrTwoUnitBuilder extends PeriodBuilderImpl {
|
||||
return new OneOrTwoUnitBuilder(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PeriodBuilder withSettings(BasicPeriodBuilderFactory.Settings settingsToUse) {
|
||||
return OneOrTwoUnitBuilder.get(settingsToUse);
|
||||
}
|
||||
|
||||
protected Period handleCreate(long duration, long referenceDate,
|
||||
@Override
|
||||
protected Period handleCreate(long duration, long referenceDate,
|
||||
boolean inPast) {
|
||||
Period period = null;
|
||||
short uset = settings.effectiveSet();
|
||||
@ -479,11 +502,13 @@ class MultiUnitBuilder extends PeriodBuilderImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PeriodBuilder withSettings(BasicPeriodBuilderFactory.Settings settingsToUse) {
|
||||
return MultiUnitBuilder.get(nPeriods, settingsToUse);
|
||||
}
|
||||
|
||||
protected Period handleCreate(long duration, long referenceDate,
|
||||
@Override
|
||||
protected Period handleCreate(long duration, long referenceDate,
|
||||
boolean inPast) {
|
||||
Period period = null;
|
||||
int n = 0;
|
||||
|
@ -26,9 +26,9 @@ class BasicPeriodFormatter implements PeriodFormatter {
|
||||
private PeriodFormatterData data;
|
||||
private Customizations customs;
|
||||
|
||||
BasicPeriodFormatter(BasicPeriodFormatterFactory factory,
|
||||
BasicPeriodFormatter(BasicPeriodFormatterFactory factory,
|
||||
String localeName,
|
||||
PeriodFormatterData data,
|
||||
PeriodFormatterData data,
|
||||
Customizations customs) {
|
||||
this.factory = factory;
|
||||
this.localeName = localeName;
|
||||
@ -36,17 +36,19 @@ class BasicPeriodFormatter implements PeriodFormatter {
|
||||
this.customs = customs;
|
||||
}
|
||||
|
||||
public String format(Period period) {
|
||||
@Override
|
||||
public String format(Period period) {
|
||||
if (!period.isSet()) {
|
||||
throw new IllegalArgumentException("period is not set");
|
||||
}
|
||||
return format(period.timeLimit, period.inFuture, period.counts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodFormatter withLocale(String locName) {
|
||||
if (!this.localeName.equals(locName)) {
|
||||
PeriodFormatterData newData = factory.getData(locName);
|
||||
return new BasicPeriodFormatter(factory, locName, newData,
|
||||
return new BasicPeriodFormatter(factory, locName, newData,
|
||||
customs);
|
||||
}
|
||||
return this;
|
||||
@ -60,7 +62,7 @@ class BasicPeriodFormatter implements PeriodFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
// if the data does not allow formatting of zero periods,
|
||||
// if the data does not allow formatting of zero periods,
|
||||
// remove these from consideration. If the result has no
|
||||
// periods set, return null to indicate we could not format
|
||||
// the duration.
|
||||
@ -79,13 +81,13 @@ class BasicPeriodFormatter implements PeriodFormatter {
|
||||
// set, merge them with seconds and force display of seconds to
|
||||
// decimal with 3 places.
|
||||
boolean forceD3Seconds = false;
|
||||
if (data.useMilliseconds() != EMilliSupport.YES &&
|
||||
if (data.useMilliseconds() != EMilliSupport.YES &&
|
||||
(mask & (1 << TimeUnit.MILLISECOND.ordinal)) != 0) {
|
||||
int sx = TimeUnit.SECOND.ordinal;
|
||||
int mx = TimeUnit.MILLISECOND.ordinal;
|
||||
int sf = 1 << sx;
|
||||
int mf = 1 << mx;
|
||||
switch (data.useMilliseconds()) {
|
||||
switch (data.useMilliseconds()) {
|
||||
case EMilliSupport.WITH_SECONDS: {
|
||||
// if there are seconds, merge with seconds, otherwise leave alone
|
||||
if ((mask & sf) != 0) {
|
||||
@ -176,7 +178,7 @@ class BasicPeriodFormatter implements PeriodFormatter {
|
||||
cv = ECountVariant.INTEGER;
|
||||
}
|
||||
boolean isLast = i == last;
|
||||
boolean mustSkip = data.appendUnit(unit, count, cv, customs.unitVariant,
|
||||
boolean mustSkip = data.appendUnit(unit, count, cv, customs.unitVariant,
|
||||
countSep, useDigitPrefix, multiple, isLast, wasSkipped, sb);
|
||||
skipped |= mustSkip;
|
||||
wasSkipped = false;
|
||||
|
@ -81,6 +81,7 @@ public class BasicPeriodFormatterFactory implements PeriodFormatterFactory {
|
||||
/**
|
||||
* Set the locale for this factory.
|
||||
*/
|
||||
@Override
|
||||
public PeriodFormatterFactory setLocale(String localeName) {
|
||||
data = null;
|
||||
this.localeName = localeName;
|
||||
@ -93,6 +94,7 @@ public class BasicPeriodFormatterFactory implements PeriodFormatterFactory {
|
||||
* @param display true if limits will be displayed
|
||||
* @return this PeriodFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public PeriodFormatterFactory setDisplayLimit(boolean display) {
|
||||
updateCustomizations().displayLimit = display;
|
||||
return this;
|
||||
@ -113,6 +115,7 @@ public class BasicPeriodFormatterFactory implements PeriodFormatterFactory {
|
||||
* @param display true if past and future will be displayed
|
||||
* @return this PeriodFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public PeriodFormatterFactory setDisplayPastFuture(boolean display) {
|
||||
updateCustomizations().displayDirection = display;
|
||||
return this;
|
||||
@ -133,6 +136,7 @@ public class BasicPeriodFormatterFactory implements PeriodFormatterFactory {
|
||||
* @param variant the variant indicating separators will be displayed
|
||||
* @return this PeriodFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public PeriodFormatterFactory setSeparatorVariant(int variant) {
|
||||
updateCustomizations().separatorVariant = (byte) variant;
|
||||
return this;
|
||||
@ -153,6 +157,7 @@ public class BasicPeriodFormatterFactory implements PeriodFormatterFactory {
|
||||
* @param variant the variant to use
|
||||
* @return this PeriodFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public PeriodFormatterFactory setUnitVariant(int variant) {
|
||||
updateCustomizations().unitVariant = (byte) variant;
|
||||
return this;
|
||||
@ -173,6 +178,7 @@ public class BasicPeriodFormatterFactory implements PeriodFormatterFactory {
|
||||
* @param variant the variant to use
|
||||
* @return this PeriodFormatterFactory
|
||||
*/
|
||||
@Override
|
||||
public PeriodFormatterFactory setCountVariant(int variant) {
|
||||
updateCustomizations().countVariant = (byte) variant;
|
||||
return this;
|
||||
@ -187,9 +193,10 @@ public class BasicPeriodFormatterFactory implements PeriodFormatterFactory {
|
||||
return customizations.countVariant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodFormatter getFormatter() {
|
||||
customizationsInUse = true;
|
||||
return new BasicPeriodFormatter(this, localeName, getData(),
|
||||
return new BasicPeriodFormatter(this, localeName, getData(),
|
||||
customizations);
|
||||
}
|
||||
|
||||
@ -221,7 +228,7 @@ public class BasicPeriodFormatterFactory implements PeriodFormatterFactory {
|
||||
byte separatorVariant = ESeparatorVariant.FULL;
|
||||
byte unitVariant = EUnitVariant.PLURALIZED;
|
||||
byte countVariant = ECountVariant.INTEGER;
|
||||
|
||||
|
||||
public Customizations copy() {
|
||||
Customizations result = new Customizations();
|
||||
result.displayLimit = displayLimit;
|
||||
|
@ -24,7 +24,7 @@ public class BasicPeriodFormatterService implements PeriodFormatterService {
|
||||
|
||||
/**
|
||||
* Return the default service instance. This uses the default data service.
|
||||
*
|
||||
*
|
||||
* @return an BasicPeriodFormatterService
|
||||
*/
|
||||
public static BasicPeriodFormatterService getInstance() {
|
||||
@ -39,25 +39,29 @@ public class BasicPeriodFormatterService implements PeriodFormatterService {
|
||||
/**
|
||||
* Construct a BasicPeriodFormatterService using the given
|
||||
* PeriodFormatterDataService.
|
||||
*
|
||||
*
|
||||
* @param ds the data service to use
|
||||
*/
|
||||
public BasicPeriodFormatterService(PeriodFormatterDataService ds) {
|
||||
this.ds = ds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DurationFormatterFactory newDurationFormatterFactory() {
|
||||
return new BasicDurationFormatterFactory(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodFormatterFactory newPeriodFormatterFactory() {
|
||||
return new BasicPeriodFormatterFactory(ds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeriodBuilderFactory newPeriodBuilderFactory() {
|
||||
return new BasicPeriodBuilderFactory(ds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAvailableLocaleNames() {
|
||||
return ds.getAvailableLocales();
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user