mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 09:53:08 +02:00
Lexer: Modified ::trim to make one less copy
This commit is contained in:
parent
182b5427cd
commit
6ce3285c77
1 changed files with 11 additions and 6 deletions
|
@ -509,22 +509,27 @@ std::string Lexer::ucFirst (const std::string& input)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Lexer::trimLeft (const std::string& in, const std::string& t /*= " "*/)
|
std::string Lexer::trimLeft (const std::string& in, const std::string& t /*= " "*/)
|
||||||
{
|
{
|
||||||
std::string out = in;
|
std::string::size_type ws = in.find_first_not_of (t);
|
||||||
return out.erase (0, in.find_first_not_of (t));
|
if (ws > 0)
|
||||||
|
{
|
||||||
|
std::string out {in};
|
||||||
|
return out.erase (0, ws);
|
||||||
|
}
|
||||||
|
|
||||||
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Lexer::trimRight (const std::string& in, const std::string& t /*= " "*/)
|
std::string Lexer::trimRight (const std::string& in, const std::string& t /*= " "*/)
|
||||||
{
|
{
|
||||||
std::string out = in;
|
std::string out {in};
|
||||||
return out.erase (out.find_last_not_of (t) + 1);
|
return out.erase (in.find_last_not_of (t) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Lexer::trim (const std::string& in, const std::string& t /*= " "*/)
|
std::string Lexer::trim (const std::string& in, const std::string& t /*= " "*/)
|
||||||
{
|
{
|
||||||
std::string out = in;
|
return trimLeft (trimRight (in, t), t);
|
||||||
return trimLeft (trimRight (out, t), t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue