FBaseDoubleMatrix3.cpp
FBaseDoubleMatrix4.cpp
FBaseIntMatrix.cpp
+ FBase_NumberUtil.cpp
collection/FBaseColMapEntry.cpp
collection/FBaseColQueue.cpp
collection/FBaseColLinkedList.cpp
#include <FBaseResult.h>
#include <FBaseCharacter.h>
#include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
namespace Tizen { namespace Base
{
Int8::Int8(char value)
- : value((signed char)value)
+ : value(static_cast< signed char >(value))
, __pInt8Impl(null)
{
}
result
Int8::Decode(const String& s, char& ret)
{
- SysTryReturn(NID_BASE, s.GetLength() >= 1, E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] The length of input String MUST be greater than 0.", GetErrorMessage(E_NUM_FORMAT));
+ long value;
+ result r = _NumberUtil::Decode(s, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
- 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[startIndex] == L'#')
- {
- radix = Character::RADIX_HEXADECIMAL;
-
- // Remove '#'
- str.Remove(startIndex, 1);
- }
- else if (s[startIndex] == L'0' && (s.GetLength() >= minLength))
- {
- if (s[startIndex + 1] == L'x' || s[startIndex + 1] == L'X')
- {
- radix = Character::RADIX_HEXADECIMAL;
- }
- else
- {
- radix = Character::RADIX_OCTAL;
- }
- }
- else
- {
- radix = Character::RADIX_DECIMAL;
- }
-
- result r = E_SUCCESS;
-
- errno = 0;
- value = wcstol(str.GetPointer(), &pEnd, radix);
- SysTryCatch(NID_BASE, (pEnd[0] == 0), r = E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Int8 decode failed. Scan stopped at (%ls).", GetErrorMessage(E_NUM_FORMAT), pEnd);
- SysTryCatch(NID_BASE, !((value == LONG_MAX || value == LONG_MIN) && (errno != 0)), r = E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Decoded value cannot fit into an Int8.", GetErrorMessage(E_NUM_FORMAT));
-
-CATCH:
if (value > Int8::VALUE_MAX)
{
ret = Int8::VALUE_MAX;
}
- else if (value < (signed char) Int8::VALUE_MIN)
+ else if (value < Int8::VALUE_MIN)
{
- ret = (signed char) Int8::VALUE_MIN;
+ ret = Int8::VALUE_MIN;
}
else
{
- ret = (char) value;
+ ret = static_cast< char >(value);
}
-
return r;
}
result
Int8::Parse(const String& s, int radix, char& ret)
{
- SysTryReturn(NID_BASE, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) ||
- (radix == Character::RADIX_DECIMAL) || (radix == Character::RADIX_HEXADECIMAL)), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
- "[%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 input String MUST be greater than 0.",
- GetErrorMessage(E_NUM_FORMAT));
-
- 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).",
- 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));
+ long value;
+ 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 < static_cast< signed char >(Int8::VALUE_MIN))
+ else if (value < Int8::VALUE_MIN)
{
- ret = static_cast< signed char >(Int8::VALUE_MIN);
+ ret = Int8::VALUE_MIN;
}
else
{
ret = static_cast< char >(value);
}
-
- return E_SUCCESS;
+ return r;
}
char
#include <FBaseResult.h>
#include <FBaseCharacter.h>
#include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
namespace Tizen { namespace Base
{
result
Integer::Decode(const String& s, int& ret)
{
- SysTryReturn(NID_BASE, s.GetLength() >= 1, E_NUM_FORMAT, 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[startIndex] == L'#')
- {
- radix = Character::RADIX_HEXADECIMAL;
-
- // Remove '#'
- str.Remove(startIndex, 1);
- }
- else if (s[startIndex] == L'0' && (s.GetLength() >= minLength))
- {
- if (s[startIndex + 1] == L'x' || s[startIndex + 1] == L'X')
- {
- radix = Character::RADIX_HEXADECIMAL;
- }
- else
- {
- radix = Character::RADIX_OCTAL;
- }
- }
- else
- {
- radix = Character::RADIX_DECIMAL;
- }
-
- errno = 0;
- ret = wcstol(str.GetPointer(), &pEnd, radix);
- SysTryReturn(NID_BASE, (pEnd[0] == 0), E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Integer decode failed. Scan stopped at (%ls).", GetErrorMessage(E_NUM_FORMAT), pEnd);
- SysTryReturn(NID_BASE, !((ret == LONG_MAX || ret == LONG_MIN) && (errno != 0)), E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Decoded value cannot fit into an Integer.", GetErrorMessage(E_NUM_FORMAT));
-
- return E_SUCCESS;
+ long value;
+ result r = _NumberUtil::Decode(s, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
+ ret = static_cast< int >(value);
+ return r;
}
int
result
Integer::Parse(const String& s, int radix, int& ret)
{
- SysTryReturn(NID_BASE, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) ||
- (radix == Character::RADIX_DECIMAL) || (radix == Character::RADIX_HEXADECIMAL)), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
- "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_OUT_OF_RANGE), radix);
+ long value;
+ result r = _NumberUtil::Parse(s, radix, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
- int len = s.GetLength();
- 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,
- "[%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));
-
- ret = tmpRet;
- return E_SUCCESS;
+ if (value > Integer::VALUE_MAX)
+ {
+ ret = Integer::VALUE_MAX;
+ }
+ else if (value < Integer::VALUE_MIN)
+ {
+ ret = Integer::VALUE_MIN;
+ }
+ else
+ {
+ ret = static_cast< int >(value);
+ }
+ return r;
}
char
#include <FBaseResult.h>
#include <FBaseCharacter.h>
#include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
namespace Tizen { namespace Base
{
result
Integer8::Decode(const String& inputStr, int8_t& ret)
{
- SysTryReturnResult(NID_BASE, inputStr.GetLength() >= 1, E_NUM_FORMAT, "The length of input String MUST be greater than 0.");
+ long value;
+ result r = _NumberUtil::Decode(inputStr, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
- long value = 0;
- int radix = 0;
- int startIndex = 0;
- int minLength = 2;
- wchar_t* pEnd = null;
- String str(inputStr);
-
- if (inputStr[0] == L'-' || inputStr[0] == L'+')
- {
- startIndex = 1;
- minLength = 3;
- }
-
- // Find radix
- if (inputStr[startIndex] == L'#')
- {
- radix = Character::RADIX_HEXADECIMAL;
-
- // Remove '#'
- str.Remove(startIndex, 1);
- }
- else if (inputStr[startIndex] == L'0' && (inputStr.GetLength() >= minLength))
- {
- if (inputStr[startIndex + 1] == L'x' || inputStr[startIndex + 1] == L'X')
- {
- radix = Character::RADIX_HEXADECIMAL;
- }
- else
- {
- radix = Character::RADIX_OCTAL;
- }
- }
- else
- {
- radix = Character::RADIX_DECIMAL;
- }
-
- result r = E_SUCCESS;
-
- errno = 0;
- value = wcstol(str.GetPointer(), &pEnd, radix);
- int sysErrno = errno;
-
- SysTryCatch(NID_BASE, pEnd[0] == 0, r = E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Integer8 decode failed. Scan stopped at (%ls).", GetErrorMessage(E_NUM_FORMAT), pEnd);
- SysTryCatch(NID_BASE, !((value == LONG_MAX || value == LONG_MIN) && (sysErrno != 0)), r = E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Decoded value cannot fit into an Integer8.", GetErrorMessage(E_NUM_FORMAT));
-
-CATCH:
if (value > Integer8::VALUE_MAX)
{
ret = Integer8::VALUE_MAX;
{
ret = static_cast< int8_t >(value);
}
-
return r;
}
result
Integer8::Parse(const String& inputStr, int radix, int8_t& ret)
{
- SysTryReturnResult(NID_BASE, ((radix >= Character::RADIX_BINARY) && (radix <= 36)), E_OUT_OF_RANGE,
- "The radix MUST be between 2 and 36.");
-
- int len = inputStr.GetLength();
- SysTryReturnResult(NID_BASE, len > 0, E_NUM_FORMAT, "The length of input String MUST be greater than 0.");
-
- errno = 0;
- wchar_t* pEnd = null;
- long value = wcstol(inputStr.GetPointer(), &pEnd, radix);
- int sysErrno = errno;
-
- SysTryReturnResult(NID_BASE, pEnd[0] == 0, E_NUM_FORMAT, "Integer8 parse failed. Scan stopped at (%ls).", pEnd);
- SysTryReturnResult(NID_BASE, !((value == LONG_MAX || value == LONG_MIN) && (sysErrno != 0)), E_NUM_FORMAT,
- "Parsed value cannot fit into an Integer8.");
+ long value;
+ result r = _NumberUtil::Parse(inputStr, radix, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
if (value > Integer8::VALUE_MAX)
{
#include <FBaseResult.h>
#include <FBaseCharacter.h>
#include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
namespace Tizen { namespace Base
{
result
Long::Decode(const String& s, long& ret)
{
- SysTryReturn(NID_BASE, s.GetLength() >= 1, E_NUM_FORMAT, 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[startIndex] == L'#')
- {
- radix = Character::RADIX_HEXADECIMAL;
-
- // Remove '#'
- str.Remove(startIndex, 1);
- }
- else if (s[startIndex] == L'0' && (s.GetLength() >= minLength))
- {
- if (s[startIndex + 1] == L'x' || s[startIndex + 1] == L'X')
- {
- radix = Character::RADIX_HEXADECIMAL;
- }
- else
- {
- radix = Character::RADIX_OCTAL;
- }
- }
- else
- {
- radix = Character::RADIX_DECIMAL;
- }
-
- errno = 0;
- ret = wcstol(str.GetPointer(), &pEnd, radix);
- SysTryReturn(NID_BASE, (pEnd[0] == 0), E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Long decode failed. Scan stopped at (%ls).", GetErrorMessage(E_NUM_FORMAT), pEnd);
- SysTryReturn(NID_BASE, !((ret == LONG_MAX || ret == LONG_MIN) && (errno != 0)), E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Decoded value cannot fit into a Long.", GetErrorMessage(E_NUM_FORMAT));
-
- return E_SUCCESS;
+ long value;
+ result r = _NumberUtil::Decode(s, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
+ ret = value;
+ return r;
}
result
result
Long::Parse(const String& s, int radix, long& ret)
{
- SysTryReturn(NID_BASE, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) ||
- (radix == Character::RADIX_DECIMAL) || (radix == Character::RADIX_HEXADECIMAL)), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
- "[%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 input String MUST be greater than 0.",
- GetErrorMessage(E_NUM_FORMAT));
-
- errno = 0;
- wchar_t* pEnd = null;
- long tmpRet = wcstol(s.GetPointer(), &pEnd, radix);
- SysTryReturn(NID_BASE, pEnd[0] == 0, E_NUM_FORMAT, E_NUM_FORMAT, "[%s] Long 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 a Long.", GetErrorMessage(E_NUM_FORMAT));
-
- ret = tmpRet;
- return E_SUCCESS;
+ long value;
+ result r = _NumberUtil::Parse(s, radix, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
+ ret = value;
+ return r;
}
char
#include <FBaseResult.h>
#include <FBaseCharacter.h>
#include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
namespace Tizen { namespace Base
{
result
LongLong::Parse(const String& s, int radix, long long& ret)
{
- SysTryReturnResult(NID_BASE, radix == Character::RADIX_BINARY || radix == Character::RADIX_OCTAL ||
- radix == Character::RADIX_DECIMAL || radix == Character::RADIX_HEXADECIMAL, E_OUT_OF_RANGE,
- "[%s] The radix(%d) MUST be one of 2, 8, 10 and 16.", GetErrorMessage(E_OUT_OF_RANGE), radix);
-
- int len = s.GetLength();
- SysTryReturnResult(NID_BASE, len > 0, E_NUM_FORMAT, "[%s] The length of input String MUST be greater than 0.",
- GetErrorMessage(E_NUM_FORMAT));
-
- errno = 0;
- wchar_t* pEnd = null;
- long long tmpRet = wcstoll(s.GetPointer(), &pEnd, radix);
- SysTryReturnResult(NID_BASE, pEnd[0] == 0, E_NUM_FORMAT, "[%s] LongLong parse failed. Scan stopped at (%ls).",
- GetErrorMessage(E_NUM_FORMAT), pEnd);
- SysTryReturnResult(NID_BASE, !(errno == ERANGE && (tmpRet == LLONG_MAX || tmpRet == LLONG_MIN)), E_NUM_FORMAT,
- "[%s] Parsed value cannot fit into a long long.", GetErrorMessage(E_NUM_FORMAT));
-
- ret = tmpRet;
- return E_SUCCESS;
+ long long value;
+ result r = _NumberUtil::Parse(s, radix, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
+ ret = value;
+ return r;
}
}} //Tizen::Base
#include <FBaseResult.h>
#include <FBaseCharacter.h>
#include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
namespace Tizen { namespace Base
{
result
Short::Decode(const String& s, short& ret)
{
- SysTryReturn(NID_BASE, s.GetLength() >= 1, E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] The length of input String MUST be greater than 0.", GetErrorMessage(E_NUM_FORMAT));
+ long value;
+ result r = _NumberUtil::Decode(s, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
- 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[startIndex] == L'#')
- {
- radix = Character::RADIX_HEXADECIMAL;
-
- // Remove '#'
- str.Remove(startIndex, 1);
- }
- else if (s[startIndex] == L'0' && (s.GetLength() >= minLength))
- {
- if (s[startIndex + 1] == L'x' || s[startIndex + 1] == L'X')
- {
- radix = Character::RADIX_HEXADECIMAL;
- }
- else
- {
- radix = Character::RADIX_OCTAL;
- }
- }
- else
- {
- radix = Character::RADIX_DECIMAL;
- }
-
- result r = E_SUCCESS;
-
- errno = 0;
- value = wcstol(str.GetPointer(), &pEnd, radix);
- SysTryCatch(NID_BASE, (pEnd[0] == 0), r = E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Short decode failed. Scan stopped at (%ls).", GetErrorMessage(E_NUM_FORMAT), pEnd);
- SysTryCatch(NID_BASE, !((value == LONG_MAX || value == LONG_MIN) && (errno != 0)), r = E_NUM_FORMAT, E_NUM_FORMAT,
- "[%s] Decoded value cannot fit into Short.", GetErrorMessage(E_NUM_FORMAT));
-
-CATCH:
if (value > Short::VALUE_MAX)
{
ret = Short::VALUE_MAX;
}
else
{
- ret = (short) value;
+ ret = static_cast< short >(value);
}
-
return r;
}
result
Short::Parse(const String& s, int radix, short& ret)
{
- SysTryReturn(NID_BASE, ((radix == Character::RADIX_BINARY) || (radix == Character::RADIX_OCTAL) ||
- (radix == Character::RADIX_DECIMAL) || (radix == Character::RADIX_HEXADECIMAL)), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
- "[%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 input String MUST be greater than 0.",
- GetErrorMessage(E_NUM_FORMAT));
-
- 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] Short parse failed. Scan stopped at (%ls).", GetErrorMessage(E_NUM_FORMAT), pEnd);
- SysTryReturn(NID_BASE, !(value > Short::VALUE_MAX || value < Short::VALUE_MIN) || (errno != 0), E_NUM_FORMAT,
- E_NUM_FORMAT, "[%s] Parsed value cannot fit into Short.", GetErrorMessage(E_NUM_FORMAT));
+ long value;
+ result r = _NumberUtil::Parse(s, radix, value);
+ SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
if (value > Short::VALUE_MAX)
{
{
ret = static_cast< short >(value);
}
-
- return E_SUCCESS;
+ return r;
}
char
--- /dev/null
+//
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file FBase_NumberUtil.cpp
+ * @brief This is the implementation file for _NumberUtil class.
+ */
+#include <wchar.h>
+#include <errno.h>
+#include <limits.h>
+#include <FBaseInteger8.h>
+#include <FBaseResult.h>
+#include <FBaseCharacter.h>
+#include <FBaseSysLog.h>
+#include "FBase_NumberUtil.h"
+
+namespace Tizen { namespace Base
+{
+
+_NumberUtil::~_NumberUtil(void)
+{
+}
+
+result
+_NumberUtil::FindRadix(String& inputStr, int& radix)
+{
+ SysTryReturnResult(NID_BASE, inputStr.GetLength() >= 1, E_NUM_FORMAT, "The length of input String MUST be greater than 0.");
+ int startIndex = 0;
+ int minLength = 2;
+ wchar_t* pEnd = null;
+ if (inputStr[0] == L'-' || inputStr[0] == L'+')
+ {
+ startIndex = 1;
+ minLength = 3;
+ }
+
+ // Find radix
+ if (inputStr[startIndex] == L'#')
+ {
+ radix = Character::RADIX_HEXADECIMAL;
+
+ // Remove '#'
+ inputStr.Remove(startIndex, 1);
+ }
+ else if (inputStr[startIndex] == L'0' && (inputStr.GetLength() >= minLength))
+ {
+ if (inputStr[startIndex + 1] == L'x' || inputStr[startIndex + 1] == L'X')
+ {
+ radix = Character::RADIX_HEXADECIMAL;
+ }
+ else
+ {
+ radix = Character::RADIX_OCTAL;
+ }
+ }
+ else
+ {
+ radix = Character::RADIX_DECIMAL;
+ }
+ return E_SUCCESS;
+}
+
+result
+_NumberUtil::Decode(const String& inputStr, long& value)
+{
+ int radix = 0;
+ String str(inputStr);
+ result res = _NumberUtil::FindRadix(str,radix);
+ res = Parse(str, radix, value);
+ SysTryReturnResult(NID_BASE, res == E_SUCCESS, res, "_NumberUtil decode failed");
+ return E_SUCCESS;
+}
+
+result
+_NumberUtil::Decode(const String& inputStr, long long& value)
+{
+ int radix = 0;
+ String str(inputStr);
+ result res = _NumberUtil::FindRadix(str,radix);
+ res = Parse(str, radix, value);
+ SysTryReturnResult(NID_BASE, res == E_SUCCESS, res, "_NumberUtil decode failed");
+ return E_SUCCESS;
+}
+
+result
+_NumberUtil::Parse(const String& inputStr, int radix, long& value)
+{
+ SysTryReturnResult(NID_BASE, ((radix >= Character::RADIX_BINARY) && (radix <= 36)), E_OUT_OF_RANGE,
+ "The radix MUST be between 2 and 36.");
+
+ int len = inputStr.GetLength();
+ SysTryReturnResult(NID_BASE, len > 0, E_NUM_FORMAT, "The length of input String MUST be greater than 0.");
+
+ errno = 0;
+ wchar_t* pEnd = null;
+ value = wcstol(inputStr.GetPointer(), &pEnd, radix);
+ 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,
+ "Parsed value cannot fit into a long.");
+
+ return E_SUCCESS;
+}
+
+result
+_NumberUtil::Parse(const String& inputStr, int radix, long long& value)
+{
+ SysTryReturnResult(NID_BASE, ((radix >= Character::RADIX_BINARY) && (radix <= 36)), E_OUT_OF_RANGE,
+ "The radix MUST be between 2 and 36.");
+
+ int len = inputStr.GetLength();
+ SysTryReturnResult(NID_BASE, len > 0, E_NUM_FORMAT, "The length of input String MUST be greater than 0.");
+
+ errno = 0;
+ wchar_t* pEnd = null;
+ value = wcstoll(inputStr.GetPointer(), &pEnd, radix);
+ 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,
+ "Parsed value cannot fit into a long long.");
+ return E_SUCCESS;
+}
+}} // Tizen::Base
--- /dev/null
+//
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file FBase_NumberUtil.h
+ * @brief This is the header file for the _NumberUtil class.
+ *
+ * This header file contains the declarations of the _NumberUtil class.
+ */
+#ifndef _FBASE_INTERNAL_NUMBER_UTIL_H_
+#define _FBASE_INTERNAL_NUMBER_UTIL_H_
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+
+namespace Tizen { namespace Base
+{
+
+class _NumberUtil
+{
+public:
+ /**
+ * This is the destructor for this class.
+ *
+ * @since 3.0
+ */
+ virtual ~_NumberUtil(void);
+
+ /**
+ * Decodes a string into a @c signed @c long.
+ *
+ * @since 3.0
+ *
+ * @return An error code
+ * @param[in] inputStr A numeric value
+ * @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.
+ * @remarks This method accepts decimal, hexadecimal, and octal numbers given by the
+ * following grammar:
+ *
+ * @code
+ * - DecodableString:
+ * Sign[opt] DecimalNumeral
+ * Sign[opt] 0x HexDigits
+ * Sign[opt] 0X HexDigits
+ * Sign[opt] # HexDigits
+ * Sign[opt] 0 OctalDigits
+ * - Sign:
+ * '-'
+ * @endcode
+ */
+ static result Decode(const String& inputStr, long& value);
+
+ /**
+ * Decodes a string into a @c signed @c long long.
+ *
+ * @since 3.0
+ *
+ * @return An error code
+ * @param[in] inputStr A numeric value
+ * @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.
+ * @remarks This method accepts decimal, hexadecimal, and octal numbers given by the
+ * following grammar:
+ *
+ * @code
+ * - DecodableString:
+ * Sign[opt] DecimalNumeral
+ * Sign[opt] 0x HexDigits
+ * Sign[opt] 0X HexDigits
+ * Sign[opt] # HexDigits
+ * Sign[opt] 0 OctalDigits
+ * - Sign:
+ * '-'
+ * @endcode
+ */
+ static result Decode(const String& inputStr, long long& value);
+
+ /**
+ * Parses the specified string representing a numeric value
+ * using the specified radix and returns the value as @c signed @c long.
+ *
+ * @since 3.0
+ *
+ * @return An error code
+ * @param[in] inputStr A string representing a numeric value
+ * @param[in] radix The radix of the string representing a numeric value @n
+ * Radix ranges in between 2 to 36.
+ * @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.
+ */
+ static result Parse(const String& inputStr, int radix, long& value);
+
+
+ /**
+ * Parses the specified string representing a numeric value
+ * using the specified radix and returns the value as @c signed @c long long.
+ *
+ * @since 3.0
+ *
+ * @return An error code
+ * @param[in] inputStr A string representing a numeric value
+ * @param[in] radix The radix of the string representing a numeric value @n
+ * Radix ranges in between 2 to 36.
+ * @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.
+ */
+ static result Parse(const String& inputStr, int radix, long long& value);
+
+private:
+ //
+ // This is the default constructor for this class.
+ //
+ // @since 3.0
+ //
+ _NumberUtil();
+
+ //
+ // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @since 3.0
+ // @param[in] rhs An instance of %_NumberUtil
+ //
+ _NumberUtil(const _NumberUtil& rhs);
+
+ //
+ // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @since 3.0
+ // @param[in] rhs An instance of %_NumberUtil
+ //
+ _NumberUtil& operator =(const _NumberUtil& rhs);
+
+ //
+ // Finds the radix by parsing the input string.
+ //
+ // @since 3.0
+ //
+ // @return An error code
+ // @param[in] inputStr A numeric value
+ // @param[out] radix radix of the input string
+ // @exception E_SUCCESS The method is successful.
+ // @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
+ // @remarks This method accepts decimal, hexadecimal, and octal numbers given by the
+ // following grammar:
+ //
+ // @code
+ // - DecodableString:
+ // Sign[opt] DecimalNumeral
+ // Sign[opt] 0x HexDigits
+ // Sign[opt] 0X HexDigits
+ // Sign[opt] # HexDigits
+ // Sign[opt] 0 OctalDigits
+ // - Sign:
+ // '-'
+ // @endcode
+ //
+ static result FindRadix(String& inputStr, int& radix);
+}; // _NumberUtil
+
+}} // Tizen::Base
+
+#endif // _FBASE_INTERNAL_NUMBER_UTIL_H_