2 // Copyright (c) 2013 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 FBase_NumberUtil.h
19 * @brief This is the header file for the _NumberUtil class.
21 * This header file contains the declarations of the _NumberUtil class.
23 #ifndef _FBASE_INTERNAL_NUMBER_UTIL_H_
24 #define _FBASE_INTERNAL_NUMBER_UTIL_H_
26 #include <FBaseObject.h>
27 #include <FBaseString.h>
29 namespace Tizen { namespace Base
36 * This is the destructor for this class.
40 virtual ~_NumberUtil(void);
43 * Decodes a string into a @c signed @c long.
47 * @return An error code
48 * @param[in] inputStr A numeric value
49 * @param[out] value The result of the operation
50 * @exception E_SUCCESS The method is successful.
51 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
52 * @exception E_OUT_OF_RANGE The decoded string value is not between VALUE_MIN and VALUE_MAX range
53 * @remarks This method accepts decimal, hexadecimal, and octal numbers given by the
58 * Sign[opt] DecimalNumeral
59 * Sign[opt] 0x HexDigits
60 * Sign[opt] 0X HexDigits
61 * Sign[opt] # HexDigits
62 * Sign[opt] 0 OctalDigits
67 static result Decode(const String& inputStr, long& value);
70 * Decodes a string into a @c signed @c long long.
74 * @return An error code
75 * @param[in] inputStr A numeric value
76 * @param[out] value The result of the operation
77 * @exception E_SUCCESS The method is successful.
78 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
79 * @exception E_OUT_OF_RANGE The decoded value is not between VALUE_MIN and VALUE_MAX range
80 * @remarks This method accepts decimal, hexadecimal, and octal numbers given by the
85 * Sign[opt] DecimalNumeral
86 * Sign[opt] 0x HexDigits
87 * Sign[opt] 0X HexDigits
88 * Sign[opt] # HexDigits
89 * Sign[opt] 0 OctalDigits
94 static result Decode(const String& inputStr, long long& value);
97 * Parses the specified string representing a numeric value
98 * using the specified radix and returns the value as @c signed @c long.
102 * @return An error code
103 * @param[in] inputStr A string representing a numeric value
104 * @param[in] radix The radix of the string representing a numeric value @n
105 * Radix ranges in between 2 to 36.
106 * @param[out] value The result of the operation
107 * @exception E_SUCCESS The method is successful.
108 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
109 * @exception E_OUT_OF_RANGE The specified @c radix is invalid.
110 * The parsed value is not between VALUE_MIN and VALUE_MAX range
112 static result Parse(const String& inputStr, int radix, long& value);
116 * Parses the specified string representing a numeric value
117 * using the specified radix and returns the value as @c signed @c long long.
121 * @return An error code
122 * @param[in] inputStr A string representing a numeric value
123 * @param[in] radix The radix of the string representing a numeric value @n
124 * Radix ranges in between 2 to 36.
125 * @param[out] value The result of the operation
126 * @exception E_SUCCESS The method is successful.
127 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
128 * @exception E_OUT_OF_RANGE The specified @c radix is invalid.
129 * The parsed value is not between VALUE_MIN and VALUE_MAX range
131 static result Parse(const String& inputStr, int radix, long long& value);
135 // This is the default constructor for this class.
142 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
145 // @param[in] rhs An instance of %_NumberUtil
147 _NumberUtil(const _NumberUtil& rhs);
150 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
153 // @param[in] rhs An instance of %_NumberUtil
155 _NumberUtil& operator =(const _NumberUtil& rhs);
158 // Finds the radix by parsing the input string.
162 // @return An error code
163 // @param[in] inputStr A numeric value
164 // @param[out] radix radix of the input string
165 // @exception E_SUCCESS The method is successful.
166 // @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
167 // @remarks This method accepts decimal, hexadecimal, and octal numbers given by the
168 // following grammar:
171 // - DecodableString:
172 // Sign[opt] DecimalNumeral
173 // Sign[opt] 0x HexDigits
174 // Sign[opt] 0X HexDigits
175 // Sign[opt] # HexDigits
176 // Sign[opt] 0 OctalDigits
181 static result FindRadix(String& inputStr, int& radix);
186 #endif // _FBASE_INTERNAL_NUMBER_UTIL_H_