summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Utility')
-rw-r--r--lldb/source/Utility/StringLexer.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/lldb/source/Utility/StringLexer.cpp b/lldb/source/Utility/StringLexer.cpp
index 4da40995e19..2f62d2cedb4 100644
--- a/lldb/source/Utility/StringLexer.cpp
+++ b/lldb/source/Utility/StringLexer.cpp
@@ -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()
{
OpenPOWER on IntegriCloud