diff --git a/mozilla/intl/uconv/src/nsUnicodeEncodeHelper.cpp b/mozilla/intl/uconv/src/nsUnicodeEncodeHelper.cpp index f1bbf4f5cab..e78fccf126a 100644 --- a/mozilla/intl/uconv/src/nsUnicodeEncodeHelper.cpp +++ b/mozilla/intl/uconv/src/nsUnicodeEncodeHelper.cpp @@ -65,6 +65,9 @@ public: NS_IMETHOD CreateCache(nsMappingCacheType aType, nsIMappingCache* aResult); NS_IMETHOD DestroyCache(nsIMappingCache aCache); + + NS_IMETHOD FillInfo(PRUint32* aInfo, uMappingTable * aMappingTable); + NS_IMETHOD FillInfo(PRUint32* aInfo, PRInt32 aTableCount, uMappingTable ** aMappingTable); }; //---------------------------------------------------------------------- @@ -180,6 +183,18 @@ NS_IMETHODIMP nsUnicodeEncodeHelper::DestroyCache(nsIMappingCache aCache) { return nsMappingCache::DestroyCache(aCache); } + +NS_IMETHODIMP nsUnicodeEncodeHelper::FillInfo(PRUint32 *aInfo, uMappingTable * aMappingTable) +{ + uFillInfo((uTable*) aMappingTable, aInfo); + return NS_OK; +} +NS_IMETHODIMP nsUnicodeEncodeHelper::FillInfo(PRUint32 *aInfo, PRInt32 aTableCount, uMappingTable ** aMappingTable) +{ + for (PRInt32 i=0; ioffsetToMapCellArray) + (item)) #define uGetFormat(uT, item) (((((PRUint16 *)uT) + (uT)->offsetToFormatArray)[(item)>> 2 ] >> (((item)% 4 ) << 2)) & 0x0f) /*================================================================================= =================================================================================*/ -MODULE_PRIVATE PRBool uMapCode(uTable *uT, PRUint16 in, PRUint16* out) +MODULE_PRIVATE void uFillInfo(const uTable *uT, PRUint32* aInfo) +{ + PRUint16 itemOfList = uT->itemOfList; + PRUint16 i; + for(i=0;iitemOfList; @@ -98,13 +127,6 @@ PRIVATE PRBool uHitFormate0(PRUint16 in,const uMapCell *cell) } /*================================================================================= -=================================================================================*/ -PRIVATE PRBool uHitFormate1(PRUint16 in,const uMapCell *cell) -{ - return uHitFormate0(in,cell); -} -/*================================================================================= - =================================================================================*/ PRIVATE PRBool uHitFormate2(PRUint16 in,const uMapCell *cell) { @@ -133,3 +155,49 @@ PRIVATE PRUint16 uMapFormate2(PRUint16 in,const uTable *uT,const uMapCell *cell) return (cell->fmt.format2.destBegin); } +#define SET_REPRESENTABLE(info, c) (info)[(c) >> 5] |= (1L << ((c) & 0x1f)) +/*================================================================================= + +=================================================================================*/ +PRIVATE void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,PRUint32* info) +{ + PRUint16 begin, end, i; + begin = cell->fmt.format0.srcBegin; + end = cell->fmt.format0.srcEnd; + if( (begin >> 5) == (end >> 5)) // High 17 bits are the same + { + for(i = begin; i <= end; i++) + SET_REPRESENTABLE(info, i); + } else { + PRUint32 b = begin >> 5; + PRUint32 e = end >> 5; + info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f)); + info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f))); + for(b++ ; b < e ; b++) + info[b] |= 0xFFFFFFFFL; + } +} +/*================================================================================= + +=================================================================================*/ +PRIVATE void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,PRUint32* info) +{ + PRUint16 begin, end, i; + PRUint16 *base; + begin = cell->fmt.format0.srcBegin; + end = cell->fmt.format0.srcEnd; + base = (((PRUint16 *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset); + for(i = begin; i <= end; i++) + { + if(0xFFFD != base[i - begin]) /* check every item */ + SET_REPRESENTABLE(info, i); + } +} +/*================================================================================= + +=================================================================================*/ +PRIVATE void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,PRUint32* info) +{ + SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin); +} + diff --git a/mozilla/intl/uconv/src/unicpriv.h b/mozilla/intl/uconv/src/unicpriv.h index 483db63bb62..6d9926dd4a4 100644 --- a/mozilla/intl/uconv/src/unicpriv.h +++ b/mozilla/intl/uconv/src/unicpriv.h @@ -26,7 +26,10 @@ extern "C" { #endif -PRBool uMapCode( uTable *uT, +void uFillInfo(const uTable *uT, + PRUint32 *info); + +PRBool uMapCode(const uTable *uT, PRUint16 in, PRUint16* out); diff --git a/mozilla/intl/uconv/ucvcn/nsUCvCnSupport.cpp b/mozilla/intl/uconv/ucvcn/nsUCvCnSupport.cpp index b7204197c01..669bb9643fc 100644 --- a/mozilla/intl/uconv/ucvcn/nsUCvCnSupport.cpp +++ b/mozilla/intl/uconv/ucvcn/nsUCvCnSupport.cpp @@ -19,8 +19,9 @@ #include "pratom.h" #include "nsIComponentManager.h" +#include "nsICharRepresentable.h" #include "nsUCvCnSupport.h" -#include "nsUCvCnDll.h" +#include "nsUCVCnDll.h" #define DEFAULT_BUFFER_CAPACITY 16 @@ -492,8 +493,13 @@ nsresult nsEncoderSupport::QueryInterface(REFNSIID aIID, NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsICharRepresentable::GetIID())) { + *aInstancePtr = (void*) ((nsICharRepresentable*)this); + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) ((nsISupports*)this); + *aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)this)); NS_ADDREF_THIS(); return NS_OK; } @@ -630,6 +636,20 @@ nsTableEncoderSupport::~nsTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] @@ -673,6 +693,20 @@ nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsMultiTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo,mTableCount, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] diff --git a/mozilla/intl/uconv/ucvcn/nsUCvCnSupport.h b/mozilla/intl/uconv/ucvcn/nsUCvCnSupport.h index 2894f2ae952..2d59883e336 100644 --- a/mozilla/intl/uconv/ucvcn/nsUCvCnSupport.h +++ b/mozilla/intl/uconv/ucvcn/nsUCvCnSupport.h @@ -24,6 +24,7 @@ #include "nsIUnicodeDecoder.h" #include "nsIUnicodeEncodeHelper.h" #include "nsIUnicodeDecodeHelper.h" +#include "nsICharRepresentable.h" #define ONE_BYTE_TABLE_SIZE 256 @@ -264,7 +265,7 @@ protected: * @created 17/Feb/1999 * @author Catalin Rotaru [CATA] */ -class nsEncoderSupport : public nsIUnicodeEncoder +class nsEncoderSupport : public nsIUnicodeEncoder, public nsICharRepresentable { NS_DECL_ISUPPORTS @@ -330,6 +331,10 @@ public: NS_IMETHOD Reset(); NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, nsIUnicharEncoder * aEncoder, PRUnichar aChar); + + //-------------------------------------------------------------------- + // Interface nsICharRepresentable [declaration] + NS_IMETHOD FillInfo(PRUint32 *aInfo) = 0; }; //---------------------------------------------------------------------- @@ -355,6 +360,7 @@ public: * Class destructor. */ virtual ~nsTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: @@ -392,6 +398,7 @@ public: * Class destructor. */ virtual ~nsMultiTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: diff --git a/mozilla/intl/uconv/ucvcn/nsUnicodeToGB2312.cpp b/mozilla/intl/uconv/ucvcn/nsUnicodeToGB2312.cpp index 9ad368116d8..1d901d7ad0c 100644 --- a/mozilla/intl/uconv/ucvcn/nsUnicodeToGB2312.cpp +++ b/mozilla/intl/uconv/ucvcn/nsUnicodeToGB2312.cpp @@ -43,8 +43,12 @@ nsUnicodeToGB2312::nsUnicodeToGB2312() nsresult nsUnicodeToGB2312::CreateInstance(nsISupports ** aResult) { - *aResult = new nsUnicodeToGB2312(); - return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK; + nsIUnicodeEncoder *p = new nsUnicodeToGB2312(); + if(p) { + *aResult = p; + return NS_OK; + } + return NS_ERROR_OUT_OF_MEMORY; } //---------------------------------------------------------------------- diff --git a/mozilla/intl/uconv/ucvja/nsUCvJaSupport.cpp b/mozilla/intl/uconv/ucvja/nsUCvJaSupport.cpp index f0511f7465a..c555b0e7caa 100644 --- a/mozilla/intl/uconv/ucvja/nsUCvJaSupport.cpp +++ b/mozilla/intl/uconv/ucvja/nsUCvJaSupport.cpp @@ -19,6 +19,7 @@ #include "pratom.h" #include "nsIComponentManager.h" +#include "nsICharRepresentable.h" #include "nsUCvJaSupport.h" #include "nsUCVJADll.h" @@ -492,8 +493,13 @@ nsresult nsEncoderSupport::QueryInterface(REFNSIID aIID, NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsICharRepresentable::GetIID())) { + *aInstancePtr = (void*) ((nsICharRepresentable*)this); + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) ((nsISupports*)this); + *aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)this)); NS_ADDREF_THIS(); return NS_OK; } @@ -630,6 +636,20 @@ nsTableEncoderSupport::~nsTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] @@ -673,6 +693,20 @@ nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsMultiTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo,mTableCount, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] diff --git a/mozilla/intl/uconv/ucvja/nsUCvJaSupport.h b/mozilla/intl/uconv/ucvja/nsUCvJaSupport.h index 883814462ab..db0c8e312bd 100644 --- a/mozilla/intl/uconv/ucvja/nsUCvJaSupport.h +++ b/mozilla/intl/uconv/ucvja/nsUCvJaSupport.h @@ -24,6 +24,7 @@ #include "nsIUnicodeDecoder.h" #include "nsIUnicodeEncodeHelper.h" #include "nsIUnicodeDecodeHelper.h" +#include "nsICharRepresentable.h" #define ONE_BYTE_TABLE_SIZE 256 @@ -264,7 +265,7 @@ protected: * @created 17/Feb/1999 * @author Catalin Rotaru [CATA] */ -class nsEncoderSupport : public nsIUnicodeEncoder +class nsEncoderSupport : public nsIUnicodeEncoder, public nsICharRepresentable { NS_DECL_ISUPPORTS @@ -330,6 +331,10 @@ public: NS_IMETHOD Reset(); NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, nsIUnicharEncoder * aEncoder, PRUnichar aChar); + + //-------------------------------------------------------------------- + // Interface nsICharRepresentable [declaration] + NS_IMETHOD FillInfo(PRUint32 *aInfo) = 0; }; //---------------------------------------------------------------------- @@ -355,6 +360,7 @@ public: * Class destructor. */ virtual ~nsTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: @@ -392,6 +398,7 @@ public: * Class destructor. */ virtual ~nsMultiTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: diff --git a/mozilla/intl/uconv/ucvja/nsUnicodeToSJIS.cpp b/mozilla/intl/uconv/ucvja/nsUnicodeToSJIS.cpp index 3dddf05c911..cc059f7606d 100644 --- a/mozilla/intl/uconv/ucvja/nsUnicodeToSJIS.cpp +++ b/mozilla/intl/uconv/ucvja/nsUnicodeToSJIS.cpp @@ -45,8 +45,12 @@ nsUnicodeToSJIS::nsUnicodeToSJIS() nsresult nsUnicodeToSJIS::CreateInstance(nsISupports ** aResult) { - *aResult = new nsUnicodeToSJIS(); - return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK; + nsIUnicodeEncoder *p = new nsUnicodeToSJIS(); + if(p) { + *aResult = p; + return NS_OK; + } + return NS_ERROR_OUT_OF_MEMORY; } //---------------------------------------------------------------------- diff --git a/mozilla/intl/uconv/ucvja2/nsUCvJa2Support.cpp b/mozilla/intl/uconv/ucvja2/nsUCvJa2Support.cpp index 34eb09b010c..8dcc5101715 100644 --- a/mozilla/intl/uconv/ucvja2/nsUCvJa2Support.cpp +++ b/mozilla/intl/uconv/ucvja2/nsUCvJa2Support.cpp @@ -19,6 +19,7 @@ #include "pratom.h" #include "nsIComponentManager.h" +#include "nsICharRepresentable.h" #include "nsUCvJa2Support.h" #include "nsUCVJA2Dll.h" @@ -492,8 +493,13 @@ nsresult nsEncoderSupport::QueryInterface(REFNSIID aIID, NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsICharRepresentable::GetIID())) { + *aInstancePtr = (void*) ((nsICharRepresentable*)this); + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) ((nsISupports*)this); + *aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)this)); NS_ADDREF_THIS(); return NS_OK; } @@ -630,6 +636,20 @@ nsTableEncoderSupport::~nsTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] @@ -673,6 +693,20 @@ nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsMultiTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo,mTableCount, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] diff --git a/mozilla/intl/uconv/ucvja2/nsUCvJa2Support.h b/mozilla/intl/uconv/ucvja2/nsUCvJa2Support.h index 5ffe67ccf63..d424c2e90ab 100644 --- a/mozilla/intl/uconv/ucvja2/nsUCvJa2Support.h +++ b/mozilla/intl/uconv/ucvja2/nsUCvJa2Support.h @@ -24,6 +24,7 @@ #include "nsIUnicodeDecoder.h" #include "nsIUnicodeEncodeHelper.h" #include "nsIUnicodeDecodeHelper.h" +#include "nsICharRepresentable.h" #define ONE_BYTE_TABLE_SIZE 256 @@ -264,7 +265,7 @@ protected: * @created 17/Feb/1999 * @author Catalin Rotaru [CATA] */ -class nsEncoderSupport : public nsIUnicodeEncoder +class nsEncoderSupport : public nsIUnicodeEncoder, public nsICharRepresentable { NS_DECL_ISUPPORTS @@ -330,6 +331,10 @@ public: NS_IMETHOD Reset(); NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, nsIUnicharEncoder * aEncoder, PRUnichar aChar); + + //-------------------------------------------------------------------- + // Interface nsICharRepresentable [declaration] + NS_IMETHOD FillInfo(PRUint32 *aInfo) = 0; }; //---------------------------------------------------------------------- @@ -355,6 +360,7 @@ public: * Class destructor. */ virtual ~nsTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: @@ -392,6 +398,7 @@ public: * Class destructor. */ virtual ~nsMultiTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: diff --git a/mozilla/intl/uconv/ucvja2/nsUnicodeToEUCJP.cpp b/mozilla/intl/uconv/ucvja2/nsUnicodeToEUCJP.cpp index c4d0d7db78f..2c839a10609 100644 --- a/mozilla/intl/uconv/ucvja2/nsUnicodeToEUCJP.cpp +++ b/mozilla/intl/uconv/ucvja2/nsUnicodeToEUCJP.cpp @@ -64,8 +64,12 @@ nsUnicodeToEUCJP::nsUnicodeToEUCJP() nsresult nsUnicodeToEUCJP::CreateInstance(nsISupports ** aResult) { - *aResult = new nsUnicodeToEUCJP(); - return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK; + nsIUnicodeEncoder *p = new nsUnicodeToEUCJP(); + if(p) { + *aResult = p; + return NS_OK; + } + return NS_ERROR_OUT_OF_MEMORY; } //---------------------------------------------------------------------- diff --git a/mozilla/intl/uconv/ucvja2/nsUnicodeToISO2022JP.cpp b/mozilla/intl/uconv/ucvja2/nsUnicodeToISO2022JP.cpp index a130ca5e7ab..188bf88afed 100644 --- a/mozilla/intl/uconv/ucvja2/nsUnicodeToISO2022JP.cpp +++ b/mozilla/intl/uconv/ucvja2/nsUnicodeToISO2022JP.cpp @@ -75,8 +75,12 @@ nsUnicodeToISO2022JP::~nsUnicodeToISO2022JP() nsresult nsUnicodeToISO2022JP::CreateInstance(nsISupports ** aResult) { - *aResult = new nsUnicodeToISO2022JP(); - return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK; + nsIUnicodeEncoder *p = new nsUnicodeToISO2022JP(); + if(p) { + *aResult = p; + return NS_OK; + } + return NS_ERROR_OUT_OF_MEMORY; } nsresult nsUnicodeToISO2022JP::ChangeCharset(PRInt32 aCharset, @@ -124,6 +128,19 @@ nsresult nsUnicodeToISO2022JP::ChangeCharset(PRInt32 aCharset, //---------------------------------------------------------------------- // Subclassing of nsTableEncoderSupport class [implementation] +NS_IMETHODIMP nsUnicodeToISO2022JP::FillInfo(PRUint32* aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + return mHelper->FillInfo(aInfo, 4, (uMappingTable **) g_ufMappingTables); + +} NS_IMETHODIMP nsUnicodeToISO2022JP::ConvertNoBuffNoErr( const PRUnichar * aSrc, PRInt32 * aSrcLength, diff --git a/mozilla/intl/uconv/ucvja2/nsUnicodeToISO2022JP.h b/mozilla/intl/uconv/ucvja2/nsUnicodeToISO2022JP.h index 974a5aaa11d..4259b92722e 100644 --- a/mozilla/intl/uconv/ucvja2/nsUnicodeToISO2022JP.h +++ b/mozilla/intl/uconv/ucvja2/nsUnicodeToISO2022JP.h @@ -67,6 +67,7 @@ protected: NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength, PRInt32 * aDestLength); NS_IMETHOD Reset(); + NS_IMETHOD FillInfo(PRUint32 *aInfo); }; #endif /* nsUnicodeToISO2022JP_h___ */ diff --git a/mozilla/intl/uconv/ucvko/nsUCvKOSupport.cpp b/mozilla/intl/uconv/ucvko/nsUCvKOSupport.cpp index 7d167d4cb32..059f44e0aac 100644 --- a/mozilla/intl/uconv/ucvko/nsUCvKOSupport.cpp +++ b/mozilla/intl/uconv/ucvko/nsUCvKOSupport.cpp @@ -19,8 +19,9 @@ #include "pratom.h" #include "nsIComponentManager.h" +#include "nsICharRepresentable.h" #include "nsUCvKOSupport.h" -#include "nsUCvKODll.h" +#include "nsUCVKODll.h" #define DEFAULT_BUFFER_CAPACITY 16 @@ -492,8 +493,13 @@ nsresult nsEncoderSupport::QueryInterface(REFNSIID aIID, NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsICharRepresentable::GetIID())) { + *aInstancePtr = (void*) ((nsICharRepresentable*)this); + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) ((nsISupports*)this); + *aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)this)); NS_ADDREF_THIS(); return NS_OK; } @@ -630,6 +636,20 @@ nsTableEncoderSupport::~nsTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] @@ -673,6 +693,20 @@ nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsMultiTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo,mTableCount, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] diff --git a/mozilla/intl/uconv/ucvko/nsUCvKOSupport.h b/mozilla/intl/uconv/ucvko/nsUCvKOSupport.h index 6f9a8d72dec..ba5b746c8e0 100644 --- a/mozilla/intl/uconv/ucvko/nsUCvKOSupport.h +++ b/mozilla/intl/uconv/ucvko/nsUCvKOSupport.h @@ -24,6 +24,7 @@ #include "nsIUnicodeDecoder.h" #include "nsIUnicodeEncodeHelper.h" #include "nsIUnicodeDecodeHelper.h" +#include "nsICharRepresentable.h" #define ONE_BYTE_TABLE_SIZE 256 @@ -264,7 +265,7 @@ protected: * @created 17/Feb/1999 * @author Catalin Rotaru [CATA] */ -class nsEncoderSupport : public nsIUnicodeEncoder +class nsEncoderSupport : public nsIUnicodeEncoder, public nsICharRepresentable { NS_DECL_ISUPPORTS @@ -330,6 +331,10 @@ public: NS_IMETHOD Reset(); NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, nsIUnicharEncoder * aEncoder, PRUnichar aChar); + + //-------------------------------------------------------------------- + // Interface nsICharRepresentable [declaration] + NS_IMETHOD FillInfo(PRUint32 *aInfo) = 0; }; //---------------------------------------------------------------------- @@ -355,6 +360,7 @@ public: * Class destructor. */ virtual ~nsTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: @@ -392,6 +398,7 @@ public: * Class destructor. */ virtual ~nsMultiTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: diff --git a/mozilla/intl/uconv/ucvko/nsUnicodeToEUCKR.cpp b/mozilla/intl/uconv/ucvko/nsUnicodeToEUCKR.cpp index b498b45a2c9..d66a5cc54c1 100644 --- a/mozilla/intl/uconv/ucvko/nsUnicodeToEUCKR.cpp +++ b/mozilla/intl/uconv/ucvko/nsUnicodeToEUCKR.cpp @@ -43,8 +43,12 @@ nsUnicodeToEUCKR::nsUnicodeToEUCKR() nsresult nsUnicodeToEUCKR::CreateInstance(nsISupports ** aResult) { - *aResult = new nsUnicodeToEUCKR(); - return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK; + nsIUnicodeEncoder *p = new nsUnicodeToEUCKR(); + if(p) { + *aResult = p; + return NS_OK; + } + return NS_ERROR_OUT_OF_MEMORY; } //---------------------------------------------------------------------- diff --git a/mozilla/intl/uconv/ucvtw/nsUCvTWSupport.cpp b/mozilla/intl/uconv/ucvtw/nsUCvTWSupport.cpp index 61719f1c23e..52ca8718b75 100644 --- a/mozilla/intl/uconv/ucvtw/nsUCvTWSupport.cpp +++ b/mozilla/intl/uconv/ucvtw/nsUCvTWSupport.cpp @@ -19,8 +19,9 @@ #include "pratom.h" #include "nsIComponentManager.h" +#include "nsICharRepresentable.h" #include "nsUCvTWSupport.h" -#include "nsUCvTWDll.h" +#include "nsUCVTWDll.h" #define DEFAULT_BUFFER_CAPACITY 16 @@ -492,8 +493,13 @@ nsresult nsEncoderSupport::QueryInterface(REFNSIID aIID, NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsICharRepresentable::GetIID())) { + *aInstancePtr = (void*) ((nsICharRepresentable*)this); + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) ((nsISupports*)this); + *aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)this)); NS_ADDREF_THIS(); return NS_OK; } @@ -630,6 +636,20 @@ nsTableEncoderSupport::~nsTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] @@ -673,6 +693,20 @@ nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsMultiTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo,mTableCount, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] diff --git a/mozilla/intl/uconv/ucvtw/nsUCvTWSupport.h b/mozilla/intl/uconv/ucvtw/nsUCvTWSupport.h index 2bd0420461c..918a230212e 100644 --- a/mozilla/intl/uconv/ucvtw/nsUCvTWSupport.h +++ b/mozilla/intl/uconv/ucvtw/nsUCvTWSupport.h @@ -24,6 +24,7 @@ #include "nsIUnicodeDecoder.h" #include "nsIUnicodeEncodeHelper.h" #include "nsIUnicodeDecodeHelper.h" +#include "nsICharRepresentable.h" #define ONE_BYTE_TABLE_SIZE 256 @@ -264,7 +265,7 @@ protected: * @created 17/Feb/1999 * @author Catalin Rotaru [CATA] */ -class nsEncoderSupport : public nsIUnicodeEncoder +class nsEncoderSupport : public nsIUnicodeEncoder, public nsICharRepresentable { NS_DECL_ISUPPORTS @@ -330,6 +331,10 @@ public: NS_IMETHOD Reset(); NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, nsIUnicharEncoder * aEncoder, PRUnichar aChar); + + //-------------------------------------------------------------------- + // Interface nsICharRepresentable [declaration] + NS_IMETHOD FillInfo(PRUint32 *aInfo) = 0; }; //---------------------------------------------------------------------- @@ -355,6 +360,7 @@ public: * Class destructor. */ virtual ~nsTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: @@ -392,6 +398,7 @@ public: * Class destructor. */ virtual ~nsMultiTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: diff --git a/mozilla/intl/uconv/ucvtw/nsUnicodeToBIG5.cpp b/mozilla/intl/uconv/ucvtw/nsUnicodeToBIG5.cpp index 46401e2e33c..ffa59b009c3 100644 --- a/mozilla/intl/uconv/ucvtw/nsUnicodeToBIG5.cpp +++ b/mozilla/intl/uconv/ucvtw/nsUnicodeToBIG5.cpp @@ -43,8 +43,12 @@ nsUnicodeToBIG5::nsUnicodeToBIG5() nsresult nsUnicodeToBIG5::CreateInstance(nsISupports ** aResult) { - *aResult = new nsUnicodeToBIG5(); - return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK; + nsIUnicodeEncoder *p = new nsUnicodeToBIG5(); + if(p) { + *aResult = p; + return NS_OK; + } + return NS_ERROR_OUT_OF_MEMORY; } //---------------------------------------------------------------------- diff --git a/mozilla/intl/uconv/ucvtw2/nsUCvTW2Support.cpp b/mozilla/intl/uconv/ucvtw2/nsUCvTW2Support.cpp index 2874a73efb8..c7cfc4821e3 100644 --- a/mozilla/intl/uconv/ucvtw2/nsUCvTW2Support.cpp +++ b/mozilla/intl/uconv/ucvtw2/nsUCvTW2Support.cpp @@ -19,8 +19,9 @@ #include "pratom.h" #include "nsIComponentManager.h" +#include "nsICharRepresentable.h" #include "nsUCvTW2Support.h" -#include "nsUCvTW2Dll.h" +#include "nsUCVTW2Dll.h" #define DEFAULT_BUFFER_CAPACITY 16 @@ -492,8 +493,13 @@ nsresult nsEncoderSupport::QueryInterface(REFNSIID aIID, NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(nsICharRepresentable::GetIID())) { + *aInstancePtr = (void*) ((nsICharRepresentable*)this); + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) ((nsISupports*)this); + *aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)this)); NS_ADDREF_THIS(); return NS_OK; } @@ -630,6 +636,20 @@ nsTableEncoderSupport::~nsTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] @@ -673,6 +693,20 @@ nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport() NS_IF_RELEASE(mHelper); } +NS_IMETHODIMP nsMultiTableEncoderSupport::FillInfo(PRUint32 *aInfo) +{ + nsresult res; + + if (mHelper == nsnull) { + res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL, + kIUnicodeEncodeHelperIID, (void**) & mHelper); + + if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER; + } + + res = mHelper->FillInfo(aInfo,mTableCount, mMappingTable); + return res; +} //---------------------------------------------------------------------- // Subclassing of nsEncoderSupport class [implementation] diff --git a/mozilla/intl/uconv/ucvtw2/nsUCvTW2Support.h b/mozilla/intl/uconv/ucvtw2/nsUCvTW2Support.h index 11134344fbc..e3c2d30a69c 100644 --- a/mozilla/intl/uconv/ucvtw2/nsUCvTW2Support.h +++ b/mozilla/intl/uconv/ucvtw2/nsUCvTW2Support.h @@ -24,6 +24,7 @@ #include "nsIUnicodeDecoder.h" #include "nsIUnicodeEncodeHelper.h" #include "nsIUnicodeDecodeHelper.h" +#include "nsICharRepresentable.h" #define ONE_BYTE_TABLE_SIZE 256 @@ -264,7 +265,7 @@ protected: * @created 17/Feb/1999 * @author Catalin Rotaru [CATA] */ -class nsEncoderSupport : public nsIUnicodeEncoder +class nsEncoderSupport : public nsIUnicodeEncoder, public nsICharRepresentable { NS_DECL_ISUPPORTS @@ -330,6 +331,10 @@ public: NS_IMETHOD Reset(); NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, nsIUnicharEncoder * aEncoder, PRUnichar aChar); + + //-------------------------------------------------------------------- + // Interface nsICharRepresentable [declaration] + NS_IMETHOD FillInfo(PRUint32 *aInfo) = 0; }; //---------------------------------------------------------------------- @@ -355,6 +360,7 @@ public: * Class destructor. */ virtual ~nsTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: @@ -392,6 +398,7 @@ public: * Class destructor. */ virtual ~nsMultiTableEncoderSupport(); + NS_IMETHOD FillInfo( PRUint32 *aInfo); protected: diff --git a/mozilla/intl/uconv/ucvtw2/nsUnicodeToEUCTW.cpp b/mozilla/intl/uconv/ucvtw2/nsUnicodeToEUCTW.cpp index 8cf63d5b1ec..bb3f4786115 100644 --- a/mozilla/intl/uconv/ucvtw2/nsUnicodeToEUCTW.cpp +++ b/mozilla/intl/uconv/ucvtw2/nsUnicodeToEUCTW.cpp @@ -43,8 +43,12 @@ nsUnicodeToEUCTW::nsUnicodeToEUCTW() nsresult nsUnicodeToEUCTW::CreateInstance(nsISupports ** aResult) { - *aResult = new nsUnicodeToEUCTW(); - return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK; + nsIUnicodeEncoder *p = new nsUnicodeToEUCTW(); + if(p) { + *aResult = p; + return NS_OK; + } + return NS_ERROR_OUT_OF_MEMORY; } //---------------------------------------------------------------------- diff --git a/mozilla/intl/uconv/util/nsUnicodeEncodeHelper.cpp b/mozilla/intl/uconv/util/nsUnicodeEncodeHelper.cpp index f1bbf4f5cab..e78fccf126a 100644 --- a/mozilla/intl/uconv/util/nsUnicodeEncodeHelper.cpp +++ b/mozilla/intl/uconv/util/nsUnicodeEncodeHelper.cpp @@ -65,6 +65,9 @@ public: NS_IMETHOD CreateCache(nsMappingCacheType aType, nsIMappingCache* aResult); NS_IMETHOD DestroyCache(nsIMappingCache aCache); + + NS_IMETHOD FillInfo(PRUint32* aInfo, uMappingTable * aMappingTable); + NS_IMETHOD FillInfo(PRUint32* aInfo, PRInt32 aTableCount, uMappingTable ** aMappingTable); }; //---------------------------------------------------------------------- @@ -180,6 +183,18 @@ NS_IMETHODIMP nsUnicodeEncodeHelper::DestroyCache(nsIMappingCache aCache) { return nsMappingCache::DestroyCache(aCache); } + +NS_IMETHODIMP nsUnicodeEncodeHelper::FillInfo(PRUint32 *aInfo, uMappingTable * aMappingTable) +{ + uFillInfo((uTable*) aMappingTable, aInfo); + return NS_OK; +} +NS_IMETHODIMP nsUnicodeEncodeHelper::FillInfo(PRUint32 *aInfo, PRInt32 aTableCount, uMappingTable ** aMappingTable) +{ + for (PRInt32 i=0; ioffsetToMapCellArray) + (item)) #define uGetFormat(uT, item) (((((PRUint16 *)uT) + (uT)->offsetToFormatArray)[(item)>> 2 ] >> (((item)% 4 ) << 2)) & 0x0f) /*================================================================================= =================================================================================*/ -MODULE_PRIVATE PRBool uMapCode(uTable *uT, PRUint16 in, PRUint16* out) +MODULE_PRIVATE void uFillInfo(const uTable *uT, PRUint32* aInfo) +{ + PRUint16 itemOfList = uT->itemOfList; + PRUint16 i; + for(i=0;iitemOfList; @@ -98,13 +127,6 @@ PRIVATE PRBool uHitFormate0(PRUint16 in,const uMapCell *cell) } /*================================================================================= -=================================================================================*/ -PRIVATE PRBool uHitFormate1(PRUint16 in,const uMapCell *cell) -{ - return uHitFormate0(in,cell); -} -/*================================================================================= - =================================================================================*/ PRIVATE PRBool uHitFormate2(PRUint16 in,const uMapCell *cell) { @@ -133,3 +155,49 @@ PRIVATE PRUint16 uMapFormate2(PRUint16 in,const uTable *uT,const uMapCell *cell) return (cell->fmt.format2.destBegin); } +#define SET_REPRESENTABLE(info, c) (info)[(c) >> 5] |= (1L << ((c) & 0x1f)) +/*================================================================================= + +=================================================================================*/ +PRIVATE void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,PRUint32* info) +{ + PRUint16 begin, end, i; + begin = cell->fmt.format0.srcBegin; + end = cell->fmt.format0.srcEnd; + if( (begin >> 5) == (end >> 5)) // High 17 bits are the same + { + for(i = begin; i <= end; i++) + SET_REPRESENTABLE(info, i); + } else { + PRUint32 b = begin >> 5; + PRUint32 e = end >> 5; + info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f)); + info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f))); + for(b++ ; b < e ; b++) + info[b] |= 0xFFFFFFFFL; + } +} +/*================================================================================= + +=================================================================================*/ +PRIVATE void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,PRUint32* info) +{ + PRUint16 begin, end, i; + PRUint16 *base; + begin = cell->fmt.format0.srcBegin; + end = cell->fmt.format0.srcEnd; + base = (((PRUint16 *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset); + for(i = begin; i <= end; i++) + { + if(0xFFFD != base[i - begin]) /* check every item */ + SET_REPRESENTABLE(info, i); + } +} +/*================================================================================= + +=================================================================================*/ +PRIVATE void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,PRUint32* info) +{ + SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin); +} + diff --git a/mozilla/intl/uconv/util/unicpriv.h b/mozilla/intl/uconv/util/unicpriv.h index 483db63bb62..6d9926dd4a4 100644 --- a/mozilla/intl/uconv/util/unicpriv.h +++ b/mozilla/intl/uconv/util/unicpriv.h @@ -26,7 +26,10 @@ extern "C" { #endif -PRBool uMapCode( uTable *uT, +void uFillInfo(const uTable *uT, + PRUint32 *info); + +PRBool uMapCode(const uTable *uT, PRUint16 in, PRUint16* out);