A string tokeniser. More...
#include <tokeniser.hpp>
Collaboration diagram for Tokeniser:Public Member Functions | |
| Tokeniser () | |
| Constructs a new Tokeniser. | |
| std::vector< std::vector< std::string > > | Feed (const std::string &raw) |
| Feeds a string into a Tokeniser. More... | |
Private Types | |
| enum | QuoteType : std::uint8_t { QuoteType::NONE, QuoteType::SINGLE, QuoteType::DOUBLE } |
| Enumeration of quotation types. More... | |
Private Member Functions | |
| void | Emit () |
| Finishes the current word and sends the line to the CommandHandler. | |
| void | EndWord () |
| Finishes the current word, adding it to the tokenised line. | |
| void | Push (char c) |
| Pushes a raw character onto the end of the current word. More... | |
Private Attributes | |
| std::vector< std::vector< std::string > > | ready_lines |
| The current vector of completed, tokenised lines. More... | |
| std::vector< std::string > | words |
| The current vector of completed, tokenised words. | |
| std::string | current_word |
| The current, incomplete word to which new characters should be added. More... | |
| bool | escape_next |
| Whether the next character is to be interpreted as an escape code. More... | |
| bool | in_word |
| Whether the tokeniser is currently in a word. | |
| QuoteType | quote_type |
| The type of quotation currently being used in this Tokeniser. | |
A string tokeniser.
A Tokeniser is fed chunks of incoming data from the IO system, and emits any fully-formed command lines it encounters to the command handler.
Definition at line 24 of file tokeniser.hpp.
|
strongprivate |
Enumeration of quotation types.
| Enumerator | |
|---|---|
| NONE | Not currently in a quote pair. |
| SINGLE | In single quotes (''). |
| DOUBLE | In double quotes (""). |
Definition at line 42 of file tokeniser.hpp.
| std::vector< std::vector< std::string > > Tokeniser::Feed | ( | const std::string & | raw | ) |
Feeds a string into a Tokeniser.
| raw | Const reference to the raw string to feed. The string need not contain complete lines. |
Definition at line 24 of file tokeniser.cpp.
References DOUBLE, Emit(), EndWord(), escape_next, in_word, NONE, Push(), quote_type, ready_lines, and SINGLE.
Referenced by Connection::Read().
|
private |
Pushes a raw character onto the end of the current word.
This also clears the escape_next flag.
| c | The character to push onto the current word. |
Definition at line 98 of file tokeniser.cpp.
References current_word, escape_next, in_word, NONE, and quote_type.
Referenced by Feed().
|
private |
The current, incomplete word to which new characters should be added.
Definition at line 57 of file tokeniser.hpp.
|
private |
Whether the next character is to be interpreted as an escape code.
This usually gets set to true when a backslash is detected.
Definition at line 61 of file tokeniser.hpp.
|
private |
The current vector of completed, tokenised lines.
This is cleared at the end of every Tokeniser::Feed.
Definition at line 50 of file tokeniser.hpp.