sync with tizen_2.0
[platform/framework/native/appfw.git] / src / text / FTextUcs2Encoding.cpp
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                FTextUcs2Encoding.cpp
20  * @brief               This is the implementation file for UCS2 Encoding class.
21  */
22
23 #include <FTextUcs2Encoding.h>
24 #include <FBaseSysLog.h>
25 #include "FText_EncodingImpl.h"
26
27
28 #define ENCODING_NAME L"UCS-2"
29
30 using namespace Tizen::Base;
31
32 namespace Tizen { namespace Text
33 {
34
35
36 Ucs2Encoding::Ucs2Encoding(void)
37         : __pUcs2EncodingImpl(null)
38 {
39         _pEncodingImpl = new (std::nothrow) _EncodingImpl;
40         if (_pEncodingImpl)
41         {
42                 result r = _pEncodingImpl->Construct(ENCODING_NAME);
43                 if (IsFailed(r))
44                 {
45                         delete _pEncodingImpl;
46                         _pEncodingImpl = null;
47                 }
48         }
49
50         SysAssert(_pEncodingImpl);
51 }
52
53
54 Ucs2Encoding::~Ucs2Encoding(void)
55 {
56         delete _pEncodingImpl;
57 }
58
59
60 result
61 Ucs2Encoding::GetByteCount(const String& str, int& byteCount) const
62 {
63         return _pEncodingImpl->GetByteCount(str, byteCount);
64 }
65
66
67 result
68 Ucs2Encoding::GetByteCount(const WcharBuffer& chars, int& byteCount) const
69 {
70         return _pEncodingImpl->GetByteCount(chars, byteCount);
71 }
72
73
74 result
75 Ucs2Encoding::GetByteCount(const WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const
76 {
77         return _pEncodingImpl->GetByteCount(chars, charIndex, charCount, byteCount);
78 }
79
80
81 ByteBuffer*
82 Ucs2Encoding::GetBytesN(const WcharBuffer& chars) const
83 {
84         return _pEncodingImpl->GetBytesN(chars);
85 }
86
87
88 ByteBuffer*
89 Ucs2Encoding::GetBytesN(const String& str) const
90 {
91         return _pEncodingImpl->GetBytesN(str);
92 }
93
94
95 result
96 Ucs2Encoding::GetBytes(const WcharBuffer& chars, int charIndex, int charCount, ByteBuffer& bytes, int byteIndex) const
97 {
98         return _pEncodingImpl->GetBytes(chars, charIndex, charCount, bytes, byteIndex);
99 }
100
101
102 result
103 Ucs2Encoding::GetBytes(const String& str, int charIndex, int charCount, ByteBuffer& bytes, int byteIndex) const
104 {
105         return _pEncodingImpl->GetBytes(str, charIndex, charCount, bytes, byteIndex);
106 }
107
108
109 result
110 Ucs2Encoding::GetCharCount(const ByteBuffer& bytes, int& charCount) const
111 {
112         return _pEncodingImpl->GetCharCount(bytes, charCount);
113 }
114
115
116 result
117 Ucs2Encoding::GetCharCount(const ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const
118 {
119         return _pEncodingImpl->GetCharCount(bytes, byteIndex, byteCount, charCount);
120 }
121
122
123 WcharBuffer*
124 Ucs2Encoding::GetCharsN(const ByteBuffer& bytes) const
125 {
126         return _pEncodingImpl->GetCharsN(bytes);
127 }
128
129
130 result
131 Ucs2Encoding::GetChars(const ByteBuffer& bytes, int byteIndex, int byteCount, WcharBuffer& chars, int charIndex) const
132 {
133         return _pEncodingImpl->GetChars(bytes, byteIndex, byteCount, chars, charIndex);
134 }
135
136
137 result
138 Ucs2Encoding::GetString(const ByteBuffer& bytes, String& str) const
139 {
140         return _pEncodingImpl->GetString(bytes, str);
141 }
142
143
144 result
145 Ucs2Encoding::GetString(const ByteBuffer& bytes, int byteIndex, int byteCount, String& str) const
146 {
147         return _pEncodingImpl->GetString(bytes, byteIndex, byteCount, str);
148 }
149
150
151 int
152 Ucs2Encoding::GetMaxByteCount(int charCount) const
153 {
154         return (charCount + 1) * 2;
155 }
156
157
158 int
159 Ucs2Encoding::GetMaxCharCount(int byteCount) const
160 {
161         return byteCount;
162 }
163
164
165 Encoder*
166 Ucs2Encoding::GetEncoderN(void) const
167 {
168         return null;
169 }
170
171
172 Decoder*
173 Ucs2Encoding::GetDecoderN(void) const
174 {
175         return null;
176 }
177
178
179 String
180 Ucs2Encoding::GetEncodingType(void) const
181 {
182         return String(ENCODING_NAME);
183 }
184
185 } } // Tizen::Text