michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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 nsSaveAsCharset_h__ michael@0: #define nsSaveAsCharset_h__ michael@0: michael@0: #include "nsStringFwd.h" michael@0: #include "nsTArray.h" michael@0: #include "nsISaveAsCharset.h" michael@0: michael@0: michael@0: #define MASK_FALLBACK(a) (nsISaveAsCharset::mask_Fallback & (a)) michael@0: #define MASK_ENTITY(a) (nsISaveAsCharset::mask_Entity & (a)) michael@0: #define MASK_CHARSET_FALLBACK(a) (nsISaveAsCharset::mask_CharsetFallback & (a)) michael@0: #define ATTR_NO_FALLBACK(a) (nsISaveAsCharset::attr_FallbackNone == MASK_FALLBACK(a) && \ michael@0: nsISaveAsCharset::attr_EntityAfterCharsetConv != MASK_ENTITY(a)) michael@0: michael@0: class nsIUnicodeEncoder; michael@0: class nsIEntityConverter; michael@0: michael@0: class nsSaveAsCharset : public nsISaveAsCharset michael@0: { michael@0: public: michael@0: michael@0: // michael@0: // implementation methods michael@0: // michael@0: nsSaveAsCharset(); michael@0: virtual ~nsSaveAsCharset(); michael@0: michael@0: // michael@0: // nsISupports michael@0: // michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // michael@0: // nsIEntityConverter michael@0: // michael@0: NS_IMETHOD Init(const char *charset, uint32_t attr, uint32_t entityVersion); michael@0: michael@0: NS_IMETHOD Convert(const char16_t *inString, char **_retval); michael@0: michael@0: NS_IMETHODIMP GetCharset(char * *aCharset); michael@0: michael@0: protected: michael@0: michael@0: NS_IMETHOD DoCharsetConversion(const char16_t *inString, char **outString); michael@0: michael@0: NS_IMETHOD DoConversionFallBack(uint32_t inUCS4, char *outString, int32_t bufferLength); michael@0: michael@0: // do the fallback, reallocate the buffer if necessary michael@0: // need to pass destination buffer info (size, current position and estimation of rest of the conversion) michael@0: NS_IMETHOD HandleFallBack(uint32_t character, char **outString, int32_t *bufferLength, michael@0: int32_t *currentPos, int32_t estimatedLength); michael@0: michael@0: nsresult SetupUnicodeEncoder(const char* charset); michael@0: michael@0: nsresult SetupCharsetList(const char *charsetList); michael@0: michael@0: const char * GetNextCharset(); michael@0: michael@0: uint32_t mAttribute; // conversion attribute michael@0: uint32_t mEntityVersion; // see nsIEntityConverter michael@0: nsCOMPtr mEncoder; // encoder (convert from unicode) michael@0: nsCOMPtr mEntityConverter; michael@0: nsTArray mCharsetList; michael@0: int32_t mCharsetListIndex; michael@0: }; michael@0: michael@0: #endif