2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FTextEncoding.cpp
19 * @brief This is the implementation file for Encoding class.
22 #include <FTextAsciiEncoding.h>
23 #include <FTextUtf8Encoding.h>
24 #include <FTextLatin1Encoding.h>
25 #include <FTextGsmEncoding.h>
26 #include <FTextUcs2Encoding.h>
27 #include <FBaseSysLog.h>
28 #include "FText_EncodingImpl.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
33 namespace Tizen { namespace Text
36 Encoding::Encoding(void)
37 : _pEncodingImpl(null)
42 Encoding::~Encoding(void)
48 Encoding::GetByteCount(const String& str, int& byteCount) const
50 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
51 return _pEncodingImpl->GetByteCount(str, byteCount);
56 Encoding::GetByteCount(const WcharBuffer& chars, int& byteCount) const
58 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
59 return _pEncodingImpl->GetByteCount(chars, byteCount);
64 Encoding::GetByteCount(const WcharBuffer& chars, int charIndex, int charCount, int& byteCount) const
66 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
67 return _pEncodingImpl->GetByteCount(chars, charIndex, charCount, byteCount);
71 Encoding::GetCharCount(const ByteBuffer& bytes, int& charCount) const
73 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
74 return _pEncodingImpl->GetCharCount(bytes, charCount);
79 Encoding::GetCharCount(const ByteBuffer& bytes, int byteIndex, int byteCount, int& charCount) const
81 SysAssertf(_pEncodingImpl != null, "Not yet constructed! Construct() should be called before use.");
82 return _pEncodingImpl->GetCharCount(bytes, byteIndex, byteCount, charCount);
86 Encoding::GetUtf8Encoding(void)
88 static Utf8Encoding utf8;
93 Encoding::GetUcs2Encoding(void)
95 static Ucs2Encoding ucs2;
100 Encoding::GetGsmEncoding(void)
102 static GsmEncoding gsm;
107 Encoding::GetLatin1Encoding(void)
109 static Latin1Encoding latin1;
114 Encoding::GetAsciiEncoding(void)
116 static AsciiEncoding ascii;
121 Encoding::GetEncodingN(const Tizen::Base::String& encodingType)
124 result r = E_SUCCESS;
126 std::unique_ptr< _EncodingImpl > pEncodingImpl(new (std::nothrow) _EncodingImpl());
127 SysTryReturn(NID_TEXT, pEncodingImpl != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
129 r = pEncodingImpl->Construct(encodingType);
130 SysTryReturn(NID_TEXT, !IsFailed(r), null, r , "[%s] Encoder construct failed.", GetErrorMessage(r));
131 return pEncodingImpl.release();
135 Encoding::GetEncodingType(const Encoding& encoding)
137 return encoding.GetEncodingType();
141 Encoding::GetAvailableEncodingsN(void)
143 return _EncodingImpl::GetAvailableEncodingsImplN();
147 Encoding::ConvertN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes)
149 return _EncodingImpl::ConvertImplN(src, dst, srcBytes);
153 Encoding::ConvertN(const Encoding& src, const Encoding& dst, const ByteBuffer& srcBytes, int index, int count)
155 return _EncodingImpl::ConvertImplN(src, dst, srcBytes, index, count);