[ACR][20/08/2013][Add]Enhance Double::ToString() andFloat::ToString() to set a specif...
[platform/framework/native/appfw.git] / src / base / inc / FBase_LocalizedNumParser.h
1 //
2 // Copyright (c) 2013 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        FBase_LocalizedNumParser.h
19  * @brief       This is the header file for the %_LocalizedNumParser class.
20  *
21  * This header file contains the declarations of the %_LocalizedNumParser class.
22  */
23 #ifndef _FBASE_INTERNAL_LOCALIZED_NUM_PARSER_H_
24 #define _FBASE_INTERNAL_LOCALIZED_NUM_PARSER_H_
25
26 #include <FBaseString.h>
27
28 namespace Tizen { namespace Base
29 {
30
31 class _OSP_EXPORT_ _LocalizedNumParser
32 {
33 public:
34         /**
35          * Locale specifiable version of Double::Parse(). @n
36          * This method is affected by the specified @c pLocale.
37          *
38          * @since 2.1
39          *
40          * @return              The converted numeric value
41          * @param[in]   str                     A unicode representation of @c signed @c double value
42          * @param[in]   pLocale         A specific locale identifier. @n
43          *                                              The @c pLocale can have below values.
44          *                                              - "" : the system default locale
45          *                                              - "C" or "POSIX" : the POSIX locale
46          *                                              - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
47          * @exception   E_SUCCESS               The method is successful.
48          * @exception   E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
49          * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
50          * @remarks
51          *                              - When an error is occurred, this method returns Not-a-Number(NaN).
52          *                              - The behavior of this method is dependent on the specified locale setting.
53          *                              - The specific error code can be accessed using the GetLastResult() method.
54          */
55         static double ToDouble(const String& str, const char* pLocale);
56
57         /**
58          * Locale specifiable version of Float::Parse(). @n
59          * This method is affected by the specified @c pLocale.
60          *
61          * @since 2.1
62          *
63          * @return              The converted numeric value
64          * @param[in]   str                     A unicode representation of @c signed @c float value
65          * @param[in]   pLocale         A specific locale identifier. @n
66          *                                              The @c pLocale can have below values.
67          *                                              - "" : the system default locale
68          *                                              - "C" or "POSIX" : the POSIX locale
69          *                                              - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
70          * @exception   E_SUCCESS               The method is successful.
71          * @exception   E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
72          * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
73          * @remarks
74          *                              - When an error is occurred, this method returns Not-a-Number(NaN).
75          *                              - The behavior of this method is dependent on the specified locale setting.
76          *                              - The specific error code can be accessed using the GetLastResult() method.
77          */
78         static float ToFloat(const String& str, const char* pLocale);
79
80         /**
81          * Locale specifiable version of Double::ToString(). @n
82          * This method is affected by the specified @c pLocale.
83          *
84          * @since 2.1
85          *
86          * @return              A string containing a Unicode representation of the specified @c double value
87          * @param[in]   value           A @c double value to convert
88          * @param[in]   pLocale         A specific locale identifier. @n
89          *                                              The @c pLocale can have below values.
90          *                                              - "" : the system default locale
91          *                                              - "C" or "POSIX" : the POSIX locale
92          *                                              - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
93          * @exception   E_SUCCESS               The method is successful.
94          * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
95          * @remarks
96          *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
97          *                              Furthermore, infinity produces the result "Infinity". @n
98          *                              6 digits are given for the precision of this method. Use Double::ToString(int precision) to set the specific precision.
99          *                              - The behavior of this method is dependent on the specified locale setting.
100          *                              - The specific error code can be accessed using the GetLastResult() method.
101          */
102         static String ToString(double value, const char* pLocale);
103
104         /**
105          * Locale specifiable version of Double::ToString(int precision). @n
106          * This method is affected by the specified @c pLocale.
107          *
108          * @since 3.0
109          *
110          * @return                      A string containing a Unicode representation of the specified @c double value
111          * @param[in]   value           A @c double value to convert
112          * @param[in]   pLocale         A specific locale identifier. @n
113          *                                      The @c pLocale can have below values.
114          *                                      - "" : the system default locale
115          *                                      - "C" or "POSIX" : the POSIX locale
116          *                                      - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
117          * @param[in]   precision       Number of digits after a decimal separator
118          * @exception   E_SUCCESS       The method is successful.
119          * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
120          * @remarks
121          *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
122          *                              Furthermore, infinity produces the result "Infinity". @n
123          *                              - The behavior of this method is dependent on the specified locale setting.
124          *                              - The specific error code can be accessed using the GetLastResult() method.
125          */
126         static String ToString(double value, const char* pLocale, int precision);
127
128         /**
129          * Locale specifiable version of Float::ToString(). @n
130          * This method is affected by the specified @c pLocale.
131          *
132          * @since 2.1
133          *
134          * @return              A string containing a Unicode representation of the specified @c float value
135          * @param[in]   value           A @c float value to convert
136          * @param[in]   pLocale         A specific locale identifier. @n
137          *                                              The @c pLocale can have below values.
138          *                                              - "" : the system default locale
139          *                                              - "C" or "POSIX" : the POSIX locale
140          *                                              - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
141          * @exception   E_SUCCESS               The method is successful.
142          * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
143          * @remarks
144          *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
145          *                              Furthermore, infinity produces the result "Infinity". @n
146          *                              6 digits are given for the precision of this method. Use Float::ToString(int precision) to set the specific precision.
147          *                              - The behavior of this method is dependent on the specified locale setting.
148          *                              - The specific error code can be accessed using the GetLastResult() method.
149          */
150         static String ToString(float value, const char* pLocale);
151
152         /**
153          * Locale specifiable version of Float::ToString(int precision). @n
154          * This method is affected by the specified @c pLocale.
155          *
156          * @since 3.0
157          *
158          * @return                      A string containing a Unicode representation of the specified @c float value
159          * @param[in]   value           A @c float value to convert
160          * @param[in]   pLocale         A specific locale identifier. @n
161          *                                      The @c pLocale can have below values.
162          *                                      - "" : the system default locale
163          *                                      - "C" or "POSIX" : the POSIX locale
164          *                                      - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
165          * @param[in]   precision       Number of digits after a decimal separator
166          * @exception   E_SUCCESS       The method is successful.
167          * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
168          * @remarks
169          *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
170          *                              Furthermore, infinity produces the result "Infinity". @n
171          *                              - The behavior of this method is dependent on the specified locale setting.
172          *                              - The specific error code can be accessed using the GetLastResult() method.
173          */
174         static String ToString(float value, const char* pLocale, int precision);
175
176 private:
177         //
178         // This default constructor is intentionally declared as private because this class is not constructible.
179         //
180         // @since               2.1
181         //
182         _LocalizedNumParser(void);
183
184         //
185         // This destructor is intentionally declared as private because this class is not constructible.
186         //
187         // @since               2.1
188         //
189         ~_LocalizedNumParser(void);
190
191         //
192         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
193         //
194         // @since               2.1
195         //
196         // @param[in]   rhs             A reference to the %_LocalizedNumParser instance
197         //
198         _LocalizedNumParser(const _LocalizedNumParser& rhs);
199
200         //
201         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
202         //
203         // @since               2.1
204         //
205         // @return              A reference to the %_LocalizedNumParser instance
206         // @param[in]   rhs             A reference to the %_LocalizedNumParser instance
207         //
208         _LocalizedNumParser& operator =(const _LocalizedNumParser& rhs);
209
210         static const int FLOAT_LENGTH_MAX = 7 + 38 + 3; // significant decimal digits + exponent + extra characters
211         static const int DBL_MAX_LENGTH = 17 + 308 + 3; // significant decimal digits + exponent + extra characters
212 };
213 }}  // Tizen::Base
214 #endif  // _FBASE_INTERNAL_LOCALIZED_NUM_PARSER_H_