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 pEncoderDecoder = _Ucs2EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
58 return pEncoderDecoder;
61 pEncoderDecoder = _IcuEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
64 return pEncoderDecoder;
67 pEncoderDecoder = _GsmEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
70 return pEncoderDecoder;
73 pEncoderDecoder = _Iso885916EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
76 return pEncoderDecoder;
83 _EncodingCore::GetAvailableEncodingsN(void)
88 unique_ptr<LinkedList, AllElementsDeleter> pList(new (std::nothrow) LinkedList());
89 SysTryReturn(NID_TEXT, pList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
91 _IcuEncodingCore icuConverter;
92 _GsmEncodingCore gsmConverter;
93 _Ucs2EncodingCore ucs2Converter;
94 _Iso885916EncodingCore iso885916Converter;
96 r = icuConverter.GetAvailableEncodingsN(pList.get());
97 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Available encoding list is empty. List allocation failed.", GetErrorMessage(r));
99 r = gsmConverter.GetAvailableEncodingsN(pList.get());
100 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Available encoding list is empty. List allocation failed.", GetErrorMessage(r));
102 r = ucs2Converter.GetAvailableEncodingsN(pList.get());
103 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Available encoding list is empty. List allocation failed.", GetErrorMessage(r));
105 r = iso885916Converter.GetAvailableEncodingsN(pList.get());
106 SysTryReturn(NID_TEXT, !IsFailed(r), null, r, "[%s] Available encoding list is empty. List allocation failed.", GetErrorMessage(r));
108 return pList.release();
112 _EncodingCore::ConvertN(_EncodingCore* pDstConverter, const byte* pSrc, int srcLength, int& retLength)
114 result r = E_SUCCESS;
116 SysTryReturn(NID_TEXT, pDstConverter != null, null, E_INVALID_ARG,
117 "[%s] Invalid argument is used. Unable to get encoder decoder object. pDstConverter can not be null", GetErrorMessage(E_INVALID_ARG));
119 unique_ptr<wchar_t[]> pWchar(DecodeN(pSrc, srcLength, retLength));
121 SysTryReturn(NID_TEXT, (pWchar != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
123 unique_ptr<byte[]> pByte(pDstConverter->EncodeN(pWchar.get(), retLength, retLength));
125 SysTryReturn(NID_TEXT, (pByte != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
127 SetLastResult(E_SUCCESS);
128 return pByte.release();
132 _EncodingCore::EncodeExN(const wchar_t* pSrc, int srcLength, int& retLength, bool flush)
134 SetLastResult(E_UNSUPPORTED_OPERATION);
139 _EncodingCore::DecodeExN(const byte* pSrc, int srcLength, int& retLength, bool flush)
141 SetLastResult(E_UNSUPPORTED_OPERATION);