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 FText_EncodingCore.cpp
20 * @brief This is the implementation file for _EncodingCore class.
24 #include <unique_ptr.h>
25 #include "FText_EncodingCore.h"
26 #include <FBaseSysLog.h>
27 #include <FBaseColLinkedList.h>
28 #include "FText_IcuEncodingCore.h"
29 #include "FText_GsmEncodingCore.h"
30 #include "FText_Ucs2EncodingCore.h"
31 #include "FText_Iso885916EncodingCore.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
37 namespace Tizen { namespace Text
40 _EncodingCore::_EncodingCore(void)
46 _EncodingCore::~_EncodingCore(void)
52 _EncodingCore::GetEncodingCoreN(const Tizen::Base::String& encodingFrom, const Tizen::Base::String& encodingTo)
54 _EncodingCore* pEncoderDecoder = null;
56 pEncoderDecoder = _Ucs2EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
59 return pEncoderDecoder;
62 pEncoderDecoder = _IcuEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
65 return pEncoderDecoder;
68 pEncoderDecoder = _GsmEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
71 return pEncoderDecoder;
74 pEncoderDecoder = _Iso885916EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
77 return pEncoderDecoder;
84 _EncodingCore::GetAvailableEncodingsN(void)
89 unique_ptr<LinkedList, AllElementsDeleter> pList(new (std::nothrow) LinkedList());
90 SysTryReturn(NID_TEXT, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
92 _IcuEncodingCore icuConverter;
93 _GsmEncodingCore gsmConverter;
94 _Ucs2EncodingCore ucs2Converter;
95 _Iso885916EncodingCore iso885916Converter;
97 r = icuConverter.GetAvailableEncodingsN(pList.get());
98 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Available encoding list is empty. List allocation failed.", GetErrorMessage(r));
100 r = gsmConverter.GetAvailableEncodingsN(pList.get());
101 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Available encoding list is empty. List allocation failed.", GetErrorMessage(r));
103 r = ucs2Converter.GetAvailableEncodingsN(pList.get());
104 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Available encoding list is empty. List allocation failed.", GetErrorMessage(r));
106 r = iso885916Converter.GetAvailableEncodingsN(pList.get());
107 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Available encoding list is empty. List allocation failed.", GetErrorMessage(r));
109 return pList.release();
113 _EncodingCore::ConvertN(_EncodingCore* pDstConverter, const byte* pSrc, int srcLength, int& retLength)
115 result r = E_SUCCESS;
117 SysTryReturn(NID_TEXT, pDstConverter != null, null, E_INVALID_ARG,
118 "[%s] Invalid argument is used. Unable to get encoder decoder object. pDstConverter can not be null", GetErrorMessage(E_INVALID_ARG));
120 unique_ptr<wchar_t[]> pWchar(DecodeN(pSrc, srcLength, retLength));
122 SysTryReturn(NID_TEXT, (pWchar != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
124 unique_ptr<byte[]> pByte(pDstConverter->EncodeN(pWchar.get(), retLength, retLength));
126 SysTryReturn(NID_TEXT, (pByte != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
128 SetLastResult(E_SUCCESS);
129 return pByte.release();
133 _EncodingCore::EncodeExN(const wchar_t* pSrc, int srcLength, int& retLength, bool flush)
135 SetLastResult(E_UNSUPPORTED_OPERATION);
140 _EncodingCore::DecodeExN(const byte* pSrc, int srcLength, int& retLength, bool flush)
142 SetLastResult(E_UNSUPPORTED_OPERATION);