This commit is contained in:
cata%netscape.com 1999-03-11 22:36:40 +00:00
Родитель 8cb4f1a4b6
Коммит d0c8035a37
4 изменённых файлов: 103 добавлений и 1 удалений

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

@ -56,6 +56,13 @@ public:
NS_IMETHOD ConvertByTable(const PRUnichar * aSrc, PRInt32 * aSrcLength,
char * aDest, PRInt32 * aDestLength, uShiftTable * aShiftTable,
uMappingTable * aMappingTable) = 0;
/**
* Converts data using a set of lookup tables.
*/
NS_IMETHOD ConvertByTables(const PRUnichar * aSrc, PRInt32 * aSrcLength,
char * aDest, PRInt32 * aDestLength, PRInt32 aTableCount,
uShiftTable ** aShiftTable, uMappingTable ** aMappingTable) = 0;
};

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

@ -55,6 +55,10 @@ public:
NS_IMETHOD ConvertByTable(const PRUnichar * aSrc, PRInt32 * aSrcLength,
char * aDest, PRInt32 * aDestLength, uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
NS_IMETHOD ConvertByTables(const PRUnichar * aSrc, PRInt32 * aSrcLength,
char * aDest, PRInt32 * aDestLength, PRInt32 aTableCount,
uShiftTable ** aShiftTable, uMappingTable ** aMappingTable);
};
//----------------------------------------------------------------------
@ -114,6 +118,49 @@ NS_IMETHODIMP nsUnicodeEncodeHelper::ConvertByTable(const PRUnichar * aSrc,
return res;
}
NS_IMETHODIMP nsUnicodeEncodeHelper::ConvertByTables(const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength,
PRInt32 aTableCount,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
{
const PRUnichar * src = aSrc;
const PRUnichar * srcEnd = aSrc + *aSrcLength;
char * dest = aDest;
PRInt32 destLen = *aDestLength;
PRUnichar med;
PRInt32 bcw; // byte count for write;
nsresult res = NS_OK;
PRInt32 i;
while (src < srcEnd) {
for (i=0; i<aTableCount; i++)
if (uMapCode((uTable*) aMappingTable[i], *src, &med)) break;
src++;
if (i == aTableCount) {
res = NS_ERROR_UENC_NOMAPPING;
break;
}
if (!uGenerate(aShiftTable[i], 0, med, (PRUint8 *)dest, destLen,
(PRUint32 *)&bcw)) {
src--;
res = NS_OK_UENC_MOREOUTPUT;
break;
}
dest += bcw;
destLen -= bcw;
}
*aSrcLength = src - aSrc;
*aDestLength = dest - aDest;
return res;
}
//----------------------------------------------------------------------
// Class nsEncodeHelperFactory [implementation]

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

@ -27,8 +27,9 @@
mDecArray[4].mCID = &kISO2022JPToUnicodeCID;
mDecArray[5].mCID = &kEUCJPToUnicodeCID;
mEncSize = 2;
mEncSize = 3;
mEncArray = new ConverterInfo [mEncSize];
mEncArray[0].mCID = &kUnicodeToLatin1CID;
mEncArray[1].mCID = &kUnicodeToSJISCID;
mEncArray[2].mCID = &kUnicodeToEUCJPCID;

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

@ -55,6 +55,10 @@ public:
NS_IMETHOD ConvertByTable(const PRUnichar * aSrc, PRInt32 * aSrcLength,
char * aDest, PRInt32 * aDestLength, uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
NS_IMETHOD ConvertByTables(const PRUnichar * aSrc, PRInt32 * aSrcLength,
char * aDest, PRInt32 * aDestLength, PRInt32 aTableCount,
uShiftTable ** aShiftTable, uMappingTable ** aMappingTable);
};
//----------------------------------------------------------------------
@ -114,6 +118,49 @@ NS_IMETHODIMP nsUnicodeEncodeHelper::ConvertByTable(const PRUnichar * aSrc,
return res;
}
NS_IMETHODIMP nsUnicodeEncodeHelper::ConvertByTables(const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength,
PRInt32 aTableCount,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
{
const PRUnichar * src = aSrc;
const PRUnichar * srcEnd = aSrc + *aSrcLength;
char * dest = aDest;
PRInt32 destLen = *aDestLength;
PRUnichar med;
PRInt32 bcw; // byte count for write;
nsresult res = NS_OK;
PRInt32 i;
while (src < srcEnd) {
for (i=0; i<aTableCount; i++)
if (uMapCode((uTable*) aMappingTable[i], *src, &med)) break;
src++;
if (i == aTableCount) {
res = NS_ERROR_UENC_NOMAPPING;
break;
}
if (!uGenerate(aShiftTable[i], 0, med, (PRUint8 *)dest, destLen,
(PRUint32 *)&bcw)) {
src--;
res = NS_OK_UENC_MOREOUTPUT;
break;
}
dest += bcw;
destLen -= bcw;
}
*aSrcLength = src - aSrc;
*aDestLength = dest - aDest;
return res;
}
//----------------------------------------------------------------------
// Class nsEncodeHelperFactory [implementation]