9139bdeeb44d40760dae44c540f8c20108321dec
[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 String::Format() 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 Float::ToString(). @n
106          * This method is affected by the specified @c pLocale.
107          *
108          * @since 2.1
109          *
110          * @return              A string containing a Unicode representation of the specified @c float value
111          * @param[in]   value           A @c float 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          * @exception   E_SUCCESS               The method is successful.
118          * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
119          * @remarks
120          *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
121          *                              Furthermore, infinity produces the result "Infinity". @n
122          *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
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(float value, const char* pLocale);
127
128 private:
129         //
130         // This default constructor is intentionally declared as private because this class is not constructible.
131         //
132         // @since               2.1
133         //
134         _LocalizedNumParser(void);
135
136         //
137         // This destructor is intentionally declared as private because this class is not constructible.
138         //
139         // @since               2.1
140         //
141         ~_LocalizedNumParser(void);
142
143         //
144         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
145         //
146         // @since               2.1
147         //
148         // @param[in]   rhs             A reference to the %_LocalizedNumParser instance
149         //
150         _LocalizedNumParser(const _LocalizedNumParser& rhs);
151
152         //
153         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
154         //
155         // @since               2.1
156         //
157         // @return              A reference to the %_LocalizedNumParser instance
158         // @param[in]   rhs             A reference to the %_LocalizedNumParser instance
159         //
160         _LocalizedNumParser& operator =(const _LocalizedNumParser& rhs);
161
162         static const int FLOAT_LENGTH_MAX = 7 + 38 + 3; // significant decimal digits + exponent + extra characters
163         static const int DBL_MAX_LENGTH = 17 + 308 + 3; // significant decimal digits + exponent + extra characters
164 };
165 }}  // Tizen::Base
166 #endif  // _FBASE_INTERNAL_LOCALIZED_NUM_PARSER_H_