1 //===--------------------- StringLexer.cpp -----------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Utility/StringLexer.h" 11 12 using namespace lldb_utility; 13 14 StringLexer::StringLexer (std::string s) : 15 m_data(s), 16 m_position(0), 17 m_putback_data() 18 { } 19 20 StringLexer::StringLexer (const StringLexer& rhs) : 21 m_data(rhs.m_data), 22 m_position(rhs.m_position), 23 m_putback_data(rhs.m_putback_data) 24 { } 25 26 StringLexer::Character 27 StringLexer::Peek () 28 { 29 if (m_putback_data.empty()) 30 return m_data[m_position]; 31 else 32 return m_putback_data.front(); 33 } 34 35 bool 36 StringLexer::NextIf (Character c) 37 { 38 auto val = Peek(); 39 if (val == c) 40 { 41 Next(); 42 return true; 43 } 44 return false; 45 } 46 47 StringLexer::Character 48 StringLexer::Next () 49 { 50 auto val = Peek(); 51 Consume(); 52 return val; 53 } 54 55 bool 56 StringLexer::HasAtLeast (Size s) 57 { 58 return m_data.size()-m_position >= s; 59 } 60 61 62 void 63 StringLexer::PutBack (Character c) 64 { 65 m_putback_data.push_back(c); 66 } 67 68 bool 69 StringLexer::HasAny (Character c) 70 { 71 return m_data.find(c, m_position) != std::string::npos; 72 } 73 74 void 75 StringLexer::Consume() 76 { 77 if (m_putback_data.empty()) 78 m_position++; 79 else 80 m_putback_data.pop_front(); 81 } 82 83 StringLexer& 84 StringLexer::operator = (const StringLexer& rhs) 85 { 86 if (this != &rhs) 87 { 88 m_data = rhs.m_data; 89 m_position = rhs.m_position; 90 m_putback_data = rhs.m_putback_data; 91 } 92 return *this; 93 } 94