diff --git a/Tle.cpp b/Tle.cpp index f00aaaf..e1500d3 100644 --- a/Tle.cpp +++ b/Tle.cpp @@ -2,6 +2,8 @@ #include "Util.h" +#include + namespace { /* diff --git a/Util.cpp b/Util.cpp index eb56926..eed94c2 100644 --- a/Util.cpp +++ b/Util.cpp @@ -1,39 +1,28 @@ #include "Util.h" +#include +#include + namespace Util { - void TrimLeft(std::string& str) + void TrimLeft(std::string& s) { - std::string whitespaces(" \t\f\n\r"); - - if (!str.empty()) { - std::string::size_type pos = str.find_first_not_of(whitespaces); - - if (pos != std::string::npos) - str.erase(0, pos); - else - str.clear(); - } + s.erase(s.begin(), + std::find_if(s.begin(), s.end(), + std::not1(std::ptr_fun(std::isspace)))); } - void TrimRight(std::string& str) + void TrimRight(std::string& s) { - std::string whitespaces(" \t\f\n\r"); - - if (!str.empty()) { - std::string::size_type pos = str.find_last_not_of(whitespaces); - - if (pos != std::string::npos) - str.erase(pos + 1); - else - str.clear(); - } + s.erase(std::find_if(s.rbegin(), s.rend(), + std::not1(std::ptr_fun(std::isspace))).base(), + s.end()); } - void Trim(std::string& str) + void Trim(std::string& s) { - TrimLeft(str); - TrimRight(str); + TrimLeft(s); + TrimRight(s); } } diff --git a/Util.h b/Util.h index 56824e6..a47f6d8 100644 --- a/Util.h +++ b/Util.h @@ -63,9 +63,9 @@ namespace Util } } - void TrimLeft(std::string& str); - void TrimRight(std::string& str); - void Trim(std::string& str); + void TrimLeft(std::string& s); + void TrimRight(std::string& s); + void Trim(std::string& s); } #endif