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 FLcl_CurrencyImpl.cpp
19 * @brief This is the implementation file for _CurrencyImpl class.
21 #include <unique_ptr.h>
22 #include <unicode/dcfmtsym.h>
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"
32 using namespace Tizen::Base;
34 namespace Tizen { namespace Locales
38 _CurrencyImpl::GetCurrencyCodeSymbol(const Locale& locale, Tizen::Base::String& currencyCodeSymbol)
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");
44 UErrorCode ec = U_ZERO_ERROR;
45 IcuDecimalFormatSymbols sym(pLclImpl->GetIcuLocale(), ec);
48 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
49 String currSym = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
51 if (currCode.IsEmpty() || currSym.IsEmpty())
59 currencyCodeSymbol = currCode + "_" + currSym;
64 return (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
68 _CurrencyImpl::GetCurrencyCodeSymbol(const String currencyCode, String& currencyCodeSymbol)
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.");
74 for (int i = 0; i < count; i++)
76 SysTryReturnResult(NID_LCL, (pIcuLocaleList + i) != null, E_SYSTEM, "The method cannot proceed due to a severe system error.");
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.");
82 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
83 if (currCode == currencyCode)
85 String currencySymbol= _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
86 currencyCodeSymbol = currencyCode + "_" + currencySymbol;
94 _CurrencyImpl::GetAvailableCurrenciesN(void)
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));
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));
104 for (int i = 0; i < count; i++)
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));
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));
114 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
115 String currSymbol= _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
117 if (!currCode.IsEmpty() && !currSymbol.IsEmpty())
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));
122 pCurr->__currencyCodeSymbol = currCode + "_" + currSymbol;
123 if (!pNewList->Contains(*(pCurr.get())))
125 result r = pNewList->Add(pCurr.get());
126 SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "Itis fail to make the currency list.");
132 SetLastResult(E_SUCCESS);
133 return pNewList.release();