Move system-server under server/system.
[platform/framework/native/appfw.git] / inc / FTextGsmEncoding.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                FTextGsmEncoding.h
19  * @brief               This is the header file for the %GsmEncoding class.
20  *
21  * This header file contains the declarations of the %GsmEncoding class.
22  * This class is derived from the Encoding class.
23  */
24 #ifndef _FTEXT_GSM_ENCODING_H_
25 #define _FTEXT_GSM_ENCODING_H_
26
27 #include <FTextEncoding.h>
28
29
30 namespace Tizen { namespace Text
31 {
32 /**
33  * @class       GsmEncoding
34  * @brief       This class is an implementation of the GSM character encoding.
35  *
36  * @since       2.0
37  *
38  * @final       This class is not intended for extension.
39  *
40  * The %GsmEncoding class is an implementation of the GSM character encoding.
41  * The Global System for Mobile Communications (GSM) consists of 128 European characters. It supports a 7-bit
42  * default alphabet extension table for encoding. It is a target-dependent encoding type.
43  *
44  * 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>.
45  *
46  * The following example demonstrates how to use the %GsmEncoding class.
47  *
48  *      @code
49  *      #include <FBase.h>
50  *      #include <FText.h>
51  *
52  *      using namespace Tizen::Base;
53  *      using namespace Tizen::Text;
54  *
55  *      void
56  *      MyClass::GsmEncodingSample(void)
57  *      {
58  *              GsmEncoding gsm;
59  *
60  *              String str(L"GSM Encoding test");
61  *
62  *              int byteCount;
63  *              gsm.GetByteCount(str, byteCount);
64  *
65  *              // Encodes
66  *              ByteBuffer* pBuffer = gsm.GetBytesN(str);
67  *
68  *              int charCount;
69  *              gsm.GetCharCount(*pBuffer, charCount);
70  *
71  *              // Decodes
72  *              String decodedStr;
73  *              gsm.GetString(*pBuffer, decodedStr);
74  *
75  *              if (str.Equals(decodedStr))     
76  *              {
77  *                      //....
78  *              }
79  *
80  *              delete pBuffer;
81  *      }
82  *  @endcode
83  */
84
85 class _OSP_EXPORT_ GsmEncoding
86         : public Encoding
87 {
88 public:
89         /**
90          * This is the default constructor for this class.
91          *
92          * @since       2.0
93          *
94          */
95         GsmEncoding(void);
96
97         /**
98          * This is the destructor for this class. @n
99          * This destructor overrides Tizen::Text::Encoding::~Encoding().
100          *
101          * @since       2.0
102          */
103         virtual ~GsmEncoding(void);
104
105         /**
106          * Gets the total number of bytes that are required to encode the specified Tizen::Base::String instance.
107          *
108          * @since                       2.0
109          *
110          * @return              An error code
111          * @param[in]   str                     A string to encode
112          * @param[out]  byteCount               The total number of bytes required to encode the specified string
113          * @exception   E_SUCCESS                The method is successful.
114          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c str is empty.
115          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
116          * @remarks     This method determines the total number of bytes
117          *              that are generated when the specified string is encoded.
118          * @see         GetMaxByteCount()
119          */
120         virtual result GetByteCount(const Tizen::Base::String& str, int& byteCount) const;
121
122         /**
123          * Gets the total number of bytes that are required to encode the specified Tizen::Base::WcharBuffer instance.
124          *
125          * @since                       2.0
126          *
127          * @return              An error code
128          * @param[in]   chars                 An instance of Tizen::Base::WcharBuffer to encode
129          * @param[out]  byteCount             The total number of bytes required to encode the specified range of characters
130          * @exception   E_SUCCESS                The method is successful.
131          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c chars is empty.
132          * @exception   E_INVALID_ENCODING_RANGE  The specified string contains code points that are outside the bounds of the character encoding scheme.
133          * @remarks     This method determines the total number of bytes
134          *              that are generated when the specified array of characters is encoded.
135          * @see         GetMaxByteCount()
136          */
137         virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int& byteCount) const;
138
139         /**
140          * Gets the total number of bytes that are required to encode a range of characters in the specified Tizen::Base::WcharBuffer instance.
141          *
142          * @since                       2.0
143          *
144          * @return              An error code
145          * @param[in]   chars          An instance of Tizen::Base::WcharBuffer to encode
146          * @param[in]   charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
147          * @param[in]   charCount        The total number of characters to encode
148          * @param[out]  byteCount      The total number of bytes required to encode the specified range of characters
149          * @exception   E_SUCCESS                The method is successful.
150          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c chars is empty.
151          * @exception   E_OUT_OF_RANGE                   The value of an argument is outside the valid range defined by the method, or the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
152          * @exception   E_UNDERFLOW              This operation has caused the memory to underflow, or the sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
153          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
154          * @remarks     This method determines the total number of bytes
155          *              that are generated when the specified array of characters is encoded.
156          * @see                 GetMaxByteCount()
157          */
158         virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const;
159
160         /**
161          * Encodes an instance of the specified Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
162          *
163          * @since                       2.0
164          *
165          * @return              A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
166          *                              else @c null if an exception occurs @n
167          *                                              The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
168          * @param[in]   chars                An instance of Tizen::Base::WcharBuffer to encode
169          * @exception   E_SUCCESS                The method is successful.
170          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
171          * @exception   E_INVALID_ARG            The specified @c chars is invalid or empty.
172          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
173          * @remarks             The specific error code can be accessed using the GetLastResult() method.
174          * @remarks              The pointer to the Tizen::Base::ByteBuffer instance is not terminated by a @c null character.
175          * @see                 GetCharsN()
176          */
177         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars) const;
178
179         /**
180          * Encodes an instance of the specified Tizen::Base::String into an instance of Tizen::Base::ByteBuffer.
181          *
182          * @since                       2.0
183          *
184          * @return              A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
185          *                              else @c null if an exception occurs @n
186          *                              The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
187          * @param[in]   str                  A string to encode
188          * @exception   E_SUCCESS                The method is successful.
189          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
190          * @exception   E_INVALID_ARG            The specified @c str is invalid or empty.
191          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
192          * @remarks             The specific error code can be accessed using the GetLastResult() method.
193          * @remarks             The pointer to the Tizen::Base::ByteBuffer instance is not terminated by a @c null character.
194          * @see                 GetString()
195          */
196         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::String& str) const;
197
198         /**
199          * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
200          * The position and limit of the %Tizen::Base::ByteBuffer instance is not changed.
201          *
202          * @since                       2.0
203          *
204          * @return              An error code
205          * @param[in]   chars                An instance of Tizen::Base::WcharBuffer to encode
206          * @param[in]   charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
207          * @param[in]   charCount                 The total number of characters to encode
208          * @param[out]  bytes                     The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
209          * @param[in]   byteIndex                 The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
210          * @exception   E_SUCCESS                The method is successful.
211          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
212          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c chars or @c bytes is empty.
213          * @exception   E_OUT_OF_RANGE           The value of an argument is outside the valid range defined by the method, or the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
214          * @exception   E_UNDERFLOW                  This operation has caused the memory to underflow, or the sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
215          * @exception   E_OVERFLOW               This operation has caused the memory to overflow, or the specified @c bytes does not contain sufficient space to store the encoded characters.
216          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
217          * @remarks     This method encodes a range of characters in Tizen::Base::WcharBuffer into a range of bytes in Tizen::Base::ByteBuffer.
218          * @see                 GetChars()
219          */
220         virtual result GetBytes(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount,
221                 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
222
223         /**
224          * Encodes an instance of Tizen::Base::String into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
225          * The position and limit of the %Tizen::Base::ByteBuffer instance is not changed.
226          *
227          * @since                       2.0
228          *
229          * @return              An error code
230          * @param[in]   str                   A string to encode
231          * @param[in]   charIndex             The index from where encoding begins in the Tizen::Base::WcharBuffer instance
232          * @param[in]   charCount               The total number of characters to encode
233          * @param[out]  bytes                  The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
234          * @param[in]   byteIndex               The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
235          * @exception   E_SUCCESS                The method is successful.
236          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
237          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c str or @c bytes is empty.
238          * @exception   E_OUT_OF_RANGE               The value of an argument is outside the valid range defined by the method, or the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c str.
239          * @exception   E_UNDERFLOW              This operation has caused the memory to underflow, or the sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c str.
240          * @exception   E_OVERFLOW               This operation has caused the memory to overflow, or the specified @c bytes does not contain sufficient space to store the encoded characters.
241          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
242          * @see                 GetString()
243          */
244         virtual result GetBytes(const Tizen::Base::String& str, int charIndex, int charCount,
245                 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
246
247         /**
248          * Gets the total number of characters that are generated by decoding an instance of Tizen::Base::ByteBuffer.
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]  charCount          The total number of characters that are generated by decoding the specified Tizen::Base::ByteBuffer instance
255          * @exception   E_SUCCESS                The method is successful.
256          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c bytes is empty.
257          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
258          * @remarks     This method determines the total number of characters
259          *              that are generated when the specified range of bytes are decoded.
260          * @see                 GetMaxCharCount()
261          */
262         virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int& charCount) const;
263
264         /**
265          * Gets the total number of characters that are generated by decoding a range of elements specified in the Tizen::Base::ByteBuffer instance.
266          *
267          * @since                       2.0
268          *
269          * @return              An error code
270          * @param[in]   bytes             An instance of Tizen::Base::ByteBuffer to decode
271          * @param[in]   byteIndex          The index from where decoding begins
272          * @param[in]   byteCount         The total number of bytes to decode
273          * @param[out]  charCount         The total number of characters that are generated by decoding the specified Tizen::Base::ByteBuffer instance
274          * @exception   E_SUCCESS                The method is successful.
275          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c bytes is empty.
276          * @exception   E_OUT_OF_RANGE            The value of an argument is outside the valid range defined by the method, or the length of the specified @c byteIndex or @c byteCount is greater than the length of the specified @c bytes.
277          * @exception   E_UNDERFLOW               This operation has caused the memory to underflow, or the sum of the length of the specified @c byteIndex and @c byteCount is greater than the length of the specified @c bytes.
278          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
279          * @remarks     This method determines the total number of characters
280          *              that are generated when the specified range of bytes are decoded.
281          * @see                 GetMaxCharCount()
282          */
283         virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const;
284
285         /**
286          * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer.
287          *
288          * @since                       2.0
289          *
290          * @return              A pointer to the Tizen::Base::WcharBuffer instance where the resultant decoded data is stored, @n
291          *                              else @c null if an exception occurs @n
292          *                                              The buffer limit is the position of the last decoded byte plus one and the starting position is zero.
293          * @param[in]   bytes                An instance of Tizen::Base::ByteBuffer to decode
294          * @exception   E_SUCCESS                The method is successful.
295          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
296          * @exception   E_INVALID_ARG            The specified @c bytes is invalid or empty.
297          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
298          * @remarks             The specific error code can be accessed using the GetLastResult() method.
299          * @see                 GetBytesN()
300          */
301         virtual Tizen::Base::WcharBuffer* GetCharsN(const Tizen::Base::ByteBuffer& bytes) const;
302
303         /**
304          * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer as per the specified range. @n
305          * The position and limit of the %Tizen::Base::WcharBuffer instance is not changed.
306          *
307          * @since                       2.0
308          *
309          * @return              An error code
310          * @param[in]   bytes                  An instance of Tizen::Base::ByteBuffer to decode
311          * @param[in]   byteIndex              The index from where decoding begins
312          * @param[in]   byteCount              The total number of bytes to decode
313          * @param[out]  chars                  The Tizen::Base::WcharBuffer instance where the resultant decoded data is stored
314          * @param[in]   charIndex              The index from where encoding begins in the Tizen::Base::WcharBuffer instance
315          * @exception   E_SUCCESS                The method is successful.
316          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
317          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c bytes or @c chars is empty.
318          * @exception   E_OUT_OF_RANGE           The value of an argument is outside the valid range defined by the method, or the length of the specified @c byteIndex or @c byteCount is greater than the length of the specified @c bytes.
319          * @exception   E_UNDERFLOW                  This operation has caused the memory to underflow, or the sum of the length of the specified @c byteIndex and @c byteCount is greater than the length of the specified @c bytes.
320          * @exception   E_OVERFLOW                   This operation has caused the memory to overflow, or the specified @c chars does not contain sufficient space to store the decoded bytes.
321          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
322          * @see                 GetBytes()
323          */
324         virtual result GetChars(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount,
325                 Tizen::Base::WcharBuffer& chars, int charIndex = 0) const;
326
327         /**
328          * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
329          *
330          * @since                       2.0
331          *
332          * @return              An error code
333          * @param[in]   bytes               An instance of Tizen::Base::ByteBuffer to decode
334          * @param[out]  str                 A Tizen::Base::String instance @n
335          *                                  It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
336          * @exception   E_SUCCESS                The method is successful.
337          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
338          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c bytes is empty.
339          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
340          * @see                 GetBytesN()
341          */
342         virtual result GetString(const Tizen::Base::ByteBuffer& bytes, Tizen::Base::String& str) const;
343
344         /**
345          * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
346          *
347          * @since                       2.0
348          *
349          * @return              An error code
350          * @param[in]   bytes                      An instance of Tizen::Base::ByteBuffer to decode
351          * @param[in]   index                      The index from where decoding begins
352          * @param[in]   count                      The total number of bytes to decode
353          * @param[out]  str                        A Tizen::Base::String instance @n
354          *                                         It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
355          * @exception   E_SUCCESS                The method is successful.
356          * @exception   E_OUT_OF_MEMORY          The memory is insufficient.
357          * @exception   E_INVALID_ARG            A specified input parameter is invalid, or the specified @c bytes is empty.
358          * @exception   E_OUT_OF_RANGE           The value of an argument is outside the valid range defined by the method, or the sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
359          * @exception   E_UNDERFLOW                              This operation has caused the memory to underflow, or the sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
360          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
361          * @see                 GetBytes()
362          */
363         virtual result GetString(const Tizen::Base::ByteBuffer& bytes, int index, int count, Tizen::Base::String& str) const;
364
365
366         /**
367          * Gets the maximum number of bytes required for encoding the specified number of characters.
368          *
369          * @since                       2.0
370          *
371          * @return              The maximum number of bytes required for encoding the specified number of characters
372          * @param[in]   charCount    The total number of characters to encode
373          * @remarks   This method determines an appropriate buffer size for the byte arrays passed to GetBytes() for encoding.
374          * @see                 GetByteCount()
375          */
376         virtual int GetMaxByteCount(int charCount) const;
377
378
379         /**
380         * Gets the maximum number of characters that are generated by decoding the specified number of bytes.
381         *
382         * @since                        2.0
383         *
384         * @return               The maximum number of characters that are generated by decoding the specified number of bytes
385         * @param[in]    byteCount The total number of bytes to encode
386         * @remarks   This method determines an appropriate buffer size for character arrays passed to
387         *                 GetChars() or a decoder for encoding.
388         * @see                          GetByteCount()
389         */
390         virtual int GetMaxCharCount(int byteCount) const;
391
392
393         /**
394          * Gets an encoder for the current encoding.
395          *
396          * @since                               2.0
397          *
398          * @return                      A pointer to the Encoder instance for the current encoding
399          * @remarks     Contrary to GetBytes(), an encoder can convert partial sequences of characters into
400          *              partial sequences of bytes by maintaining the appropriate state between the conversions.
401          *              Currently only UTF-8 encoding supports this method. The other classes return a value of @c null.
402          * @see                 GetBytes()
403          */
404         virtual Encoder* GetEncoderN(void) const;
405
406         /**
407          * Gets a decoder for the current encoding.
408          *
409          * @since                               2.0
410          *
411          * @return                      A pointer to the Decoder instance for the current encoding
412          * @remarks     Contrary to GetChars(), a decoder can convert partial sequences of bytes
413          *              into partial sequences of characters by maintaining the appropriate state between the conversions.
414          *              Currently only UTF-8 encoding supports this method. The other classes return a value of @c null.
415          * @see                 GetChars()
416          */
417         virtual Decoder* GetDecoderN(void) const;
418
419         /**
420         * Gets the encoding type of the current instance.
421         *
422         * @since                        2.0
423         *
424         * @return               An encoding type
425         */
426         virtual Tizen::Base::String GetEncodingType(void) const;
427
428 private:
429         /**
430          * The implementation of this copy constructor is intentionally blank and declared as private to
431          * prohibit copying of objects.
432          */
433         GsmEncoding(const GsmEncoding& gsmEncoding);
434
435         /**
436          * The implementation of this copy assignment operator is intentionally blank and declared as private
437          * to prohibit copying of objects.
438          */
439         GsmEncoding& operator =(const GsmEncoding& gsmEncoding);
440
441         friend class _GsmEncodingImpl;
442         class _GsmEncodingImpl* __pGsmEncodingImpl;
443 };
444
445 } } // Tizen::Text
446 #endif //_FTEXT_GSM_ENCODING_H_