Bug 997115 - Remove ISO-2022-CN and ISO-2022-KR from m-c. r=emk.

This commit is contained in:
Henri Sivonen 2014-06-16 15:54:34 +03:00
parent 018685a11e
commit 61894527f1
8 changed files with 0 additions and 953 deletions

View File

@ -26,7 +26,6 @@ UNIFIED_SOURCES += [
'../ucvcn/nsGBKConvUtil.cpp',
'../ucvcn/nsGBKToUnicode.cpp',
'../ucvcn/nsHZToUnicode.cpp',
'../ucvcn/nsISO2022CNToUnicode.cpp',
'../ucvcn/nsUnicodeToGB2312V2.cpp',
'../ucvcn/nsUnicodeToGBK.cpp',
'../ucvcn/nsUnicodeToHZ.cpp',
@ -57,7 +56,6 @@ UNIFIED_SOURCES += [
UNIFIED_SOURCES += [
'../ucvko/nsCP949ToUnicode.cpp',
'../ucvko/nsISO2022KRToUnicode.cpp',
'../ucvko/nsUnicodeToCP949.cpp',
]

View File

@ -178,7 +178,6 @@
#include "nsUCvKODll.h"
#include "nsCP949ToUnicode.h"
#include "nsUnicodeToCP949.h"
#include "nsISO2022KRToUnicode.h"
// ucvcn
#include "nsUCvCnCID.h"
@ -188,7 +187,6 @@
#include "nsUnicodeToGBK.h"
#include "nsGB2312ToUnicodeV2.h"
#include "nsUnicodeToGB2312V2.h"
#include "nsISO2022CNToUnicode.h"
#include "gbku.h"
NS_CONVERTER_REGISTRY_START
@ -280,14 +278,12 @@ NS_UCONV_REG_UNREG_ENCODER("hkscs-1" , NS_UNICODETOHKSCS_CID)
// ucvko
NS_UCONV_REG_UNREG("EUC-KR", NS_EUCKRTOUNICODE_CID, NS_UNICODETOEUCKR_CID)
NS_UCONV_REG_UNREG_DECODER("ISO-2022-KR", NS_ISO2022KRTOUNICODE_CID)
// ucvcn
NS_UCONV_REG_UNREG("GB2312", NS_GB2312TOUNICODE_CID, NS_UNICODETOGB2312_CID)
NS_UCONV_REG_UNREG("gbk", NS_GBKTOUNICODE_CID, NS_UNICODETOGBK_CID)
NS_UCONV_REG_UNREG("HZ-GB-2312", NS_HZTOUNICODE_CID, NS_UNICODETOHZ_CID)
NS_UCONV_REG_UNREG("gb18030", NS_GB18030TOUNICODE_CID, NS_UNICODETOGB18030_CID)
NS_UCONV_REG_UNREG_DECODER("ISO-2022-CN", NS_ISO2022CNTOUNICODE_CID)
NS_CONVERTER_REGISTRY_END
@ -316,7 +312,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToISO2022JP)
// ucvtw
// ucvko
NS_GENERIC_FACTORY_CONSTRUCTOR(nsISO2022KRToUnicode)
// ucvcn
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToGB2312V2)
@ -325,7 +320,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsHZToUnicode)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToHZ)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsGB18030ToUnicode)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToGB18030)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsISO2022CNToUnicode)
//----------------------------------------------------------------------------
@ -595,7 +589,6 @@ NS_DEFINE_NAMED_CID(NS_UNICODETOHKSCS_CID);
NS_DEFINE_NAMED_CID(NS_BIG5HKSCSTOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_EUCKRTOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_UNICODETOEUCKR_CID);
NS_DEFINE_NAMED_CID(NS_ISO2022KRTOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_GB2312TOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_UNICODETOGB2312_CID);
NS_DEFINE_NAMED_CID(NS_GBKTOUNICODE_CID);
@ -604,7 +597,6 @@ NS_DEFINE_NAMED_CID(NS_HZTOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_UNICODETOHZ_CID);
NS_DEFINE_NAMED_CID(NS_GB18030TOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_UNICODETOGB18030_CID);
NS_DEFINE_NAMED_CID(NS_ISO2022CNTOUNICODE_CID);
static const mozilla::Module::CIDEntry kUConvCIDs[] = {
{ &kNS_TEXTTOSUBURI_CID, false, nullptr, nsTextToSubURIConstructor },
@ -757,7 +749,6 @@ static const mozilla::Module::CIDEntry kUConvCIDs[] = {
{ &kNS_BIG5HKSCSTOUNICODE_CID, false, nullptr, nsBIG5HKSCSToUnicodeConstructor },
{ &kNS_EUCKRTOUNICODE_CID, false, nullptr, nsCP949ToUnicodeConstructor },
{ &kNS_UNICODETOEUCKR_CID, false, nullptr, nsUnicodeToCP949Constructor },
{ &kNS_ISO2022KRTOUNICODE_CID, false, nullptr, nsISO2022KRToUnicodeConstructor },
{ &kNS_GB2312TOUNICODE_CID, false, nullptr, nsGB18030ToUnicodeConstructor },
{ &kNS_UNICODETOGB2312_CID, false, nullptr, nsUnicodeToGB2312V2Constructor },
{ &kNS_GBKTOUNICODE_CID, false, nullptr, nsGB18030ToUnicodeConstructor },
@ -766,7 +757,6 @@ static const mozilla::Module::CIDEntry kUConvCIDs[] = {
{ &kNS_UNICODETOHZ_CID, false, nullptr, nsUnicodeToHZConstructor },
{ &kNS_GB18030TOUNICODE_CID, false, nullptr, nsGB18030ToUnicodeConstructor },
{ &kNS_UNICODETOGB18030_CID, false, nullptr, nsUnicodeToGB18030Constructor },
{ &kNS_ISO2022CNTOUNICODE_CID, false, nullptr, nsISO2022CNToUnicodeConstructor },
{ nullptr },
};
@ -921,7 +911,6 @@ static const mozilla::Module::ContractIDEntry kUConvContracts[] = {
{ NS_UNICODEDECODER_CONTRACTID_BASE "Big5-HKSCS", &kNS_BIG5HKSCSTOUNICODE_CID },
{ NS_UNICODEDECODER_CONTRACTID_BASE "EUC-KR", &kNS_EUCKRTOUNICODE_CID },
{ NS_UNICODEENCODER_CONTRACTID_BASE "EUC-KR", &kNS_UNICODETOEUCKR_CID },
{ NS_UNICODEDECODER_CONTRACTID_BASE "ISO-2022-KR", &kNS_ISO2022KRTOUNICODE_CID },
{ NS_UNICODEDECODER_CONTRACTID_BASE "GB2312", &kNS_GB2312TOUNICODE_CID },
{ NS_UNICODEENCODER_CONTRACTID_BASE "GB2312", &kNS_UNICODETOGB2312_CID },
{ NS_UNICODEDECODER_CONTRACTID_BASE "gbk", &kNS_GBKTOUNICODE_CID },
@ -930,7 +919,6 @@ static const mozilla::Module::ContractIDEntry kUConvContracts[] = {
{ NS_UNICODEENCODER_CONTRACTID_BASE "HZ-GB-2312", &kNS_UNICODETOHZ_CID },
{ NS_UNICODEDECODER_CONTRACTID_BASE "gb18030", &kNS_GB18030TOUNICODE_CID },
{ NS_UNICODEENCODER_CONTRACTID_BASE "gb18030", &kNS_UNICODETOGB18030_CID },
{ NS_UNICODEDECODER_CONTRACTID_BASE "ISO-2022-CN", &kNS_ISO2022CNTOUNICODE_CID },
{ nullptr }
};

View File

@ -1,563 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISO2022CNToUnicode.h"
#include "nsUCSupport.h"
#include "mozilla/dom/EncodingUtils.h"
using mozilla::dom::EncodingUtils;
NS_IMETHODIMP nsISO2022CNToUnicode::GB2312_To_Unicode(unsigned char *aSrc, int32_t aSrcLength, char16_t * aDest, int32_t * aDestLength)
{
nsresult rv;
if(!mGB2312_Decoder) {
// creating a delegate converter (GB2312)
mGB2312_Decoder = EncodingUtils::DecoderForEncoding(NS_LITERAL_CSTRING("GB2312"));
}
if(!mGB2312_Decoder) // failed creating a delegate converter
return NS_ERROR_UNEXPECTED;
rv = mGB2312_Decoder->Convert((const char *)aSrc, &aSrcLength, aDest, aDestLength);
return rv;
}
NS_IMETHODIMP nsISO2022CNToUnicode::EUCTW_To_Unicode(unsigned char *aSrc, int32_t aSrcLength, char16_t * aDest, int32_t * aDestLength)
{
nsresult rv;
if(!mEUCTW_Decoder) {
// creating a delegate converter (x-euc-tw)
mEUCTW_Decoder = EncodingUtils::DecoderForEncoding(NS_LITERAL_CSTRING("x-euc-tw"));
}
if(!mEUCTW_Decoder) // failed creating a delegate converter
return NS_ERROR_UNEXPECTED;
rv = mEUCTW_Decoder->Convert((const char *)aSrc, &aSrcLength, aDest, aDestLength);
return(rv);
}
NS_IMETHODIMP nsISO2022CNToUnicode::Convert(const char * aSrc, int32_t * aSrcLen, char16_t * aDest, int32_t * aDestLen)
{
const unsigned char * srcEnd = (unsigned char *)aSrc + *aSrcLen;
const unsigned char * src = (unsigned char *) aSrc;
char16_t* destEnd = aDest + *aDestLen;
char16_t* dest = aDest;
nsresult rv;
int32_t aLen;
while ((src < srcEnd))
{
switch (mState)
{
case eState_ASCII:
if(ESC == *src) {
mState = eState_ESC;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_ESC: // ESC
if('$' == *src) {
mState = eState_ESC_24;
} else {
if (CHECK_OVERRUN(dest, destEnd, 2))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_ESC_24: // ESC $
if(')' == *src) {
mState = eState_ESC_24_29;
} else if('*' == *src) {
mState = eState_ESC_24_2A;
} else if('+' == *src) {
mState = eState_ESC_24_2B;
} else {
if (CHECK_OVERRUN(dest, destEnd, 3))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_ESC_24_29: // ESC $ )
if('A' == *src) {
mState = eState_ESC_24_29_A;
} else if('G' == *src) {
mState = eState_ESC_24_29_G;
} else {
if (CHECK_OVERRUN(dest, destEnd, 4))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) ')';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_ESC_24_29_A: // ESC $ ) A
if(SO == *src) {
mState = eState_GB2312_1980;
mRunLength = 0;
} else {
if (CHECK_OVERRUN(dest, destEnd, 5))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) ')';
*dest++ = (char16_t) 'A';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_GB2312_1980: // ESC $ ) A SO
if(SI == *src) { // Shift-In (SI)
mState = eState_ESC_24_29_A_SO_SI;
if (mRunLength == 0) {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
}
mRunLength = 0;
} else if(ESC == *src) {
mState = eState_ESC;
} else {
if(0x20 < *src && *src < 0x7f) {
mData = *src;
mState = eState_GB2312_1980_2ndbyte;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
}
}
break;
case eState_GB2312_1980_2ndbyte: // ESC $ ) A SO
if(0x20 < *src && *src < 0x7f) {
unsigned char gb[2];
int32_t gbLen = 2;
gb[0] = mData | 0x80;
gb[1] = *src | 0x80;
aLen = destEnd - dest;
rv = GB2312_To_Unicode(gb, gbLen, dest, &aLen);
++mRunLength;
if(rv == NS_OK_UDEC_MOREOUTPUT) {
goto error1;
} else if(NS_FAILED(rv)) {
goto error2;
}
dest += aLen;
} else {
if (CHECK_OVERRUN(dest, destEnd, 2))
goto error1;
*dest++ = (char16_t) mData;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
}
mState = eState_GB2312_1980;
break;
case eState_ESC_24_29_A_SO_SI: // ESC $ ) A SO SI
if(SO == *src) {
mState = eState_GB2312_1980;
mRunLength = 0;
} else if(ESC == *src) {
mState = eState_ESC;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ESC_24_29_A_SO_SI;
}
break;
case eState_ESC_24_29_G: // ESC $ ) G
if(SO == *src) {
mState = eState_CNS11643_1;
mRunLength = 0;
} else {
if (CHECK_OVERRUN(dest, destEnd, 5))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) ')';
*dest++ = (char16_t) 'G';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_CNS11643_1: // ESC $ ) G SO
if(SI == *src) { // Shift-In (SI)
mState = eState_ESC_24_29_G_SO_SI;
if (mRunLength == 0) {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
}
mRunLength = 0;
} else if(ESC == *src) {
mState = eState_ESC;
} else {
if(0x20 < *src && *src < 0x7f) {
mData = *src;
mState = eState_CNS11643_1_2ndbyte;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
}
}
break;
case eState_CNS11643_1_2ndbyte: // ESC $ ) G SO
if(0x20 < *src && *src < 0x7f) {
unsigned char cns[4];
int32_t cnsLen = 2;
cns[0] = mData | 0x80;
cns[1] = *src | 0x80;
aLen = destEnd - dest;
rv = EUCTW_To_Unicode(cns, cnsLen, dest, &aLen);
++mRunLength;
if(rv == NS_OK_UDEC_MOREOUTPUT) {
goto error1;
} else if(NS_FAILED(rv)) {
goto error2;
}
dest += aLen;
} else {
if (CHECK_OVERRUN(dest, destEnd, 2))
goto error1;
*dest++ = (char16_t) mData;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
}
mState = eState_CNS11643_1;
break;
case eState_ESC_24_29_G_SO_SI: // ESC $ ) G SO SI
if(SO == *src) {
mState = eState_CNS11643_1;
mRunLength = 0;
} else if(ESC == *src) {
mState = eState_ESC;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ESC_24_29_G_SO_SI;
}
break;
case eState_ESC_24_2A: // ESC $ *
if('H' == *src) {
mState = eState_ESC_24_2A_H;
} else {
if (CHECK_OVERRUN(dest, destEnd, 4))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) '*';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_ESC_24_2A_H: // ESC $ * H
if(ESC == *src) {
mState = eState_ESC_24_2A_H_ESC;
} else {
if (CHECK_OVERRUN(dest, destEnd, 5))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) '*';
*dest++ = (char16_t) 'H';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_ESC_24_2A_H_ESC: // ESC $ * H ESC
if(SS2 == *src) {
mState = eState_CNS11643_2;
mRunLength = 0;
} else if('$' == *src) {
mState = eState_ESC_24;
} else {
if (CHECK_OVERRUN(dest, destEnd, 6))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) '*';
*dest++ = (char16_t) 'H';
*dest++ = (char16_t) ESC;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_CNS11643_2: // ESC $ * H ESC SS2
if(SI == *src) { // Shift-In (SI)
mState = eState_ESC_24_2A_H_ESC_SS2_SI;
if (mRunLength == 0) {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
}
mRunLength = 0;
} else if(ESC == *src) {
mState = eState_ESC_24_2A_H_ESC;
} else {
if(0x20 < *src && *src < 0x7f) {
mData = *src;
mState = eState_CNS11643_2_2ndbyte;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
}
}
break;
case eState_CNS11643_2_2ndbyte: // ESC $ * H ESC SS2
if(0x20 < *src && *src < 0x7f) {
unsigned char cns[4];
int32_t cnsLen = 4;
cns[0] = (unsigned char) MBYTE;
cns[1] = (unsigned char) (PMASK + 2);
cns[2] = mData | 0x80;
cns[3] = *src | 0x80;
aLen = destEnd - dest;
rv = EUCTW_To_Unicode(cns, cnsLen, dest, &aLen);
++mRunLength;
if(rv == NS_OK_UDEC_MOREOUTPUT) {
goto error1;
} else if(NS_FAILED(rv)) {
goto error2;
}
dest += aLen;
} else {
if (CHECK_OVERRUN(dest, destEnd, 2))
goto error1;
*dest++ = (char16_t) mData;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
}
mState = eState_CNS11643_2;
break;
case eState_ESC_24_2A_H_ESC_SS2_SI: // ESC $ * H ESC SS2 SI
if(ESC == *src) {
mState = eState_ESC_24_2A_H_ESC_SS2_SI_ESC;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ESC_24_2A_H_ESC_SS2_SI;
}
break;
case eState_ESC_24_2A_H_ESC_SS2_SI_ESC: // ESC $ * H ESC SS2 SI ESC
if(SS2 == *src) {
mState = eState_CNS11643_2;
mRunLength = 0;
} else if('$' == *src) {
mState = eState_ESC_24;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ESC_24_2A_H_ESC_SS2_SI;
}
break;
case eState_ESC_24_2B: // ESC $ +
if('I' <= *src && *src <= 'M') {
mState = eState_ESC_24_2B_I;
mPlaneID = *src - 'I' + 3;
} else {
if (CHECK_OVERRUN(dest, destEnd, 4))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) '+';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_ESC_24_2B_I: // ESC $ + I
if(ESC == *src) {
mState = eState_ESC_24_2B_I_ESC;
} else {
if (CHECK_OVERRUN(dest, destEnd, 5))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) '+';
*dest++ = (char16_t) 'I' + mPlaneID - 3;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_ESC_24_2B_I_ESC: // ESC $ + I ESC
if(SS3 == *src) {
mState = eState_CNS11643_3;
mRunLength = 0;
} else if('$' == *src) {
mState = eState_ESC_24;
} else {
if (CHECK_OVERRUN(dest, destEnd, 6))
goto error1;
*dest++ = (char16_t) ESC;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) '+';
*dest++ = (char16_t) 'I' + mPlaneID - 3;
*dest++ = (char16_t) ESC;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ASCII;
}
break;
case eState_CNS11643_3: // ESC $ + I ESC SS3
if(SI == *src) { // Shift-In (SI)
mState = eState_ESC_24_2B_I_ESC_SS3_SI;
if (mRunLength == 0) {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
}
mRunLength = 0;
} else if(ESC == *src) {
mState = eState_ESC_24_2B_I_ESC;
} else {
if(0x20 < *src && *src < 0x7f) {
mData = *src;
mState = eState_CNS11643_3_2ndbyte;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
}
}
break;
case eState_CNS11643_3_2ndbyte: // ESC $ + I ESC SS3
if(0x20 < *src && *src < 0x7f) {
unsigned char cns[4];
int32_t cnsLen = 4;
cns[0] = (unsigned char) MBYTE;
cns[1] = (unsigned char) (PMASK + mPlaneID);
cns[2] = mData | 0x80;
cns[3] = *src | 0x80;
aLen = destEnd - dest;
rv = EUCTW_To_Unicode(cns, cnsLen, dest, &aLen);
++mRunLength;
if(rv == NS_OK_UDEC_MOREOUTPUT) {
goto error1;
} else if(NS_FAILED(rv)) {
goto error2;
}
dest += aLen;
} else {
if (CHECK_OVERRUN(dest, destEnd, 2))
goto error1;
*dest++ = (char16_t) mData;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
}
mState = eState_CNS11643_3;
break;
case eState_ESC_24_2B_I_ESC_SS3_SI: // ESC $ + I ESC SS3 SI
if(ESC == *src) {
mState = eState_ESC_24_2B_I_ESC_SS3_SI_ESC;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ESC_24_2B_I_ESC_SS3_SI;
}
break;
case eState_ESC_24_2B_I_ESC_SS3_SI_ESC: // ESC $ + I ESC SS3 SI ESC
if(SS3 == *src) {
mState = eState_CNS11643_3;
mRunLength = 0;
} else if('$' == *src) {
mState = eState_ESC_24;
} else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = eState_ESC_24_2B_I_ESC_SS3_SI;
}
break;
case eState_ERROR:
NS_NOTREACHED("unhandled case");
goto error2;
} // switch
src++;
}
*aDestLen = dest- aDest;
return NS_OK;
error1:
*aDestLen = dest-aDest;
*aSrcLen = src - (const unsigned char*)aSrc;
return NS_OK_UDEC_MOREOUTPUT;
error2:
*aSrcLen = src - (const unsigned char*)aSrc;
*aDestLen = dest-aDest;
mState = eState_ASCII;
return NS_ERROR_UNEXPECTED;
}

View File

@ -1,107 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsISO2022CNToUnicode_h__
#define nsISO2022CNToUnicode_h__
#include "nsCOMPtr.h"
#include "nsUCSupport.h"
#include "mozilla/Telemetry.h"
#define MBYTE 0x8e
#undef PMASK
#define PMASK 0xa0
#define SI 0x0f
#define SO 0x0e
#define ESC 0x1b
#define SS2 0x4e
#define SS3 0x4f
class nsISO2022CNToUnicode : public nsBasicDecoderSupport
{
public:
nsISO2022CNToUnicode() :
mState(eState_ASCII),
mPlaneID(0),
mRunLength(0)
{
mozilla::Telemetry::Accumulate(
mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022CN, true);
}
virtual ~nsISO2022CNToUnicode() {}
NS_IMETHOD Convert(const char *aSrc, int32_t * aSrcLength,
char16_t * aDest, int32_t * aDestLength) ;
NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength,
int32_t * aDestLength)
{
*aDestLength = aSrcLength;
return NS_OK;
}
NS_IMETHOD Reset()
{
mState = eState_ASCII;
mPlaneID = 0;
mRunLength = 0;
return NS_OK;
}
private:
// State Machine ID
enum {
eState_ASCII,
eState_ESC, // ESC
eState_ESC_24, // ESC $
eState_ESC_24_29, // ESC $ )
eState_ESC_24_29_A, // ESC $ ) A
eState_GB2312_1980, // ESC $ ) A SO
eState_GB2312_1980_2ndbyte, // ESC $ ) A SO
eState_ESC_24_29_A_SO_SI, // ESC $ ) A SO SI
eState_ESC_24_29_G, // ESC $ ) G or H
eState_CNS11643_1, // ESC $ ) G SO
eState_CNS11643_1_2ndbyte, // ESC $ ) G SO
eState_ESC_24_29_G_SO_SI, // ESC $ ) G SO SI
eState_ESC_24_2A, // ESC $ *
eState_ESC_24_2A_H, // ESC $ * H
eState_ESC_24_2A_H_ESC, // ESC $ * H ESC
eState_CNS11643_2, // ESC $ * H ESC SS2
eState_CNS11643_2_2ndbyte, // ESC $ * H ESC SS2
eState_ESC_24_2A_H_ESC_SS2_SI, // ESC $ * H ESC SS2 SI
eState_ESC_24_2A_H_ESC_SS2_SI_ESC, // ESC $ * H ESC SS2 SI ESC
eState_ESC_24_2B, // ESC $ +
eState_ESC_24_2B_I, // ESC $ + I
eState_ESC_24_2B_I_ESC, // ESC $ + I ESC
eState_CNS11643_3, // ESC $ + I ESC SS3
eState_CNS11643_3_2ndbyte, // ESC $ + I ESC SS3
eState_ESC_24_2B_I_ESC_SS3_SI, // ESC $ + I ESC SI
eState_ESC_24_2B_I_ESC_SS3_SI_ESC, // ESC $ + I ESC SI ESC
eState_ERROR
} mState;
char mData;
// Plane number for CNS11643 code
int mPlaneID;
// Length of non-ASCII run
uint32_t mRunLength;
// Decoder handler
nsCOMPtr<nsIUnicodeDecoder> mGB2312_Decoder;
nsCOMPtr<nsIUnicodeDecoder> mEUCTW_Decoder;
NS_IMETHOD GB2312_To_Unicode(unsigned char *aSrc, int32_t aSrcLength,
char16_t * aDest, int32_t * aDestLength) ;
NS_IMETHOD EUCTW_To_Unicode(unsigned char *aSrc, int32_t aSrcLength,
char16_t * aDest, int32_t * aDestLength) ;
};
#endif // nsISO2022CNToUnicode_h__

View File

@ -12,11 +12,6 @@
#define NS_GB2312TOUNICODE_CID \
{ 0x379c2774, 0xec77, 0x11d2, {0x8a, 0xac, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36}}
// Class ID for our ISO2022CNToUnicode charset converter
// {BA615199-1DFA-11d3-B3BF-00805F8A6670}
#define NS_ISO2022CNTOUNICODE_CID \
{ 0xba615199, 0x1dfa, 0x11d3, {0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70}}
// Class ID for our HZToUnicode charset converter
// {BA61519A-1DFA-11d3-B3BF-00805F8A6670}
#define NS_HZTOUNICODE_CID \
@ -37,11 +32,6 @@
#define NS_UNICODETOGBK_CID \
{ 0xba61519b, 0x1dfa, 0x11d3, {0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70}}
// Class ID for our UnicodeToISO2022CN charset converter
// {BA61519C-1DFA-11d3-B3BF-00805F8A6670}
#define NS_UNICODETOISO2022CN_CID \
{ 0xba61519c, 0x1dfa, 0x11d3, {0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70}}
// Class ID for our UnicodeToHZ charset converter
// {BA61519D-1DFA-11d3-B3BF-00805F8A6670}
#define NS_UNICODETOHZ_CID \

View File

@ -1,184 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISO2022KRToUnicode.h"
#include "nsUCSupport.h"
#include "mozilla/dom/EncodingUtils.h"
using mozilla::dom::EncodingUtils;
NS_IMETHODIMP nsISO2022KRToUnicode::Convert(const char * aSrc, int32_t * aSrcLen, char16_t * aDest, int32_t * aDestLen)
{
const unsigned char* srcEnd = (unsigned char*)aSrc + *aSrcLen;
const unsigned char* src =(unsigned char*) aSrc;
char16_t* destEnd = aDest + *aDestLen;
char16_t* dest = aDest;
while((src < srcEnd))
{
// if LF/CR, return to US-ASCII unconditionally.
if ( *src == 0x0a || *src == 0x0d )
mState = mState_Init;
switch(mState)
{
case mState_Init:
if(0x1b == *src) {
mLastLegalState = mState_ASCII;
mState = mState_ESC;
break;
}
mState = mState_ASCII;
// fall through
case mState_ASCII:
if(0x0e == *src) { // Shift-Out
mState = mState_KSX1001_1992;
mRunLength = 0;
}
else if(*src & 0x80) {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
}
else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = (char16_t) *src;
}
break;
case mState_ESC:
if('$' == *src) {
mState = mState_ESC_24;
}
else {
if (CHECK_OVERRUN(dest, destEnd, 2))
goto error1;
*dest++ = (char16_t) 0x1b;
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = mLastLegalState;
}
break;
case mState_ESC_24: // ESC $
if(')' == *src) {
mState = mState_ESC_24_29;
}
else {
if (CHECK_OVERRUN(dest, destEnd, 3))
goto error1;
*dest++ = (char16_t) 0x1b;
*dest++ = (char16_t) '$';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = mLastLegalState;
}
break;
case mState_ESC_24_29: // ESC $ )
mState = mLastLegalState;
if('C' == *src) {
mState = mState_ASCII;
mRunLength = 0;
}
else {
if (CHECK_OVERRUN(dest, destEnd, 4))
goto error1;
*dest++ = (char16_t) 0x1b;
*dest++ = (char16_t) '$';
*dest++ = (char16_t) ')';
*dest++ = (0x80 & *src) ? 0xFFFD : (char16_t) *src;
mState = mLastLegalState;
}
break;
case mState_KSX1001_1992:
if (0x20 < (uint8_t) *src && (uint8_t) *src < 0x7f) {
mData = (uint8_t) *src;
mState = mState_KSX1001_1992_2ndbyte;
}
else if (0x0f == *src) { // Shift-In (SI)
mState = mState_ASCII;
if (mRunLength == 0) {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
}
mRunLength = 0;
}
else if ((uint8_t) *src == 0x20 || (uint8_t) *src == 0x09) {
// Allow space and tab between SO and SI (i.e. in Hangul segment)
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
mState = mState_KSX1001_1992;
*dest++ = (char16_t) *src;
++mRunLength;
}
else { // Everything else is invalid.
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
}
break;
case mState_KSX1001_1992_2ndbyte:
if ( 0x20 < (uint8_t) *src && (uint8_t) *src < 0x7f ) {
if (!mEUCKRDecoder) {
// creating a delegate converter (EUC-KR)
mEUCKRDecoder =
EncodingUtils::DecoderForEncoding(NS_LITERAL_CSTRING("EUC-KR"));
}
if (!mEUCKRDecoder) {// failed creating a delegate converter
*dest++ = 0xFFFD;
}
else {
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
unsigned char ksx[2];
char16_t uni;
int32_t ksxLen = 2, uniLen = 1;
// mData is the original 1st byte.
// *src is the present 2nd byte.
// Put 2 bytes (one character) to ksx[] with EUC-KR encoding.
ksx[0] = mData | 0x80;
ksx[1] = *src | 0x80;
// Convert EUC-KR to unicode.
mEUCKRDecoder->Convert((const char *)ksx, &ksxLen, &uni, &uniLen);
*dest++ = uni;
++mRunLength;
}
mState = mState_KSX1001_1992;
}
else { // Invalid
if ( 0x0f == *src ) { // Shift-In (SI)
mState = mState_ASCII;
}
else {
mState = mState_KSX1001_1992;
}
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
}
break;
case mState_ERROR:
mState = mLastLegalState;
if (CHECK_OVERRUN(dest, destEnd, 1))
goto error1;
*dest++ = 0xFFFD;
break;
} // switch
src++;
}
*aDestLen = dest - aDest;
return NS_OK;
error1:
*aDestLen = dest-aDest;
*aSrcLen = src-(unsigned char*)aSrc;
return NS_OK_UDEC_MOREOUTPUT;
}

View File

@ -1,65 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsISO2022KRToUnicode_h__
#define nsISO2022KRToUnicode_h__
#include "nsUCSupport.h"
#include "mozilla/Telemetry.h"
class nsISO2022KRToUnicode : public nsBasicDecoderSupport
{
public:
nsISO2022KRToUnicode()
{
mState = mState_Init;
mLastLegalState = mState_ASCII;
mData = 0;
mEUCKRDecoder = nullptr;
mRunLength = 0;
mozilla::Telemetry::Accumulate(
mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022KR, true);
}
virtual ~nsISO2022KRToUnicode()
{
}
NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength,
char16_t * aDest, int32_t * aDestLength) ;
NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength,
int32_t * aDestLength)
{
*aDestLength = aSrcLength;
return NS_OK;
}
NS_IMETHOD Reset()
{
mState = mState_Init;
mLastLegalState = mState_ASCII;
mRunLength = 0;
return NS_OK;
}
private:
enum {
mState_Init,
mState_ASCII,
mState_ESC,
mState_ESC_24,
mState_ESC_24_29,
mState_KSX1001_1992,
mState_KSX1001_1992_2ndbyte,
mState_ERROR
} mState, mLastLegalState;
uint8_t mData;
// Length of non-ASCII run
uint32_t mRunLength;
nsCOMPtr<nsIUnicodeDecoder> mEUCKRDecoder;
};
#endif // nsISO2022KRToUnicode_h__

View File

@ -13,19 +13,9 @@
#define NS_EUCKRTOUNICODE_CID \
{ 0x379c2775, 0xec77, 0x11d2, {0x8a, 0xac, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36}}
// Class ID for our ISO2022KRToUnicode charset converter
// {BA61519f-1DFA-11d3-B3BF-00805F8A6670}
#define NS_ISO2022KRTOUNICODE_CID \
{ 0xba61519f, 0x1dfa, 0x11d3, {0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70}}
// Class ID for our UnicodeToEUCKR charset converter
// {379C2778-EC77-11d2-8AAC-00600811A836}
#define NS_UNICODETOEUCKR_CID \
{ 0x379c2778, 0xec77, 0x11d2, {0x8a, 0xac, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36}}
// Class ID for our UnicodeToISO2022KR charset converter
// {BA6151A0-1DFA-11d3-B3BF-00805F8A6670}
#define NS_UNICODETOISO2022KR_CID \
{ 0xba6151a0, 0x1dfa, 0x11d3, {0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70}}
#endif /* nsUCvKOCID_h___ */