Implementation to support E_OUT_OF_RANGE in Parse() & Decode()
authordarpan.ka <darpan.ka@samsung.com>
Fri, 13 Sep 2013 03:01:21 +0000 (12:01 +0900)
committerdarpan.ka <darpan.ka@samsung.com>
Mon, 23 Sep 2013 09:04:14 +0000 (18:04 +0900)
Change-Id: Ief2890b96186c406aac8c96b3324caef631cd059
Signed-off-by: darpan.ka <darpan.ka@samsung.com>
src/base/FBaseInt8.cpp
src/base/FBaseInteger8.cpp
src/base/FBaseShort.cpp
src/base/FBase_NumberUtil.cpp
src/base/FBase_NumberUtil.h

index 24a28ec..1ea54c1 100644 (file)
@@ -27,6 +27,7 @@
 #include <FBaseCharacter.h>
 #include <FBaseSysLog.h>
 #include "FBase_NumberUtil.h"
+#include "FApp_AppInfo.h"
 
 namespace Tizen { namespace Base
 {
@@ -100,19 +101,27 @@ Int8::Decode(const String& s, char& ret)
        result r = _NumberUtil::Decode(s, value);
        SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
 
-       if (value > Int8::VALUE_MAX)
+       if ((Tizen::App::_AppInfo::GetApiVersion() >= _API_VERSION_2_0) && (Tizen::App::_AppInfo::GetApiVersion() <= _API_VERSION_2_2))
        {
-               ret = Int8::VALUE_MAX;
-       }
-       else if (value < Int8::VALUE_MIN)
-       {
-               ret = Int8::VALUE_MIN;
+               if (value > Int8::VALUE_MAX)
+               {
+                       ret = Int8::VALUE_MAX;
+               }
+               else if (value < Int8::VALUE_MIN)
+               {
+                       ret = Int8::VALUE_MIN;
+               }
+               else
+               {
+                       ret = static_cast< char >(value);
+               }
        }
        else
        {
+               SysTryReturnResult(NID_BASE, (value >= Int8::VALUE_MIN) && (value <= Int8::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
                ret = static_cast< char >(value);
        }
-       return r;
+       return E_SUCCESS;
 }
 
 result
@@ -128,19 +137,27 @@ Int8::Parse(const String& s, int radix, char& ret)
        result r = _NumberUtil::Parse(s, radix, value);
        SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
 
-       if (value > Int8::VALUE_MAX)
-       {
-               ret = Int8::VALUE_MAX;
-       }
-       else if (value < Int8::VALUE_MIN)
+       if ((Tizen::App::_AppInfo::GetApiVersion() >= _API_VERSION_2_0) && (Tizen::App::_AppInfo::GetApiVersion() <= _API_VERSION_2_2))
        {
-               ret = Int8::VALUE_MIN;
+               if (value > Int8::VALUE_MAX)
+               {
+                       ret = Int8::VALUE_MAX;
+               }
+               else if (value < Int8::VALUE_MIN)
+               {
+                       ret = Int8::VALUE_MIN;
+               }
+               else
+               {
+                       ret = static_cast< char >(value);
+               }
        }
        else
        {
+               SysTryReturnResult(NID_BASE, (value >= Int8::VALUE_MIN) && (value <= Int8::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
                ret = static_cast< char >(value);
        }
-       return r;
+       return E_SUCCESS;
 }
 
 char
index bebb823..5d32253 100755 (executable)
@@ -27,6 +27,7 @@
 #include <FBaseCharacter.h>
 #include <FBaseSysLog.h>
 #include "FBase_NumberUtil.h"
+#include "FApp_AppInfo.h"
 
 namespace Tizen { namespace Base
 {
@@ -106,19 +107,9 @@ Integer8::Decode(const String& inputStr, int8_t& ret)
        result r = _NumberUtil::Decode(inputStr, value);
        SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
 
-       if (value > Integer8::VALUE_MAX)
-       {
-               ret = Integer8::VALUE_MAX;
-       }
-       else if (value < Integer8::VALUE_MIN)
-       {
-               ret = Integer8::VALUE_MIN;
-       }
-       else
-       {
-               ret = static_cast< int8_t >(value);
-       }
-       return r;
+       SysTryReturnResult(NID_BASE, (value >= Integer8::VALUE_MIN) && (value <= Integer8::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
+       ret = static_cast< int8_t >(value);
+       return E_SUCCESS;
 }
 
 result
@@ -134,19 +125,8 @@ Integer8::Parse(const String& inputStr, int radix, int8_t& ret)
        result r = _NumberUtil::Parse(inputStr, radix, value);
        SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
 
-       if (value > Integer8::VALUE_MAX)
-       {
-               ret = Integer8::VALUE_MAX;
-       }
-       else if (value < Integer8::VALUE_MIN)
-       {
-               ret = Integer8::VALUE_MIN;
-       }
-       else
-       {
-               ret = static_cast< int8_t >(value);
-       }
-
+       SysTryReturnResult(NID_BASE, (value >= Integer8::VALUE_MIN) && (value <= Integer8::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
+       ret = static_cast< int8_t >(value);
        return E_SUCCESS;
 }
 
index 99ffbfa..ac9ef93 100644 (file)
@@ -27,6 +27,7 @@
 #include <FBaseCharacter.h>
 #include <FBaseSysLog.h>
 #include "FBase_NumberUtil.h"
+#include "FApp_AppInfo.h"
 
 namespace Tizen { namespace Base
 {
@@ -106,19 +107,27 @@ Short::Decode(const String& s, short& ret)
        result r = _NumberUtil::Decode(s, value);
        SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
 
-       if (value > Short::VALUE_MAX)
+       if ((Tizen::App::_AppInfo::GetApiVersion() >= _API_VERSION_2_0) && (Tizen::App::_AppInfo::GetApiVersion() <= _API_VERSION_2_2))
        {
-               ret = Short::VALUE_MAX;
-       }
-       else if (value < Short::VALUE_MIN)
-       {
-               ret = Short::VALUE_MIN;
+               if (value > Short::VALUE_MAX)
+               {
+                       ret = Short::VALUE_MAX;
+               }
+               else if (value < Short::VALUE_MIN)
+               {
+                       ret = Short::VALUE_MIN;
+               }
+               else
+               {
+                       ret = static_cast< short >(value);
+               }
        }
        else
        {
+               SysTryReturnResult(NID_BASE, (value >= Short::VALUE_MIN) && (value <= Short::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
                ret = static_cast< short >(value);
        }
-       return r;
+       return E_SUCCESS;
 }
 
 result
@@ -134,19 +143,27 @@ Short::Parse(const String& s, int radix, short& ret)
        result r = _NumberUtil::Parse(s, radix, value);
        SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
 
-       if (value > Short::VALUE_MAX)
-       {
-               ret = Short::VALUE_MAX;
-       }
-       else if (value < Short::VALUE_MIN)
+       if ((Tizen::App::_AppInfo::GetApiVersion() >= _API_VERSION_2_0) && (Tizen::App::_AppInfo::GetApiVersion() <= _API_VERSION_2_2))
        {
-               ret = Short::VALUE_MIN;
+               if (value > Short::VALUE_MAX)
+               {
+                       ret = Short::VALUE_MAX;
+               }
+               else if (value < Short::VALUE_MIN)
+               {
+                       ret = Short::VALUE_MIN;
+               }
+               else
+               {
+                       ret = static_cast< short >(value);
+               }
        }
        else
        {
+               SysTryReturnResult(NID_BASE, (value >= Short::VALUE_MIN) && (value <= Short::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
                ret = static_cast< short >(value);
        }
-       return r;
+       return E_SUCCESS;
 }
 
 char
index 04b6caf..ed72ccf 100644 (file)
@@ -26,6 +26,7 @@
 #include <FBaseCharacter.h>
 #include <FBaseSysLog.h>
 #include "FBase_NumberUtil.h"
+#include "FApp_AppInfo.h"
 
 namespace Tizen { namespace Base
 {
@@ -110,8 +111,15 @@ _NumberUtil::Parse(const String& inputStr, int radix, long& value)
        int sysErrno = errno;
 
        SysTryReturnResult(NID_BASE, pEnd[0] == 0, E_NUM_FORMAT, "_NumberUtil parse failed. Scan stopped at (%ls).", pEnd);
-       SysTryReturnResult(NID_BASE, !((value == LONG_MAX || value == LONG_MIN) && (sysErrno != 0)), E_NUM_FORMAT,
+       if ((Tizen::App::_AppInfo::GetApiVersion() >= _API_VERSION_2_0) && (Tizen::App::_AppInfo::GetApiVersion() <= _API_VERSION_2_2))
+       {
+               SysTryReturnResult(NID_BASE, !((value == LONG_MAX || value == LONG_MIN) && (sysErrno != 0)), E_NUM_FORMAT,
                "Parsed value cannot fit into a long.");
+       }
+       else
+       {
+               SysTryReturnResult(NID_BASE, sysErrno !=  ERANGE, E_OUT_OF_RANGE, "Parsed value cannot fit into a long.");
+       }
 
        return E_SUCCESS;
 }
@@ -131,8 +139,15 @@ _NumberUtil::Parse(const String& inputStr, int radix, long long& value)
        int sysErrno = errno;
 
        SysTryReturnResult(NID_BASE, pEnd[0] == 0, E_NUM_FORMAT, "_NumberUtil parse failed. Scan stopped at (%ls).", pEnd);
-       SysTryReturnResult(NID_BASE, !((value == LLONG_MAX || value == LLONG_MIN) && (sysErrno != 0)), E_NUM_FORMAT,
+       if ((Tizen::App::_AppInfo::GetApiVersion() >= _API_VERSION_2_0) && (Tizen::App::_AppInfo::GetApiVersion() <= _API_VERSION_2_2))
+       {
+               SysTryReturnResult(NID_BASE, !((value == LLONG_MAX || value == LLONG_MIN) && (sysErrno != 0)), E_NUM_FORMAT,
                "Parsed value cannot fit into a long long.");
+       }
+       else
+       {
+               SysTryReturnResult(NID_BASE, sysErrno !=  ERANGE, E_OUT_OF_RANGE, "Parsed value cannot fit into a long long.");
+       }
        return E_SUCCESS;
 }
 }} // Tizen::Base
index 83cf166..029a701 100644 (file)
@@ -49,6 +49,7 @@ public:
         *      @param[out]     value           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 string value is not between VALUE_MIN and VALUE_MAX range
         *      @remarks        This method accepts decimal, hexadecimal, and octal numbers given by the
         *                              following grammar:
         *
@@ -75,6 +76,7 @@ public:
         *      @param[out]     value           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 accepts decimal, hexadecimal, and octal numbers given by the
         *                              following grammar:
         *
@@ -104,7 +106,8 @@ public:
         *      @param[out]     value           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 specified @c radix is invalid.
+        *      @exception      E_OUT_OF_RANGE  The specified @c radix is invalid.
+        *                                      The parsed value is not between VALUE_MIN and VALUE_MAX range
         */
         static result Parse(const String& inputStr, int radix, long& value);
 
@@ -122,7 +125,8 @@ public:
         *      @param[out]     value           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 specified @c radix is invalid.
+        *      @exception      E_OUT_OF_RANGE  The specified @c radix is invalid.
+        *                                      The parsed value is not between VALUE_MIN and VALUE_MAX range
         */
         static result Parse(const String& inputStr, int radix, long long& value);