URY playd
C++ minimalist audio player
tokeniser.hpp
Go to the documentation of this file.
1 // This file is part of playd.
2 // playd is licensed under the MIT licence: see LICENSE.txt.
3 
10 #ifndef PLAYD_TOKENISER_HPP
11 #define PLAYD_TOKENISER_HPP
12 
13 #include "response.hpp"
14 
24 class Tokeniser
25 {
26 public:
28  Tokeniser();
29 
38  std::vector<std::vector<std::string>> Feed(const std::string &raw);
39 
40 private:
42  enum class QuoteType : std::uint8_t {
43  NONE,
44  SINGLE,
45  DOUBLE
46  };
47 
50  std::vector<std::vector<std::string>> ready_lines;
51 
53  std::vector<std::string> words;
54 
57  std::string current_word;
58 
62 
64  bool in_word;
65 
68 
70  void Emit();
71 
73  void EndWord();
74 
80  void Push(char c);
81 };
82 
83 #endif // PLAYD_TOKENISER_HPP
A string tokeniser.
Definition: tokeniser.hpp:24
bool escape_next
Whether the next character is to be interpreted as an escape code.
Definition: tokeniser.hpp:61
void Push(char c)
Pushes a raw character onto the end of the current word.
Definition: tokeniser.cpp:98
QuoteType quote_type
The type of quotation currently being used in this Tokeniser.
Definition: tokeniser.hpp:67
Tokeniser()
Constructs a new Tokeniser.
Definition: tokeniser.cpp:19
void EndWord()
Finishes the current word, adding it to the tokenised line.
Definition: tokeniser.cpp:108
void Emit()
Finishes the current word and sends the line to the CommandHandler.
Definition: tokeniser.cpp:119
bool in_word
Whether the tokeniser is currently in a word.
Definition: tokeniser.hpp:64
QuoteType
Enumeration of quotation types.
Definition: tokeniser.hpp:42
std::vector< std::vector< std::string > > Feed(const std::string &raw)
Feeds a string into a Tokeniser.
Definition: tokeniser.cpp:24
In single quotes (&#39;&#39;).
std::vector< std::string > words
The current vector of completed, tokenised words.
Definition: tokeniser.hpp:53
Declaration of classes pertaining to responses to the client.
Not currently in a quote pair.
std::vector< std::vector< std::string > > ready_lines
The current vector of completed, tokenised lines.
Definition: tokeniser.hpp:50
In double quotes ("").
std::string current_word
The current, incomplete word to which new characters should be added.
Definition: tokeniser.hpp:57