Updated trim functions
parent
1f2fe033fe
commit
2930cc649b
2
Tle.cpp
2
Tle.cpp
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
|
39
Util.cpp
39
Util.cpp
|
@ -1,39 +1,28 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
namespace Util
|
namespace Util
|
||||||
{
|
{
|
||||||
void TrimLeft(std::string& str)
|
void TrimLeft(std::string& s)
|
||||||
{
|
{
|
||||||
std::string whitespaces(" \t\f\n\r");
|
s.erase(s.begin(),
|
||||||
|
std::find_if(s.begin(), s.end(),
|
||||||
if (!str.empty()) {
|
std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||||
std::string::size_type pos = str.find_first_not_of(whitespaces);
|
|
||||||
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
str.erase(0, pos);
|
|
||||||
else
|
|
||||||
str.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrimRight(std::string& str)
|
void TrimRight(std::string& s)
|
||||||
{
|
{
|
||||||
std::string whitespaces(" \t\f\n\r");
|
s.erase(std::find_if(s.rbegin(), s.rend(),
|
||||||
|
std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
|
||||||
if (!str.empty()) {
|
s.end());
|
||||||
std::string::size_type pos = str.find_last_not_of(whitespaces);
|
|
||||||
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
str.erase(pos + 1);
|
|
||||||
else
|
|
||||||
str.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trim(std::string& str)
|
void Trim(std::string& s)
|
||||||
{
|
{
|
||||||
TrimLeft(str);
|
TrimLeft(s);
|
||||||
TrimRight(str);
|
TrimRight(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue