Fixed a defect of GsmEncoding
[platform/framework/native/appfw.git] / src / text / FText_EncoderImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FText_EncoderImpl.h
20  * @brief               This is the header file for the _EncoderImpl class.
21  */
22
23 #ifndef _FTEXT_INTERNAL_ENCODER_IMPL_H_
24 #define _FTEXT_INTERNAL_ENCODER_IMPL_H_
25
26 // Include
27 #include <unique_ptr.h>
28 #include <FTextEncoder.h>
29 #include <FBase.h>
30
31
32 namespace Tizen { namespace Text
33 {
34
35 class _EncodingCore;
36
37 class _EncoderImpl
38         : public Encoder
39 {
40 // Lifecycle
41 public:
42         /**
43          * This is the destructor for this class.
44          *
45          * @since       1.0
46          */
47         virtual ~_EncoderImpl(void);
48
49         static _EncoderImpl* GetEncoderN(const Tizen::Base::String& encodingType);
50 // Operations
51 // Operations
52 public:
53         /**
54          * Calculates the number of bytes required to encode a range of characters in the specified WcharBuffer.
55          *
56          * @since               1.0
57          * @return              An error code
58          * @param[in]   chars                       The buffer containing the character array to encode
59          * @param[in]   charIndex                   The starting index of the WcharBuffer to encode
60          * @param[in]   charCount                   The number of characters to encode
61          * @param[in]   flush                       Set to @c true, to allow this instance to flush its state at the end of the conversion @n
62          *                                          @c false, otherwise
63          * @param[out]  byteCount                   The number of bytes required to encode the specified range of characters
64          * @exception   E_SUCCESS                   The method was successful.
65          * @exception   E_INVALID_ARG               A specified input parameter is invalid. @n
66          *                                          The specified @c chars is empty.
67          * @exception   E_OUT_OF_RANGE              The value of the argument is outside the valid range defined by the method. @n
68          *                                          The length of the specified @c charIndex or @c charCount is greater than the @n
69          *                                          length of the specified @c chars.
70          * @exception   E_UNDERFLOW                 This operation caused an underflow. @n
71          *                                          The sum of the length of the specified @c charIndex and @c charCount is greater
72          *                                          than the length of the specified @c chars.
73          * @exception   E_INVALID_ENCODING_RANGE    The specified string contains code points, which are outside the bounds specified @n
74          *                                          by the character encoding scheme.
75          *
76          * @see                         Decoder::GetCharCount()
77          */
78         virtual result GetByteCount(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, int& byteCount, bool flush = false) const;
79
80         /**
81          * Encodes a specified WcharBuffer into a ByteBuffer.
82          *
83          * @since                       1.0
84          * @return              A new ByteBuffer where the resulting encoded string is stored @n
85          *                                              @c null, if an exception occurs @n
86          *                                              The buffer's limit is the position of the last encoded byte plus one in the buffer, and the position is zero
87          * @param[in]   chars The WcharBuffer to encode
88          * @param[in]   flush Set to @c true, to allow this instance to flush its state at the end of the conversion @n
89          *                              @c false, otherwise
90          * @exception   E_SUCCESS                The method was successful.
91          * @exception   E_OUT_OF_MEMORY          Insufficient memory.
92          * @exception   E_INVALID_ARG            A specified input parameter is invalid. @n
93          *                                         The specified @c chars is empty.
94          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points, which are outside the bounds specified by the character encoding scheme.
95          * @remarks             The specific error code can be accessed using the GetLastResult() method.
96          *
97          * @see       Decoder::GetCharsN()
98          */
99         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, bool flush = false) const;
100
101         /**
102          * Encodes a range of characters from a WcharBuffer into a ByteBuffer.
103          *
104          * @since                       1.0
105          * @return              A new ByteBuffer where the resulting encoded string is stored @n
106          *                                              @c null if an exception occurs @n
107          *                                              The buffer's limit is the position of the last encoded byte in the buffer, and the position is zero
108          * @param[in]   chars The buffer containing the character array to encode
109          * @param[in]   charIndex The starting index of the WcharBuffer to encode
110          * @param[in]   charCount The number of characters to encode
111          * @param[in] flush Set to @c true, to allow this instance to flush its state at the end of the conversion @n
112          *                                              @c false, otherwise
113          * @exception   E_SUCCESS                The method was successful.
114          * @exception   E_OUT_OF_MEMORY          Insufficient memory.
115          * @exception   E_INVALID_ARG            A specified input parameter is invalid. @n
116          *                                         The specified @c chars is empty.
117          * @exception   E_OUT_OF_RANGE       The value of the argument is outside the valid range defined by the method. @n
118          *                                         The length of the specified @c charIndex or @c charCount is greater than the length of the specified @c chars.
119          * @exception   E_UNDERFLOW                  This operation caused an underflow. @n
120          *                                         The sum of the length of the specified @c charIndex and @c charCount is greater than the length of the specified @c chars.
121          * @exception   E_INVALID_ENCODING_RANGE The specified string contains code points, which are outside the bounds specified by the character encoding scheme.
122          * @remarks             The specific error code can be accessed using the GetLastResult() method.
123          * @remarks             The new ByteBuffer isn't terminated by @c null character.
124          *
125          * @see         Decoder::GetCharsN()
126          */
127         virtual Tizen::Base::ByteBuffer* GetBytesN(const Tizen::Base::WcharBuffer& chars, int charIndex, int charCount, bool flush = false) const;
128
129 private:
130         _EncoderImpl();
131
132         result GetBufferSize(const Tizen::Base::WcharBuffer& chars, int& charBufSize) const;
133         result CheckBufferInput(int inBufSize, int inIndex, int inCount) const;
134         result Encode(const wchar_t* pSrc, int srcLength, Tizen::Base::ByteBuffer*& pByteBuffer, int index, bool flush) const;
135
136         _EncoderImpl(const _EncoderImpl& encoderImpl);
137         _EncoderImpl& operator =(const _EncoderImpl& encoderImpl);
138
139 private:
140         std::unique_ptr<_EncodingCore> __pEncoder;
141         Tizen::Base::String __encodingType;
142
143 }; // _EncoderImpl
144
145 } } // Tizen::Text
146
147 #endif  //_FTEXT_INTERNAL_ENCODER_IMPL_H_