- added NumericString.h

- NumberParser improvements (internal Poco locale-awareness and parsing)
This commit is contained in:
Aleksandar Fabijanic
2012-09-30 05:17:56 +00:00
parent 3efcb444e0
commit f70ac1ca07
27 changed files with 904 additions and 199 deletions

View File

@@ -39,7 +39,6 @@
#include "Poco/RotateStrategy.h"
#include "Poco/PurgeStrategy.h"
#include "Poco/Message.h"
#include "Poco/NumberParser.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTime.h"
#include "Poco/LocalDateTime.h"
@@ -48,7 +47,6 @@
#include "Poco/Exception.h"
#include "Poco/Ascii.h"
namespace Poco {
@@ -232,7 +230,6 @@ void FileChannel::setRotation(const std::string& rotation)
while (it != end && Ascii::isSpace(*it)) ++it;
std::string unit;
while (it != end && Ascii::isAlpha(*it)) unit += *it++;
RotateStrategy* pStrategy = 0;
if ((rotation.find(',') != std::string::npos) || (rotation.find(':') != std::string::npos))
{

View File

@@ -36,13 +36,14 @@
#include "Poco/NumberParser.h"
#include "Poco/Exception.h"
#include "Poco/MemoryStream.h"
#include "Poco/String.h"
#if !defined(POCO_NO_LOCALE)
#include <locale>
#endif
#include "Poco/NumericString.h"
#include <cstdio>
#include <cctype>
#include <stdlib.h>
#if !defined(POCO_NO_LOCALE)
#include <locale>
#endif
#if defined(POCO_LONG_IS_64_BIT)
@@ -71,7 +72,7 @@ int NumberParser::parse(const std::string& s)
bool NumberParser::tryParse(const std::string& s, int& value)
{
return strToIntDec(s, value);
return strToInt(s.c_str(), value, NUM_BASE_DEC);
}
@@ -87,7 +88,7 @@ unsigned NumberParser::parseUnsigned(const std::string& s)
bool NumberParser::tryParseUnsigned(const std::string& s, unsigned& value)
{
return strToIntDec(s, value);
return strToInt(s.c_str(), value, NUM_BASE_DEC);
}
@@ -103,7 +104,7 @@ unsigned NumberParser::parseHex(const std::string& s)
bool NumberParser::tryParseHex(const std::string& s, unsigned& value)
{
return strToIntHex(s, value);
return strToInt(s.c_str(), value, NUM_BASE_HEX);
}
@@ -119,7 +120,7 @@ unsigned NumberParser::parseOct(const std::string& s)
bool NumberParser::tryParseOct(const std::string& s, unsigned& value)
{
return strToIntOct(s, value);
return strToInt(s.c_str(), value, NUM_BASE_OCT);
}
@@ -138,7 +139,7 @@ Int64 NumberParser::parse64(const std::string& s)
bool NumberParser::tryParse64(const std::string& s, Int64& value)
{
return strToIntDec(s, value);
return strToInt(s.c_str(), value, NUM_BASE_DEC);
}
@@ -154,7 +155,7 @@ UInt64 NumberParser::parseUnsigned64(const std::string& s)
bool NumberParser::tryParseUnsigned64(const std::string& s, UInt64& value)
{
return strToIntDec(s, value);
return strToInt(s.c_str(), value, NUM_BASE_DEC);
}
@@ -170,7 +171,7 @@ UInt64 NumberParser::parseHex64(const std::string& s)
bool NumberParser::tryParseHex64(const std::string& s, UInt64& value)
{
return strToIntHex(s, value);
return strToInt(s.c_str(), value, NUM_BASE_HEX);
}
@@ -186,7 +187,7 @@ UInt64 NumberParser::parseOct64(const std::string& s)
bool NumberParser::tryParseOct64(const std::string& s, UInt64& value)
{
return strToIntOct(s, value);
return strToInt(s.c_str(), value, NUM_BASE_OCT);
}
@@ -205,12 +206,7 @@ double NumberParser::parseFloat(const std::string& s)
bool NumberParser::tryParseFloat(const std::string& s, double& value)
{
Poco::MemoryInputStream istr(s.data(), s.size());
#if !defined(POCO_NO_LOCALE)
istr.imbue(std::locale::classic());
#endif
istr >> value;
return istr.eof() && !istr.fail();
return strToFloat(s.c_str(), value);
}

View File

@@ -52,19 +52,19 @@ int icompare(const std::string& str, std::string::size_type pos, std::string::si
std::string::const_iterator end1 = str.begin() + pos + n;
while (it1 != end1 && it2 != end2)
{
std::string::value_type c1 = Ascii::toLower(*it1);
std::string::value_type c2 = Ascii::toLower(*it2);
if (c1 < c2)
return -1;
else if (c1 > c2)
return 1;
++it1; ++it2;
std::string::value_type c1 = Ascii::toLower(*it1);
std::string::value_type c2 = Ascii::toLower(*it2);
if (c1 < c2)
return -1;
else if (c1 > c2)
return 1;
++it1; ++it2;
}
if (it1 == end1)
if (it1 == end1)
return it2 == end2 ? 0 : -1;
else
return 1;
else
return 1;
}
@@ -122,19 +122,19 @@ int icompare(const std::string& str, std::string::size_type pos, std::string::si
std::string::const_iterator end = str.begin() + pos + n;
while (it != end && *ptr)
{
std::string::value_type c1 = Ascii::toLower(*it);
std::string::value_type c2 = Ascii::toLower(*ptr);
if (c1 < c2)
return -1;
else if (c1 > c2)
return 1;
++it; ++ptr;
std::string::value_type c1 = Ascii::toLower(*it);
std::string::value_type c2 = Ascii::toLower(*ptr);
if (c1 < c2)
return -1;
else if (c1 > c2)
return 1;
++it; ++ptr;
}
if (it == end)
if (it == end)
return *ptr == 0 ? 0 : -1;
else
return 1;
else
return 1;
}