|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: A misc. char-encoding related utilities. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef XML_ENCODING_H |
|
20 #define XML_ENCODING_H |
|
21 |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // MACROS |
|
30 |
|
31 // DATA TYPES |
|
32 |
|
33 // FUNCTION PROTOTYPES |
|
34 |
|
35 // FORWARD DECLARATIONS |
|
36 class CCnvCharacterSetConverter; |
|
37 |
|
38 // CLASS DECLARATION |
|
39 |
|
40 |
|
41 /** |
|
42 * A misc. char-encoding related utilities. |
|
43 * |
|
44 * \b Library: FeedsEngine.lib |
|
45 * |
|
46 * @since 3.0 |
|
47 */ |
|
48 class CXmlEncoding: public CBase |
|
49 { |
|
50 private: // Data types |
|
51 struct SupportedEncodings |
|
52 { |
|
53 TDesC8* charEncoding; |
|
54 TUint uid; |
|
55 }; |
|
56 |
|
57 |
|
58 public: // Constructors and destructor |
|
59 /** |
|
60 * Two-phased constructor. |
|
61 */ |
|
62 IMPORT_C static CXmlEncoding* NewL(); |
|
63 |
|
64 /** |
|
65 * Destructor. |
|
66 */ |
|
67 virtual ~CXmlEncoding(); |
|
68 |
|
69 |
|
70 public: // New methods |
|
71 /** |
|
72 * Resolves the given char-encoding into its uid. |
|
73 * |
|
74 * @since 3.0 |
|
75 * @param aCharEncoding The encoding. |
|
76 * @param aUid The resulting uid for the given encoding. |
|
77 * @return ETrue if the encoding was resolved. |
|
78 */ |
|
79 TBool ResolveCharEncodingL(const TDesC8& aCharEncoding, TUint& aUid) const; |
|
80 |
|
81 /** |
|
82 * Determine the char-encoding. |
|
83 * |
|
84 * @since 3.0 |
|
85 * @param aBuffer The native buffer. |
|
86 * @param aCharSet The char-set provided by the orignal source |
|
87 * @param aEncoding The resulting encoding. |
|
88 * @return ETrue if a encoding was determined. |
|
89 */ |
|
90 IMPORT_C TBool DetermineCharEncodingL(const TDesC8& aBuffer, |
|
91 const TDesC& aCharSet, TUint& aEncoding) const; |
|
92 |
|
93 /** |
|
94 * Determine the char-encoding from the BOM. |
|
95 * |
|
96 * @since 3.0 |
|
97 * @param aBuffer The native buffer. |
|
98 * @param aEncoding The resulting encoding. |
|
99 * @return ETrue if a encoding was determined. |
|
100 */ |
|
101 TBool DetermineCharEncodingFromBom(const TDesC8& aBuffer, TUint& aEncoding) const; |
|
102 |
|
103 /** |
|
104 * Determine the char-encoding from the char-encoding in the xml-prolog. |
|
105 * |
|
106 * @since 3.1 |
|
107 * @param aBuffer The native buffer. |
|
108 * @param aEncoding The resulting encoding. |
|
109 * @return ETrue if a encoding was determined. |
|
110 */ |
|
111 TBool DetermineCharEncodingFromXmlProlog(const TDesC8& aBuffer, TUint& aEncoding) const; |
|
112 |
|
113 /** |
|
114 * Erase the char-encoding attribute (if any) from the xml-prolog. |
|
115 * |
|
116 * @since 3.0 |
|
117 * @param aUtf8Buffer The utf8 buffer. |
|
118 * @return void |
|
119 */ |
|
120 void StripCharEncoding(HBufC8& aUtf8Buffer) const; |
|
121 |
|
122 /** |
|
123 * Erase the char-encoding attribute (if any) from the xml-prolog. |
|
124 * |
|
125 * @since 3.0 |
|
126 * @param aUtf8Buffer The utf8 buffer. |
|
127 * @return void |
|
128 */ |
|
129 void StripCharEncoding(HBufC16& aUcs2Buffer) const; |
|
130 |
|
131 /** |
|
132 * Converts the given native buffer into utf8. |
|
133 * |
|
134 * @since 3.0 |
|
135 * @param aEncoding The encoding. |
|
136 * @param aBuffer The native buffer. |
|
137 * @return The converted buffer. |
|
138 */ |
|
139 IMPORT_C HBufC8* ConvertToUtf8L(TUint aEncoding, const TDesC8& aBuffer) const; |
|
140 |
|
141 /** |
|
142 * Converts the given native buffer into ucs2. |
|
143 * |
|
144 * @since 3.0 |
|
145 * @param aEncoding The encoding. |
|
146 * @param aBuffer The native buffer. |
|
147 * @return The converted buffer. |
|
148 */ |
|
149 IMPORT_C HBufC16* ConvertToUcs2L(TUint aEncoding, const TDesC8& aBuffer) const; |
|
150 |
|
151 |
|
152 private: |
|
153 /** |
|
154 * C++ default constructor. |
|
155 */ |
|
156 CXmlEncoding(); |
|
157 |
|
158 /** |
|
159 * By default Symbian 2nd phase constructor is private. |
|
160 */ |
|
161 void ConstructL(); |
|
162 |
|
163 /** |
|
164 * Converts the given ucs2 buffer into utf8. |
|
165 * |
|
166 * @since 3.0 |
|
167 * @param aUsc2Buffer The ucs2 buffer. |
|
168 * @return The converted buffer. |
|
169 */ |
|
170 HBufC8* ConvertToUtf8L(HBufC16& aUsc2Buffer) const; |
|
171 |
|
172 /** |
|
173 * Finds the location of the encoding attribute in the xml-prolog. |
|
174 * |
|
175 * @since 3.0 |
|
176 * @param aBuffer The native buffer. |
|
177 * @param aBegin The beginning of the attribute. |
|
178 * @param aEnd The end of the attribute. |
|
179 * @param aValueBegin The beginning of the encoding's value. |
|
180 * @param aValueEnd The end of the encoding's value |
|
181 * @return ETrue if the encoding was found. |
|
182 */ |
|
183 TBool CXmlEncoding::FindEncoding(const TDesC8& aBuffer, |
|
184 TInt& aBegin, TInt& aEnd, TInt& aValueBegin, TInt& aValueEnd) const; |
|
185 |
|
186 /** |
|
187 * Finds the location of the encoding attribute in the xml-prolog. |
|
188 * |
|
189 * @since 3.0 |
|
190 * @param aBuffer The ucs2 buffer. |
|
191 * @param aBegin The beginning of the attribute. |
|
192 * @param aEnd The end of the attribute. |
|
193 * @param aValueBegin The beginning of the encoding's value. |
|
194 * @param aValueEnd The end of the encoding's value |
|
195 * @return ETrue if the encoding was found. |
|
196 */ |
|
197 TBool CXmlEncoding::FindEncoding(const TDesC& aBuffer, |
|
198 TInt& aBegin, TInt& aEnd, TInt& aValueBegin, TInt& aValueEnd) const; |
|
199 |
|
200 |
|
201 private: // Data |
|
202 RFs iRfs; |
|
203 CCnvCharacterSetConverter* iConverter; |
|
204 |
|
205 RArray<SupportedEncodings> iCharEncodings; |
|
206 }; |
|
207 |
|
208 #endif // XML_ENCODING_H |
|
209 |
|
210 // End of File |