Removed a couple of static helpers in the data formatters, replaced with new general logic in StringLexer

llvm-svn: 222058
This commit is contained in:
Enrico Granata
2014-11-14 22:58:11 +00:00
parent 603d316517
commit e65a28f36f
3 changed files with 65 additions and 32 deletions

View File

@@ -42,6 +42,42 @@ StringLexer::NextIf (Character c)
return false;
}
std::pair<bool, StringLexer::Character>
StringLexer::NextIf (std::initializer_list<Character> cs)
{
auto val = Peek();
for (auto c : cs)
{
if (val == c)
{
Next();
return {true,c};
}
}
return {false,0};
}
bool
StringLexer::AdvanceIf (const std::string& token)
{
auto pos = m_position;
bool matches = true;
for (auto c : token)
{
if (!NextIf(c))
{
matches = false;
break;
}
}
if (!matches)
{
m_position = pos;
return false;
}
return true;
}
StringLexer::Character
StringLexer::Next ()
{
@@ -69,6 +105,12 @@ StringLexer::HasAny (Character c)
return m_data.find(c, m_position) != std::string::npos;
}
std::string
StringLexer::GetUnlexed ()
{
return std::string(m_data, m_position);
}
void
StringLexer::Consume()
{