A location in parser input, as a character offset and optional line information.
More...
#include "donner/base/FileOffset.h"
|
| struct | LineInfo |
| | Represents line information within a file, including the line number and the character offset on that line. More...
|
|
| FileOffset | resolveOffset (std::string_view sourceString) const |
| | Return the actual offset of the error in the string, resolving the character offset to a location inside the source string.
|
| FileOffset | addParentOffset (FileOffset parentOffset) const |
| | Assuming this FileOffset is from a subparser that ran on a substring of the original string, take the resulting FileOffset and convert it back to absolute coordinates.
|
|
bool | operator== (const FileOffset &other) const |
| | Equality operator.
|
|
|
std::optional< size_t > | offset |
| | Character offset of the error in the string, if known.
|
|
std::optional< LineInfo > | lineInfo |
| | Line information for multi-line strings, if known.
|
|
|
std::ostream & | operator<< (std::ostream &os, const FileOffset &value) |
| | Print the offset to an ostream.
|
A location in parser input, as a character offset and optional line information.
An unset offset refers to the end of the input, see EndOfString().
- Examples
- svg_viewer.cc.
◆ addParentOffset()
| FileOffset donner::FileOffset::addParentOffset |
( |
FileOffset | parentOffset | ) |
const |
|
inlinenodiscard |
Assuming this FileOffset is from a subparser that ran on a substring of the original string, take the resulting FileOffset and convert it back to absolute coordinates.
An unset offset in this FileOffset is treated as 0, not as the end of the substring; call resolveOffset first to map it to the substring's length.
- Precondition
parentOffset has an offset (checked by assert in debug builds).
- Parameters
-
| parentOffset | Offset of the current string in the parent parser. |
◆ Offset()
| FileOffset donner::FileOffset::Offset |
( |
size_t | offset | ) |
|
|
inlinestatic |
Create a FileOffset for a single-line string.
- Parameters
-
| offset | Character offset of the error in the string. |
◆ OffsetWithLineInfo()
| FileOffset donner::FileOffset::OffsetWithLineInfo |
( |
size_t | offset, |
|
|
LineInfo | lineInfo ) |
|
inlinestatic |
Create a FileOffset for a multi-line string.
- Parameters
-
| offset | Character offset of the error in the string. |
| lineInfo | Line and column info for the offset. |
◆ resolveOffset()
| FileOffset donner::FileOffset::resolveOffset |
( |
std::string_view | sourceString | ) |
const |
|
inline |
Return the actual offset of the error in the string, resolving the character offset to a location inside the source string.
- Parameters
-
| sourceString | Corresponding string containing the file source, used to resolve the string offset. |
- Returns
- Resolved offset with EndOfString() converted to the length of the source string.
The documentation for this struct was generated from the following file: