Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::base::parser::FileOffset Struct Reference

Error context for a failed parse, such as the error reason, line, and character offset. More...

#include "donner/base/parser/FileOffset.h"

Public Member Functions

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.
 

Static Public Member Functions

static FileOffset Offset (size_t offset)
 Create a FileOffset for a single-line string.
 
static FileOffset LineAndOffset (size_t line, size_t offset)
 Create a FileOffset for a multi-line string.
 
static FileOffset EndOfString ()
 Indicates an error occurred at the end of the input string.
 

Public Attributes

size_t line = 0
 Line number of the error.
 
std::optional< size_toffset = 0
 Character offset of the error in the string.
 

Friends

std::ostream & operator<< (std::ostream &os, const FileOffset &value)
 Print the offset to an ostream.
 

Detailed Description

Error context for a failed parse, such as the error reason, line, and character offset.

Member Function Documentation

◆ addParentOffset()

FileOffset donner::base::parser::FileOffset::addParentOffset ( FileOffset parentOffset) const
inline

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.

Parameters
parentOffsetOffset of the current string in the parent parser.

◆ LineAndOffset()

static FileOffset donner::base::parser::FileOffset::LineAndOffset ( size_t line,
size_t offset )
inlinestatic

Create a FileOffset for a multi-line string.

Parameters
lineLine number of the error.
offsetCharacter offset of the error in the string.

◆ Offset()

static FileOffset donner::base::parser::FileOffset::Offset ( size_t offset)
inlinestatic

Create a FileOffset for a single-line string.

Parameters
offsetCharacter offset of the error in the string.

◆ resolveOffset()

FileOffset donner::base::parser::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
sourceStringCorresponding 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: