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 FTextEncoding.cpp
20 * @brief This is the implementation file for Encoding class.
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"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
34 namespace Tizen { namespace Text
37 Encoding::Encoding(void)
38 : _pEncodingImpl(null)
43 Encoding::~Encoding(void)
49 Encoding::GetByteCount(const String& str, int& byteCount) const
51 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
52 return _pEncodingImpl->GetByteCount(str, byteCount);
57 Encoding::GetByteCount(const WcharBuffer& chars, int& byteCount) const
59 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
60 return _pEncodingImpl->GetByteCount(chars, byteCount);
65 Encoding::GetByteCount(const WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const
67 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
68 return _pEncodingImpl->GetByteCount(chars, charIndex, charCount, byteCount);
72 Encoding::GetCharCount(const ByteBuffer& bytes, int& charCount) const
74 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
75 return _pEncodingImpl->GetCharCount(bytes, charCount);
80 Encoding::GetCharCount(const ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const
82 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
83 return _pEncodingImpl->GetCharCount(bytes, byteIndex, byteCount, charCount);
87 Encoding::GetUtf8Encoding(void)
89 static Utf8Encoding utf8;
94 Encoding::GetUcs2Encoding(void)
96 static Ucs2Encoding ucs2;
101 Encoding::GetGsmEncoding(void)
103 static GsmEncoding gsm;
108 Encoding::GetLatin1Encoding(void)
110 static Latin1Encoding latin1;
115 Encoding::GetAsciiEncoding(void)
117 static AsciiEncoding ascii;
122 Encoding::GetEncodingN(const Tizen::Base::String& encodingType)
125 result r = E_SUCCESS;
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));
130 r = pEncodingImpl->Construct(encodingType);
131 SysTryCatch(NID_TEXT, (!IsFailed(r)), , r, "[%s] Encoder construct failed.", GetErrorMessage(r));
133 return pEncodingImpl;
136 delete pEncodingImpl;
141 Encoding::GetEncodingType(const Encoding& encoding)
143 return encoding.GetEncodingType();
147 Encoding::GetAvailableEncodingsN(void)
149 return _EncodingImpl::GetAvailableEncodingsImplN();
153 Encoding::ConvertN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes)
155 return _EncodingImpl::ConvertImplN(src, dst, srcBytes);
159 Encoding::ConvertN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes, int index, int count)
161 return _EncodingImpl::ConvertImplN(src, dst, srcBytes, index, count);