1 //===--------------------- StringLexer.cpp -----------------------*- C++-*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/StringLexer.h"
14 using namespace lldb_utility;
16 StringLexer::StringLexer(std::string s) : m_data(s), m_position(0) {}
18 StringLexer::Character StringLexer::Peek() { return m_data[m_position]; }
20 bool StringLexer::NextIf(Character c) {
29 std::pair<bool, StringLexer::Character>
30 StringLexer::NextIf(std::initializer_list<Character> cs) {
41 bool StringLexer::AdvanceIf(const std::string &token) {
42 auto pos = m_position;
44 for (auto c : token) {
57 StringLexer::Character StringLexer::Next() {
63 bool StringLexer::HasAtLeast(Size s) {
64 return (m_data.size() - m_position) >= s;
67 void StringLexer::PutBack(Size s) {
68 assert(m_position >= s);
72 std::string StringLexer::GetUnlexed() {
73 return std::string(m_data, m_position);
76 void StringLexer::Consume() { m_position++; }
78 StringLexer &StringLexer::operator=(const StringLexer &rhs) {
81 m_position = rhs.m_position;