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 FText_EncodingCore.cpp
19 * @brief This is the implementation file for _EncodingCore class.
23 #include <unique_ptr.h>
24 #include "FText_EncodingCore.h"
25 #include <FBaseSysLog.h>
26 #include <FBaseColLinkedList.h>
27 #include "FText_IcuEncodingCore.h"
28 #include "FText_GsmEncodingCore.h"
29 #include "FText_Ucs2EncodingCore.h"
30 #include "FText_Iso885916EncodingCore.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace Text
39 _EncodingCore::_EncodingCore(void)
45 _EncodingCore::~_EncodingCore(void)
51 _EncodingCore::GetEncodingCoreN(const Tizen::Base::String& encodingFrom, const Tizen::Base::String& encodingTo)
53 _EncodingCore* pEncoderDecoder = null;
55 if (encodingFrom.Contains(L"UCS-2") == true)
57 pEncoderDecoder = _Ucs2EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
60 return pEncoderDecoder;
63 else if (encodingFrom.Contains(L"GSM") == true)
65 pEncoderDecoder = _GsmEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
68 return pEncoderDecoder;
71 else if (encodingFrom.Contains(L"ISO-8859-16") == true)
73 pEncoderDecoder = _Iso885916EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
76 return pEncoderDecoder;
81 pEncoderDecoder = _IcuEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
84 return pEncoderDecoder;
93 _EncodingCore::ConvertN(_EncodingCore* pDstConverter, const byte* pSrc, int srcLength, int& retLength)
97 SysTryReturn(NID_TEXT, pDstConverter != null, null, E_INVALID_ARG,
98 "[%s] Invalid argument is used. Unable to get encoder decoder object. pDstConverter can not be null", GetErrorMessage(E_INVALID_ARG));
100 unique_ptr<wchar_t[]> pWchar(DecodeN(pSrc, srcLength, retLength));
102 SysTryReturn(NID_TEXT, (pWchar != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
104 unique_ptr<byte[]> pByte(pDstConverter->EncodeN(pWchar.get(), retLength, retLength));
106 SysTryReturn(NID_TEXT, (pByte != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
108 SetLastResult(E_SUCCESS);
109 return pByte.release();
113 _EncodingCore::EncodeExN(const wchar_t* pSrc, int srcLength, int& retLength, bool flush)
115 SetLastResult(E_UNSUPPORTED_OPERATION);
120 _EncodingCore::DecodeExN(const byte* pSrc, int srcLength, int& retLength, bool flush)
122 SetLastResult(E_UNSUPPORTED_OPERATION);