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