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 FTextAsciiEncoding.h
19 * @brief This is the header file for the %AsciiEncoding class.
21 * This header file contains the declarations of the %AsciiEncoding class. @n
22 * This class is derived from the Encoding class.
24 #ifndef _FTEXT_ASCII_ENCODING_H_
25 #define _FTEXT_ASCII_ENCODING_H_
27 #include <FTextEncoding.h>
30 namespace Tizen { namespace Text
34 * @class AsciiEncoding
35 * @brief This class is an implementation of the American Standard Code for Information Interchange (ASCII) encoding.
39 * @final This class is not intended for extension.
41 * The %AsciiEncoding class encodes Unicode characters as single 7-bit ASCII characters.
42 * This encoding only supports ASCII character values between U+0000 and U+007F.
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 %AsciiEncoding class.
52 * using namespace Tizen::Base;
53 * using namespace Tizen::Text;
56 * MyClass::AsciiEncodingSample(void)
58 * AsciiEncoding ascii;
60 * String str(L"012345 ABCDE");
63 * ascii.GetByteCount(str, byteCount);
66 * ByteBuffer* pBuffer = ascii.GetBytesN(str);
69 * ascii.GetCharCount(*pBuffer, charCount);
73 * ascii.GetString(*pBuffer, decodedStr);
75 * if (str.Equals(decodedStr))
85 class _OSP_EXPORT_ AsciiEncoding
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().
104 virtual ~AsciiEncoding(void);
107 * Encodes an instance of the specified Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer.
111 * @return A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
112 * else @c null if an exception occurs @n
113 * The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
114 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
115 * @exception E_SUCCESS The method is successful.
116 * @exception E_OUT_OF_MEMORY The memory is insufficient.
117 * @exception E_INVALID_ARG The specified @c chars is empty or invalid.
118 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
119 * @remarks The specific error code can be accessed using the GetLastResult() method.
123 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars) const;
126 * Encodes an instance of the specified Tizen::Base::String into an instance of Tizen::Base::ByteBuffer.
130 * @return A pointer to the Tizen::Base::ByteBuffer instance where the resultant encoded string is stored, @n
131 * else @c null if an exception occurs @n
132 * The buffer limit is the position of the last encoded byte plus one and the starting position is zero.
133 * @param[in] str A string to encode
134 * @exception E_SUCCESS The method is successful.
135 * @exception E_OUT_OF_MEMORY The memory is insufficient.
136 * @exception E_INVALID_ARG The specified @c str is empty or invalid.
137 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
138 * @remarks The specific error code can be accessed using the GetLastResult() method.
141 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::String& str) const;
144 * Encodes an instance of Tizen::Base::WcharBuffer into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
145 * The position and limit of the %Tizen::Base::ByteBuffer instance is not changed.
149 * @return An error code
150 * @param[in] chars An instance of Tizen::Base::WcharBuffer to encode
151 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
152 * @param[in] charCount The total number of characters to encode
153 * @param[out] bytes The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
154 * @param[in] byteIndex The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
155 * @exception E_SUCCESS The method is successful.
156 * @exception E_OUT_OF_MEMORY The memory is insufficient.
157 * @exception E_INVALID_ARG A specified input parameter is invalid, or
158 * the specified @c chars or @c bytes is empty.
159 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method, or
160 * the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
161 * @exception E_UNDERFLOW This operation has caused the memory to underflow, or
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_OVERFLOW This operation has caused the memory to overflow, or
164 * the specified @c bytes does not contain sufficient space to store the encoded characters.
165 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
168 virtual result GetBytes(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
171 * Encodes an instance of Tizen::Base::String into an instance of Tizen::Base::ByteBuffer as per the specified range. @n
172 * The position and limit of the %Tizen::Base::ByteBuffer instance is not changed.
176 * @return An error code
177 * @param[in] str A string to encode
178 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
179 * @param[in] charCount The total number of characters to encode
180 * @param[out] bytes The Tizen::Base::ByteBuffer instance where the resultant encoded string is stored
181 * @param[in] byteIndex The starting index of the resultant encoding in the Tizen::Base::ByteBuffer instance
182 * @exception E_SUCCESS The method is successful.
183 * @exception E_OUT_OF_MEMORY The memory is insufficient.
184 * @exception E_INVALID_ARG A specified input parameter is invalid, or
185 * the specified @c str or @c bytes is empty.
186 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method, or
187 * the length of the specified @c charIndex or @c charCount is greater than the length of the specified @c str.
188 * @exception E_UNDERFLOW This operation has caused the memory to underflow, or
189 * the sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c str.
190 * @exception E_OVERFLOW This operation has caused the memory to overflow, or
191 * the specified @c bytes does not contain sufficient space to store the encoded characters.
192 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
195 virtual result GetBytes(const Tizen::Base::String& str, int charIndex, int charCount,
196 Tizen::Base::ByteBuffer& bytes, int byteIndex = 0) const;
199 * Decodes an instance of the specified Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer. @n
200 * The %GetCharsN() method does not maintain state consistency between conversions as this method is intended to
201 * convert complete blocks of bytes and characters in one operation and also to decode it in a single step.
205 * @return A pointer to the Tizen::Base::WcharBuffer instance where the resultant decoded data is stored, @n
206 * else @c null if an exception occurs @n
207 * The buffer limit is the position of the last decoded byte plus one and the starting position is zero.
208 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
209 * @exception E_SUCCESS The method is successful.
210 * @exception E_OUT_OF_MEMORY The memory is insufficient.
211 * @exception E_INVALID_ARG The specified @c bytes is empty or invalid.
212 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
213 * @remarks The specific error code can be accessed using the GetLastResult() method.
216 virtual Tizen::Base::WcharBuffer* GetCharsN(const Tizen::Base::ByteBuffer& bytes) const;
219 * Decodes an instance of Tizen::Base::ByteBuffer into an instance of Tizen::Base::WcharBuffer as per the specified range. @n
220 * The position and limit of the %Tizen::Base::WcharBuffer instance is not changed.
221 * The %GetChars() method does not maintain state consistency between conversions as this is intended to
222 * convert complete blocks of bytes and characters in one operation.
226 * @return An error code
227 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
228 * @param[in] byteIndex The index from where decoding begins
229 * @param[in] byteCount The total number of bytes to decode
230 * @param[out] chars The Tizen::Base::WcharBuffer instance where the resultant decoded string is stored
231 * @param[in] charIndex The index from where encoding begins in the Tizen::Base::WcharBuffer instance
232 * @exception E_SUCCESS The method is successful.
233 * @exception E_OUT_OF_MEMORY The memory is insufficient.
234 * @exception E_INVALID_ARG A specified input parameter is invalid, or
235 * the specified @c bytes or @c chars is empty.
236 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method, or
237 * the length of the specified @c byteIndex or @c byteCount is greater than the length of the specified @c bytes.
238 * @exception E_UNDERFLOW This operation has caused the memory to underflow, or
239 * the sum of the length of the specified @c byteIndex and @c byteCount is greater than the length of the specified @c bytes.
240 * @exception E_OVERFLOW This operation has caused the memory to overflow, or
241 * the specified @c chars does not contain sufficient space to store the decoded bytes.
242 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
245 virtual result GetChars(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount, Tizen::Base::WcharBuffer& chars, int charIndex = 0) const;
248 * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
252 * @return An error code
253 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
254 * @param[out] str A Tizen::Base::String instance @n
255 * It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
256 * @exception E_SUCCESS The method is successful.
257 * @exception E_OUT_OF_MEMORY The memory is insufficient.
258 * @exception E_INVALID_ARG A specified input parameter is invalid, or
259 * the specified @c bytes is empty.
260 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds of the character encoding scheme.
261 * @remarks This method assumes that the Tizen::Base::ByteBuffer instance contains all the bytes necessary to generate the entire string.
262 * If the bytes are in multiple byte arrays, use the Decoder class, which maintains state consistency
263 * between multiple calls.
266 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, Tizen::Base::String& str) const;
269 * Gets a string containing the decoded representation of the specified Tizen::Base::ByteBuffer instance.
273 * @return An error code
274 * @param[in] bytes An instance of Tizen::Base::ByteBuffer to decode
275 * @param[in] index The index from where decoding begins
276 * @param[in] count The total number of bytes to decode
277 * @param[out] str A Tizen::Base::String instance @n
278 * It contains the decoded representation of the specified Tizen::Base::ByteBuffer instance.
279 * @exception E_SUCCESS The method is successful.
280 * @exception E_OUT_OF_MEMORY The memory is insufficient.
281 * @exception E_INVALID_ARG A specified input parameter is invalid, or
282 * the specified @c bytes is empty.
283 * @exception E_OUT_OF_RANGE The value of an argument is outside the valid range defined by the method, or
284 * the sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
285 * @exception E_UNDERFLOW This operation has caused the memory to underflow, or
286 * the sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
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 assumes that the Tizen::Base::ByteBuffer instance contains all the bytes necessary to generate the entire string.
289 * If the bytes are in multiple byte arrays, use the Decoder class, which maintains state consistency
290 * between multiple calls.
293 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, int index, int count, Tizen::Base::String& str) const;
296 * Gets the maximum number of bytes required for encoding a given number of characters.
300 * @return The maximum number of bytes required for encoding a given number of characters
301 * @param[in] charCount The total number of characters to encode
302 * @remarks This method determines an appropriate buffer size for the byte arrays passed to GetBytes() for encoding.
303 * @see Encoding::GetByteCount()
306 virtual int GetMaxByteCount(int charCount) const;
309 * Gets the maximum number of characters that are generated by decoding the specified number of bytes.
313 * @return The maximum number of characters that are generated by decoding the specified number of bytes
314 * @param[in] byteCount The total number of bytes to encode
315 * @remarks This method determines an appropriate buffer size for character arrays passed to
316 * GetChars() or a decoder for encoding.
317 * @see Encoding::GetCharCount()
320 virtual int GetMaxCharCount(int byteCount) const;
324 * Gets the encoder for the current encoding.
328 * @return A pointer to the Encoder instance for the current encoding
329 * @remarks Contrary to GetBytes(), an encoder can convert partial sequences of characters into
330 * partial sequences of bytes by maintaining the appropriate state between the conversions. @n
331 * At present, only the Utf8Encoding class supports this method. Other classes return @c null.
334 virtual Encoder* GetEncoderN(void) const;
337 * Gets the decoder for the current encoding.
341 * @return A pointer to the Decoder instance for the current encoding
342 * @remarks Contrary to GetChars(), a decoder can convert partial sequences of bytes
343 * into partial sequences of characters by maintaining the appropriate state between the conversions. @n
344 * At present, only the Utf8Encoding class supports this method. Other classes return @c null.
348 virtual Decoder* GetDecoderN(void) const;
351 * Gets the encoding type of the current instance.
355 * @return An encoding type
357 virtual Tizen::Base::String GetEncodingType(void) const;
361 * The implementation of this copy constructor is intentionally blank and declared as private to
362 * prohibit copying of objects.
364 AsciiEncoding(const AsciiEncoding& asciiEncoding);
367 * The implementation of this copy assignment operator is intentionally blank and declared as private
368 * to prohibit copying of objects.
370 AsciiEncoding& operator =(const AsciiEncoding& asciiEncoding);
372 friend class _AsciiEncodingImpl;
373 class _AsciiEncodingImpl* __pAsciiEncodingImpl;
377 #endif //_FTEXT_ASCII_ENCODING_H_