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 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()
120 virtual result GetByteCount(const Tizen::Base::String& str, int& byteCount) const;
123 * Gets the total number of bytes that are required to encode the specified Tizen::Base::WcharBuffer instance.
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()
137 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int& byteCount) const;
140 * Gets the total number of bytes that are required to encode a range of characters in the specified Tizen::Base::WcharBuffer instance.
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()
158 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const;
161 * Encodes an instance of the specified Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
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.
177 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars) const;
180 * Encodes an instance of the specified Tizen::Base::String into an instance of Tizen::Base::ByteBuffer.
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.
196 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::String& str) const;
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.
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.
220 virtual result GetBytes(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount,
221 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
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.
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.
244 virtual result GetBytes(const Tizen::Base::String& str, int charIndex, int charCount,
245 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
248 * Gets the total number of characters that are generated by decoding an instance of Tizen::Base::ByteBuffer.
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()
262 virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int& charCount) const;
265 * Gets the total number of characters that are generated by decoding a range of elements specified in the Tizen::Base::ByteBuffer instance.
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()
283 virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const;
286 * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer.
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.
301 virtual Tizen::Base::WcharBuffer* GetCharsN(const Tizen::Base::ByteBuffer& bytes) const;
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.
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.
324 virtual result GetChars(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount,
325 Tizen::Base::WcharBuffer& chars, int charIndex = 0) const;
328 * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
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.
342 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, Tizen::Base::String& str) const;
345 * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
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.
363 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, int index, int count, Tizen::Base::String& str) const;
367 * Gets the maximum number of bytes required for encoding the specified number of characters.
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()
376 virtual int GetMaxByteCount(int charCount) const;
380 * Gets the maximum number of characters that are generated by decoding the specified number of bytes.
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()
390 virtual int GetMaxCharCount(int byteCount) const;
394 * Gets an encoder for the current encoding.
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.
404 virtual Encoder* GetEncoderN(void) const;
407 * Gets a decoder for the current encoding.
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.
417 virtual Decoder* GetDecoderN(void) const;
420 * Gets the encoding type of the current instance.
424 * @return An encoding type
426 virtual Tizen::Base::String GetEncodingType(void) const;
430 * The implementation of this copy constructor is intentionally blank and declared as private to
431 * prohibit copying of objects.
433 GsmEncoding(const GsmEncoding& gsmEncoding);
436 * The implementation of this copy assignment operator is intentionally blank and declared as private
437 * to prohibit copying of objects.
439 GsmEncoding& operator =(const GsmEncoding& gsmEncoding);
441 friend class _GsmEncodingImpl;
442 class _GsmEncodingImpl* __pGsmEncodingImpl;
446 #endif //_FTEXT_GSM_ENCODING_H_