From: dahyeong.kim Date: Mon, 15 Apr 2013 07:52:29 +0000 (+0900) Subject: [N_SE-33612] In Decode(), add code to check if str[0] is '+' or '-' X-Git-Tag: accepted/tizen_2.1/20130425.034849~60 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6eb6f89104586e3ac94a7728c417260c5ffb8452;p=framework%2Fosp%2Fappfw.git [N_SE-33612] In Decode(), add code to check if str[0] is '+' or '-' Change-Id: I852f4674462538d534409551d6d20503de3cc79d Signed-off-by: dahyeong.kim --- diff --git a/inc/FBaseInt8.h b/inc/FBaseInt8.h index 7360927..9986875 100644 --- a/inc/FBaseInt8.h +++ b/inc/FBaseInt8.h @@ -198,6 +198,13 @@ public: * - Sign: * '-' * @endcode + * @remarks This method has portability issue. @n + * When the specified string is nagative number in the ARM architecture, type casting is needed like following code. + * @code + * char ret; + * Int8::Decode(L"-0X20", ret); + * SomeOutputFunction(static_cast< signed char >(ret)); + * @endcode */ static result Decode(const String& s, char& ret); diff --git a/inc/FBaseString.h b/inc/FBaseString.h index 10178ba..409a50a 100644 --- a/inc/FBaseString.h +++ b/inc/FBaseString.h @@ -92,7 +92,7 @@ public: * * @param[in] ch A Unicode character */ - String(const wchar_t ch); + String(wchar_t ch); /** * Initializes this instance of %String with the specified Unicode string. diff --git a/src/base/FBaseInt8.cpp b/src/base/FBaseInt8.cpp index 284df62..40dd62f 100644 --- a/src/base/FBaseInt8.cpp +++ b/src/base/FBaseInt8.cpp @@ -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; diff --git a/src/base/FBaseInteger.cpp b/src/base/FBaseInteger.cpp index 244374c..96563b2 100644 --- a/src/base/FBaseInteger.cpp +++ b/src/base/FBaseInteger.cpp @@ -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; } diff --git a/src/base/FBaseLong.cpp b/src/base/FBaseLong.cpp index d349748..b6ed711 100644 --- a/src/base/FBaseLong.cpp +++ b/src/base/FBaseLong.cpp @@ -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; } diff --git a/src/base/FBaseShort.cpp b/src/base/FBaseShort.cpp index f40452c..18f8fa5 100644 --- a/src/base/FBaseShort.cpp +++ b/src/base/FBaseShort.cpp @@ -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; } diff --git a/src/base/FBaseString.cpp b/src/base/FBaseString.cpp index dac9971..24dda81 100644 --- a/src/base/FBaseString.cpp +++ b/src/base/FBaseString.cpp @@ -74,7 +74,7 @@ String::String(int capacity) SysTryReturnVoidResult(NID_BASE, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed."); } -String::String(const wchar_t ch) +String::String(wchar_t ch) : __capacity(0) , __length(0) , __hash(0)