Fix SettingClient to get instance.
[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         if (encodingFrom.Contains(L"UCS-2") == true)
56         {
57                 pEncoderDecoder = _Ucs2EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
58                 if (pEncoderDecoder)
59                 {
60                         return pEncoderDecoder;
61                 }
62         }
63         else if (encodingFrom.Contains(L"GSM") == true)
64         {
65                 pEncoderDecoder = _GsmEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
66                 if (pEncoderDecoder)
67                 {
68                         return pEncoderDecoder;
69                 }
70         }
71         else if (encodingFrom.Contains(L"ISO-8859-16") == true)
72         {
73                 pEncoderDecoder = _Iso885916EncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
74                 if (pEncoderDecoder)
75                 {
76                         return pEncoderDecoder;
77                 }
78         }
79         else
80         {
81                 pEncoderDecoder = _IcuEncodingCore::GetEncodingCoreImplN(encodingFrom, encodingTo);
82                 if (pEncoderDecoder)
83                 {
84                         return pEncoderDecoder;
85                 }
86         }
87
88         return null;
89 }
90
91
92 byte*
93 _EncodingCore::ConvertN(_EncodingCore* pDstConverter, const byte* pSrc, int srcLength, int& retLength)
94 {
95         result r = E_SUCCESS;
96
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));
99
100         unique_ptr<wchar_t[]> pWchar(DecodeN(pSrc, srcLength, retLength));
101         r = GetLastResult();
102         SysTryReturn(NID_TEXT, (pWchar != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
103
104         unique_ptr<byte[]> pByte(pDstConverter->EncodeN(pWchar.get(), retLength, retLength));
105         r = GetLastResult();
106         SysTryReturn(NID_TEXT, (pByte != null), null, r, "[%s] Decoding failed", GetErrorMessage(r));
107
108         SetLastResult(E_SUCCESS);
109         return pByte.release();
110 }
111
112 byte*
113 _EncodingCore::EncodeExN(const wchar_t* pSrc, int srcLength, int& retLength, bool flush)
114 {
115         SetLastResult(E_UNSUPPORTED_OPERATION);
116         return null;
117 }
118
119 wchar_t*
120 _EncodingCore::DecodeExN(const byte* pSrc, int srcLength, int& retLength, bool flush)
121 {
122         SetLastResult(E_UNSUPPORTED_OPERATION);
123         return null;
124 }
125
126 } } // Tizen::Text