sync with tizen_2.0
[platform/framework/native/appfw.git] / src / text / FTextEncoding.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                FTextEncoding.cpp
20  * @brief               This is the implementation file for Encoding class.
21  */
22
23 #include <FTextAsciiEncoding.h>
24 #include <FTextUtf8Encoding.h>
25 #include <FTextLatin1Encoding.h>
26 #include <FTextGsmEncoding.h>
27 #include <FTextUcs2Encoding.h>
28 #include <FBaseSysLog.h>
29 #include "FText_EncodingImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33
34 namespace Tizen { namespace Text
35 {
36
37 Encoding::Encoding(void)
38         : _pEncodingImpl(null)
39 {
40
41 }
42
43 Encoding::~Encoding(void)
44 {
45
46 }
47
48 result
49 Encoding::GetByteCount(const String& str, int& byteCount) const
50 {
51         SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
52         return _pEncodingImpl->GetByteCount(str, byteCount);
53 }
54
55
56 result
57 Encoding::GetByteCount(const WcharBuffer& chars, int& byteCount) const
58 {
59         SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
60         return _pEncodingImpl->GetByteCount(chars, byteCount);
61 }
62
63
64 result
65 Encoding::GetByteCount(const WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const
66 {
67         SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
68         return _pEncodingImpl->GetByteCount(chars, charIndex, charCount, byteCount);
69 }
70
71 result
72 Encoding::GetCharCount(const ByteBuffer& bytes, int& charCount) const
73 {
74         SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
75         return _pEncodingImpl->GetCharCount(bytes, charCount);
76 }
77
78
79 result
80 Encoding::GetCharCount(const ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const
81 {
82         SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
83         return _pEncodingImpl->GetCharCount(bytes, byteIndex, byteCount, charCount);
84 }
85
86 Utf8Encoding&
87 Encoding::GetUtf8Encoding(void)
88 {
89         static Utf8Encoding utf8;
90         return utf8;
91 }
92
93 Ucs2Encoding&
94 Encoding::GetUcs2Encoding(void)
95 {
96         static Ucs2Encoding ucs2;
97         return ucs2;
98 }
99
100 GsmEncoding&
101 Encoding::GetGsmEncoding(void)
102 {
103         static GsmEncoding gsm;
104         return gsm;
105 }
106
107 Latin1Encoding&
108 Encoding::GetLatin1Encoding(void)
109 {
110         static Latin1Encoding latin1;
111         return latin1;
112 }
113
114 AsciiEncoding&
115 Encoding::GetAsciiEncoding(void)
116 {
117         static AsciiEncoding ascii;
118         return ascii;
119 }
120
121 Encoding*
122 Encoding::GetEncodingN(const Tizen::Base::String& encodingType)
123 {
124         ClearLastResult();
125         result r = E_SUCCESS;
126
127         _EncodingImpl* pEncodingImpl = new (std::nothrow) _EncodingImpl();
128         SysTryReturn(NID_TEXT, pEncodingImpl != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
129
130         r = pEncodingImpl->Construct(encodingType);
131         SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Encoder construct failed.", GetErrorMessage(r));
132
133         return pEncodingImpl;
134
135 CATCH:
136         delete pEncodingImpl;
137         return null;
138 }
139
140 String
141 Encoding::GetEncodingType(const Encoding& encoding)
142 {
143         return encoding.GetEncodingType();
144 }
145
146 IList*
147 Encoding::GetAvailableEncodingsN(void)
148 {
149         return _EncodingImpl::GetAvailableEncodingsImplN();
150 }
151
152 ByteBuffer*
153 Encoding::ConvertN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes)
154 {
155         return _EncodingImpl::ConvertImplN(src, dst, srcBytes);
156 }
157
158 ByteBuffer*
159 Encoding::ConvertN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes, int index, int count)
160 {
161         return _EncodingImpl::ConvertImplN(src, dst, srcBytes, index, count);
162 }
163
164 } } // Tizen::Text