mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Lexer: Added ::trim methods
This commit is contained in:
parent
a97f819423
commit
1ba3652c0e
3 changed files with 57 additions and 1 deletions
|
@ -123,6 +123,32 @@ bool Lexer::isEOS () const
|
|||
return _cursor >= _eos;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Lexer::trimLeft (const std::string& in, const std::string& t /*= " "*/)
|
||||
{
|
||||
std::string::size_type ws = 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 out {in};
|
||||
return out.erase (in.find_last_not_of (t) + 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Lexer::trim (const std::string& in, const std::string& t /*= " "*/)
|
||||
{
|
||||
return trimLeft (trimRight (in, t), t);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Lexer::Type::word
|
||||
// [^\s]+
|
||||
|
|
|
@ -43,6 +43,9 @@ public:
|
|||
// Static helpers.
|
||||
static bool isWhitespace (int);
|
||||
static bool isSingleCharOperator (int);
|
||||
static std::string trimLeft (const std::string& in, const std::string& t = " ");
|
||||
static std::string trimRight (const std::string& in, const std::string& t = " ");
|
||||
static std::string trim (const std::string& in, const std::string& t = " ");
|
||||
|
||||
// Stream Classifiers.
|
||||
bool isEOS () const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue