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>
27 #include "FLcl_LocaleData.h"
28 #include "FLcl_LocaleImpl.h"
29 #include "FLcl_CurrencyImpl.h"
31 using namespace Tizen::Base;
33 namespace Tizen { namespace Locales
37 _CurrencyImpl::GetCurrencyCodeSymbol(const Locale& locale, Tizen::Base::String& currencyCodeSymbol)
39 const _LocaleImpl* pLclImpl = _LocaleImpl::GetLocaleImpl(locale);
40 SysTryReturnResult(NID_LCL, pLclImpl != null && pLclImpl->IsSupported(),
41 E_INVALID_ARG, "Invalid argument is used. Given locale is not supported");
43 UErrorCode ec = U_ZERO_ERROR;
44 IcuDecimalFormatSymbols sym(pLclImpl->GetIcuLocale(), ec);
47 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
48 String currSym = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
50 if (currCode.IsEmpty() || currSym.IsEmpty())
58 currencyCodeSymbol = currCode + "_" + currSym;
63 return (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
67 _CurrencyImpl::GetCurrencyCodeSymbol(const String currencyCode, String& currencyCodeSymbol)
70 const IcuLocale* pIcuLocaleList = IcuLocale::getAvailableLocales(count);
71 SysTryReturnResult(NID_LCL, pIcuLocaleList && (count > 0), E_SYSTEM, "The method cannot proceed due to a severe system error.");
73 for (int i = 0; i < count; i++)
75 SysTryReturnResult(NID_LCL, (pIcuLocaleList + i) != null, E_SYSTEM, "The method cannot proceed due to a severe system error.");
77 UErrorCode ec = U_ZERO_ERROR;
78 IcuDecimalFormatSymbols sym(*(pIcuLocaleList + i), ec);
79 SysTryReturnResult(NID_LCL, U_SUCCESS(ec), E_SYSTEM, "The method cannot proceed due to a severe system error.");
81 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
82 if (currCode == currencyCode)
84 String currencySymbol= _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
85 currencyCodeSymbol = currencyCode + "_" + currencySymbol;
93 _CurrencyImpl::GetAvailableCurrenciesN(void)
96 const IcuLocale* pIcuLocaleList = IcuLocale::getAvailableLocales(count);
97 SysTryReturn(NID_LCL, pIcuLocaleList && (count > 0), null,E_SYSTEM,
98 "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
100 std::unique_ptr<ArrayList, AllElementsDeleter> pNewList(new (std::nothrow) ArrayList());
101 SysTryReturn(NID_LCL, pNewList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
103 for (int i = 0; i < count; i++)
105 SysTryReturn(NID_LCL, (pIcuLocaleList + i) != null, null, E_SYSTEM,
106 "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
108 UErrorCode ec = U_ZERO_ERROR;
109 IcuDecimalFormatSymbols sym(*(pIcuLocaleList + i), ec);
110 SysTryReturn(NID_LCL, U_SUCCESS(ec), null, E_SYSTEM,
111 "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
113 String currCode = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
114 String currSymbol= _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
116 if (!currCode.IsEmpty() && !currSymbol.IsEmpty())
118 std::unique_ptr< Currency > pCurr(new (std::nothrow) Currency);
119 SysTryReturn(NID_LCL, pCurr, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
121 pCurr->__currencyCodeSymbol = currCode + "_" + currSymbol;
122 if (!pNewList->Contains(*(pCurr.get())))
124 result r = pNewList->Add(*(pCurr.get()));
125 SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "Itis fail to make the currency list.");
131 SetLastResult(E_SUCCESS);
132 return pNewList.release();