2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FTextGsmEncoding.h
19 * @brief This is the header file for the %GsmEncoding class.
21 * This header file contains the declarations of the %GsmEncoding class.
22 * This class is derived from the Encoding class.
24 #ifndef _FTEXT_GSM_ENCODING_H_
25 #define _FTEXT_GSM_ENCODING_H_
27 #include <FTextEncoding.h>
30 namespace Tizen { namespace Text
34 * @brief This class is an implementation of the GSM character encoding.
38 * @final This class is not intended for extension.
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.
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>.
46 * The following example demonstrates how to use the %GsmEncoding class.
52 * using namespace Tizen::Base;
53 * using namespace Tizen::Text;
56 * MyClass::GsmEncodingSample(void)
60 * String str(L"GSM Encoding test");
63 * gsm.GetByteCount(str, byteCount);
66 * ByteBuffer* pBuffer = gsm.GetBytesN(str);
69 * gsm.GetCharCount(*pBuffer, charCount);
73 * gsm.GetString(*pBuffer, decodedStr);
75 * if (str.Equals(decodedStr))
85 class _OSP_EXPORT_ GsmEncoding
90 * This is the default constructor for this class.
98 * This is the destructor for this class. @n
99 * This destructor overrides Tizen::Text::Encoding::~Encoding().
103 virtual ~GsmEncoding(void);
106 * Gets the total number of bytes that are required to encode the specified Tizen::Base::String instance.
110 * @return An error code
111 * @param[in] str The 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 Either of the following conditions has occurred:
115 * - A specified input parameter is invalid.
116 * - The specified @c str is empty.
117 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
118 * @remarks This method determines the total number of bytes
119 * that are generated when the specified string is encoded.
120 * @see GetMaxByteCount()
122 virtual result GetByteCount(const Tizen::Base::String& str, int& byteCount) const;
125 * Gets the total number of bytes that are required to encode the specified Tizen::Base::WcharBuffer instance.
129 * @return An error code
130 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
131 * @param[out] byteCount The total number of bytes required to encode the specified range of characters
132 * @exception E_SUCCESS The method is successful.
133 * @exception E_INVALID_ARG Either of the following conditions has occurred:
134 * - A specified input parameter is invalid.
135 * - The specified @c chars is empty.
136 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
137 * @remarks This method determines the total number of bytes
138 * that are generated when the specified array of characters is encoded.
139 * @see GetMaxByteCount()
141 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int& byteCount) const;
144 * Gets the total number of bytes that are required to encode a range of characters in the specified Tizen::Base::WcharBuffer instance.
148 * @return An error code
149 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
150 * @param[in] charIndex The index from where the encoding begins in the Tizen::Base::WcharBuffer instance
151 * @param[in] charCount The total number of characters to encode
152 * @param[out] byteCount The total number of bytes required to encode the specified range of characters
153 * @exception E_SUCCESS The method is successful.
154 * @exception E_INVALID_ARG Either of the following conditions has occurred:
155 * - A specified input parameter is invalid.
156 * - The specified @c chars is empty.
157 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
158 * - A specified input parameter is outside the valid range defined by the method.
159 * - The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
160 * @exception E_UNDERFLOW Either of the following conditions has occurred:
161 * - This operation has caused the memory to underflow.
162 * - The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
163 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
164 * @remarks This method determines the total number of bytes
165 * that are generated when the specified array of characters is encoded.
166 * @see GetMaxByteCount()
168 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const;
171 * Encodes an instance of the specified Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
175 * @return A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
176 * else @c null if an exception occurs @n
177 * The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
178 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
179 * @exception E_SUCCESS The method is successful.
180 * @exception E_OUT_OF_MEMORY The memory is insufficient.
181 * @exception E_INVALID_ARG The specified @c chars is invalid or empty.
182 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
184 * - The specific error code can be accessed using the GetLastResult() method.
185 * - The pointer to the Tizen::Base::ByteBuffer instance is not terminated by a @c null character.
188 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars) const;
191 * Encodes an instance of the specified Tizen::Base::String into an instance of Tizen::Base::ByteBuffer.
195 * @return A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
196 * else @c null if an exception occurs @n
197 * The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
198 * @param[in] str The string to encode
199 * @exception E_SUCCESS The method is successful.
200 * @exception E_OUT_OF_MEMORY The memory is insufficient.
201 * @exception E_INVALID_ARG The specified @c str is invalid or empty.
202 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
204 * - The specific error code can be accessed using the GetLastResult() method.
205 * - The pointer to the Tizen::Base::ByteBuffer instance is not terminated by a @c null character.
208 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::String& str) const;
211 * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
212 * The position and limit of the %Tizen::Base::ByteBuffer instance is not changed.
216 * @return An error code
217 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
218 * @param[in] charIndex The index from where the encoding begins in the Tizen::Base::WcharBuffer instance
219 * @param[in] charCount The total number of characters to encode
220 * @param[out] bytes The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
221 * @param[in] byteIndex The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
222 * @exception E_SUCCESS The method is successful.
223 * @exception E_OUT_OF_MEMORY The memory is insufficient.
224 * @exception E_INVALID_ARG Either of the following conditions has occurred:
225 * - A specified input parameter is invalid.
226 * - The specified @c chars or @c bytes is empty.
227 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
228 * - A specified input parameter is outside the valid range defined by the method.
229 * - The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
230 * @exception E_UNDERFLOW Either of the following conditions has occurred:
231 * - This operation has caused the memory to underflow.
232 * - The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
233 * @exception E_OVERFLOW Either of the following conditions has occurred:
234 * - This operation has caused the memory to overflow.
235 * - The specified @c bytes does not contain sufficient space to store the encoded characters.
236 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
237 * @remarks This method encodes a range of characters in Tizen::Base::WcharBuffer into a range of bytes in Tizen::Base::ByteBuffer.
240 virtual result GetBytes(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount,
241 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
244 * Encodes an instance of Tizen::Base::String into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
245 * The position and limit of the %Tizen::Base::ByteBuffer instance is not changed.
249 * @return An error code
250 * @param[in] str The string to encode
251 * @param[in] charIndex The index from where the encoding begins in the Tizen::Base::WcharBuffer instance
252 * @param[in] charCount The total number of characters to encode
253 * @param[out] bytes The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
254 * @param[in] byteIndex The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
255 * @exception E_SUCCESS The method is successful.
256 * @exception E_OUT_OF_MEMORY The memory is insufficient.
257 * @exception E_INVALID_ARG Either of the following conditions has occurred:
258 * - A specified input parameter is invalid.
259 * - The specified @c str or @c bytes is empty.
260 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
261 * - A specified input parameter is outside the valid range defined by the method.
262 * - The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c str.
263 * @exception E_UNDERFLOW Either of the following conditions has occurred:
264 * - This operation has caused the memory to underflow.
265 * - The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c str.
266 * @exception E_OVERFLOW Either of the following conditions has occurred:
267 * - This operation has caused the memory to overflow.
268 * - The specified @c bytes does not contain sufficient space to store the encoded characters.
269 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
272 virtual result GetBytes(const Tizen::Base::String& str, int charIndex, int charCount,
273 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
276 * Gets the total number of characters that are generated by decoding an instance of Tizen::Base::ByteBuffer.
280 * @return An error code
281 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
282 * @param[out] charCount The total number of characters that are generated by decoding the specified Tizen::Base::ByteBuffer instance
283 * @exception E_SUCCESS The method is successful.
284 * @exception E_INVALID_ARG Either of the following conditions has occurred:
285 * - A specified input parameter is invalid.
286 * - The specified @c bytes is empty.
287 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
288 * @remarks This method determines the total number of characters that are generated when the specified range of bytes are decoded.
289 * @see GetMaxCharCount()
291 virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int& charCount) const;
294 * Gets the total number of characters that are generated by decoding a range of elements specified in the Tizen::Base::ByteBuffer instance.
298 * @return An error code
299 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
300 * @param[in] byteIndex The index from where the decoding begins
301 * @param[in] byteCount The total number of bytes to decode
302 * @param[out] charCount The total number of characters that are generated by decoding the specified Tizen::Base::ByteBuffer instance
303 * @exception E_SUCCESS The method is successful.
304 * @exception E_INVALID_ARG Either of the following conditions has occurred:
305 * - A specified input parameter is invalid.
306 * - The specified @c bytes is empty.
307 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
308 * - A specified input parameter is outside the valid range defined by the method.
309 * - The length of the specified @c byteIndex or @c byteCount is greater than the length of the specified @c bytes.
310 * @exception E_UNDERFLOW Either of the following conditions has occurred:
311 * - This operation has caused the memory to underflow.
312 * - The sum of the length of the specified @c byteIndex and @c byteCount is greater than the length of the specified @c bytes.
313 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
314 * @remarks This method determines the total number of characters
315 * that are generated when the specified range of bytes are decoded.
316 * @see GetMaxCharCount()
318 virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const;
321 * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer.
325 * @return A pointer to the Tizen::Base::WcharBuffer instance where the resultant decoded data is stored, @n
326 * else @c null if an exception occurs @n
327 * The buffer limit is the position of the last decoded byte plus one and the starting position is zero.
328 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
329 * @exception E_SUCCESS The method is successful.
330 * @exception E_OUT_OF_MEMORY The memory is insufficient.
331 * @exception E_INVALID_ARG The specified @c bytes is invalid or empty.
332 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
333 * @remarks The specific error code can be accessed using the GetLastResult() method.
336 virtual Tizen::Base::WcharBuffer* GetCharsN(const Tizen::Base::ByteBuffer& bytes) const;
339 * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer as per the specified range. @n
340 * The position and limit of the %Tizen::Base::WcharBuffer instance is not changed.
344 * @return An error code
345 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
346 * @param[in] byteIndex The index from where the decoding begins
347 * @param[in] byteCount The total number of bytes to decode
348 * @param[out] chars The Tizen::Base::WcharBuffer instance where the resultant decoded data is stored
349 * @param[in] charIndex The index from where the encoding begins in the Tizen::Base::WcharBuffer instance
350 * @exception E_SUCCESS The method is successful.
351 * @exception E_OUT_OF_MEMORY The memory is insufficient.
352 * @exception E_INVALID_ARG Either of the following conditions has occurred:
353 * - A specified input parameter is invalid.
354 * - The specified @c bytes or @c chars is empty.
355 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
356 * - A specified input parameter is outside the valid range defined by the method.
357 * - The length of the specified @c byteIndex or @c byteCount is greater than the length of the specified @c bytes.
358 * @exception E_UNDERFLOW Either of the following conditions has occurred:
359 * - This operation has caused the memory to underflow.
360 * - The sum of the length of the specified @c byteIndex and @c byteCount is greater than the length of the specified @c bytes.
361 * @exception E_OVERFLOW Either of the following conditions has occurred:
362 * - This operation has caused the memory to overflow.
363 * - The specified @c chars does not contain sufficient space to store the decoded bytes.
364 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
367 virtual result GetChars(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount,
368 Tizen::Base::WcharBuffer& chars, int charIndex = 0) const;
371 * Gets a string that contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
375 * @return An error code
376 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
377 * @param[out] str A Tizen::Base::String instance @n
378 * It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
379 * @exception E_SUCCESS The method is successful.
380 * @exception E_OUT_OF_MEMORY The memory is insufficient.
381 * @exception E_INVALID_ARG Either of the following conditions has occurred:
382 * - A specified input parameter is invalid.
383 * - The specified @c bytes is empty.
384 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
387 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, Tizen::Base::String& str) const;
390 * Gets a string that contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
394 * @return An error code
395 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
396 * @param[in] index The index from where the decoding begins
397 * @param[in] count The total number of bytes to decode
398 * @param[out] str A Tizen::Base::String instance @n
399 * It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
400 * @exception E_SUCCESS The method is successful.
401 * @exception E_OUT_OF_MEMORY The memory is insufficient.
402 * @exception E_INVALID_ARG Either of the following conditions has occurred:
403 * - A specified input parameter is invalid.
404 * - The specified @c bytes is empty.
405 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
406 * - A specified input parmater is outside the valid range defined by the method.
407 * - The sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
408 * @exception E_UNDERFLOW Either of the following conditions has occurred:
409 * - This operation has caused the memory to underflow.
410 * - The sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
411 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
414 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, int index, int count, Tizen::Base::String& str) const;
418 * Gets the maximum number of bytes required for encoding the specified number of characters.
422 * @return The maximum number of bytes required for encoding the specified number of characters
423 * @param[in] charCount The total number of characters to encode
424 * @remarks This method determines an appropriate buffer size for the byte arrays passed to GetBytes() for encoding.
425 * @see GetByteCount()
427 virtual int GetMaxByteCount(int charCount) const;
431 * Gets the maximum number of characters that are generated by decoding the specified number of bytes.
435 * @return The maximum number of characters that are generated by decoding the specified number of bytes
436 * @param[in] byteCount The total number of bytes to encode
437 * @remarks This method determines an appropriate buffer size for character arrays passed to
438 * GetChars() or a decoder for encoding.
439 * @see GetByteCount()
441 virtual int GetMaxCharCount(int byteCount) const;
445 * Gets an encoder for the current encoding.
449 * @return A pointer to the Encoder instance for the current encoding
451 * - Contrary to GetBytes(), an encoder can convert partial sequences of characters into
452 * partial sequences of bytes by maintaining the appropriate state between the conversions.
453 * - Currently only UTF-8 encoding supports this method. The other classes return a @c null value.
455 virtual Encoder* GetEncoderN(void) const;
458 * Gets a decoder for the current encoding.
462 * @return A pointer to the Decoder instance for the current encoding
464 * - Contrary to GetChars(), a decoder can convert partial sequences of bytes
465 * into partial sequences of characters by maintaining the appropriate state between the conversions.
466 * - Currently only UTF-8 encoding supports this method. The other classes return a @c null value.
468 virtual Decoder* GetDecoderN(void) const;
471 * Gets the encoding type of the current instance.
475 * @return The encoding type
477 virtual Tizen::Base::String GetEncodingType(void) const;
481 * The implementation of this copy constructor is intentionally blank and declared as private to
482 * prohibit copying of objects.
484 GsmEncoding(const GsmEncoding& gsmEncoding);
487 * The implementation of this copy assignment operator is intentionally blank and declared as private
488 * to prohibit copying of objects.
490 GsmEncoding& operator =(const GsmEncoding& gsmEncoding);
492 friend class _GsmEncodingImpl;
493 class _GsmEncodingImpl* __pGsmEncodingImpl;
497 #endif //_FTEXT_GSM_ENCODING_H_