1 //===--------------------- StringLexer.h ------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef utility_StringLexer_h_ 11 #define utility_StringLexer_h_ 12 13 #include <initializer_list> 14 #include <string> 15 #include <utility> 16 17 namespace lldb_utility { 18 19 class StringLexer { 20 public: 21 typedef std::string::size_type Position; 22 typedef std::string::size_type Size; 23 24 typedef std::string::value_type Character; 25 26 StringLexer(std::string s); 27 28 StringLexer(const StringLexer &rhs); 29 30 // These APIs are not bounds-checked. Use HasAtLeast() if you're not sure. 31 Character Peek(); 32 33 bool NextIf(Character c); 34 35 std::pair<bool, Character> NextIf(std::initializer_list<Character> cs); 36 37 bool AdvanceIf(const std::string &token); 38 39 Character Next(); 40 41 bool HasAtLeast(Size s); 42 43 std::string GetUnlexed(); 44 45 // This will assert if there are less than s characters preceding the cursor. 46 void PutBack(Size s); 47 48 StringLexer &operator=(const StringLexer &rhs); 49 50 private: 51 std::string m_data; 52 Position m_position; 53 54 void Consume(); 55 }; 56 57 } // namespace lldb_private 58 59 #endif // #ifndef utility_StringLexer_h_ 60