Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===-- StringLexer.h -------------------------------------------*- C++ -*-===// |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 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 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 9 | #ifndef LLDB_UTILITY_STRINGLEXER_H |
| 10 | #define LLDB_UTILITY_STRINGLEXER_H |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 11 | |
| 12 | #include <initializer_list> |
| 13 | #include <string> |
| 14 | #include <utility> |
| 15 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 16 | namespace lldb_private { |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 17 | |
| 18 | class StringLexer { |
| 19 | public: |
| 20 | typedef std::string::size_type Position; |
| 21 | typedef std::string::size_type Size; |
| 22 | |
| 23 | typedef std::string::value_type Character; |
| 24 | |
| 25 | StringLexer(std::string s); |
| 26 | |
| 27 | // These APIs are not bounds-checked. Use HasAtLeast() if you're not sure. |
| 28 | Character Peek(); |
| 29 | |
| 30 | bool NextIf(Character c); |
| 31 | |
| 32 | std::pair<bool, Character> NextIf(std::initializer_list<Character> cs); |
| 33 | |
| 34 | bool AdvanceIf(const std::string &token); |
| 35 | |
| 36 | Character Next(); |
| 37 | |
| 38 | bool HasAtLeast(Size s); |
| 39 | |
| 40 | std::string GetUnlexed(); |
| 41 | |
| 42 | // This will assert if there are less than s characters preceding the cursor. |
| 43 | void PutBack(Size s); |
| 44 | |
| 45 | StringLexer &operator=(const StringLexer &rhs); |
| 46 | |
| 47 | private: |
| 48 | std::string m_data; |
| 49 | Position m_position; |
| 50 | |
| 51 | void Consume(); |
| 52 | }; |
| 53 | |
| 54 | } // namespace lldb_private |
| 55 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 56 | #endif // LLDB_UTILITY_STRINGLEXER_H |