From 59c6f872b6153e62253c064fb26cbe1272f13786 Mon Sep 17 00:00:00 2001 From: "darpan.ka" Date: Thu, 24 Oct 2013 14:10:25 +0530 Subject: [PATCH] [ACR][15/10/2013][Add]Adding Decode() API in LongLong class Change-Id: Idcf8fc72be079d463592692535b4c67699e58bec Signed-off-by: darpan.ka --- inc/FBaseLongLong.h | 28 ++++++++++++++++++++++++++++ src/base/FBaseLongLong.cpp | 10 ++++++++++ 2 files changed, 38 insertions(+) diff --git a/inc/FBaseLongLong.h b/inc/FBaseLongLong.h index d748f09..3207efd 100644 --- a/inc/FBaseLongLong.h +++ b/inc/FBaseLongLong.h @@ -274,6 +274,34 @@ public: static String ToString(long long value); /** + * Decodes a string into a @c signed @c long @c long value. + * + * @since 3.0 + * + * @return An error code + * @param[in] inputStr A string representing a numeric value + * @param[out] ret The result of the operation + * @exception E_SUCCESS The method is successful. + * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed. + * @exception E_OUT_OF_RANGE The decoded value is not between VALUE_MIN and VALUE_MAX range. + * @remarks + * - This method guarantees that the original value of out-parameter is not changed when the method returns error. + * - This method accepts decimal, hexadecimal, and octal numbers given by the + * following grammar: + * @code + * - DecodableString: + * Sign[opt] DecimalNumeral + * Sign[opt] 0x HexDigits + * Sign[opt] 0X HexDigits + * Sign[opt] # HexDigits + * Sign[opt] 0 OctalDigits + * - Sign: + * '-' + * @endcode + */ + static result Decode(const String& inputStr, long long& ret); + + /** * Parses the specified string representing a numeric value and * returns the value as a @c signed @c long @c long (as out parameter). * diff --git a/src/base/FBaseLongLong.cpp b/src/base/FBaseLongLong.cpp index 995bf08..dfea06d 100644 --- a/src/base/FBaseLongLong.cpp +++ b/src/base/FBaseLongLong.cpp @@ -161,6 +161,16 @@ LongLong::ToString(long long value) } result +LongLong::Decode(const String& inputStr, long long& ret) +{ + long long value; + result r = _NumberUtil::Decode(inputStr, value); + SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating."); + ret = value; + return r; +} + +result LongLong::Parse(const String& s, long long& ret) { return Parse(s, Character::RADIX_DECIMAL, ret); -- 2.7.4