diff options
| author | Sean Callanan <scallanan@apple.com> | 2014-11-10 23:20:52 +0000 |
|---|---|---|
| committer | Sean Callanan <scallanan@apple.com> | 2014-11-10 23:20:52 +0000 |
| commit | 5c35f7cfd1f5e8f1089b11bd33c5bbd4f4a9e061 (patch) | |
| tree | 199c16394c4c59c2664f60fdcaea54bcf9ce6f12 /lldb/source/Utility | |
| parent | a9ae3e311c416065b27bcb01f3f9520456e94ea6 (diff) | |
| download | bcm5719-llvm-5c35f7cfd1f5e8f1089b11bd33c5bbd4f4a9e061.tar.gz bcm5719-llvm-5c35f7cfd1f5e8f1089b11bd33c5bbd4f4a9e061.zip | |
Cleaned up the StringLexer a little bit. It turns
out we only want to roll back text that was in the
buffer to begin with, so it's not necessary to
provide a pushback stack.
I'm going to use this slightly cleaner API to perform
lookahead for the Objective-C runtime type parser.
llvm-svn: 221640
Diffstat (limited to 'lldb/source/Utility')
| -rw-r--r-- | lldb/source/Utility/StringLexer.cpp | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/lldb/source/Utility/StringLexer.cpp b/lldb/source/Utility/StringLexer.cpp index bde2fc6a420..4da40995e19 100644 --- a/lldb/source/Utility/StringLexer.cpp +++ b/lldb/source/Utility/StringLexer.cpp @@ -10,28 +10,24 @@ #include "lldb/Utility/StringLexer.h" #include <algorithm> +#include <assert.h> using namespace lldb_utility; StringLexer::StringLexer (std::string s) : -m_data(s), -m_position(0), -m_putback_data() + m_data(s), + m_position(0) { } StringLexer::StringLexer (const StringLexer& rhs) : -m_data(rhs.m_data), -m_position(rhs.m_position), -m_putback_data(rhs.m_putback_data) + m_data(rhs.m_data), + m_position(rhs.m_position) { } StringLexer::Character StringLexer::Peek () { - if (m_putback_data.empty()) - return m_data[m_position]; - else - return m_putback_data.front(); + return m_data[m_position]; } bool @@ -57,35 +53,26 @@ StringLexer::Next () bool StringLexer::HasAtLeast (Size s) { - auto in_m_data = m_data.size()-m_position; - auto in_putback = m_putback_data.size(); - return (in_m_data + in_putback >= s); + return (m_data.size() - m_position) >= s; } - void -StringLexer::PutBack (Character c) +StringLexer::PutBack (Size s) { - m_putback_data.push_back(c); + assert (m_position >= s); + m_position -= s; } bool StringLexer::HasAny (Character c) { - const auto begin(m_putback_data.begin()); - const auto end(m_putback_data.end()); - if (std::find(begin, end, c) != end) - return true; return m_data.find(c, m_position) != std::string::npos; } void StringLexer::Consume() { - if (m_putback_data.empty()) - m_position++; - else - m_putback_data.pop_front(); + m_position++; } StringLexer& @@ -95,7 +82,6 @@ StringLexer::operator = (const StringLexer& rhs) { m_data = rhs.m_data; m_position = rhs.m_position; - m_putback_data = rhs.m_putback_data; } return *this; } |

