diff --git a/Tle.cpp b/Tle.cpp index e1500d3..aa25d7a 100644 --- a/Tle.cpp +++ b/Tle.cpp @@ -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'); } diff --git a/Util.cpp b/Util.cpp index eed94c2..2dc1ff5 100644 --- a/Util.cpp +++ b/Util.cpp @@ -1,28 +1,38 @@ -#include "Util.h" - -#include -#include - -namespace Util -{ - void TrimLeft(std::string& s) - { - s.erase(s.begin(), - std::find_if(s.begin(), s.end(), - std::not1(std::ptr_fun(std::isspace)))); - } - - void TrimRight(std::string& s) - { - s.erase(std::find_if(s.rbegin(), s.rend(), - std::not1(std::ptr_fun(std::isspace))).base(), - s.end()); - } - - void Trim(std::string& s) - { - TrimLeft(s); - TrimRight(s); - } - -} +#include "Util.h" + +#include +#include +#include + +namespace Util +{ + namespace + { + struct IsDigit: std::unary_function + { + 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(IsDigit()))); + } + + void TrimRight(std::string& s) + { + s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(IsDigit())).base(), + s.end()); + } + + void Trim(std::string& s) + { + TrimLeft(s); + TrimRight(s); + } + +}