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"

Classes

struct  LineInfo
 Represents line information within a file, including the line number and the character offset on that line. More...
 

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 OffsetWithLineInfo (size_t offset, LineInfo lineInfo)
 Create a FileOffset for a multi-line string.
 
static FileOffset EndOfString ()
 Indicates an error occurred at the end of the input string.
 

Public Attributes

std::optional< size_toffset
 Character offset of the error in the string, if known.
 
std::optional< LineInfolineInfo
 Line information for multi-line strings, if known.
 

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.

◆ 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.

◆ OffsetWithLineInfo()

static FileOffset donner::base::parser::FileOffset::OffsetWithLineInfo ( size_t offset,
LineInfo lineInfo )
inlinestatic

Create a FileOffset for a multi-line string.

Parameters
lineLine number of the error.
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: