1 //===--------------------- StringLexer.cpp -----------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #include "lldb/Utility/StringLexer.h"
16 using namespace lldb_utility;
18 StringLexer::StringLexer(std::string s) : m_data(s), m_position(0) {}
20 StringLexer::StringLexer(const StringLexer &rhs)
21 : m_data(rhs.m_data), m_position(rhs.m_position) {}
23 StringLexer::Character StringLexer::Peek() { return m_data[m_position]; }
25 bool StringLexer::NextIf(Character c) {
34 std::pair<bool, StringLexer::Character>
35 StringLexer::NextIf(std::initializer_list<Character> cs) {
46 bool StringLexer::AdvanceIf(const std::string &token) {
47 auto pos = m_position;
49 for (auto c : token) {
62 StringLexer::Character StringLexer::Next() {
68 bool StringLexer::HasAtLeast(Size s) {
69 return (m_data.size() - m_position) >= s;
72 void StringLexer::PutBack(Size s) {
73 assert(m_position >= s);
77 bool StringLexer::HasAny(Character c) {
78 return m_data.find(c, m_position) != std::string::npos;
81 std::string StringLexer::GetUnlexed() {
82 return std::string(m_data, m_position);
85 void StringLexer::Consume() { m_position++; }
87 StringLexer &StringLexer::operator=(const StringLexer &rhs) {
90 m_position = rhs.m_position;