From 958dba749949a0c8b80bab45a3c9fd9cef251b2c Mon Sep 17 00:00:00 2001 From: "darpan.ka" Date: Fri, 13 Sep 2013 12:01:21 +0900 Subject: [PATCH] Implementation to support E_OUT_OF_RANGE in Parse() & Decode() Change-Id: Ief2890b96186c406aac8c96b3324caef631cd059 Signed-off-by: darpan.ka --- src/base/FBaseInt8.cpp | 45 +++++++++++++++++++++++++++++-------------- src/base/FBaseInteger8.cpp | 32 ++++++------------------------ src/base/FBaseShort.cpp | 45 +++++++++++++++++++++++++++++-------------- src/base/FBase_NumberUtil.cpp | 19 ++++++++++++++++-- src/base/FBase_NumberUtil.h | 8 ++++++-- 5 files changed, 91 insertions(+), 58 deletions(-) diff --git a/src/base/FBaseInt8.cpp b/src/base/FBaseInt8.cpp index 24a28ec..1ea54c1 100644 --- a/src/base/FBaseInt8.cpp +++ b/src/base/FBaseInt8.cpp @@ -27,6 +27,7 @@ #include #include #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 diff --git a/src/base/FBaseInteger8.cpp b/src/base/FBaseInteger8.cpp index bebb823..5d32253 100755 --- a/src/base/FBaseInteger8.cpp +++ b/src/base/FBaseInteger8.cpp @@ -27,6 +27,7 @@ #include #include #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; } diff --git a/src/base/FBaseShort.cpp b/src/base/FBaseShort.cpp index 99ffbfa..ac9ef93 100644 --- a/src/base/FBaseShort.cpp +++ b/src/base/FBaseShort.cpp @@ -27,6 +27,7 @@ #include #include #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 diff --git a/src/base/FBase_NumberUtil.cpp b/src/base/FBase_NumberUtil.cpp index 04b6caf..ed72ccf 100644 --- a/src/base/FBase_NumberUtil.cpp +++ b/src/base/FBase_NumberUtil.cpp @@ -26,6 +26,7 @@ #include #include #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 diff --git a/src/base/FBase_NumberUtil.h b/src/base/FBase_NumberUtil.h index 83cf166..029a701 100644 --- a/src/base/FBase_NumberUtil.h +++ b/src/base/FBase_NumberUtil.h @@ -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); -- 2.7.4