2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FLcl_CurrencyImpl.cpp
20 * @brief This is the implementation file for _CurrencyImpl class.
22 #include <unique_ptr.h>
23 #include <unicode/dcfmtsym.h>
25 #include <FBaseSysLog.h>
26 #include <FApp_AppInfo.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->IsLocaleSupported(),
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 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))
125 result r = pNewList->Add(*(pCurr));
129 SetLastResult(E_SYSTEM);
136 SetLastResult(E_SUCCESS);
137 return pNewList.release();