Remove dead code in Locales.
[platform/framework/native/appfw.git] / src / base / FBaseDouble.cpp
index 5d66b87..8aebf82 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);
@@ -18,9 +17,8 @@
 /**
  * @file               FBaseDouble.cpp
  * @brief              This is the implementation file for Double class.
- * @see                        Number
+ * @see                Number
  */
-
 #include <cfloat>
 #include <math.h>
 #include <stdio.h>
@@ -29,9 +27,8 @@
 #include <limits.h>
 #include <FBaseDouble.h>
 #include <FBaseResult.h>
-#include "FBase_NativeError.h"
 #include <FBaseSysLog.h>
-
+#include "FBase_LocalizedNumParser.h"
 
 namespace Tizen { namespace Base
 {
@@ -113,7 +110,7 @@ Double::CompareTo(const Double& value) const
 bool
 Double::Equals(const Object& obj) const
 {
-       const Double* pOther = dynamic_cast <const Double*>(&obj);
+       const Double* pOther = dynamic_cast< const Double* >(&obj);
 
        if (pOther == null)
        {
@@ -133,8 +130,8 @@ Double::Equals(const Object& obj) const
 int
 Double::GetHashCode(void) const
 {
-       double* pTemp = const_cast<double*> (&value);
-       int* pValueLow = reinterpret_cast<int*> (pTemp);
+       double* pTemp = const_cast< double* >(&value);
+       int* pValueLow = reinterpret_cast< int* >(pTemp);
        int* pValueHigh = pValueLow + 1;
        return *pValueLow + *pValueHigh;
 }
@@ -142,7 +139,7 @@ Double::GetHashCode(void) const
 int
 Double::GetHashCode(double val)
 {
-       int* pValueLow = reinterpret_cast<int*> (&val);
+       int* pValueLow = reinterpret_cast< int* >(&val);
        int* pValueHigh = pValueLow + 1;
        return *pValueLow + *pValueHigh;
 }
@@ -150,13 +147,14 @@ Double::GetHashCode(double val)
 result
 Double::Parse(const String& s, double& ret)
 {
-       wchar_t* pEnd = null;
-       errno = 0;
-       double tmpRet = wcstod(s.GetPointer(), &pEnd);
-       SysTryReturnResult(NID_BASE, ((!(!Double::Compare(tmpRet, 0)  && errno == EINVAL)) && (pEnd[0] == 0)), E_NUM_FORMAT,
-               "Double parse failed with reason (%s). Scan stopped at (%ls)", __ConvertNativeErrorToMessage(errno), pEnd);
-       SysTryReturnResult(NID_BASE, !(errno != 0 && (!Double::Compare(tmpRet, HUGE_VAL)|| !Double::Compare(tmpRet, -HUGE_VAL))),
-               E_NUM_FORMAT, "Parsed value cannot fit into a Double.");
+       double tmpRet = _LocalizedNumParser::ToDouble(s, "");
+
+       if (IsNaN(tmpRet))
+       {
+               result r = GetLastResult();
+               SysLogException(NID_BASE, r, "[%s] Propagating.", GetErrorMessage(r));
+               return r;
+       }
 
        ret = tmpRet;
        return E_SUCCESS;
@@ -165,37 +163,37 @@ Double::Parse(const String& s, double& ret)
 char
 Double::ToChar(void) const
 {
-       return static_cast<char> (value);
+       return static_cast< char >(value);
 }
 
 short
 Double::ToShort(void) const
 {
-       return static_cast<short> (value);
+       return static_cast< short >(value);
 }
 
 int
 Double::ToInt(void) const
 {
-       return static_cast<int> (value);
+       return static_cast< int >(value);
 }
 
 long
 Double::ToLong(void) const
 {
-       return static_cast<long> (value);
+       return static_cast< long >(value);
 }
 
 long long
 Double::ToLongLong(void) const
 {
-       return static_cast<long long> (value);
+       return static_cast< long long >(value);
 }
 
 float
 Double::ToFloat(void) const
 {
-       return static_cast<float> (value);
+       return static_cast< float >(value);
 }
 
 double
@@ -207,29 +205,13 @@ Double::ToDouble(void) const
 String
 Double::ToString(void) const
 {
-       return(Double::ToString(value));
+       return Double::ToString(value);
 }
 
 String
 Double::ToString(double value)
 {
-       const static unsigned int MAX_DIG = 17 + 3;
-       const static unsigned int DOUBLE_LENGTH_MAX = __DBL_MAX_10_EXP + MAX_DIG;
-
-       if (Double::IsNaN(value))
-       {
-               return String(L"NaN");
-       }
-       else if (Double::IsInfinity(value))
-       {
-               return String(L"Infinity");
-       }
-       else
-       {
-               wchar_t sValue[DOUBLE_LENGTH_MAX + 1] = {0, };
-               swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%#lg", value);
-               return String(sValue);
-       }
+       return _LocalizedNumParser::ToString(value, "");
 }
 
 long long
@@ -251,31 +233,31 @@ Double::ToDoubleFromBits(long long value)
 bool
 Double::IsFinite(double d)
 {
-       return((isfinite(d) != 0) ? true : false);
+       return isfinite(d);
 }
 
 bool
 Double::IsInfinity(void) const
 {
-       return(Double::IsInfinity(value));
+       return Double::IsInfinity(value);
 }
 
 bool
 Double::IsInfinity(double value)
 {
-       return(!Double::IsFinite(value));
+       return !Double::IsFinite(value);
 }
 
 bool
 Double::IsNaN(void) const
 {
-       return(Double::IsNaN(value));
+       return Double::IsNaN(value);
 }
 
 bool
 Double::IsNaN(double value)
 {
-       return((isnan(value) != 0) ? true : false);
+       return isnan(value);
 }
 
 double