ICU-5018 fix error code propagation

X-SVN-Rev: 20251
This commit is contained in:
Winnie Yick 2006-09-07 17:53:14 +00:00
parent b21db770e7
commit 99b1b9774e
2 changed files with 9 additions and 9 deletions

View File

@ -283,11 +283,12 @@ public class CharsetUTF16 extends CharsetICU {
int sourceIndex = 0;
char trail = 0;
int length = source.remaining();
int sourceArrayIndex = source.position();
try{
/* c!=0 indicates in several places outside the main loops that a surrogate was found */
if((c=(char)fromUChar32)!=0 && UTF16.isTrailSurrogate(trail=source.get(sourceIndex)) && target.remaining()>=4) {
if((c=(char)fromUChar32)!=0 && UTF16.isTrailSurrogate(trail=source.get(sourceArrayIndex)) && target.remaining()>=4) {
/* the last buffer ended with a lead surrogate, output the surrogate pair */
++sourceIndex;
--length;
@ -305,7 +306,6 @@ public class CharsetUTF16 extends CharsetICU {
fromUChar32=c=0;
}
byte overflow[/*4*/] = new byte[4];
int sourceArrayIndex = source.position();
if(c==0) {
/* copy an even number of bytes for complete UChars */
@ -421,7 +421,7 @@ public class CharsetUTF16 extends CharsetICU {
}
} else {
/* unmatched trail surrogate */
//pErrorCode[0]=ErrorCode.U_ILLEGAL_CHAR_FOUND;
cr = CoderResult.malformedForLength(sourceArrayIndex);
}
fromUChar32=c;
}

View File

@ -286,13 +286,14 @@ public class CharsetUTF16LE extends CharsetICU {
int sourceIndex = 0;
char trail = 0;
int length = source.remaining();
int sourceArrayIndex = source.position();
try{
/* c!=0 indicates in several places outside the main loops that a surrogate was found */
if((c=(char)fromUChar32)!=0 && UTF16.isTrailSurrogate(trail=source.get(sourceIndex)) && target.remaining()>=4) {
if((c=(char)fromUChar32)!=0 && UTF16.isTrailSurrogate(trail=source.get(sourceArrayIndex)) && target.remaining()>=4) {
/* the last buffer ended with a lead surrogate, output the surrogate pair */
++sourceIndex;
++sourceArrayIndex;
--length;
target.put((byte)c);
target.put((byte)(c>>>8));
@ -308,12 +309,12 @@ public class CharsetUTF16LE extends CharsetICU {
fromUChar32=c=0;
}
byte overflow[/*4*/] = new byte[4];
int sourceArrayIndex = source.position();
if(c==0) {
/* copy an even number of bytes for complete UChars */
int count=2*length;
int targetCapacity = target.limit();
int targetCapacity = target.remaining();
if(count>targetCapacity) {
count=targetCapacity&~1;
}
@ -416,7 +417,6 @@ public class CharsetUTF16LE extends CharsetICU {
c=0;
} else {
/* unmatched lead surrogate */
//pErrorCode[0]=ErrorCode.U_ILLEGAL_CHAR_FOUND;
cr = CoderResult.malformedForLength(sourceArrayIndex);
}
} else {
@ -424,7 +424,7 @@ public class CharsetUTF16LE extends CharsetICU {
}
} else {
/* unmatched trail surrogate */
//pErrorCode[0]=ErrorCode.U_ILLEGAL_CHAR_FOUND;
cr = CoderResult.malformedForLength(sourceArrayIndex);
}
fromUChar32=c;
}