N_SE-53194 : fix AppControl::Stop() without listener
[platform/framework/native/appfw.git] / src / locales / FLcl_NumberSymbolsImpl.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            FLclNumberSymbols.cpp
19  * @brief           This is the implementation file for NumberSymbols class.
20  */
21 #include <unicode/locid.h>
22 #include <FBaseSysLog.h>
23 #include <FApp_AppInfo.h>
24 #include "FLcl_NumberSymbolsImpl.h"
25 #include "FLcl_LocaleData.h"
26
27 using namespace Tizen::Base;
28
29 namespace Tizen { namespace Locales
30 {
31
32 static U_ICU_NAMESPACE::DecimalFormatSymbols::ENumberFormatSymbol NUMBER_SYMBOL_TYPE_CONVERT_TABLE[NUMBER_SYMBOL_COUNT] =
33         { U_ICU_NAMESPACE::DecimalFormatSymbols::kDecimalSeparatorSymbol
34         , U_ICU_NAMESPACE::DecimalFormatSymbols::kGroupingSeparatorSymbol
35         , U_ICU_NAMESPACE::DecimalFormatSymbols::kPatternSeparatorSymbol
36         , U_ICU_NAMESPACE::DecimalFormatSymbols::kPercentSymbol
37         , U_ICU_NAMESPACE::DecimalFormatSymbols::kZeroDigitSymbol
38         , U_ICU_NAMESPACE::DecimalFormatSymbols::kDigitSymbol
39         , U_ICU_NAMESPACE::DecimalFormatSymbols::kCurrencySymbol
40         , U_ICU_NAMESPACE::DecimalFormatSymbols::kIntlCurrencySymbol
41         , U_ICU_NAMESPACE::DecimalFormatSymbols::kMonetarySeparatorSymbol
42         , U_ICU_NAMESPACE::DecimalFormatSymbols::kPerMillSymbol
43         , U_ICU_NAMESPACE::DecimalFormatSymbols::kExponentialSymbol
44         , U_ICU_NAMESPACE::DecimalFormatSymbols::kPlusSignSymbol
45         , U_ICU_NAMESPACE::DecimalFormatSymbols::kMinusSignSymbol
46         };
47
48 _NumberSymbolsImpl::_NumberSymbolsImpl(void)
49         : __locale(LANGUAGE_INVALID, COUNTRY_INVALID)
50         , __pIcuDecimalFormatSymbols(null)
51 {
52 }
53
54
55 _NumberSymbolsImpl::_NumberSymbolsImpl(const _NumberSymbolsImpl& other)
56         : __locale(LANGUAGE_INVALID, COUNTRY_INVALID)
57         , __pIcuDecimalFormatSymbols(null)
58 {
59         __locale = other.__locale;
60         __pIcuDecimalFormatSymbols = new U_ICU_NAMESPACE::DecimalFormatSymbols(*other.__pIcuDecimalFormatSymbols);
61         SysTryReturn(NID_LCL, __pIcuDecimalFormatSymbols, , E_OUT_OF_MEMORY, "It is not enough memory.");
62 }
63
64
65 _NumberSymbolsImpl&
66 _NumberSymbolsImpl::operator =(const _NumberSymbolsImpl& rhs)
67 {
68         if (this != &rhs)
69         {
70                 __locale = rhs.__locale;
71                 if (__pIcuDecimalFormatSymbols)
72                 {
73                         delete __pIcuDecimalFormatSymbols;
74                         __pIcuDecimalFormatSymbols = null;
75                 }
76                 __pIcuDecimalFormatSymbols = new U_ICU_NAMESPACE::DecimalFormatSymbols(*rhs.__pIcuDecimalFormatSymbols);
77         }
78
79         return *this;
80 }
81
82
83 _NumberSymbolsImpl::~_NumberSymbolsImpl(void)
84 {
85         if (__pIcuDecimalFormatSymbols)
86         {
87                 delete __pIcuDecimalFormatSymbols;
88         }
89 }
90
91 result
92 _NumberSymbolsImpl::Construct(const Locale& locale)
93 {
94         result r = (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) 
95                         ? E_UNSUPPORTED_OPERATION 
96                         : E_INVALID_ARG;
97
98         U_ICU_NAMESPACE::Locale icuLocale = _LocaleData::GetIcuLocale(locale);
99         SysTryReturnResult(NID_LCL, icuLocale.isBogus() != true, r, "It is an invalid locale.");
100
101         UErrorCode status = U_ZERO_ERROR;
102         __pIcuDecimalFormatSymbols = new U_ICU_NAMESPACE::DecimalFormatSymbols(icuLocale, status);
103         SysTryReturnResult(NID_LCL, __pIcuDecimalFormatSymbols, E_OUT_OF_MEMORY, "It is not enough memory.");
104         __locale = locale;
105
106         return E_SUCCESS;
107 }
108
109
110 String
111 _NumberSymbolsImpl::GetNumberSymbol(NumberSymbol symbol) const
112 {
113         SysTryReturn(NID_LCL, symbol < NUMBER_SYMBOL_COUNT, String(), E_INVALID_ARG, "It is an invalid argument.");
114         return  _LocaleData::GetOspString(__pIcuDecimalFormatSymbols->getSymbol(NUMBER_SYMBOL_TYPE_CONVERT_TABLE[symbol]));
115 }
116
117
118 result
119 _NumberSymbolsImpl::SetNumberSymbol(const NumberSymbol symbol, const String& str)
120 {
121         SysTryReturnResult(NID_LCL, symbol < NUMBER_SYMBOL_COUNT, E_INVALID_ARG, "It is an invalid argument.");
122         U_ICU_NAMESPACE::UnicodeString icuStr = _LocaleData::GetIcuString(str);
123         __pIcuDecimalFormatSymbols->setSymbol(NUMBER_SYMBOL_TYPE_CONVERT_TABLE[symbol], icuStr);
124         return E_SUCCESS;
125 }
126
127
128 const Locale*
129 _NumberSymbolsImpl::GetLocale(void) const
130 {
131         ClearLastResult();
132         return &__locale;
133 }
134
135
136 };
137 };      // Tizen::Locales
138