forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.hpp
87 lines (72 loc) · 2.38 KB
/
input.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @file
*
* @brief This file contains the declaration of a class that represents textual
* input.
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#ifndef ELEKTRA_PLUGIN_YAWN_INPUT_HPP
#define ELEKTRA_PLUGIN_YAWN_INPUT_HPP
// -- Imports ------------------------------------------------------------------------------------------------------------------------------
#include <fstream>
// -- Class --------------------------------------------------------------------------------------------------------------------------------
namespace yawn
{
/**
* @brief This class provides methods for a lexer to analyze textual input.
*/
class Input
{
/** This variable stores the input represented by this class. */
std::u32string input;
/** This variable stores the current position inside `input`. */
size_t position = 0;
public:
/**
* @brief This constructor creates an input from the given stream.
*
* @param stream This parameter stores the text this object operates on.
*/
Input (std::ifstream const & stream);
/**
* @brief This function returns a character that was not consumed yet.
*
* @param offset This variable specifies the index of the character
* this method should retrieve as offset to the last consumed
* character.
*
* @return A character which is `offset` positions away from the last
* consumed character
*/
size_t LA (size_t const offset) const;
/**
* @brief This method consumes the next character of `input`.
*/
void consume ();
/**
* @brief Retrieve the current position inside the input.
*
* @return The current position in number of characters
*/
size_t index () const;
/**
* @brief This method retrieves the text between `start` (inclusive) and the
* current position (exclusive).
*
* @param start This parameter specifies the start index of the string this
* functions returns.
*
* @return A UTF-8 encoded substring of input starting at `start` and ending
* one character before the current position in the input
*/
std::string getText (size_t const start) const;
/**
* @brief This method retrieves the whole text represented by this input object.
*
* @return A UTF-8 encoded string that stores the data of the input
*/
std::string toString () const;
};
} // namespace yawn
#endif // ELEKTRA_PLUGIN_YAWN_INPUT_HPP