1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsSaveAsCharset_h__
7 #define nsSaveAsCharset_h__
9 #include "nsStringFwd.h"
11 #include "nsISaveAsCharset.h"
14 #define MASK_FALLBACK(a) (nsISaveAsCharset::mask_Fallback & (a))
15 #define MASK_ENTITY(a) (nsISaveAsCharset::mask_Entity & (a))
16 #define MASK_CHARSET_FALLBACK(a) (nsISaveAsCharset::mask_CharsetFallback & (a))
17 #define ATTR_NO_FALLBACK(a) (nsISaveAsCharset::attr_FallbackNone == MASK_FALLBACK(a) && \
18 nsISaveAsCharset::attr_EntityAfterCharsetConv != MASK_ENTITY(a))
20 class nsIUnicodeEncoder
;
21 class nsIEntityConverter
;
23 class nsSaveAsCharset
: public nsISaveAsCharset
28 // implementation methods
40 NS_IMETHOD
Init(const char *charset
, uint32_t attr
, uint32_t entityVersion
) override
;
42 NS_IMETHOD
Convert(const char16_t
*inString
, char **_retval
) override
;
44 NS_IMETHODIMP
GetCharset(char * *aCharset
) override
;
48 virtual ~nsSaveAsCharset();
50 NS_IMETHOD
DoCharsetConversion(const char16_t
*inString
, char **outString
);
52 NS_IMETHOD
DoConversionFallBack(uint32_t inUCS4
, char *outString
, int32_t bufferLength
);
54 // do the fallback, reallocate the buffer if necessary
55 // need to pass destination buffer info (size, current position and estimation of rest of the conversion)
56 NS_IMETHOD
HandleFallBack(uint32_t character
, char **outString
, int32_t *bufferLength
,
57 int32_t *currentPos
, int32_t estimatedLength
);
59 nsresult
SetupUnicodeEncoder(const char* charset
);
61 nsresult
SetupCharsetList(const char *charsetList
);
63 const char * GetNextCharset();
65 uint32_t mAttribute
; // conversion attribute
66 uint32_t mEntityVersion
; // see nsIEntityConverter
67 nsCOMPtr
<nsIUnicodeEncoder
> mEncoder
; // encoder (convert from unicode)
68 nsCOMPtr
<nsIEntityConverter
> mEntityConverter
;
69 nsTArray
<nsCString
> mCharsetList
;
70 int32_t mCharsetListIndex
;