trunk/branch integration: using Poco::Ascii & memoryleak fix

This commit is contained in:
Marian Krivos 2011-08-23 06:47:41 +00:00
parent 4cea48e712
commit 9cf13e2976

View File

@ -46,7 +46,7 @@
#include "Poco/String.h" #include "Poco/String.h"
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include <cctype> #include "Poco/Ascii.h"
namespace Poco { namespace Poco {
@ -217,17 +217,17 @@ const std::string& FileChannel::path() const
void FileChannel::setRotation(const std::string& rotation) void FileChannel::setRotation(const std::string& rotation)
{ {
std::string::const_iterator it = rotation.begin(); std::string::const_iterator it = rotation.begin();
std::string::const_iterator end = rotation.end(); std::string::const_iterator end = rotation.end();
int n = 0; int n = 0;
while (it != end && std::isspace(*it)) ++it; while (it != end && Ascii::isSpace(*it)) ++it;
while (it != end && std::isdigit(*it)) { n *= 10; n += *it++ - '0'; } while (it != end && Ascii::isDigit(*it)) { n *= 10; n += *it++ - '0'; }
while (it != end && std::isspace(*it)) ++it; while (it != end && Ascii::isSpace(*it)) ++it;
std::string unit; std::string unit;
while (it != end && std::isalpha(*it)) unit += *it++; while (it != end && Ascii::isAlpha(*it)) unit += *it++;
RotateStrategy* pStrategy = 0; RotateStrategy* pStrategy = 0;
if ((rotation.find(',') != std::string::npos) || (rotation.find(':') != std::string::npos)) if ((rotation.find(',') != std::string::npos) || (rotation.find(':') != std::string::npos))
{ {
if (_times == "utc") if (_times == "utc")
pStrategy = new RotateAtTimeStrategy<DateTime>(rotation); pStrategy = new RotateAtTimeStrategy<DateTime>(rotation);
@ -302,23 +302,23 @@ void FileChannel::setCompress(const std::string& compress)
void FileChannel::setPurgeAge(const std::string& age) void FileChannel::setPurgeAge(const std::string& age)
{ {
delete _pPurgeStrategy; delete _pPurgeStrategy;
_pPurgeStrategy = 0; _pPurgeStrategy = 0;
_purgeAge = "none"; _purgeAge = "none";
if (age.empty() || 0 == icompare(age, "none")) return; if (age.empty() || 0 == icompare(age, "none")) return;
std::string::const_iterator it = age.begin(); std::string::const_iterator it = age.begin();
std::string::const_iterator end = age.end(); std::string::const_iterator end = age.end();
int n = 0; int n = 0;
while (it != end && std::isspace(*it)) ++it; while (it != end && Ascii::isSpace(*it)) ++it;
while (it != end && std::isdigit(*it)) { n *= 10; n += *it++ - '0'; } while (it != end && Ascii::isDigit(*it)) { n *= 10; n += *it++ - '0'; }
while (it != end && std::isspace(*it)) ++it; while (it != end && Ascii::isSpace(*it)) ++it;
std::string unit; std::string unit;
while (it != end && std::isalpha(*it)) unit += *it++; while (it != end && Ascii::isAlpha(*it)) unit += *it++;
Timespan::TimeDiff factor = Timespan::SECONDS; Timespan::TimeDiff factor = Timespan::SECONDS;
if (unit == "minutes") if (unit == "minutes")
factor = Timespan::MINUTES; factor = Timespan::MINUTES;
else if (unit == "hours") else if (unit == "hours")
factor = Timespan::HOURS; factor = Timespan::HOURS;
@ -328,37 +328,37 @@ void FileChannel::setPurgeAge(const std::string& age)
factor = 7*Timespan::DAYS; factor = 7*Timespan::DAYS;
else if (unit == "months") else if (unit == "months")
factor = 30*Timespan::DAYS; factor = 30*Timespan::DAYS;
else if (unit != "seconds") else if (unit != "seconds")
throw InvalidArgumentException("purgeAge", age); throw InvalidArgumentException("purgeAge", age);
if (0 == n)
throw InvalidArgumentException("Zero is not valid purge age.");
if (0 == n) _pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor*n));
throw InvalidArgumentException("Zero is not valid purge age."); _purgeAge = age;
_pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor*n));
_purgeAge = age;
} }
void FileChannel::setPurgeCount(const std::string& count) void FileChannel::setPurgeCount(const std::string& count)
{ {
delete _pPurgeStrategy; delete _pPurgeStrategy;
_pPurgeStrategy = 0; _pPurgeStrategy = 0;
_purgeAge = "none"; _purgeAge = "none";
if (count.empty() || 0 == icompare(count, "none")) return; if (count.empty() || 0 == icompare(count, "none")) return;
int n = 0; int n = 0;
std::string::const_iterator it = count.begin(); std::string::const_iterator it = count.begin();
std::string::const_iterator end = count.end(); std::string::const_iterator end = count.end();
while (it != end && std::isspace(*it)) ++it;
while (it != end && std::isdigit(*it)) { n *= 10; n += *it++ - '0'; }
while (it != end && std::isspace(*it)) ++it;
if (0 == n) while (it != end && std::isspace(*it)) ++it;
throw InvalidArgumentException("Zero is not valid purge count."); while (it != end && std::isdigit(*it)) { n *= 10; n += *it++ - '0'; }
while (it != end && std::isspace(*it)) ++it;
_pPurgeStrategy = new PurgeByCountStrategy(n); if (0 == n)
_purgeCount = count; throw InvalidArgumentException("Zero is not valid purge count.");
_pPurgeStrategy = new PurgeByCountStrategy(n);
_purgeCount = count;
} }