fix bug 73710. rewrite the multi table conversion routine to support overlap range

for HKSCS and EUC-TW
rs=ftang
This commit is contained in:
ftang%netscape.com 2001-05-16 12:40:14 +00:00
Родитель 357320f4c0
Коммит e4f6b4f8eb
1 изменённых файлов: 51 добавлений и 31 удалений

Просмотреть файл

@ -161,45 +161,65 @@ NS_IMETHODIMP nsUnicodeDecodeHelper::ConvertByMultiTable(
nsresult res = NS_OK;
PRInt32 i;
while ((srcLen > 0) && (dest < destEnd)) {
for (i=0; i<aTableCount; i++)
if ((aRangeArray[i].min <= *src) && (*src <= aRangeArray[i].max)) break;
if (i == aTableCount) {
if (*src == (PRUint8)0xa0)
*dest = 0x00a0;
else
*dest = 0xfffd;
bcr = 1;
}
else
while ((srcLen > 0) && (dest < destEnd))
{
PRBool done= PR_FALSE;
for (i=0; (!done) && (i<aTableCount); i++)
{
if (!uScan(aShiftTable[i], NULL, src, NS_REINTERPRET_CAST(PRUint16*, &med), srcLen,
(PRUint32 *)&bcr)) {
res = NS_OK_UDEC_MOREINPUT;
break;
}
if (!uMapCode((uTable*) aMappingTable[i], NS_STATIC_CAST(PRUint16, med), NS_REINTERPRET_CAST(PRUint16*, dest))) {
if (med < 0x20) {
// somehow some table miss the 0x00 - 0x20 part
*dest = med;
} else {
// 2 for EUC-KR code set 1 and EUC-JP codeset 1 and 2
// 3 for EUC-JP codeset 3, 4 for EUC-TW code set 3(CNS 11643 Plane 2 - 7)
if (bcr >= 2 && !(*(src+1) & 0x80) ) {
bcr-= (bcr-1);
if ((aRangeArray[i].min <= *src) && (*src <= aRangeArray[i].max))
{
if (uScan(aShiftTable[i], NULL, src,
NS_REINTERPRET_CAST(PRUint16*, &med), srcLen,
(PRUint32 *)&bcr))
{
done = uMapCode((uTable*) aMappingTable[i],
NS_STATIC_CAST(PRUint16, med),
NS_REINTERPRET_CAST(PRUint16*, dest));
} // if (uScan ... )
} // if Range
} // for loop
if(! done)
{
bcr = 1;
if (med < 0x20) {
// somehow some table miss the 0x00 - 0x20 part
*dest = med;
} else {
// we need to decide how many byte we skip. We can use uScan to do this
for (i=0; i<aTableCount; i++)
{
if ((aRangeArray[i].min <= *src) && (*src <= aRangeArray[i].max))
{
if (uScan(aShiftTable[i], NULL, src,
NS_REINTERPRET_CAST(PRUint16*, &med), srcLen,
(PRUint32*)&bcr))
{
// match the patten
PRInt32 k;
for(k = 1; k < bcr; k++)
{
if(0 == (src[k] & 0x80))
{ // only skip if all bytes > 0x80
// if we hit bytes <= 0x80, skip only one byte
bcr = 1;
break;
}
}
break;
}
// If stand-alone 0xa0 gets this far (BIG5), leave it alone.
// Otherwise, use Unicode replacement value for unmappable chars
*dest = (*src == (PRUint8)0xa0 ) ? 0x00a0 : 0xfffd;
}
}
}
// treat it as NSBR if bcr == 1 and it is 0xa0
*dest = ((1==bcr)&&(*src == (PRUint8)0xa0 )) ? 0x00a0 : 0xfffd;
}
}
src += bcr;
srcLen -= bcr;
dest++;
}
} // while
if ((srcLen > 0) && (res == NS_OK)) res = NS_OK_UDEC_MOREOUTPUT;