|
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/. */ |
|
5 |
|
6 #ifndef nsSaveAsCharset_h__ |
|
7 #define nsSaveAsCharset_h__ |
|
8 |
|
9 #include "nsStringFwd.h" |
|
10 #include "nsTArray.h" |
|
11 #include "nsISaveAsCharset.h" |
|
12 |
|
13 |
|
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)) |
|
19 |
|
20 class nsIUnicodeEncoder; |
|
21 class nsIEntityConverter; |
|
22 |
|
23 class nsSaveAsCharset : public nsISaveAsCharset |
|
24 { |
|
25 public: |
|
26 |
|
27 // |
|
28 // implementation methods |
|
29 // |
|
30 nsSaveAsCharset(); |
|
31 virtual ~nsSaveAsCharset(); |
|
32 |
|
33 // |
|
34 // nsISupports |
|
35 // |
|
36 NS_DECL_ISUPPORTS |
|
37 |
|
38 // |
|
39 // nsIEntityConverter |
|
40 // |
|
41 NS_IMETHOD Init(const char *charset, uint32_t attr, uint32_t entityVersion); |
|
42 |
|
43 NS_IMETHOD Convert(const char16_t *inString, char **_retval); |
|
44 |
|
45 NS_IMETHODIMP GetCharset(char * *aCharset); |
|
46 |
|
47 protected: |
|
48 |
|
49 NS_IMETHOD DoCharsetConversion(const char16_t *inString, char **outString); |
|
50 |
|
51 NS_IMETHOD DoConversionFallBack(uint32_t inUCS4, char *outString, int32_t bufferLength); |
|
52 |
|
53 // do the fallback, reallocate the buffer if necessary |
|
54 // need to pass destination buffer info (size, current position and estimation of rest of the conversion) |
|
55 NS_IMETHOD HandleFallBack(uint32_t character, char **outString, int32_t *bufferLength, |
|
56 int32_t *currentPos, int32_t estimatedLength); |
|
57 |
|
58 nsresult SetupUnicodeEncoder(const char* charset); |
|
59 |
|
60 nsresult SetupCharsetList(const char *charsetList); |
|
61 |
|
62 const char * GetNextCharset(); |
|
63 |
|
64 uint32_t mAttribute; // conversion attribute |
|
65 uint32_t mEntityVersion; // see nsIEntityConverter |
|
66 nsCOMPtr<nsIUnicodeEncoder> mEncoder; // encoder (convert from unicode) |
|
67 nsCOMPtr<nsIEntityConverter> mEntityConverter; |
|
68 nsTArray<nsCString> mCharsetList; |
|
69 int32_t mCharsetListIndex; |
|
70 }; |
|
71 |
|
72 #endif |