2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FTextGsmEncoding.h
20 * @brief This is the header file for the %GsmEncoding class.
22 * This header file contains the declarations of the %GsmEncoding class.
23 * The %GsmEncoding class is derived from the Encoding class.
25 #ifndef _FTEXT_GSM_ENCODING_H_
26 #define _FTEXT_GSM_ENCODING_H_
28 #include <FTextEncoding.h>
31 namespace Tizen { namespace Text
35 * @brief This class is an implementation of the GSM character encoding.
39 * @final This class is not intended for extension.
41 * The %GsmEncoding class is an implementation of the GSM character encoding.
42 * The Global System for Mobile Communications (GSM) consists of 128 European characters. It supports a 7-bit
43 * default alphabet extension table for encoding. It is a target-dependent encoding type.
45 * 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>.
47 * The following example demonstrates how to use the %GsmEncoding class.
53 * using namespace Tizen::Base;
54 * using namespace Tizen::Text;
57 * MyClass::GsmEncodingSample(void)
61 * String str(L"GSM Encoding test");
64 * gsm.GetByteCount(str, byteCount);
67 * ByteBuffer* pBuffer = gsm.GetBytesN(str);
70 * gsm.GetCharCount(*pBuffer, charCount);
74 * gsm.GetString(*pBuffer, decodedStr);
76 * if (str.Equals(decodedStr))
86 class _OSP_EXPORT_ GsmEncoding
91 * This is the default constructor for this class.
99 * This is the destructor for this class. @n
100 * This destructor overrides Tizen::Text::Encoding::~Encoding().
104 virtual ~GsmEncoding(void);
107 * Gets the total number of bytes that are required to encode a specified Tizen::Base::String instance.
111 * @return An error code
112 * @param[in] str A string to encode
113 * @param[out] byteCount The total number of bytes required to encode the specified string
114 * @exception E_SUCCESS The method is successful.
115 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c str is empty.
116 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
117 * @remarks This method determines the total number of bytes
118 * that are generated when the specified string is encoded.
119 * @see GetMaxByteCount()
121 virtual result GetByteCount(const Tizen::Base::String& str, int& byteCount) const;
124 * Gets the total number of bytes that are required to encode a specified Tizen::Base::WcharBuffer instance.
128 * @return An error code
129 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
130 * @param[out] byteCount The total number of bytes required to encode the specified range of characters
131 * @exception E_SUCCESS The method is successful.
132 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c chars is empty.
133 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
134 * @remarks This method determines the total number of bytes
135 * that are generated when the specified array of characters is encoded.
136 * @see GetMaxByteCount()
138 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int& byteCount) const;
141 * Gets the total number of bytes that are required to encode a range of characters in the specified Tizen::Base::WcharBuffer instance.
145 * @return An error code
146 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
147 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
148 * @param[in] charCount The total number of characters to encode
149 * @param[out] byteCount The total number of bytes required to encode the specified range of characters
150 * @exception E_SUCCESS The method is successful.
151 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c chars is empty.
152 * @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.
153 * @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.
154 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
155 * @remarks This method determines the total number of bytes
156 * that are generated when the specified array of characters is encoded.
157 * @see GetMaxByteCount()
159 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const;
162 * Encodes an instance of the specified Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
166 * @return A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
167 * else @c null if an exception occurs @n
168 * The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
169 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
170 * @exception E_SUCCESS The method is successful.
171 * @exception E_OUT_OF_MEMORY The memory is insufficient.
172 * @exception E_INVALID_ARG The specified @c chars is invalid or empty.
173 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
174 * @remarks The specific error code can be accessed using the GetLastResult() method.
175 * @remarks The pointer to the Tizen::Base::ByteBuffer instance is not terminated by a @c null character.
178 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars) const;
181 * Encodes an instance of the specified Tizen::Base::String into an instance of Tizen::Base::ByteBuffer.
185 * @return A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
186 * else @c null if an exception occurs @n
187 * The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
188 * @param[in] str A string to encode
189 * @exception E_SUCCESS The method is successful.
190 * @exception E_OUT_OF_MEMORY The memory is insufficient.
191 * @exception E_INVALID_ARG The specified @c str is invalid or empty.
192 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
193 * @remarks The specific error code can be accessed using the GetLastResult() method.
194 * @remarks The pointer to the Tizen::Base::ByteBuffer instance is not terminated by a @c null character.
197 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::String& str) const;
200 * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
201 * The position and limit of the %Tizen::Base::ByteBuffer instance is not changed.
205 * @return An error code
206 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
207 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
208 * @param[in] charCount The total number of characters to encode
209 * @param[out] bytes The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
210 * @param[in] byteIndex The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
211 * @exception E_SUCCESS The method is successful.
212 * @exception E_OUT_OF_MEMORY The memory is insufficient.
213 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c chars or @c bytes is empty.
214 * @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.
215 * @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.
216 * @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.
217 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
218 * @remarks This method encodes a range of characters in Tizen::Base::WcharBuffer into a range of bytes in Tizen::Base::ByteBuffer.
221 virtual result GetBytes(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount,
222 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
225 * Encodes an instance of Tizen::Base::String into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
226 * The position and limit of the %Tizen::Base::ByteBuffer instance is not changed.
230 * @return An error code
231 * @param[in] str A string to encode
232 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
233 * @param[in] charCount The total number of characters to encode
234 * @param[out] bytes The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
235 * @param[in] byteIndex The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
236 * @exception E_SUCCESS The method is successful.
237 * @exception E_OUT_OF_MEMORY The memory is insufficient.
238 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c str or @c bytes is empty.
239 * @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.
240 * @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.
241 * @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.
242 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
245 virtual result GetBytes(const Tizen::Base::String& str, int charIndex, int charCount,
246 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
249 * Gets the total number of characters that are generated by decoding an instance of Tizen::Base::ByteBuffer.
253 * @return An error code
254 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
255 * @param[out] charCount The total number of characters that are generated by decoding the specified Tizen::Base::ByteBuffer instance
256 * @exception E_SUCCESS The method is successful.
257 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c bytes is empty.
258 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
259 * @remarks This method determines the total number of characters
260 * that are generated when the specified range of bytes are decoded.
261 * @see GetMaxCharCount()
263 virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int& charCount) const;
266 * Gets the total number of characters that are generated by decoding a range of elements specified in the Tizen::Base::ByteBuffer instance.
270 * @return An error code
271 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
272 * @param[in] byteIndex The index from where decoding begins
273 * @param[in] byteCount The total number of bytes to decode
274 * @param[out] charCount The total number of characters that are generated by decoding the specified Tizen::Base::ByteBuffer instance
275 * @exception E_SUCCESS The method is successful.
276 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c bytes is empty.
277 * @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.
278 * @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.
279 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
280 * @remarks This method determines the total number of characters
281 * that are generated when the specified range of bytes are decoded.
282 * @see GetMaxCharCount()
284 virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const;
287 * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer.
291 * @return A pointer to the Tizen::Base::WcharBuffer instance where the resultant decoded data is stored, @n
292 * else @c null if an exception occurs @n
293 * The buffer limit is the position of the last decoded byte plus one and the starting position is zero.
294 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
295 * @exception E_SUCCESS The method is successful.
296 * @exception E_OUT_OF_MEMORY The memory is insufficient.
297 * @exception E_INVALID_ARG The specified @c bytes is invalid or empty.
298 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
299 * @remarks The specific error code can be accessed using the GetLastResult() method.
302 virtual Tizen::Base::WcharBuffer* GetCharsN(const Tizen::Base::ByteBuffer& bytes) const;
305 * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer as per the specified range. @n
306 * The position and limit of the %Tizen::Base::WcharBuffer instance is not changed.
310 * @return An error code
311 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
312 * @param[in] byteIndex The index from where decoding begins
313 * @param[in] byteCount The total number of bytes to decode
314 * @param[out] chars The Tizen::Base::WcharBuffer instance where the resultant decoded data is stored
315 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
316 * @exception E_SUCCESS The method is successful.
317 * @exception E_OUT_OF_MEMORY The memory is insufficient.
318 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c bytes or @c chars is empty.
319 * @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.
320 * @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.
321 * @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.
322 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
325 virtual result GetChars(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount,
326 Tizen::Base::WcharBuffer& chars, int charIndex = 0) const;
329 * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
333 * @return An error code
334 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
335 * @param[out] str A Tizen::Base::String instance @n
336 * It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
337 * @exception E_SUCCESS The method is successful.
338 * @exception E_OUT_OF_MEMORY The memory is insufficient.
339 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c bytes is empty.
340 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
343 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, Tizen::Base::String& str) const;
346 * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
350 * @return An error code
351 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
352 * @param[in] index The index from where decoding begins
353 * @param[in] count The total number of bytes to decode
354 * @param[out] str A Tizen::Base::String instance @n
355 * It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
356 * @exception E_SUCCESS The method is successful.
357 * @exception E_OUT_OF_MEMORY The memory is insufficient.
358 * @exception E_INVALID_ARG A specified input parameter is invalid, or the specified @c bytes is empty.
359 * @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.
360 * @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.
361 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
364 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, int index, int count, Tizen::Base::String& str) const;
368 * Gets the maximum number of bytes required for encoding the specified number of characters.
372 * @return The maximum number of bytes required for encoding the specified number of characters
373 * @param[in] charCount The total number of characters to encode
374 * @remarks This method determines an appropriate buffer size for the byte arrays passed to GetBytes() for encoding.
375 * @see GetByteCount()
377 virtual int GetMaxByteCount(int charCount) const;
381 * Gets the maximum number of characters that are generated by decoding the specified number of bytes.
385 * @return The maximum number of characters that are generated by decoding the specified number of bytes
386 * @param[in] byteCount The total number of bytes to encode
387 * @remarks This method determines an appropriate buffer size for character arrays passed to
388 * GetChars() or a decoder for encoding.
389 * @see GetByteCount()
391 virtual int GetMaxCharCount(int byteCount) const;
395 * Gets an encoder for the current encoding.
399 * @return A pointer to the Encoder instance for the current encoding
400 * @remarks Contrary to GetBytes(), an encoder can convert partial sequences of characters into
401 * partial sequences of bytes by maintaining the appropriate state between the conversions.
402 * Currently only UTF-8 encoding supports this method. The other classes return a value of @c null.
405 virtual Encoder* GetEncoderN(void) const;
408 * Gets a decoder for the current encoding.
412 * @return A pointer to the Decoder instance for the current encoding
413 * @remarks Contrary to GetChars(), a decoder can convert partial sequences of bytes
414 * into partial sequences of characters by maintaining the appropriate state between the conversions.
415 * Currently only UTF-8 encoding supports this method. The other classes return a value of @c null.
418 virtual Decoder* GetDecoderN(void) const;
421 * Gets the encoding type of the current instance.
425 * @return An encoding type
427 virtual Tizen::Base::String GetEncodingType(void) const;
431 * The implementation of this copy constructor is intentionally blank and declared as private to
432 * prohibit copying of objects.
434 GsmEncoding(const GsmEncoding& gsmEncoding);
437 * The implementation of this copy assignment operator is intentionally blank and declared as private
438 * to prohibit copying of objects.
440 GsmEncoding& operator =(const GsmEncoding& gsmEncoding);
442 friend class _GsmEncodingImpl;
443 class _GsmEncodingImpl* __pGsmEncodingImpl;
447 #endif //_FTEXT_GSM_ENCODING_H_