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 FText_EncodingImpl.h
20 * @brief This is the header file for the _EncodingImpl class.
23 #ifndef _FTEXT_INTERNAL_ENCODING_IMPL_H_
24 #define _FTEXT_INTERNAL_ENCODING_IMPL_H_
27 #include <unique_ptr.h>
28 #include <FTextEncoding.h>
32 namespace Tizen { namespace Text
43 * This is the constructor for this class.
49 * This is the destructor for this class.
51 virtual ~_EncodingImpl(void);
55 * Constructs the instance of this class.
57 result Construct(const Tizen::Base::String& encoding);
63 * Calculates the number of bytes required to encode the specified string.
66 * @return An error code
67 * @param[in] str The string to encode
68 * @param[out] byteCount The number of bytes required to encode @c str
70 * @exception E_SUCCESS The method was successful.
71 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
72 * The specified @c str is an empty string.
73 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds @n
74 * specified by the character encoding scheme.
76 * @remarks This method can be used to determine the exact number of bytes
77 * that are produced if the specified string is encoded.
79 * @see GetMaxByteCount()
81 virtual result GetByteCount(const Tizen::Base::String& str, int& byteCount) const;
84 * Calculates the number of bytes required to encode the specified characters.
87 * @return An error code
88 * @param[in] chars The buffer containing the character array to encode
89 * @param[out] byteCount The number of bytes required to encode the specified range of characters
90 * @exception E_SUCCESS The method was successful.
91 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
92 * The specified @c chars is empty.
93 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
94 * @remarks This method can be used to determine the exact number of bytes
95 * that are produced if the specified array of characters is encoded.
97 * @see GetMaxByteCount(), GetByteCount()
99 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int& byteCount) const;
102 * Calculates the number of bytes required to encode a range of characters in the specified WcharBuffer.
105 * @return An error code
106 * @param[in] chars The buffer containing the character array to encode
107 * @param[in] charIndex The starting index of the WcharBuffer to encode
108 * @param[in] charCount The number of characters to encode
109 * @param[out] byteCount The number of bytes required to encode the specified range of characters
110 * @exception E_SUCCESS The method was successful.
111 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
112 * The specified @c chars is empty.
113 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method. @n
114 * The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
115 * @exception E_UNDERFLOW This operation has caused an underflow. @n
116 * The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
117 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
118 * @remarks This method can be used to determine the exact number of bytes
119 * that are produced if the specified array of characters is encoded.
121 * @see GetMaxByteCount(), GetByteCount()
123 virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const;
126 * Encodes the specified WcharBuffer into a ByteBuffer.
129 * @return A new ByteBuffer where the resulting encoded string is stored @n
130 * @c null, if an exception occurs @n
131 * The buffer's limit is the position of the last encoded byte plus one in the buffer, and the position @c 0
132 * @param[in] chars The WcharBuffer to encode
133 * @exception E_SUCCESS The method was successful.
134 * @exception E_OUT_OF_MEMORY Insufficient memory.
135 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
136 * The specified @c chars is empty.
137 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
138 * @remarks The specific error code can be accessed using the GetLastResult() method.
140 * @see GetCharsN(), GetBytesN()
142 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars) const;
145 * Encodes the specified string into a ByteBuffer.
148 * @return A new ByteBuffer where the resulting encoded string is stored @n
149 * @c null, if an exception occurs @n
150 * The buffer's limit is the position of the last encoded byte plus one in the buffer, and the position @c 0
151 * @param[in] str The string to encode
152 * @exception E_SUCCESS The method was successful.
153 * @exception E_OUT_OF_MEMORY Insufficient memory.
154 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
155 * The specified @c str is an empty string.
156 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
157 * @remarks The specific error code can be accessed using the GetLastResult() method.
161 virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::String& str) const;
164 * Encodes a range of characters from the specified WcharBuffer into a ByteBuffer.
165 * The ByteBuffer's position and limit are not changed.
168 * @return An error code
169 * @param[in] chars The buffer containing the character array to encode
170 * @param[in] charIndex The starting index of the WcharBuffer to encode
171 * @param[in] charCount The number of characters to encode
172 * @param[out] bytes The ByteBuffer where the resulting encoded string is stored
173 * @param[in] byteIndex The starting index of the resulting encoding in the ByteBuffer
174 * @exception E_SUCCESS The method was successful.
175 * @exception E_OUT_OF_MEMORY Insufficient memory.
176 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
177 * The specified @c chars or @c bytes is empty.
178 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method. @n
179 * The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
180 * @exception E_UNDERFLOW This operation has caused an underflow. @n
181 * The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
182 * @exception E_OVERFLOW This operation has caused an overflow. @n
183 * The specified @c bytes do not contain sufficient space to store the encoded characters.
184 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
185 * @remarks This method encodes a range of characters in a WcharBuffer into a range of bytes in a ByteBuffer.
189 virtual result GetBytes(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, Tizen::Base::ByteBuffer& bytes, int byteIndex) const;
192 * Encodes the specified range of a string into the specified range of a ByteBuffer.
193 * The ByteBuffer's position and limit are not changed.
196 * @return An error code
197 * @param[in] str The string to encode
198 * @param[in] charIndex The starting index of the WcharBuffer to encode
199 * @param[in] charCount The number of characters to encode
200 * @param[out] bytes The ByteBuffer where the resulting encoded string is stored
201 * @param[in] byteIndex The starting index of the resulting encoding in the ByteBuffer
202 * @exception E_SUCCESS The method was successful.
203 * @exception E_OUT_OF_MEMORY Insufficient memory.
204 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
205 * The specified @c str or @c bytes is empty.
206 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method. @n
207 * The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c str.
208 * @exception E_UNDERFLOW This operation has caused an underflow. @n
209 * The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c str.
210 * @exception E_OVERFLOW This operation has caused an overflow. @n
211 * The specified @c bytes does not contain sufficient space to store the encoded characters.
212 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
216 virtual result GetBytes(const Tizen::Base::String& str, int charIndex, int charCount, Tizen::Base::ByteBuffer& bytes, int byteIndex) const;
219 * Calculates the number of characters produced by decoding a ByteBuffer.
222 * @return An error code
223 * @param[in] bytes The ByteBuffer to decode
224 * @param[out] charCount The number of characters produced by decoding a range of bytes in the specified ByteBuffer
225 * @exception E_SUCCESS The method was successful.
226 * @exception E_OUT_OF_MEMORY Insufficient memory.
227 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
228 * The specified @c bytes is empty.
229 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
230 * @remarks This method can be used to determine the exact number of characters
231 * that are produced if the specified range of bytes is encoded.
233 * @see GetMaxCharCount(), GetCharCount()
235 virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int& charCount) const;
238 * Calculates the number of characters produced by decoding a specified range of elements in a ByteBuffer.
241 * @return An error code
242 * @param[in] bytes The ByteBuffer to decode
243 * @param[in] byteIndex The starting index where decoding begins
244 * @param[in] byteCount The number of bytes to decode
245 * @param[out] charCount The number of characters produced by decoding a range of bytes in the specified ByteBuffer
246 * @exception E_SUCCESS The method was successful.
247 * @exception E_OUT_OF_MEMORY Insufficient memory.
248 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
249 * The specified @c bytes is empty.
250 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method. @n
251 * The length of the specified @c byteIndex or @c byteCount is greater than the length of the specified @c bytes.
252 * @exception E_UNDERFLOW This operation has caused an underflow. @n
253 * The sum of the length of the specified @c byteIndex and @c byteCount is greater than the length of the specified @c bytes.
254 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
255 * @remarks This method can be used to determine the exact number of characters
256 * that are produced if the specified range of bytes is encoded.
258 * @see GetMaxCharCount(), GetCharCount()
260 virtual result GetCharCount(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const;
263 * Decodes a ByteBuffer into a WcharBuffer.
266 * @return A new WcharBuffer where the resulting decoded data is stored @n
267 * @c null, if an exception occurs @n
268 * The buffer's limit is the position of the last decoded byte plus one in the buffer, and the position is @c 0
269 * @param[in] bytes The buffer containing ByteBuffer to decode
270 * @exception E_SUCCESS The method was successful.
271 * @exception E_OUT_OF_MEMORY Insufficient memory.
272 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
273 * The specified @c bytes is empty.
274 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
275 * @remarks The specific error code can be accessed using the GetLastResult() method.
277 * @see GetBytesN(), GetCharsN()
279 virtual Tizen::Base::WcharBuffer* GetCharsN(const Tizen::Base::ByteBuffer& bytes) const;
282 * Decodes a range of bytes in ByteBuffer into a range of characters in WcharBuffer.
283 * The WcharBuffer's position and limit are not changed.
286 * @return An error code
287 * @param[in] bytes The buffer containing the ByteBuffer to decode
288 * @param[in] byteIndex The starting index where decoding begins
289 * @param[in] byteCount The number of bytes to decode
290 * @param[out] chars The buffer containing WcharBuffer where the resulting decoded data is stored
291 * @param[in] charIndex The starting index of the resulting decoding in the WcharBuffer
292 * @exception E_SUCCESS The method was successful.
293 * @exception E_OUT_OF_MEMORY Insufficient memory.
294 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
295 * The specified @c bytes is empty.
296 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method. @n
297 * The length of the specified @c byteIndex or @c byteCount is greater than the length of the specified @c bytes.
298 * @exception E_UNDERFLOW This operation has caused an underflow. @n
299 * The sum of the length of the specified @c byteIndex and @c byteCount is greater than the length of the specified @c bytes.
300 * @exception E_OVERFLOW This operation has caused an overflow. @n
301 * The specified @c chars does not contain sufficient space to store the decoded bytes.
302 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
304 * @see GetBytes(), GetChars()
306 virtual result GetChars(const Tizen::Base::ByteBuffer& bytes, int byteIndex, int byteCount, Tizen::Base::WcharBuffer& chars, int charIndex) const;
309 * Gets a string containing the decoded representation of a range of bytes in the specified ByteBuffer.
312 * @return An error code
313 * @param[in] bytes The ByteBuffer to decode
314 * @param[out] str A String containing the decoded representation of a range of bytes in the specified ByteBuffer
315 * @exception E_SUCCESS The method was successful.
316 * @exception E_OUT_OF_MEMORY Insufficient memory.
317 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
318 * The specified @c bytes is empty.
319 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
321 * @see GetBytesN(), GetString()
323 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, Tizen::Base::String& str) const;
326 * Gets a string containing the decoded representation of a range of bytes in the specified ByteBuffer.
329 * @return An error code
330 * @param[in] bytes The buffer containing the ByteBuffer to decode
331 * @param[in] index The starting index where decoding begins
332 * @param[in] count The number of bytes to decode
333 * @param[out] str A String containing the decoded representation of a range of bytes in the specified ByteBuffer
334 * @exception E_SUCCESS The method was successful.
335 * @exception E_OUT_OF_MEMORY Insufficient memory.
336 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
337 * The specified @c bytes is empty.
338 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method. @n
339 * The sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
340 * @exception E_UNDERFLOW This operation has caused an underflow. @n
341 * The sum of the length of the specified @c index and @c count is greater than the length of the specified @c bytes.
342 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
344 * @see GetBytes(), GetString()
346 virtual result GetString(const Tizen::Base::ByteBuffer& bytes, int index, int count, Tizen::Base::String& str) const;
349 * Gets the maximum number of bytes required for encoding the specified number of characters.
352 * @return The maximum number of bytes required for encoding a given number of characters
353 * @param[in] charCount The number of characters to encode
354 * @remarks This method can be used to determine an appropriate buffer size for the byte arrays passed to the GetBytes() method for encoding.
356 * @see GetByteCount(), GetBytes()
358 virtual int GetMaxByteCount(int charCount) const;
361 * Gets the maximum number of characters produced by decoding the specified number of bytes.
364 * @return The maximum number of characters produced by decoding the specified number of bytes
365 * @param[in] byteCount The number of bytes to encode
366 * @remarks This method can be used to determine an appropriate buffer size for character arrays passed to
367 * GetChars() or a decoder for encoding.
369 * @see GetCharCount(), GetChars()
371 virtual int GetMaxCharCount(int byteCount) const;
374 * Gets the encoder for the current encoding.
377 * @return A pointer to Encoder for the current encoding
378 * @remarks Contrary to GetBytes(), an Encoder can convert partial sequences of characters into
379 * partial sequences of bytes by maintaining an appropriate state between the conversions. @n
380 * Currently, only Utf8Encoding supports this method. Other classes return @c null.
384 virtual Encoder* GetEncoderN(void) const;
387 * Gets the decoder for the current encoding.
390 * @return A decoder for the current encoding
391 * @remarks Contrary to the GetChars() methods, a Decoder can convert partial sequences of bytes
392 * into partial sequences of characters by maintaining an appropriate state between the conversions. @n
393 * Currently, only Utf8Encoding supports this method. Other classes return @c null.
397 virtual Decoder* GetDecoderN(void) const;
400 * Gets the encoding type of the current instance.
403 * @return An encoding type
405 virtual Tizen::Base::String GetEncodingType(void) const;
408 * Gets a list of all the available encodings.
411 * @return A list of String instances (ASCII, UTF-8, ISO-8859-1, ISO-8859-2, Windows-1254, ...) @n
412 * @c null, if the method fails
413 * @exception E_SUCCESS The method was successful.
414 * @exception E_SYSTEM A system error occurred.
415 * @remarks The specific error code can be accessed using the GetLastResult() method.
417 static Tizen::Base::Collection::IList* GetAvailableEncodingsImplN(void);
420 * Converts a range of bytes in a ByteBuffer from one encoding to another.
423 * @return A new buffer for storing result of the conversion @n
424 * @c null, if an exception occurs @n
425 * The buffer's limit is the position of the last converted byte plus one, and the position @c 0
426 * @param[in] src The source of the encoding
427 * @param[in] dst The destination of the encoding
428 * @param[in] srcBytes The ByteBuffer where the resulting encoded string is stored
429 * @param[in] index The starting index of the resulting encoding in the ByteBuffer
430 * @param[in] count The number of bytes to convert
431 * @exception E_SUCCESS The method was successful.
432 * @exception E_OUT_OF_MEMORY Insufficient memory.
433 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
434 * The specified @c srcBytes is empty.
435 * @exception E_OUT_OF_RANGE The value of the argument is outside the valid range defined by the method. @n
436 * The @c index or @c count is greater than the length of @c srcBytes.
437 * @exception E_UNDERFLOW This operation has caused an underflow. @n
438 * The sum of the length of the specified @c index and @c count is greater than the length of the specified @c srcBytes.
439 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
440 * @remarks The specific error code can be accessed using the GetLastResult() method.
442 * @see GetBytes(), GetChars()
444 static Tizen::Base::ByteBuffer* ConvertImplN(const Encoding& src, const Encoding& dst,
445 const Tizen::Base::ByteBuffer& srcBytes, int index, int count);
448 * Converts a ByteBuffer from one encoding to another.
451 * @return A new buffer for storing the result of the conversion @n
452 * @c null, if an exception occurs @n
453 * The buffer's limit is the position of the last converted byte plus one, and the position @c 0
454 * @param[in] src The source of the encoding
455 * @param[in] dst The destination of the encoding
456 * @param[in] srcBytes The ByteBuffer where the resulting encoded string is stored
457 * @exception E_SUCCESS The method was successful.
458 * @exception E_OUT_OF_MEMORY Insufficient memory.
459 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
460 * The specified @c srcBytes is empty.
461 * @exception E_INVALID_ENCODING_RANGE The specified string contains code points that are outside the bounds specified by the character encoding scheme.
462 * @remarks The specific error code can be accessed using the GetLastResult() method.
464 * @see GetBytes(), GetChars()
466 static Tizen::Base::ByteBuffer* ConvertImplN(const Encoding& src, const Encoding& dst,
467 const Tizen::Base::ByteBuffer& srcBytes);
471 result Encode(const wchar_t* pSrc, int srcLength, Tizen::Base::ByteBuffer*& pByteBuffer, int index) const;
472 result Decode(const byte* pSrc, int srcLength, Tizen::Base::WcharBuffer*& pWcharBuffer, int index) const;
473 result Decode(const byte* pSrc, int srcLength, Tizen::Base::String& outStr, int index) const;
475 result GetBufferSize(const Tizen::Base::WcharBuffer& chars, int& charBufSize) const;
476 result GetBufferSize(const Tizen::Base::ByteBuffer& bytes, int& byteBufSize) const;
477 result CheckBufferInput(int inBufSize, int inIndex, int inCount) const;
478 result CheckBufferInput(int inBufSize, int inIndex, int inCount, int outBufSize, int outIndex) const;
480 bool IsEncodingSupported(const Tizen::Base::String& encodingStr) const;
482 _EncodingImpl(const _EncodingImpl& encodingImpl);
483 _EncodingImpl& operator =(const _EncodingImpl& encodingImpl);
486 Tizen::Base::String __encodingType;
487 std::unique_ptr<_EncodingCore> __pEncodingCore;
489 friend class Encoding;
495 #endif //_FTEXT_INTERNAL_ENCODING_IMPL_H_