Fixed the memory leak
[platform/framework/native/appfw.git] / src / text / FText_EncodingCore.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FText_EncodingCore.cpp
19  * @brief               This is the implementation file for _EncodingCore class.
20  */
21
22 // Includes
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"
31
32 using namespace std;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35
36 namespace Tizen { namespace Text
37 {
38
39 _EncodingCore::_EncodingCore(void)
40         : _encodingTo()
41         , _encodingFrom()
42 {
43 }
44
45 _EncodingCore::~_EncodingCore(void)
46 {
47 }
48
49
50 _EncodingCore*
51 _EncodingCore::GetEncodingCoreN(const Tizen::Base::String& encodingFrom, const Tizen::Base::String& encodingTo)
52 {
53         _EncodingCore* pEncoderDecoder = null;
54
55         pEncoderDecoder = _Ucs2EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
56         if (pEncoderDecoder)
57         {
58                 return pEncoderDecoder;
59         }
60
61         pEncoderDecoder = _IcuEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
62         if (pEncoderDecoder)
63         {
64                 return pEncoderDecoder;
65         }
66
67         pEncoderDecoder = _GsmEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
68         if (pEncoderDecoder)
69         {
70                 return pEncoderDecoder;
71         }
72
73         pEncoderDecoder = _Iso885916EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
74         if (pEncoderDecoder)
75         {
76                 return pEncoderDecoder;
77         }
78
79         return null;
80 }
81
82
83 byte*
84 _EncodingCore::ConvertN(_EncodingCore* pDstConverter, const byte* pSrc, int srcLength, int& retLength)
85 {
86         result r = E_SUCCESS;
87
88         SysTryReturn(NID_TEXT, pDstConverter != null, null, E_INVALID_ARG,
89                 "[%s] Invalid argument is used. Unable to get encoder decoder object. pDstConverter can not be null", GetErrorMessage(E_INVALID_ARG));
90
91         unique_ptr<wchar_t[]> pWchar(DecodeN(pSrc, srcLength, retLength));
92         r = GetLastResult();
93         SysTryReturn(NID_TEXT, (pWchar != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
94
95         unique_ptr<byte[]> pByte(pDstConverter->EncodeN(pWchar.get(), retLength, retLength));
96         r = GetLastResult();
97         SysTryReturn(NID_TEXT, (pByte != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
98
99         SetLastResult(E_SUCCESS);
100         return pByte.release();
101 }
102
103 byte*
104 _EncodingCore::EncodeExN(const wchar_t* pSrc, int srcLength, int& retLength, bool flush)
105 {
106         SetLastResult(E_UNSUPPORTED_OPERATION);
107         return null;
108 }
109
110 wchar_t*
111 _EncodingCore::DecodeExN(const byte* pSrc, int srcLength, int& retLength, bool flush)
112 {
113         SetLastResult(E_UNSUPPORTED_OPERATION);
114         return null;
115 }
116
117 } } // Tizen::Text