[N_SE-33612] In Decode(), add code to check if str[0] is '+' or '-'
authordahyeong.kim <dahyeong.kim@samsung.com>
Sun, 14 Apr 2013 10:50:30 +0000 (19:50 +0900)
committerdahyeong.kim <dahyeong.kim@samsung.com>
Sun, 14 Apr 2013 10:51:56 +0000 (19:51 +0900)
Change-Id: Iaa9e9d7763c847cc1d9054de2fb207342d196f01
Signed-off-by: dahyeong.kim <dahyeong.kim@samsung.com>
src/base/FBaseInt8.cpp
src/base/FBaseInteger.cpp
src/base/FBaseLong.cpp
src/base/FBaseShort.cpp

index 284df62..40dd62f 100644 (file)
@@ -109,7 +109,7 @@ Int8::Decode(const String& s, char& ret)
        wchar_t* pEnd = null;
        String str(s);
 
-       if (s[0] == L'-')
+       if (s[0] == L'-' || s[0] == L'+')
        {
                startIndex = 1;
                minLength = 3;
index 244374c..96563b2 100644 (file)
@@ -90,20 +90,28 @@ Integer::Decode(const String& s, int& ret)
                "[%s] The length of s 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;
                }
index d349748..b6ed711 100644 (file)
@@ -101,20 +101,28 @@ Long::Decode(const String& s, long& ret)
                "[%s] The length of s 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;
                }
index f40452c..18f8fa5 100644 (file)
@@ -108,20 +108,28 @@ Short::Decode(const String& s, short& ret)
 
        long value = 0;
        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;
                }