[3.0][Cherry-pick] Remove privacy input data in log & Remove needless log
[platform/framework/native/appfw.git] / src / base / FBaseInteger.cpp
index 244374c..12b5fdc 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 Integer class.
  * @see                        Number
  */
-
 #include <wchar.h>
 #include <limits.h>
 #include <errno.h>
@@ -74,7 +72,7 @@ Integer::CompareTo(const Integer& value) const
 bool
 Integer::Equals(const Object& obj) const
 {
-       const Integer* pOther = dynamic_cast <const Integer*>(&obj);
+       const Integer* pOther = dynamic_cast< const Integer* >(&obj);
        if (pOther == null)
        {
                return false;
@@ -87,23 +85,31 @@ result
 Integer::Decode(const String& s, int& ret)
 {
        SysTryReturn(NID_BASE, s.GetLength() >= 1, E_NUM_FORMAT, E_NUM_FORMAT,
-               "[%s] The length of s MUST be greater than 0.", GetErrorMessage(E_NUM_FORMAT));
+               "[%s] The length of input String MUST be greater than 0.", GetErrorMessage(E_NUM_FORMAT));
 
        int radix = 0;
+       int startIndex = 0;
+       int minLength = 2;
        wchar_t* pEnd = null;
        String str(s);
 
+       if (s[0] == L'-' || s[0] == L'+')
+       {
+               startIndex = 1;
+               minLength = 3;
+       }
+
        // Find radix
-       if (s[0] == L'#')
+       if (s[startIndex] == L'#')
        {
                radix = Character::RADIX_HEXADECIMAL;
 
                // Remove '#'
-               str.Remove(0, 1);
+               str.Remove(startIndex, 1);
        }
-       else if (s[0] == L'0' && (s.GetLength() >= 2))
+       else if (s[startIndex] == L'0' && (s.GetLength() >= minLength))
        {
-               if (s[1] == L'x' || s[1] == L'X')
+               if (s[startIndex + 1] == L'x' || s[startIndex + 1] == L'X')
                {
                        radix = Character::RADIX_HEXADECIMAL;
                }
@@ -142,11 +148,6 @@ Integer::GetHashCode(int val)
 result
 Integer::Parse(const String& s, int& ret)
 {
-       int len = s.GetLength();
-       SysTryReturn(NID_BASE, (len > 0 && len < 12), E_NUM_FORMAT, E_NUM_FORMAT,
-               "[%s] The length of s(%ls) MUST be greater than 0 and less than 12.",
-               GetErrorMessage(E_NUM_FORMAT), s.GetPointer());
-
        return Parse(s, Character::RADIX_DECIMAL, ret);
 }
 
@@ -158,13 +159,13 @@ Integer::Parse(const String& s, int radix, int& ret)
                "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_OUT_OF_RANGE), radix);
 
        int len = s.GetLength();
-       SysTryReturn(NID_BASE, (len > 0), E_NUM_FORMAT, E_NUM_FORMAT, "[%s] The length of s MUST be greater than 0.",
+       SysTryReturn(NID_BASE, len > 0, E_NUM_FORMAT, E_NUM_FORMAT, "[%s] The length of input String MUST be greater than 0.",
                GetErrorMessage(E_NUM_FORMAT));
 
        errno = 0;
        wchar_t* pEnd = null;
        int tmpRet = wcstol(s.GetPointer(), &pEnd, radix);
-       SysTryReturn(NID_BASE, (pEnd[0] == 0), E_NUM_FORMAT, E_NUM_FORMAT,
+       SysTryReturn(NID_BASE, pEnd[0] == 0, E_NUM_FORMAT, E_NUM_FORMAT,
                "[%s] Integer parse failed. Scan stopped at (%ls).", GetErrorMessage(E_NUM_FORMAT), pEnd);
        SysTryReturn(NID_BASE, !((tmpRet == LONG_MAX || tmpRet == LONG_MIN) && (errno != 0)), E_NUM_FORMAT, E_NUM_FORMAT,
                "[%s] Parsed value cannot fit into an Integer.", GetErrorMessage(E_NUM_FORMAT));
@@ -176,13 +177,13 @@ Integer::Parse(const String& s, int radix, int& ret)
 char
 Integer::ToChar(void) const
 {
-       return static_cast<char> (value);
+       return static_cast< char >(value);
 }
 
 short
 Integer::ToShort(void) const
 {
-       return static_cast<short> (value);
+       return static_cast< short >(value);
 }
 
 int
@@ -194,25 +195,25 @@ Integer::ToInt(void) const
 long
 Integer::ToLong(void) const
 {
-       return static_cast<long> (value);
+       return static_cast< long >(value);
 }
 
 long long
 Integer::ToLongLong(void) const
 {
-       return static_cast<long long> (value);
+       return static_cast< long long >(value);
 }
 
 float
 Integer::ToFloat(void) const
 {
-       return static_cast<float> (value);
+       return static_cast< float >(value);
 }
 
 double
 Integer::ToDouble(void) const
 {
-       return static_cast<double> (value);
+       return static_cast< double >(value);
 }
 
 String