diff options
| -rw-r--r-- | lldb/include/lldb/Utility/StringLexer.h | 5 | ||||
| -rw-r--r-- | lldb/source/Utility/StringLexer.cpp | 36 | 
2 files changed, 14 insertions, 27 deletions
diff --git a/lldb/include/lldb/Utility/StringLexer.h b/lldb/include/lldb/Utility/StringLexer.h index 42c169c5cf9..1fffba606f3 100644 --- a/lldb/include/lldb/Utility/StringLexer.h +++ b/lldb/include/lldb/Utility/StringLexer.h @@ -27,6 +27,7 @@ public:      StringLexer (const StringLexer& rhs); +    // These APIs are not bounds-checked.  Use HasAtLeast() if you're not sure.      Character      Peek (); @@ -42,8 +43,9 @@ public:      bool      HasAny (Character c); +    // This will assert if there are less than s characters preceding the cursor.      void -    PutBack (Character c); +    PutBack (Size s);      StringLexer&      operator = (const StringLexer& rhs); @@ -51,7 +53,6 @@ public:  private:      std::string m_data;      Position m_position; -    std::list<Character> m_putback_data;      void      Consume(); 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;  }  | 

