//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
* @brief This is the implementation file for Int8 class.
* @see Number class
*/
-
#include <wchar.h>
#include <errno.h>
#include <limits.h>
#include <FBaseCharacter.h>
#include <FBaseSysLog.h>
-
-
namespace Tizen { namespace Base
{
bool
Int8::Equals(const Object& obj) const
{
- const Int8* pOther = dynamic_cast <const Int8*>(&obj);
+ const Int8* pOther = dynamic_cast< const Int8* >(&obj);
if (pOther == null)
{
return (false);
int
Int8::GetHashCode(void) const
{
- return static_cast<int> (value);
+ return static_cast< int >(value);
}
int
Int8::GetHashCode(char val)
{
- return static_cast<int> (val);
+ return static_cast< int >(val);
}
result
Int8::Decode(const String& s, char& ret)
{
SysTryReturn(NID_BASE, s.GetLength() >= 1, E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] The length of string 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));
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;
}
result
Int8::Parse(const String& s, char& ret)
{
- int len = s.GetLength();
- SysTryReturn(NID_BASE, (len > 0 && len < 5), E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] The length of s(%ls) MUST be greater than 0 and less than 5.", GetErrorMessage(E_NUM_FORMAT), s.GetPointer());
-
return Parse(s, Character::RADIX_DECIMAL, 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));
- result r = E_SUCCESS;
-
errno = 0;
wchar_t* pEnd = null;
long value = wcstol(s.GetPointer(), &pEnd, radix);
- SysTryReturn(NID_BASE, (pEnd[0] == 0), E_NUM_FORMAT, E_NUM_FORMAT, "[%s] Int8 parse failed. Scan stopped at (%ls).",
+ SysTryReturn(NID_BASE, pEnd[0] == 0, E_NUM_FORMAT, E_NUM_FORMAT, "[%s] Int8 parse failed. Scan stopped at (%ls).",
GetErrorMessage(E_NUM_FORMAT), pEnd);
SysTryReturn(NID_BASE, !((value == LONG_MAX || value == LONG_MIN) && (errno != 0)), E_NUM_FORMAT, E_NUM_FORMAT,
"[%s] Parsed value cannot fit into an Int8.", GetErrorMessage(E_NUM_FORMAT));
ret = static_cast< char >(value);
}
- return r;
+ return E_SUCCESS;
}
char
Int8::ToChar(void) const
{
- return static_cast<char> (value);
+ return static_cast< char >(value);
}
short
Int8::ToShort(void) const
{
- return static_cast<short> (value);
+ return static_cast< short >(value);
}
int
Int8::ToInt(void) const
{
- return static_cast<int> (value);
+ return static_cast< int >(value);
}
long
Int8::ToLong(void) const
{
- return static_cast<long> (value);
+ return static_cast< long >(value);
}
long long
Int8::ToLongLong(void) const
{
- return static_cast<long long> (value);
+ return static_cast< long long >(value);
}
float
Int8::ToFloat(void) const
{
- return static_cast<float> (value);
+ return static_cast< float >(value);
}
double
Int8::ToDouble(void) const
{
- return static_cast<double> (value);
+ return static_cast< double >(value);
}
String