LLDB mainline
StringLexer.cpp
Go to the documentation of this file.
1//===-- StringLexer.cpp ---------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
10
11#include <algorithm>
12#include <cassert>
13#include <utility>
14
15using namespace lldb_private;
16
17StringLexer::StringLexer(std::string s) : m_data(std::move(s)), m_position(0) {}
18
20
22 auto val = Peek();
23 if (val == c) {
24 Next();
25 return true;
26 }
27 return false;
28}
29
30std::pair<bool, StringLexer::Character>
31StringLexer::NextIf(std::initializer_list<Character> cs) {
32 auto val = Peek();
33 for (auto c : cs) {
34 if (val == c) {
35 Next();
36 return {true, c};
37 }
38 }
39 return {false, 0};
40}
41
42bool StringLexer::AdvanceIf(const std::string &token) {
43 auto pos = m_position;
44 bool matches = true;
45 for (auto c : token) {
46 if (!NextIf(c)) {
47 matches = false;
48 break;
49 }
50 }
51 if (!matches) {
52 m_position = pos;
53 return false;
54 }
55 return true;
56}
57
59 auto val = Peek();
60 Consume();
61 return val;
62}
63
65 return (m_data.size() - m_position) >= s;
66}
67
69 assert(m_position >= s);
70 m_position -= s;
71}
72
74 return std::string(m_data, m_position);
75}
76
78
80 if (this != &rhs) {
81 m_data = rhs.m_data;
83 }
84 return *this;
85}
bool AdvanceIf(const std::string &token)
Definition: StringLexer.cpp:42
StringLexer & operator=(const StringLexer &rhs)
Definition: StringLexer.cpp:79
std::string::value_type Character
Definition: StringLexer.h:23
bool NextIf(Character c)
Definition: StringLexer.cpp:21
std::string::size_type Size
Definition: StringLexer.h:21
StringLexer(std::string s)
Definition: StringLexer.cpp:17
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14