michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsUCvJaSupport_h___ michael@0: #define nsUCvJaSupport_h___ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIUnicodeEncoder.h" michael@0: #include "nsIUnicodeDecoder.h" michael@0: #include "uconvutil.h" michael@0: #include "mozilla/Mutex.h" michael@0: michael@0: #define ONE_BYTE_TABLE_SIZE 256 michael@0: michael@0: inline bool WillOverrun(char16_t* aDest, char16_t* aDestEnd, uint32_t aLength) michael@0: { michael@0: NS_ASSERTION(aDest <= aDestEnd, "Pointer overrun even before check"); michael@0: return (uint32_t(aDestEnd - aDest) < aLength); michael@0: } michael@0: #define CHECK_OVERRUN(dest, destEnd, length) (WillOverrun(dest, destEnd, length)) michael@0: michael@0: #ifdef DEBUG michael@0: // {7AFC9F0A-CFE1-44ea-A755-E3B86AB1226E} michael@0: #define NS_IBASICDECODER_IID \ michael@0: { 0x7afc9f0a, 0xcfe1, 0x44ea, { 0xa7, 0x55, 0xe3, 0xb8, 0x6a, 0xb1, 0x22, 0x6e } } michael@0: michael@0: // {65968A7B-6467-4c4a-B50A-3E0C97A32F07} michael@0: #define NS_IBASICENCODER_IID \ michael@0: { 0x65968a7b, 0x6467, 0x4c4a, { 0xb5, 0xa, 0x3e, 0xc, 0x97, 0xa3, 0x2f, 0x7 } } michael@0: michael@0: class nsIBasicDecoder : public nsISupports { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASICDECODER_IID) michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIBasicDecoder, NS_IBASICDECODER_IID) michael@0: michael@0: class nsIBasicEncoder : public nsISupports { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASICENCODER_IID) michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIBasicEncoder, NS_IBASICENCODER_IID) michael@0: michael@0: #endif michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Class nsBasicDecoderSupport [declaration] michael@0: michael@0: /** michael@0: * Support class for the Unicode decoders. michael@0: * michael@0: * The class source files for this class are in /ucvlatin/nsUCvJaSupport. michael@0: * However, because these objects requires non-xpcom subclassing, local copies michael@0: * will be made into the other directories using them. Just don't forget to michael@0: * keep in sync with the master copy! michael@0: * michael@0: * This class implements: michael@0: * - nsISupports michael@0: * - nsIUnicodeDecoder michael@0: * michael@0: * @created 19/Apr/1999 michael@0: * @author Catalin Rotaru [CATA] michael@0: */ michael@0: class nsBasicDecoderSupport : public nsIUnicodeDecoder michael@0: #ifdef DEBUG michael@0: ,public nsIBasicDecoder michael@0: #endif michael@0: { michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Class constructor. michael@0: */ michael@0: nsBasicDecoderSupport(); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsBasicDecoderSupport(); michael@0: michael@0: //-------------------------------------------------------------------- michael@0: // Interface nsIUnicodeDecoder [declaration] michael@0: michael@0: virtual void SetInputErrorBehavior(int32_t aBehavior); michael@0: virtual char16_t GetCharacterForUnMapped(); michael@0: michael@0: protected: michael@0: int32_t mErrBehavior; michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Class nsBufferDecoderSupport [declaration] michael@0: michael@0: /** michael@0: * Support class for the Unicode decoders. michael@0: * michael@0: * This class implements: michael@0: * - the buffer management michael@0: * michael@0: * @created 15/Mar/1999 michael@0: * @author Catalin Rotaru [CATA] michael@0: */ michael@0: class nsBufferDecoderSupport : public nsBasicDecoderSupport michael@0: { michael@0: protected: michael@0: michael@0: /** michael@0: * Internal buffer for partial conversions. michael@0: */ michael@0: char * mBuffer; michael@0: int32_t mBufferCapacity; michael@0: int32_t mBufferLength; michael@0: michael@0: uint32_t mMaxLengthFactor; michael@0: michael@0: /** michael@0: * Convert method but *without* the buffer management stuff. michael@0: */ michael@0: NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength) = 0; michael@0: michael@0: void FillBuffer(const char ** aSrc, int32_t aSrcLength); michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Class constructor. michael@0: */ michael@0: nsBufferDecoderSupport(uint32_t aMaxLengthFactor); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsBufferDecoderSupport(); michael@0: michael@0: //-------------------------------------------------------------------- michael@0: // Interface nsIUnicodeDecoder [declaration] michael@0: michael@0: NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength); michael@0: NS_IMETHOD Reset(); michael@0: NS_IMETHOD GetMaxLength(const char *aSrc, michael@0: int32_t aSrcLength, michael@0: int32_t* aDestLength); michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Class nsTableDecoderSupport [declaration] michael@0: michael@0: /** michael@0: * Support class for a single-table-driven Unicode decoder. michael@0: * michael@0: * @created 15/Mar/1999 michael@0: * @author Catalin Rotaru [CATA] michael@0: */ michael@0: class nsTableDecoderSupport : public nsBufferDecoderSupport michael@0: { michael@0: public: michael@0: michael@0: /** michael@0: * Class constructor. michael@0: */ michael@0: nsTableDecoderSupport(uScanClassID aScanClass, uShiftInTable * aShiftInTable, michael@0: uMappingTable * aMappingTable, uint32_t aMaxLengthFactor); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsTableDecoderSupport(); michael@0: michael@0: protected: michael@0: michael@0: uScanClassID mScanClass; michael@0: uShiftInTable * mShiftInTable; michael@0: uMappingTable * mMappingTable; michael@0: michael@0: //-------------------------------------------------------------------- michael@0: // Subclassing of nsBufferDecoderSupport class [declaration] michael@0: michael@0: NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength); michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Class nsMultiTableDecoderSupport [declaration] michael@0: michael@0: /** michael@0: * Support class for a multi-table-driven Unicode decoder. michael@0: * michael@0: * @created 24/Mar/1999 michael@0: * @author Catalin Rotaru [CATA] michael@0: */ michael@0: class nsMultiTableDecoderSupport : public nsBufferDecoderSupport michael@0: { michael@0: public: michael@0: michael@0: /** michael@0: * Class constructor. michael@0: */ michael@0: nsMultiTableDecoderSupport(int32_t aTableCount, const uRange * aRangeArray, michael@0: uScanClassID * aScanClassArray, michael@0: uMappingTable ** aMappingTable, michael@0: uint32_t aMaxLengthFactor); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsMultiTableDecoderSupport(); michael@0: michael@0: protected: michael@0: michael@0: int32_t mTableCount; michael@0: const uRange * mRangeArray; michael@0: uScanClassID * mScanClassArray; michael@0: uMappingTable ** mMappingTable; michael@0: michael@0: //-------------------------------------------------------------------- michael@0: // Subclassing of nsBufferDecoderSupport class [declaration] michael@0: michael@0: NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength); michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Class nsBufferDecoderSupport [declaration] michael@0: michael@0: /** michael@0: * Support class for a single-byte Unicode decoder. michael@0: * michael@0: * @created 19/Apr/1999 michael@0: * @author Catalin Rotaru [CATA] michael@0: */ michael@0: class nsOneByteDecoderSupport : public nsBasicDecoderSupport michael@0: { michael@0: public: michael@0: michael@0: /** michael@0: * Class constructor. michael@0: */ michael@0: nsOneByteDecoderSupport(uMappingTable * aMappingTable); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsOneByteDecoderSupport(); michael@0: michael@0: protected: michael@0: michael@0: uMappingTable * mMappingTable; michael@0: char16_t mFastTable[ONE_BYTE_TABLE_SIZE]; michael@0: bool mFastTableCreated; michael@0: mozilla::Mutex mFastTableMutex; michael@0: michael@0: //-------------------------------------------------------------------- michael@0: // Subclassing of nsBasicDecoderSupport class [declaration] michael@0: michael@0: NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, michael@0: char16_t * aDest, int32_t * aDestLength); michael@0: NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, michael@0: int32_t * aDestLength); michael@0: NS_IMETHOD Reset(); michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Class nsBasicEncoder [declaration] michael@0: michael@0: class nsBasicEncoder : public nsIUnicodeEncoder michael@0: #ifdef DEBUG michael@0: ,public nsIBasicEncoder michael@0: #endif michael@0: { michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: public: michael@0: /** michael@0: * Class constructor. michael@0: */ michael@0: nsBasicEncoder(); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsBasicEncoder(); michael@0: michael@0: }; michael@0: //---------------------------------------------------------------------- michael@0: // Class nsEncoderSupport [declaration] michael@0: michael@0: /** michael@0: * Support class for the Unicode encoders. michael@0: * michael@0: * This class implements: michael@0: * - nsISupports michael@0: * - the buffer management michael@0: * - error handling procedure(s) michael@0: * michael@0: * @created 17/Feb/1999 michael@0: * @author Catalin Rotaru [CATA] michael@0: */ michael@0: class nsEncoderSupport : public nsBasicEncoder michael@0: { michael@0: michael@0: protected: michael@0: michael@0: /** michael@0: * Internal buffer for partial conversions. michael@0: */ michael@0: char * mBuffer; michael@0: int32_t mBufferCapacity; michael@0: char * mBufferStart; michael@0: char * mBufferEnd; michael@0: michael@0: /** michael@0: * Error handling stuff michael@0: */ michael@0: int32_t mErrBehavior; michael@0: nsCOMPtr mErrEncoder; michael@0: char16_t mErrChar; michael@0: uint32_t mMaxLengthFactor; michael@0: michael@0: /** michael@0: * Convert method but *without* the buffer management stuff and *with* michael@0: * error handling stuff. michael@0: */ michael@0: NS_IMETHOD ConvertNoBuff(const char16_t * aSrc, int32_t * aSrcLength, michael@0: char * aDest, int32_t * aDestLength); michael@0: michael@0: /** michael@0: * Convert method but *without* the buffer management stuff and *without* michael@0: * error handling stuff. michael@0: */ michael@0: NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc, int32_t * aSrcLength, michael@0: char * aDest, int32_t * aDestLength) = 0; michael@0: michael@0: /** michael@0: * Finish method but *without* the buffer management stuff. michael@0: */ michael@0: NS_IMETHOD FinishNoBuff(char * aDest, int32_t * aDestLength); michael@0: michael@0: /** michael@0: * Copy as much as possible from the internal buffer to the destination. michael@0: */ michael@0: nsresult FlushBuffer(char ** aDest, const char * aDestEnd); michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Class constructor. michael@0: */ michael@0: nsEncoderSupport(uint32_t aMaxLengthFactor); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsEncoderSupport(); michael@0: michael@0: //-------------------------------------------------------------------- michael@0: // Interface nsIUnicodeEncoder [declaration] michael@0: michael@0: NS_IMETHOD Convert(const char16_t * aSrc, int32_t * aSrcLength, michael@0: char * aDest, int32_t * aDestLength); michael@0: NS_IMETHOD Finish(char * aDest, int32_t * aDestLength); michael@0: NS_IMETHOD Reset(); michael@0: NS_IMETHOD SetOutputErrorBehavior(int32_t aBehavior, michael@0: nsIUnicharEncoder * aEncoder, char16_t aChar); michael@0: NS_IMETHOD GetMaxLength(const char16_t * aSrc, michael@0: int32_t aSrcLength, michael@0: int32_t * aDestLength); michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Class nsTableEncoderSupport [declaration] michael@0: michael@0: /** michael@0: * Support class for a single-table-driven Unicode encoder. michael@0: * michael@0: * @created 17/Feb/1999 michael@0: * @author Catalin Rotaru [CATA] michael@0: */ michael@0: class nsTableEncoderSupport : public nsEncoderSupport michael@0: { michael@0: public: michael@0: michael@0: /** michael@0: * Class constructors. michael@0: */ michael@0: nsTableEncoderSupport(uScanClassID aScanClass, michael@0: uShiftOutTable * aShiftOutTable, michael@0: uMappingTable * aMappingTable, michael@0: uint32_t aMaxLengthFactor); michael@0: michael@0: nsTableEncoderSupport(uScanClassID aScanClass, michael@0: uMappingTable * aMappingTable, michael@0: uint32_t aMaxLengthFactor); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsTableEncoderSupport(); michael@0: michael@0: protected: michael@0: michael@0: uScanClassID mScanClass; michael@0: uShiftOutTable * mShiftOutTable; michael@0: uMappingTable * mMappingTable; michael@0: michael@0: //-------------------------------------------------------------------- michael@0: // Subclassing of nsEncoderSupport class [declaration] michael@0: michael@0: NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc, int32_t * aSrcLength, michael@0: char * aDest, int32_t * aDestLength); michael@0: }; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Class nsMultiTableEncoderSupport [declaration] michael@0: michael@0: /** michael@0: * Support class for a multi-table-driven Unicode encoder. michael@0: * michael@0: * @created 11/Mar/1999 michael@0: * @author Catalin Rotaru [CATA] michael@0: */ michael@0: class nsMultiTableEncoderSupport : public nsEncoderSupport michael@0: { michael@0: public: michael@0: michael@0: /** michael@0: * Class constructor. michael@0: */ michael@0: nsMultiTableEncoderSupport(int32_t aTableCount, michael@0: uScanClassID * aScanClassArray, michael@0: uShiftOutTable ** aShiftOutTable, michael@0: uMappingTable ** aMappingTable, michael@0: uint32_t aMaxLengthFactor); michael@0: michael@0: /** michael@0: * Class destructor. michael@0: */ michael@0: virtual ~nsMultiTableEncoderSupport(); michael@0: michael@0: protected: michael@0: michael@0: int32_t mTableCount; michael@0: uScanClassID * mScanClassArray; michael@0: uShiftOutTable ** mShiftOutTable; michael@0: uMappingTable ** mMappingTable; michael@0: michael@0: //-------------------------------------------------------------------- michael@0: // Subclassing of nsEncoderSupport class [declaration] michael@0: michael@0: NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc, int32_t * aSrcLength, michael@0: char * aDest, int32_t * aDestLength); michael@0: }; michael@0: michael@0: michael@0: #endif /* nsUCvJaSupport_h___ */