Remove unused code.
[platform/framework/native/appfw.git] / src / locales / FLcl_CurrencyImpl.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            FLcl_CurrencyImpl.cpp
19  * @brief           This is the implementation file for _CurrencyImpl class.
20  */
21 #include <unique_ptr.h>
22 #include <unicode/dcfmtsym.h>
23
24 #include <FBaseSysLog.h>
25 #include <FApp_AppInfo.h>
26 #include <FBaseColArrayList.h>
27 #include <FBaseColAllElementsDeleter.h>
28 #include "FLcl_LocaleData.h"
29 #include "FLcl_LocaleImpl.h"
30 #include "FLcl_CurrencyImpl.h"
31
32 using namespace Tizen::Base;
33
34 namespace Tizen { namespace Locales
35 {
36
37 result
38 _CurrencyImpl::GetCurrencyCodeSymbol(const Locale& locale, Tizen::Base::String& currencyCodeSymbol)
39 {
40         const _LocaleImpl* pLclImpl = _LocaleImpl::GetLocaleImpl(locale);
41         SysTryReturnResult(NID_LCL, pLclImpl != null && pLclImpl->IsSupported(),
42                                         E_INVALID_ARG, "Invalid argument is used. Given locale is not supported");
43
44         UErrorCode ec = U_ZERO_ERROR;
45         IcuDecimalFormatSymbols sym(pLclImpl->GetIcuLocale(), ec);
46         if (U_SUCCESS(ec))
47         {
48                 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
49                 String currSym = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
50
51                 if (currCode.IsEmpty() || currSym.IsEmpty())
52                 {
53                         currCode = "";
54                         currSym = "";
55                         return E_SYSTEM;
56                 }
57                 else
58                 {
59                         currencyCodeSymbol = currCode + "_" + currSym;
60                         return E_SUCCESS;
61                 }
62         }
63
64         return (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
65 }
66
67 result
68 _CurrencyImpl::GetCurrencyCodeSymbol(const String currencyCode, String& currencyCodeSymbol)
69 {
70         int count = 0;
71         const IcuLocale* pIcuLocaleList = IcuLocale::getAvailableLocales(count);
72         SysTryReturnResult(NID_LCL, pIcuLocaleList && (count > 0), E_SYSTEM, "The method cannot proceed due to a severe system error.");
73
74         for (int i = 0; i < count; i++)
75         {
76                 SysTryReturnResult(NID_LCL, (pIcuLocaleList + i) != null, E_SYSTEM, "The method cannot proceed due to a severe system error.");
77
78                 UErrorCode ec = U_ZERO_ERROR;
79                 IcuDecimalFormatSymbols sym(*(pIcuLocaleList + i), ec);
80                 SysTryReturnResult(NID_LCL, U_SUCCESS(ec), E_SYSTEM, "The method cannot proceed due to a severe system error.");
81
82                 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
83                 if (currCode == currencyCode)
84                 {
85                         String currencySymbol= _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
86                         currencyCodeSymbol = currencyCode + "_" + currencySymbol;
87                         return E_SUCCESS;
88                 }
89         }
90         return E_INVALID_ARG;
91 }
92
93 IList*
94 _CurrencyImpl::GetAvailableCurrenciesN(void)
95 {
96         int count = 0;
97         const IcuLocale* pIcuLocaleList = IcuLocale::getAvailableLocales(count);
98         SysTryReturn(NID_LCL, pIcuLocaleList && (count > 0), null,E_SYSTEM,
99                                 "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
100
101         std::unique_ptr<ArrayList, AllElementsDeleter> pNewList(new (std::nothrow) ArrayList());
102         SysTryReturn(NID_LCL, pNewList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
103
104         for (int i = 0; i < count; i++)
105         {
106                 SysTryReturn(NID_LCL, (pIcuLocaleList + i) != null, null, E_SYSTEM,
107                                         "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
108
109                 UErrorCode ec = U_ZERO_ERROR;
110                 IcuDecimalFormatSymbols sym(*(pIcuLocaleList + i), ec);
111                 SysTryReturn(NID_LCL, U_SUCCESS(ec), null, E_SYSTEM,
112                                         "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
113
114                 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
115                 String currSymbol= _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
116
117                 if (!currCode.IsEmpty() && !currSymbol.IsEmpty())
118                 {
119                         std::unique_ptr< Currency > pCurr(new (std::nothrow) Currency);
120                         SysTryReturn(NID_LCL, pCurr, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
121
122                         pCurr->__currencyCodeSymbol = currCode + "_" + currSymbol;
123                         if (!pNewList->Contains(*(pCurr.get())))
124                         {
125                                 result r = pNewList->Add(pCurr.get());
126                                 SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "Itis fail to make the currency list.");
127                                 pCurr.release();
128                         }
129                 }
130         }
131
132         SetLastResult(E_SUCCESS);
133         return pNewList.release();
134 }
135
136
137 }}//Tizen::Locales