1 //===-- StringLexer.cpp ---------------------------------------------------===//
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"
15 using namespace lldb_private
;
17 StringLexer::StringLexer(std::string s
) : m_data(std::move(s
)), m_position(0) {}
19 StringLexer::Character
StringLexer::Peek() { return m_data
[m_position
]; }
21 bool StringLexer::NextIf(Character c
) {
30 std::pair
<bool, StringLexer::Character
>
31 StringLexer::NextIf(std::initializer_list
<Character
> cs
) {
42 bool StringLexer::AdvanceIf(const std::string
&token
) {
43 auto pos
= m_position
;
45 for (auto c
: token
) {
58 StringLexer::Character
StringLexer::Next() {
64 bool StringLexer::HasAtLeast(Size s
) {
65 return (m_data
.size() - m_position
) >= s
;
68 void StringLexer::PutBack(Size s
) {
69 assert(m_position
>= s
);
73 std::string
StringLexer::GetUnlexed() {
74 return std::string(m_data
, m_position
);
77 void StringLexer::Consume() { m_position
++; }
79 StringLexer
&StringLexer::operator=(const StringLexer
&rhs
) {
82 m_position
= rhs
.m_position
;