Using locale when using isspace etc

feature/19
Daniel Warner 2011-12-24 00:07:23 +00:00
parent ed881ea58a
commit 3ca8edbc96
2 changed files with 44 additions and 32 deletions

10
Tle.cpp
View File

@ -351,7 +351,7 @@ void Tle::ValidateLine(const std::string& line, const std::string& pattern)
/*
* number or ' '
*/
if (!isdigit(mtch) && mtch != ' ')
if (!std::isdigit(mtch, std::locale::classic()) && mtch != ' ')
{
throw TleException("Invalid character");
}
@ -364,7 +364,7 @@ void Tle::ValidateLine(const std::string& line, const std::string& pattern)
*/
if (mtch != '+' && mtch != '-'
&& mtch != ' ' && mtch != '0'
&& !isdigit(mtch))
&& !std::isdigit(mtch, std::locale::classic()))
{
throw TleException("Invalid character");
}
@ -397,7 +397,9 @@ void Tle::ValidateLine(const std::string& line, const std::string& pattern)
/*
* alpha or ' '
*/
if (!isupper(mtch) && !isalpha(mtch) && mtch != ' ')
if (!std::isupper(mtch, std::locale::classic()) &&
!std::isalpha(mtch, std::locale::classic()) &&
mtch != ' ')
{
throw TleException("Invalid character");
}
@ -424,7 +426,7 @@ int Tle::CheckSum(const std::string & str)
{
char ch = str[i];
if (isdigit(ch))
if (std::isdigit(ch, std::locale::classic()))
{
xsum += (ch - '0');
}

View File

@ -2,20 +2,30 @@
#include <algorithm>
#include <locale>
#include <functional>
namespace Util
{
namespace
{
struct IsDigit: std::unary_function<char, bool>
{
bool operator()(char c) const
{
return std::isdigit(c, std::locale::classic()) == 0;
}
};
}
void TrimLeft(std::string& s)
{
s.erase(s.begin(),
std::find_if(s.begin(), s.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
std::find_if(s.begin(), s.end(), std::not1(IsDigit())));
}
void TrimRight(std::string& s)
{
s.erase(std::find_if(s.rbegin(), s.rend(),
std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(IsDigit())).base(),
s.end());
}