Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::parser::SVGParserContext Class Reference

Stores the current state of SVGParser during parsing. More...

#include "donner/svg/parser/details/SVGParserContext.h"

Public Member Functions

 SVGParserContext (std::string_view input, std::vector< ParseError > *warningsStorage, const SVGParser::Options &options)
 Construct a new context for the given input string.
 
const SVGParser::Optionsoptions () const
 Get the parser options.
 
void setNamespacePrefix (const RcString &namespacePrefix)
 Set the XML document's default namespace prefix, such as "http://www.w3.org/2000/svg".
 
std::string_view namespacePrefix () const
 Get the XML document's default namespace prefix, such as "http://www.w3.org/2000/svg".
 
ParseError fromSubparser (ParseError &&error, ParserOrigin origin)
 Remap a parse error from a subparser back to the original input string, translating the line numbers.
 
void addWarning (ParseError &&warning)
 Add a warning to the list of warnings.
 
void addSubparserWarning (ParseError &&warning, ParserOrigin origin)
 Add a warning from a subparser to the list of warnings, remapping the error back to the original input string.
 
std::optional< base::parser::FileOffsetgetAttributeLocation (const SVGElement &element, const xml::XMLQualifiedNameRef &attributeName) const
 Get the location of an element's attribute in the input string.
 
ParserOrigin parserOriginFrom (std::string_view substring) const
 Create a ParserOrigin for the given substring, where substring is within the XML parser's original string, input_.
 
size_t offsetToLine (size_t offset) const
 Return line numbers for the given offset.
 
size_t lineOffset (size_t line) const
 Returns the offset of a given 1-indexed line number.
 

Detailed Description

Stores the current state of SVGParser during parsing.

Used to add parse warnings and store global state like the parsing options.

Constructor & Destructor Documentation

◆ SVGParserContext()

donner::svg::parser::SVGParserContext::SVGParserContext ( std::string_view input,
std::vector< ParseError > * warningsStorage,
const SVGParser::Options & options )
inline

Construct a new context for the given input string.

Parameters
inputInput string.
warningsStorageStorage for warnings, may be nullptr to disable warnings.
optionsOptions for parsing.

Member Function Documentation

◆ addSubparserWarning()

void donner::svg::parser::SVGParserContext::addSubparserWarning ( ParseError && warning,
ParserOrigin origin )
inline

Add a warning from a subparser to the list of warnings, remapping the error back to the original input string.

Parameters
warningWarning to add.
originOrigin of the subparser.

◆ addWarning()

void donner::svg::parser::SVGParserContext::addWarning ( ParseError && warning)
inline

Add a warning to the list of warnings.

Parameters
warningWarning to add.

◆ fromSubparser()

ParseError donner::svg::parser::SVGParserContext::fromSubparser ( ParseError && error,
ParserOrigin origin )
inline

Remap a parse error from a subparser back to the original input string, translating the line numbers.

Parameters
errorError to remap.
originOrigin of the subparser.
Returns
ParseError Remapped error.

◆ getAttributeLocation()

std::optional< base::parser::FileOffset > donner::svg::parser::SVGParserContext::getAttributeLocation ( const SVGElement & element,
const xml::XMLQualifiedNameRef & attributeName ) const
inline

Get the location of an element's attribute in the input string.

Parameters
elementElement containing the attribute.
attributeNameName of the attribute.
Returns
std::optional<size_t> Offset of the element's attribute in the input string.

◆ lineOffset()

size_t donner::svg::parser::SVGParserContext::lineOffset ( size_t line) const
inline

Returns the offset of a given 1-indexed line number.

Parameters
lineLine number, 1-indexed.

◆ offsetToLine()

size_t donner::svg::parser::SVGParserContext::offsetToLine ( size_t offset) const
inline

Return line numbers for the given offset.

For example, given a string: "abc\n123", offsets 0-3 would be considered line 1, and offsets after 4 (corresponding to the index of '1'), would be line 2. Values beyond the length of the string return the last line number.

Parameters
offsetCharacter index.
Returns
size_t Line number, 1-indexed.

◆ parserOriginFrom()

ParserOrigin donner::svg::parser::SVGParserContext::parserOriginFrom ( std::string_view substring) const
inline

Create a ParserOrigin for the given substring, where substring is within the XML parser's original string, input_.

Parameters
substringSubstring within the XML parser's original string.

◆ setNamespacePrefix()

void donner::svg::parser::SVGParserContext::setNamespacePrefix ( const RcString & namespacePrefix)
inline

Set the XML document's default namespace prefix, such as "http://www.w3.org/2000/svg".

Parameters
namespacePrefixThe default namespace prefix, such as "http://www.w3.org/2000/svg".

The documentation for this class was generated from the following file: