d24dbaec769af3444cf9cb45b3535135b51c3610
[platform/framework/native/appfw.git] / inc / FTextLatin1Encoding.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FTextLatin1Encoding.h
19  * @brief               This is the header file for the %Latin1Encoding class.
20  *
21  * This header file contains the declarations of the %Latin1Encoding class.
22  * This class is derived from the Encoding class.
23  */
24 #ifndef _FTEXT_LATIN1_ENCODING_H_
25 #define _FTEXT_LATIN1_ENCODING_H_
26
27 #include <FTextEncoding.h>
28
29
30 namespace Tizen { namespace Text
31 {
32 /**
33  * @class       Latin1Encoding
34  * @brief       This class is an implementation of the Latin1 encoding.
35  *
36  * @since       2.0
37  *
38  * @final       This class is not intended for extension.
39  *
40  * The %Latin1Encoding class is an implementation of the Latin1 encoding.
41  * ISO Latin-1 is a superset of the American Standard Code for Information Interchange(ASCII) character set and is very similar to the American National Standards Institute (ANSI) character set used in Windows,
42  * though the two are not identical.
43  * Latin1 also serves as the basis for the ANSI character set of MS Windows.
44  * Only the characters in ISO Latin-1 are guaranteed to be supported on an Internet website.
45  * When a %Web browser, such as Internet Explorer or Firefox formats a %Web page on a client system, such as
46  * Windows, it maps the ISO Latin-1 characters as best it can into the default character set.
47  *
48  *  For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/text/converting_all_text_data.htm">Converting All Text Data at Once</a>.
49  *
50  *  The following example demonstrates how to use the %Latin1Encoding class.
51  *
52  *  @code
53  *      #include <FBase.h>
54  *      #include <FText.h>
55  *
56  *      using namespace Tizen::Base;
57  *      using namespace Tizen::Text;
58  *
59  *      void
60  *      MyClass::Latin1EncodingSample(void)
61  *      {
62  *              Latin1Encoding latin1;
63  *
64  *              String str(L"Latin1Test \u00A1\u00A2");
65  *
66  *              int byteCount;
67  *              latin1.GetByteCount(str, byteCount);
68  *
69  *              // Encodes
70  *              ByteBuffer* pBuffer = latin1.GetBytesN(str);
71  *
72  *              int charCount;
73  *              latin1.GetCharCount(*pBuffer, charCount);
74  *
75  *              // Decodes
76  *              String decodedStr;
77  *              latin1.GetString(*pBuffer, decodedStr);
78  *
79  *              if (str.Equals(decodedStr))     
80  *              {
81  *                      //....
82  *              }
83  *
84  *              delete pBuffer;
85  *      }
86  *  @endcode
87  */
88
89 class _OSP_EXPORT_ Latin1Encoding
90         : public Encoding
91 {
92 public:
93         /**
94          * This is the default constructor for this class.
95          *
96          * @since       2.0
97          */
98         Latin1Encoding(void);
99
100         /**
101          * This is the destructor for this class. @n
102          * This destructor overrides Tizen::Text::Encoding::~Encoding().
103          *
104          * @since       2.0
105          */
106         virtual ~Latin1Encoding(void);
107
108         /**
109          * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
110          *
111          * @since                       2.0
112          *
113          * @return                                        A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
114          *                                        else @c null if an exception occurs @n
115          *                                                               The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
116          * @param[in]   chars                    An instance of Tizen::Base::WcharBuffer to encode
117          * @exception   E_SUCCESS                The method is successful.
118          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
119          * @exception   E_INVALID_ARG            The specified @c chars is empty or invalid.
120          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
121          * @remarks             The specific error code can be accessed using the GetLastResult() method.
122          * @see                 GetCharsN()
123          */
124         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars) const;
125
126         /**
127          * Encodes an instance of Tizen::Base::String into an instance of Tizen::Base::ByteBuffer.
128          *
129          * @since                       2.0
130          *
131          * @return                                        A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
132          *                                        else @c null if an exception occurs @n
133          *                                                                The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
134          * @param[in]   str                       A string to encode
135          * @exception   E_SUCCESS                The method is successful.
136          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
137          * @exception   E_INVALID_ARG            The specified @c str is empty or invalid.
138          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
139          * @remarks             The specific error code can be accessed using the GetLastResult() method.
140          * @see                 GetString()
141          */
142         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::String& str) const;
143
144         /**
145          * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
146          * The position and limit of the pointer to the %Tizen::Base::ByteBuffer instance is not changed.
147          *
148          * @since                       2.0
149          *
150          * @return              An error code
151          * @param[in]   chars                     An instance of Tizen::Base::WcharBuffer to encode
152          * @param[in]   charIndex                 The index from where encoding begins in the Tizen::Base::WcharBuffer instance
153          * @param[in]   charCount                   The total number of characters to encode
154          * @param[out]  bytes                     The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
155          * @param[in]   byteIndex                 The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
156          * @exception   E_SUCCESS                 The method is successful.
157          * @exception   E_OUT_OF_MEMORY           The memory is insufficient.
158          * @exception   E_INVALID_ARG             A specified input parameter is invalid, or
159          *                                        the specified @c chars or @c bytes is empty.
160          * @exception   E_OUT_OF_RANGE            The value of an argument is outside the valid range defined by the method, or
161          *                                        the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
162          * @exception   E_UNDERFLOW                   This operation has caused the memory to underflow, or
163          *                                        the sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
164          * @exception   E_OVERFLOW                This operation has caused the memory to overflow, or
165          *                                        the specified @c bytes does not contain sufficient space to store the encoded characters.
166          * @exception   E_INVALID_ENCODING_RANGE  The specified string contains code points that are outside the bounds of the character encoding scheme.
167          * @remarks     This method encodes a range of characters in Tizen::Base::WcharBuffer into a range of bytes in Tizen::Base::ByteBuffer.
168          * @see                 GetChars()
169          */
170         virtual result GetBytes(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount,
171                 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
172
173         /**
174          * Encodes an instance of Tizen::Base::String into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
175          * The position and limit of the pointer to the %Tizen::Base::ByteBuffer instance is not changed.
176          *
177          * @since                       2.0
178          *
179          * @return              An error code
180          * @param[in]   str                      A string to encode
181          * @param[in]   charIndex                The index from where encoding begins in the Tizen::Base::WcharBuffer instance
182          * @param[in]   charCount                  The total number of characters to encode
183          * @param[out]  bytes                    The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
184          * @param[in]   byteIndex                  The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
185          * @exception   E_SUCCESS                The method is successful.
186          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
187          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or
188          *                                         the specified @c str or @c bytes is empty.
189          * @exception   E_OUT_OF_RANGE               The value of an argument is outside the valid range defined by the method, or
190          *                                          the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c str.
191          * @exception   E_UNDERFLOW              This operation has caused the memory to underflow, or
192          *                                                                                 the sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c str.
193          * @exception   E_OVERFLOW               This operation has caused the memory to overflow, or
194          *                                                                                 the specified @c bytes does not contain sufficient space to store the encoded characters.
195          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
196          * @see                 GetString()
197          */
198         virtual result GetBytes(const Tizen::Base::String& str, int charIndex, int charCount,
199                 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
200
201         /**
202          * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer.
203          *
204          * @since                       2.0
205          *
206          * @return                                      A pointer to the Tizen::Base::WcharBuffer instance where the resultant decoded data is stored, @n
207          *                                      else @c null if an exception occurs @n
208          *                                                              The buffer limit is the position of the last decoded byte plus one and the starting position is zero.
209          * @param[in]   bytes                    An instance of Tizen::Base::ByteBuffer to decode
210          * @exception   E_SUCCESS                The method is successful.
211          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
212          * @exception   E_INVALID_ARG            The specified @c bytes is empty.
213          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
214          * @remarks             The specific error code can be accessed using the GetLastResult() method.
215          * @see                 GetBytesN()
216          */
217         virtual Tizen::Base::WcharBuffer* GetCharsN(const Tizen::Base::ByteBuffer& bytes) const;
218
219         /**
220          * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer as per the specified range. @n
221          * The position and limit of the pointer to the %Tizen::Base::WcharBuffer instance is not changed.
222          *
223          * @since                       2.0
224          *
225          * @return              An error code
226          * @param[in]   bytes                       An instance of Tizen::Base::ByteBuffer to decode
227          * @param[in]   byteIndex                   The index from where decoding begins
228          * @param[in]   byteCount                   The total number of bytes to decode
229          * @param[out]  chars                       The Tizen::Base::WcharBuffer instance where the resultant decoded data is stored
230          * @param[in]   charIndex                    The index from where encoding begins in the Tizen::Base::WcharBuffer instance
231          * @exception   E_SUCCESS                   The method is successful.
232          * @exception   E_OUT_OF_MEMORY             The memory is insufficient.
233          * @exception   E_INVALID_ARG               A specified input parameter is invalid, or
234          *                                          the specified @c bytes or @c chars is empty.
235          * @exception   E_OUT_OF_RANGE              The value of an argument is outside the valid range defined by the method, or
236          *                                                                              the length of the specified @c byteIndex or @c byteCount is greater than the length of the specified @c bytes.
237          * @exception   E_UNDERFLOW                     This operation has caused the memory to underflow, or
238          *                                                                                  the sum of the length of the specified @c byteIndex and @c byteCount is greater than the length of the specified @c bytes.
239          * @exception   E_OVERFLOW                     This operation has caused the memory to overflow, or
240          *                                                                                  the specified @c chars does not contain sufficient space to store the decoded bytes.
241          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
242          * @see                 GetBytes()
243          */
244         virtual result GetChars(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount,
245                 Tizen::Base::WcharBuffer& chars, int charIndex = 0) const;
246
247         /**
248          * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
249          *
250          * @since                       2.0
251          *
252          * @return              An error code
253          * @param[in]   bytes                    An instance of Tizen::Base::ByteBuffer to decode
254          * @param[out]  str                      A Tizen::Base::String instance @n
255          *                                       It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
256          * @exception   E_SUCCESS                The method is successful.
257          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
258          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or
259          *                                         the specified @c bytes is empty.
260          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
261          * @see                 GetBytesN()
262          */
263         virtual result GetString(const Tizen::Base::ByteBuffer& bytes, Tizen::Base::String& str) const;
264
265         /**
266          * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
267          *
268          * @since                       2.0
269          *
270          * @return              An error code
271          * @param[in]   bytes                       An instance of Tizen::Base::ByteBuffer to decode
272          * @param[in]   index                       The index from where decoding begins
273          * @param[in]   count                       The total number of bytes to decode
274          * @param[out]  str                         A Tizen::Base::String instance @n
275          *                                          It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
276          * @exception   E_SUCCESS                The method is successful.
277          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
278          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or
279          *                                         the specified @c bytes is empty.
280          * @exception   E_OUT_OF_RANGE           The value of an argument is outside the valid range defined by the method, or
281          *                                                                                 the sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
282          * @exception   E_UNDERFLOW                              This operation has caused the memory to underflow, or
283          *                                                                                 the sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
284          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
285          * @see                 GetBytes()
286          */
287         virtual result GetString(const Tizen::Base::ByteBuffer& bytes, int index, int count, Tizen::Base::String& str) const;
288
289
290         /**
291          * Gets the maximum number of bytes required for encoding a given number of characters.
292          *
293          * @since                       2.0
294          *
295          * @return                      The maximum number of bytes required for encoding a given number of characters
296          * @param[in]   charCount The total number of characters to encode
297          * @remarks    This method determines an appropriate buffer size for the byte arrays passed to GetBytes() for encoding.
298          * @see         Encoding::GetByteCount()
299          */
300         virtual int GetMaxByteCount(int charCount) const;
301
302
303         /**
304          * Gets the maximum number of characters that are generated by decoding the specified number of bytes.
305          *
306          * @since                       2.0
307          *
308          * @return                      The maximum number of characters generated by decoding the specified number of bytes
309          * @param[in]   byteCount The total number of bytes to encode
310          * @remarks    This method determines an appropriate buffer size for character arrays passed to
311          *                  GetChars() or a decoder for encoding.
312          * @see         Encoding::GetByteCount()
313          */
314         virtual int GetMaxCharCount(int byteCount) const;
315
316
317         /**
318          * Gets the encoder for the current encoding.
319          *
320          * @since                               2.0
321          *
322          * @return                      A pointer to the Encoder instance for the current encoding
323          * @remarks     Contrary to GetBytes(), an encoder can convert partial sequences of characters into
324          *              partial sequences of bytes by maintaining the appropriate state between the conversions.
325          *              Currently only Utf8Encoding supports this method. Other classes return @c null.
326          * @see                 GetBytes()
327          */
328         virtual Encoder* GetEncoderN(void) const;
329
330         /**
331          * Gets the decoder for the current encoding.
332          *
333          * @since                               2.0
334          *
335          * @return              A pointer to the Decoder instance for the current encoding
336          * @remarks     Contrary to GetChars(), a decoder can convert partial sequences of bytes
337          *              into partial sequences of characters by maintaining the appropriate state between the conversions.
338          *              Currently only Utf8Encoding supports this method. Other classes return @c null.
339          * @see                 GetChars()
340          */
341         virtual Decoder* GetDecoderN(void) const;
342
343         /**
344         * Gets the encoding type of the current instance.
345         *
346         * @since                        2.0
347         *
348         * @return               An encoding type
349         */
350         virtual Tizen::Base::String GetEncodingType(void) const;
351
352 private:
353         /**
354          * The implementation of this copy constructor is intentionally blank and declared as private to
355          * prohibit copying of objects.
356          */
357         Latin1Encoding(const Latin1Encoding& latin1Encoding);
358
359         /**
360          * The implementation of this copy assignment operator is intentionally blank and declared as private
361          * to prohibit copying of objects.
362          */
363         Latin1Encoding& operator =(const Latin1Encoding& latin1Encoding);
364
365         friend class _Latin1EncodingImpl;
366         class _Latin1EncodingImpl* __pLatin1EncodingImpl;
367 };
368
369 } } // Tizen::Text
370 #endif //_FTEXT_LATIN1_ENCODING_H_