Updated trim functions
parent
1f2fe033fe
commit
2930cc649b
39
Util.cpp
39
Util.cpp
|
@ -1,39 +1,28 @@
|
|||
#include "Util.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
|
||||
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<int, int>(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<int, int>(std::isspace))).base(),
|
||||
s.end());
|
||||
}
|
||||
|
||||
void Trim(std::string& str)
|
||||
void Trim(std::string& s)
|
||||
{
|
||||
TrimLeft(str);
|
||||
TrimRight(str);
|
||||
TrimLeft(s);
|
||||
TrimRight(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue