From 6da5d16514d85895a860ad46acc93149b8c59bd3 Mon Sep 17 00:00:00 2001 From: "ftang%netscape.com" Date: Thu, 14 Jan 1999 07:39:45 +0000 Subject: [PATCH] add ucvlatin, add cp1253, iso-8859-1, windows-1253 converter, change the nsIUnicodeDecodeUtil interface --- intl/uconv/makefile.win | 1 + intl/uconv/public/nsConverterCID.h | 4 +- intl/uconv/public/nsICharsetConverterInfo.h | 5 +- intl/uconv/public/nsIUnicodeDecodeUtil.h | 65 +++++--- intl/uconv/src/makefile.win | 16 +- intl/uconv/src/nsAscii2Unicode.cpp | 0 intl/uconv/src/nsAscii2Unicode.h | 0 intl/uconv/src/nsCharsetConverterManager.cpp | 12 +- intl/uconv/src/nsUConvDll.cpp | 27 ---- intl/uconv/src/nsUnicodeDecodeUtil.cpp | 151 +++++++++++++------ intl/uconv/src/nsUnicodeDecodeUtil.h | 53 ++++--- intl/uconv/src/registryhack1.h | 1 + intl/uconv/src/registryhack2.h | 6 +- intl/uconv/tests/makefile.win | 4 +- intl/uconv/tests/nsTestUConv.cpp | 57 +++---- intl/uconv/ucvja/makefile.win | 1 - intl/uconv/ucvja/nsSJIS2Unicode.cpp | 17 ++- intl/uconv/ucvja/nsSJIS2Unicode.h | 4 +- 18 files changed, 246 insertions(+), 178 deletions(-) delete mode 100644 intl/uconv/src/nsAscii2Unicode.cpp delete mode 100644 intl/uconv/src/nsAscii2Unicode.h diff --git a/intl/uconv/makefile.win b/intl/uconv/makefile.win index 9a1363978ee..d0e14000393 100644 --- a/intl/uconv/makefile.win +++ b/intl/uconv/makefile.win @@ -18,6 +18,7 @@ DEPTH=..\.. DIRS=public src \ + ucvlatin \ ucvja \ tests diff --git a/intl/uconv/public/nsConverterCID.h b/intl/uconv/public/nsConverterCID.h index a2b291b7cf6..3521e389cb4 100644 --- a/intl/uconv/public/nsConverterCID.h +++ b/intl/uconv/public/nsConverterCID.h @@ -22,9 +22,9 @@ #include "nsISupports.h" -// Class ID for our Ascii2Unicode charset converter +// Class ID for our Latin1ToUnicode charset converter // {A3254CB0-8E20-11d2-8A98-00600811A836} -NS_DECLARE_ID(kAscii2UnicodeCID, +NS_DECLARE_ID(kLatin1ToUnicodeCID, 0xa3254cb0, 0x8e20, 0x11d2, 0x8a, 0x98, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36); #endif /* nsConverterCID_h___ */ diff --git a/intl/uconv/public/nsICharsetConverterInfo.h b/intl/uconv/public/nsICharsetConverterInfo.h index 7b0e4d76d9f..21f407eb40b 100644 --- a/intl/uconv/public/nsICharsetConverterInfo.h +++ b/intl/uconv/public/nsICharsetConverterInfo.h @@ -20,7 +20,6 @@ #ifndef nsICharsetConverterInfo_h___ #define nsICharsetConverterInfo_h___ -#include "nsString.h" #include "nsISupports.h" // Interface ID for our Converter Information interface @@ -50,14 +49,14 @@ public: * * @param aCharset [OUT] a name/alias for the source charset */ - NS_IMETHOD GetCharsetSrc(nsString ** aCharset) = 0; + NS_IMETHOD GetCharsetSrc(char ** aCharset) = 0; /** * Returns the character set this converter is converting into. * * @param aCharset [OUT] a name/alias for the destination charset */ - NS_IMETHOD GetCharsetDest(nsString ** aCharset) = 0; + NS_IMETHOD GetCharsetDest(char ** aCharset) = 0; }; #endif /* nsICharsetConverterInfo_h___ */ diff --git a/intl/uconv/public/nsIUnicodeDecodeUtil.h b/intl/uconv/public/nsIUnicodeDecodeUtil.h index d7a2d6fbeb7..b3638bdc400 100644 --- a/intl/uconv/public/nsIUnicodeDecodeUtil.h +++ b/intl/uconv/public/nsIUnicodeDecodeUtil.h @@ -31,28 +31,57 @@ NS_DECLARE_ID ( kIUnicodeDecodeUtilIID, class nsIUnicodeDecodeUtil : public nsISupports { public: - NS_IMETHOD ConvertBy1Table( - PRUnichar *aDest, - PRInt32 aDestOffset, - PRInt32 *aDestLength, - const char *aSrc, - PRInt32 aSrcOffset, - PRInt32 *aSrcLength, - uShiftTable *aShiftTable, + /* + * + */ + NS_IMETHOD Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + PRInt32 aBehavior, + uShiftTable *aShiftTable, uMappingTable *aMappingTable ) = 0; - NS_IMETHOD ConvertByNTable( - PRUnichar *aDest, - PRInt32 aDestOffset, - PRInt32 *aDestLength, - const char *aSrc, - PRInt32 aSrcOffset, - PRInt32 *aSrcLength, - PRUint16 numOfTable, - uRange *aRangeArray, - uShiftTable *aShiftTableArray, + /* + * + */ + NS_IMETHOD Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + PRInt32 aBehavior, + PRUint16 numOfTable, + uRange *aRangeArray, + uShiftTable *aShiftTableArray, uMappingTable *aMappingTableArray ) = 0; + + /* + * + */ + NS_IMETHOD Init1ByteFastTable( + uMappingTable *aMappingTable, + PRUnichar *aFastTable + ) = 0; + + /* + * + */ + NS_IMETHOD Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + const PRUnichar *aFastTable + ) = 0; }; #endif diff --git a/intl/uconv/src/makefile.win b/intl/uconv/src/makefile.win index 31112ef0ef4..5783c36282d 100644 --- a/intl/uconv/src/makefile.win +++ b/intl/uconv/src/makefile.win @@ -28,28 +28,26 @@ DLL=.\$(OBJDIR)\$(DLLNAME).dll CPPSRCS = \ nsCharsetConverterManager.cpp \ - nsAscii2Unicode.cpp \ nsUnicodeDecodeUtil.cpp \ nsUConvDll.cpp \ $(NULL) CPP_OBJS= \ .\$(OBJDIR)\nsCharsetConverterManager.obj \ - .\$(OBJDIR)\nsAscii2Unicode.obj \ .\$(OBJDIR)\nsUnicodeDecodeUtil.obj \ .\$(OBJDIR)\nsUConvDll.obj \ $(NULL) -CSRCS = \ +CSRCS = \ umap.c \ ugen.c \ uscan.c \ $(NULL) -OBJS = \ - .\$(OBJDIR)\umap.obj \ - .\$(OBJDIR)\ugen.obj \ - .\$(OBJDIR)\uscan.obj \ +OBJS = \ + .\$(OBJDIR)\umap.obj \ + .\$(OBJDIR)\ugen.obj \ + .\$(OBJDIR)\uscan.obj \ $(NULL) EXPORTS= \ @@ -59,8 +57,8 @@ LINCS= \ -I$(PUBLIC)\raptor \ -I$(PUBLIC)\xpcom \ -I$(PUBLIC)\uconv \ -# the following lines are hacks - -I$(PUBLIC)\ucvja \ + -I..\ucvja \ + -I..\ucvlatin \ $(NULL) LLIBS= \ diff --git a/intl/uconv/src/nsAscii2Unicode.cpp b/intl/uconv/src/nsAscii2Unicode.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/intl/uconv/src/nsAscii2Unicode.h b/intl/uconv/src/nsAscii2Unicode.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/intl/uconv/src/nsCharsetConverterManager.cpp b/intl/uconv/src/nsCharsetConverterManager.cpp index e94fee5083f..db4ecdb107e 100644 --- a/intl/uconv/src/nsCharsetConverterManager.cpp +++ b/intl/uconv/src/nsCharsetConverterManager.cpp @@ -72,6 +72,7 @@ struct ConverterInfo * XXX What happens in a multithreaded environment?! * XXX Make this a service; use the service manager; etc. * XXX Have a clear and consistent extensibility model. + * XXX Charset names are case-insensitive! * * @created 17/Nov/1998 * @author Catalin Rotaru [CATA] @@ -209,8 +210,7 @@ nsresult nsCharsetConverterManager::CreateMapping() // slots. nsresult nsCharsetConverterManager::CreateConvertersList() { - -#include "registryhack2.h" + #include "registryhack2.h" return NS_OK; } @@ -225,7 +225,9 @@ nsresult nsCharsetConverterManager::GatherConvertersInfo() info = GetICharsetConverterInfo(mEncArray, i, &mEncSize); if (info == NULL) continue; - info->GetCharsetDest(&str); + char *charset; + info->GetCharsetDest(&charset); + str = new nsString(charset); GetCharsetName(str,&mEncArray[i].mCharset); delete str; @@ -236,7 +238,9 @@ nsresult nsCharsetConverterManager::GatherConvertersInfo() info = GetICharsetConverterInfo(mDecArray, i, &mDecSize); if (info == NULL) continue; - info->GetCharsetSrc(&str); + char *charset; + info->GetCharsetSrc(&charset); + str = new nsString(charset); GetCharsetName(str,&mDecArray[i].mCharset); delete str; diff --git a/intl/uconv/src/nsUConvDll.cpp b/intl/uconv/src/nsUConvDll.cpp index 025873cf0f5..33672b49c10 100644 --- a/intl/uconv/src/nsUConvDll.cpp +++ b/intl/uconv/src/nsUConvDll.cpp @@ -19,11 +19,7 @@ #include "nsRepository.h" #include "nsICharsetConverterManager.h" -#include "nsIUnicodeEncoder.h" -#include "nsIUnicodeDecoder.h" #include "nsCharsetConverterManager.h" -#include "nsAscii2Unicode.h" -#include "nsConverterCID.h" //---------------------------------------------------------------------- // Global functions and data [declaration] @@ -59,20 +55,6 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID, return res; } - - // the Ascii2Unicode converter - if (aCID.Equals(kAscii2UnicodeCID)) { - nsAscii2UnicodeFactory *factory = new nsAscii2UnicodeFactory(); - nsresult res = factory->QueryInterface(kIFactoryIID, (void **) aFactory); - - if (NS_FAILED(res)) { - *aFactory = NULL; - delete factory; - } - - return res; - } - return NS_NOINTERFACE; } @@ -80,12 +62,6 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(const char * path) { nsresult res; - if (NS_FAILED(res)) return res; - - res = nsRepository::RegisterFactory(kAscii2UnicodeCID, path, - PR_TRUE, PR_TRUE); - if (NS_FAILED(res)) return res; - res = nsRepository::RegisterFactory(kCharsetConverterManagerCID, path, PR_TRUE, PR_TRUE); return res; @@ -95,9 +71,6 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(const char * path) { nsresult res; - res = nsRepository::UnregisterFactory(kAscii2UnicodeCID, path); - if (NS_FAILED(res)) return res; - res = nsRepository::UnregisterFactory(kCharsetConverterManagerCID, path); return res; } diff --git a/intl/uconv/src/nsUnicodeDecodeUtil.cpp b/intl/uconv/src/nsUnicodeDecodeUtil.cpp index 8975e28c1d4..6552c33c3fc 100644 --- a/intl/uconv/src/nsUnicodeDecodeUtil.cpp +++ b/intl/uconv/src/nsUnicodeDecodeUtil.cpp @@ -40,32 +40,35 @@ nsUnicodeDecodeUtil::~nsUnicodeDecodeUtil() } #ifdef NO_OPTIMIZATION_FOR_1TABLE -NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertBy1Table( - PRUnichar *aDest, - PRInt32 aDestOffset, - PRInt32 *aDestLength, - const char *aSrc, - PRInt32 aSrcOffset, - PRInt32 *aSrcLength, - uShiftTable *aShiftTable, - uMappingTable *aMappingTable +NS_IMETHODIMP nsUnicodeDecodeUtil::Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + PRInt32 aBehavior, + uShiftTable *aShiftTable, + uMappingTable *aMappingTable ) { uRange range = {0x00, 0xff}; - return ConvertByNTable(aDest, aDestOffset, aDestLength, aSrc, aSrcOffset, aSrcLength, - 1, &range, - aShiftTable, aMappingTable); + return Convert(aDest, aDestOffset, aDestLength, + aSrc, aSrcOffset, aSrcLength, + aBehavior, 1, &range, + aShiftTable, aMappingTable); } #else -NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertBy1Table( - PRUnichar *aDest, - PRInt32 aDestOffset, - PRInt32 *aDestLength, - const char *aSrc, - PRInt32 aSrcOffset, - PRInt32 *aSrcLength, - uShiftTable *aShiftTable, - uMappingTable *aMappingTable +NS_IMETHODIMP nsUnicodeDecodeUtil::Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + PRInt32 aBehavior, + uShiftTable *aShiftTable, + uMappingTable *aMappingTable ) { PRUint32 ubuflen = *aDestLength; @@ -83,18 +86,20 @@ NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertBy1Table( if(uScan(aShiftTable, (PRInt32*) 0, src, &med, srclen, &scanlen)) { uMapCode((uTable*) aMappingTable,med, dest); if(*dest == NOMAPPING) { - //------ - // Fallback handling - need to change - //------ - // ERROR_ILLEGAL_INPUT + if(nsIUnicodeDecoder::kOnError_Signal == aBehavior) + { + *aSrcLength -= srclen; + *aDestLength = validlen; + return NS_ERROR_ILLEGAL_INPUT; + } if(scanlen == 0) scanlen = 1; } } else { - *aSrcLength -= srclen; + *aSrcLength -= srclen; *aDestLength = validlen; - return NS_PARTIAL_MORE_INPUT; - } + return NS_PARTIAL_MORE_INPUT; + } } *aSrcLength -= srclen; *aDestLength = validlen; @@ -105,17 +110,18 @@ NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertBy1Table( } #endif -NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertByNTable( - PRUnichar *aDest, - PRInt32 aDestOffset, - PRInt32 *aDestLength, - const char *aSrc, - PRInt32 aSrcOffset, - PRInt32 *aSrcLength, - PRUint16 numberOfTable, - uRange *aRangeArray, - uShiftTable *aShiftTableArray, - uMappingTable *aMappingTableArray +NS_IMETHODIMP nsUnicodeDecodeUtil::Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + PRInt32 aBehavior, + PRUint16 numberOfTable, + uRange *aRangeArray, + uShiftTable *aShiftTableArray, + uMappingTable *aMappingTableArray ) { PRUint32 ubuflen = *aDestLength; @@ -147,13 +153,15 @@ NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertByNTable( } } if(i == numberOfTable) { - //------ - // Fallback handling - need to change - //------ - // ERROR_ILLEGAL_INPUT - if(scanlen == 0) - scanlen = 1; - *dest= NOMAPPING; + if(nsIUnicodeDecoder::kOnError_Signal == aBehavior) + { + *aSrcLength -= srclen; + *aDestLength = validlen; + return NS_ERROR_ILLEGAL_INPUT; + } + if(scanlen == 0) + scanlen = 1; + *dest= NOMAPPING; } } *aSrcLength -= srclen; @@ -164,3 +172,54 @@ NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertByNTable( return NS_OK; } + +NS_IMETHODIMP nsUnicodeDecodeUtil::Init1ByteFastTable( + uMappingTable *aMappingTable, + PRUnichar *aFastTable +) +{ + static PRInt16 g1ByteShiftTable[] = { + 0, u1ByteCharset, + ShiftCell(0, 0,0,0,0,0,0,0), + }; + static char dmy[256]; + static PRBool init=PR_FALSE; + if(! init) + { + for(int i= 0;i < 256; i++) + dmy[i] = (char) dmy; + init = PR_TRUE; + } + PRInt32 dm1 = 256; + PRInt32 dm2 = 256; + return Convert(aFastTable, 0, &dm1, dmy, 0, &dm2, + nsIUnicodeDecoder::kOnError_Recover, + (uShiftTable*) &g1ByteShiftTable, aMappingTable); +} + +NS_IMETHODIMP nsUnicodeDecodeUtil::Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + const PRUnichar *aFastTable +) +{ + PRUnichar *pD = aDest + aDestOffset; + unsigned char *pS = (unsigned char*) (aSrc + aSrcOffset); + PRInt32 srclen = *aSrcLength; + PRInt32 destlen = *aDestLength; + + for( ; ((srclen > 0) && ( destlen > 0)); srclen--, destlen--) + *pD++ = aFastTable[*pS++]; + + *aSrcLength -= srclen; + *aDestLength -= destlen; + + if(srclen > 0) + return NS_PARTIAL_MORE_OUTPUT; + else + return NS_OK; +} diff --git a/intl/uconv/src/nsUnicodeDecodeUtil.h b/intl/uconv/src/nsUnicodeDecodeUtil.h index 998d53849c3..8fa256ee53a 100644 --- a/intl/uconv/src/nsUnicodeDecodeUtil.h +++ b/intl/uconv/src/nsUnicodeDecodeUtil.h @@ -41,29 +41,46 @@ public: ~nsUnicodeDecodeUtil(); public: - NS_IMETHOD ConvertBy1Table( - PRUnichar *aDest, - PRInt32 aDestOffset, - PRInt32 *aDestLength, - const char *aSrc, - PRInt32 aSrcOffset, - PRInt32 *aSrcLength, - uShiftTable *aShiftTable, + NS_IMETHOD Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + PRInt32 aBehavior, + uShiftTable *aShiftTable, uMappingTable *aMappingTable ); - NS_IMETHOD ConvertByNTable( - PRUnichar *aDest, - PRInt32 aDestOffset, - PRInt32 *aDestLength, - const char *aSrc, - PRInt32 aSrcOffset, - PRInt32 *aSrcLength, - PRUint16 numOfTable, - uRange *aRangeArray, - uShiftTable *aShiftTableArray, + NS_IMETHOD Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + PRInt32 aBehavior, + PRUint16 numOfTable, + uRange *aRangeArray, + uShiftTable *aShiftTableArray, uMappingTable *aMappingTableArray ); + + NS_IMETHOD Init1ByteFastTable( + uMappingTable *aMappingTable, + PRUnichar *aFastTable + ); + + NS_IMETHOD Convert( + PRUnichar *aDest, + PRInt32 aDestOffset, + PRInt32 *aDestLength, + const char *aSrc, + PRInt32 aSrcOffset, + PRInt32 *aSrcLength, + const PRUnichar *aFastTable + ); }; #endif diff --git a/intl/uconv/src/registryhack1.h b/intl/uconv/src/registryhack1.h index 3ef2de1a659..1f523fcb877 100644 --- a/intl/uconv/src/registryhack1.h +++ b/intl/uconv/src/registryhack1.h @@ -21,5 +21,6 @@ #include "nsConverterCID.h" #include "nsUCVJACID.h" +#include "nsUCvLatinCID.h" #endif /* __REGISTRYHACK1_H__ */ diff --git a/intl/uconv/src/registryhack2.h b/intl/uconv/src/registryhack2.h index 1217af49af3..668ce84b27f 100644 --- a/intl/uconv/src/registryhack2.h +++ b/intl/uconv/src/registryhack2.h @@ -17,11 +17,13 @@ * Netscape Communications Corporation. All Rights Reserved. */ - mDecSize = 2; + mDecSize = 4; mDecArray = new ConverterInfo [mDecSize]; - mDecArray[0].mCID = &kAscii2UnicodeCID; + mDecArray[0].mCID = &kLatin1ToUnicodeCID; mDecArray[1].mCID = &kSJIS2UnicodeCID; + mDecArray[2].mCID = &kISO88597ToUnicodeCID; + mDecArray[3].mCID = &kCP1253ToUnicodeCID; mEncSize = 0; mEncArray = NULL; diff --git a/intl/uconv/tests/makefile.win b/intl/uconv/tests/makefile.win index 7a976c7d13b..a1b8851a65e 100644 --- a/intl/uconv/tests/makefile.win +++ b/intl/uconv/tests/makefile.win @@ -39,8 +39,8 @@ OBJS = \ LINCS= \ -I$(PUBLIC)\xpcom \ -I$(PUBLIC)\raptor \ - -I$(PUBLIC)\uconv \ - -I$(PUBLIC)\ucvja \ + -I..\public \ + -I..\ucvja \ $(NULL) LLIBS= \ diff --git a/intl/uconv/tests/nsTestUConv.cpp b/intl/uconv/tests/nsTestUConv.cpp index a36b8a65c8b..b55481892fa 100644 --- a/intl/uconv/tests/nsTestUConv.cpp +++ b/intl/uconv/tests/nsTestUConv.cpp @@ -24,35 +24,26 @@ #include "nsISupports.h" #include "nsICharsetConverterManager.h" #include "nsConverterCID.h" - -#define TEST_SJIS -#ifdef TEST_SJIS #include "nsUCVJACID.h" -#ifdef XP_UNIX -#define UCVJA_DLL "libucvja.so" -#else -#ifdef XP_MAC -#define UCVJA_DLL "UCVJA_DLL" -#else /* XP_MAC */ -#define UCVJA_DLL "ucvja.dll" -#endif -#endif - -#endif - - #ifdef XP_UNIX -#define UCONV_DLL "libuconv.so" -#else + +#define UCONV_DLL "libuconv.so" +#define UCVLATIN_DLL "libucvlatin.so" +#define UCVJA_DLL "libucvja.so" +#else /* XP_UNIX */ #ifdef XP_MAC #define UCONV_DLL "UCONV_DLL" +#define UCVLATIN_DLL "UCVLATIN_DLL" +#define UCVJA_DLL "UCVJA_DLL" #else /* XP_MAC */ #define UCONV_DLL "uconv.dll" +#define UCVLATIN_DLL "ucvlatin.dll" +#define UCVJA_DLL "ucvja.dll" +#endif #endif -#endif -#define TABLE_SIZE1 5 +#define TABLE_SIZE1 5 nsICharsetConverterManager * ccMan = NULL; @@ -63,15 +54,13 @@ nsresult setupRegistry() res = nsRepository::RegisterFactory(kCharsetConverterManagerCID, UCONV_DLL, PR_FALSE, PR_FALSE); if (NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res; - res = nsRepository::RegisterFactory(kAscii2UnicodeCID, UCONV_DLL, PR_FALSE, PR_FALSE); - -#ifdef TEST_SJIS + res = nsRepository::RegisterFactory(kLatin1ToUnicodeCID, UCVLATIN_DLL, PR_FALSE, PR_FALSE); if (NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res; res = nsRepository::RegisterFactory(kSJIS2UnicodeCID, UCVJA_DLL, PR_FALSE, PR_FALSE); -#endif + if (NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res; - return res; + return NS_OK; } nsresult init() @@ -79,7 +68,7 @@ nsresult init() nsresult res; res = setupRegistry(); - if (NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) { + if (NS_FAILED(res)) { printf("Error setting up registry: 0x%x",res); return res; } @@ -140,13 +129,13 @@ nsresult testCharsetConverterManager() return NS_OK; } -nsresult testAsciiDecoder() +nsresult testLatin1Decoder() { - printf("\n[T2] Ascii2Unicode\n"); + printf("\n[T2] Latin1ToUnicode\n"); // create converter nsIUnicodeDecoder * dec; - nsAutoString str("Ascii"); + nsAutoString str("iso-8859-1"); nsresult res = ccMan->GetUnicodeDecoder(&str,&dec); if (NS_FAILED(res)) { printf("ERROR 0x%x: Cannot instantiate.\n",res); @@ -187,7 +176,7 @@ nsresult testAsciiDecoder() return NS_OK; } -#ifdef TEST_SJIS + #define SJIS_TEST_SRC_SIZE 40 #define SJIS_TEST_DEST_SIZE 24 @@ -347,7 +336,6 @@ U+FF11 U+FF12 U+FF13 U+FF21 U+FF22 U+FF23 return NS_OK; } -#endif nsresult run() { nsresult res; @@ -355,13 +343,8 @@ nsresult run() res = testCharsetConverterManager(); if (NS_FAILED(res)) return res; - res = testAsciiDecoder(); - -#ifdef TEST_SJIS - if (NS_FAILED(res)) return res; - + res = testLatin1Decoder(); res = testSJISDecoder(); -#endif return NS_OK; } diff --git a/intl/uconv/ucvja/makefile.win b/intl/uconv/ucvja/makefile.win index adde2480147..3637debf0b3 100644 --- a/intl/uconv/ucvja/makefile.win +++ b/intl/uconv/ucvja/makefile.win @@ -43,7 +43,6 @@ OBJS = \ $(NULL) EXPORTS= \ - nsUCVJACID.h \ $(NULL) LINCS= \ diff --git a/intl/uconv/ucvja/nsSJIS2Unicode.cpp b/intl/uconv/ucvja/nsSJIS2Unicode.cpp index cf06f2ec1f1..ef3b6fa5e78 100644 --- a/intl/uconv/ucvja/nsSJIS2Unicode.cpp +++ b/intl/uconv/ucvja/nsSJIS2Unicode.cpp @@ -81,6 +81,7 @@ public: NS_IMETHOD SetInputErrorBehavior(PRInt32 aBehavior); private: + PRInt32 mBehavior; nsIUnicodeDecodeUtil *mUtil; }; @@ -108,6 +109,7 @@ nsSJIS2Unicode::nsSJIS2Unicode() NS_INIT_REFCNT(); PR_AtomicIncrement(&g_InstanceCount); mUtil = nsnull; + mBehavior = kOnError_Recover; } nsSJIS2Unicode::~nsSJIS2Unicode() @@ -142,8 +144,9 @@ NS_IMETHODIMP nsSJIS2Unicode::Convert(PRUnichar * aDest, PRInt32 aDestOffset, return res; } } - return mUtil->ConvertBy1Table( aDest, aDestOffset, aDestLength, + return mUtil->Convert( aDest, aDestOffset, aDestLength, aSrc, aSrcOffset, aSrcLength, + mBehavior, (uShiftTable*) &gShiftTable, (uMappingTable*)&gMappingTable); } @@ -161,7 +164,7 @@ NS_IMETHODIMP nsSJIS2Unicode::Length(const char * aSrc, PRInt32 aSrcOffset, PRInt32 * aDestLength) { *aDestLength = aSrcLength; - return NS_EXACT_LENGTH; + return NS_OK; } NS_IMETHODIMP nsSJIS2Unicode::Reset() @@ -171,7 +174,7 @@ NS_IMETHODIMP nsSJIS2Unicode::Reset() NS_IMETHODIMP nsSJIS2Unicode::SetInputErrorBehavior(PRInt32 aBehavior) { - // no input error possible, this encoding is too simple + mBehavior = aBehavior; return NS_OK; } @@ -257,14 +260,14 @@ NS_IMETHODIMP nsSJIS2UnicodeFactory::LockFactory(PRBool aLock) //---------------------------------------------------------------------- // Interface nsICharsetConverterInfo [implementation] -NS_IMETHODIMP nsSJIS2UnicodeFactory::GetCharsetSrc(nsString ** aCharset) +NS_IMETHODIMP nsSJIS2UnicodeFactory::GetCharsetSrc(char ** aCharset) { - (*aCharset) = new nsString(NS_SRC_CHARSET); + (*aCharset) = NS_SRC_CHARSET; return NS_OK; } -NS_IMETHODIMP nsSJIS2UnicodeFactory::GetCharsetDest(nsString ** aCharset) +NS_IMETHODIMP nsSJIS2UnicodeFactory::GetCharsetDest(char ** aCharset) { - (*aCharset) = new nsString(NS_DEST_CHARSET); + (*aCharset) = NS_DEST_CHARSET; return NS_OK; } diff --git a/intl/uconv/ucvja/nsSJIS2Unicode.h b/intl/uconv/ucvja/nsSJIS2Unicode.h index 78d6db9def8..f78bedbed8f 100644 --- a/intl/uconv/ucvja/nsSJIS2Unicode.h +++ b/intl/uconv/ucvja/nsSJIS2Unicode.h @@ -57,8 +57,8 @@ public: //-------------------------------------------------------------------- // Interface nsICharsetConverterInfo [declaration] - NS_IMETHOD GetCharsetSrc(nsString ** aCharset); - NS_IMETHOD GetCharsetDest(nsString ** aCharset); + NS_IMETHOD GetCharsetSrc(char ** aCharset); + NS_IMETHOD GetCharsetDest(char ** aCharset); };