1 //===--------------------- StringLexer.cpp -----------------------*- C++-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Utility/StringLexer.h"
15 using namespace lldb_utility;
17 StringLexer::StringLexer(std::string s) : m_data(s), m_position(0) {}
19 StringLexer::StringLexer(const StringLexer &rhs)
20 : m_data(rhs.m_data), m_position(rhs.m_position) {}
22 StringLexer::Character StringLexer::Peek() { return m_data[m_position]; }
24 bool StringLexer::NextIf(Character c) {
33 std::pair<bool, StringLexer::Character>
34 StringLexer::NextIf(std::initializer_list<Character> cs) {
45 bool StringLexer::AdvanceIf(const std::string &token) {
46 auto pos = m_position;
48 for (auto c : token) {
61 StringLexer::Character StringLexer::Next() {
67 bool StringLexer::HasAtLeast(Size s) {
68 return (m_data.size() - m_position) >= s;
71 void StringLexer::PutBack(Size s) {
72 assert(m_position >= s);
76 std::string StringLexer::GetUnlexed() {
77 return std::string(m_data, m_position);
80 void StringLexer::Consume() { m_position++; }
82 StringLexer &StringLexer::operator=(const StringLexer &rhs) {
85 m_position = rhs.m_position;