[ACR][15/10/2013][Add]Adding Decode() API in LongLong class
[platform/framework/native/appfw.git] / src / base / FBaseLongLong.cpp
index f941ece..dfea06d 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -20,7 +19,6 @@
  * @brief              This is the implementation file for LongLong class.
  * @see                        Number
  */
-
 #include <wchar.h>
 #include <limits.h>
 #include <errno.h>
@@ -28,6 +26,7 @@
 #include <FBaseResult.h>
 #include <FBaseCharacter.h>
 #include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
 
 namespace Tizen { namespace Base
 {
@@ -73,7 +72,7 @@ LongLong::CompareTo(const LongLong& value) const
 bool
 LongLong::Equals(const Object& obj) const
 {
-       const LongLong* pOther = dynamic_cast <const LongLong*>(&obj);
+       const LongLong* pOther = dynamic_cast< const LongLong* >(&obj);
        if (pOther == null)
        {
                return false;
@@ -85,49 +84,55 @@ LongLong::Equals(const Object& obj) const
 int
 LongLong::GetHashCode(void) const
 {
-       return static_cast<int> (value);
+       return static_cast< int >(value);
 }
 
 int
 LongLong::GetHashCode(long long val)
 {
-       return static_cast<int> (val);
+       return static_cast< int >(val);
 }
 
 char
 LongLong::ToChar(void) const
 {
-       return static_cast<char> (value);
+       return static_cast< char >(value);
+}
+
+int8_t
+LongLong::ToInt8(void) const
+{
+       return static_cast< int8_t >(value);
 }
 
 short
 LongLong::ToShort(void) const
 {
-       return static_cast<short> (value);
+       return static_cast< short >(value);
 }
 
 int
 LongLong::ToInt(void) const
 {
-       return static_cast<int> (value);
+       return static_cast< int >(value);
 }
 
 long
 LongLong::ToLong(void) const
 {
-       return static_cast<long> (value);
+       return static_cast< long >(value);
 }
 
 float
 LongLong::ToFloat(void) const
 {
-       return static_cast<float> (value);
+       return static_cast< float >(value);
 }
 
 double
 LongLong::ToDouble(void) const
 {
-       return static_cast<double> (value);
+       return static_cast< double >(value);
 }
 
 long long
@@ -156,38 +161,29 @@ LongLong::ToString(long long value)
 }
 
 result
-LongLong::Parse(const String& s, long long& ret)
+LongLong::Decode(const String& inputStr, long long& ret)
 {
-       wchar_t* pEnd = null;
-
-       int len = s.GetLength();
-       SysTryReturnResult(NID_BASE, (len > 0), E_NUM_FORMAT, "[%s] The length of s MUST be greater than 0.",
-               GetErrorMessage(E_NUM_FORMAT));
+       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);
 }
 
 result
 LongLong::Parse(const String& s, int radix, long long& ret)
 {
-       SysTryReturnResult(NID_BASE, radix == Character::RADIX_BINARY || radix == Character::RADIX_OCTAL ||
-               radix == Character::RADIX_DECIMAL || radix == Character::RADIX_HEXADECIMAL, E_OUT_OF_RANGE,
-               "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_OUT_OF_RANGE), radix);
-
-       int len = s.GetLength();
-       SysTryReturnResult(NID_BASE, (len > 0), E_NUM_FORMAT, "[%s] The length of s MUST be greater than 0.",
-               GetErrorMessage(E_NUM_FORMAT));
-
-       errno = 0;
-       wchar_t* pEnd = null;
-       long long tmpRet = wcstoll(s.GetPointer(), &pEnd, radix);
-       SysTryReturnResult(NID_BASE, (pEnd[0] == 0), E_NUM_FORMAT, "[%s] LongLong parse failed. Scan stopped at (%ls).",
-               GetErrorMessage(E_NUM_FORMAT), pEnd);
-       SysTryReturnResult(NID_BASE, !(errno == ERANGE && (tmpRet == LLONG_MAX || tmpRet == LLONG_MIN)), E_NUM_FORMAT,
-               "[%s] Parsed value cannot fit into a long long.", GetErrorMessage(E_NUM_FORMAT));
-
-       ret = tmpRet;
-       return E_SUCCESS;
+       long long value;
+       result r = _NumberUtil::Parse(s, radix, value);
+       SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
+       ret = value;
+       return r;
 }
 
 }} //Tizen::Base