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

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

#include "donner/svg/xml/details/XMLParserContext.h"

Public Member Functions

 XMLParserContext (std::string_view input, std::vector< ParseError > *warningsStorage, const XMLParser::Options &options)
 Construct a new context for the given input string.
 
const XMLParser::Optionsoptions () const
 Get the parser options.
 
void setNamespacePrefix (std::string_view 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.
 
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 XMLParser during parsing.

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

Constructor & Destructor Documentation

◆ XMLParserContext()

donner::svg::parser::XMLParserContext::XMLParserContext ( std::string_view input,
std::vector< ParseError > * warningsStorage,
const XMLParser::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::XMLParserContext::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::XMLParserContext::addWarning ( ParseError && warning)
inline

Add a warning to the list of warnings.

Parameters
warningWarning to add.

◆ fromSubparser()

ParseError donner::svg::parser::XMLParserContext::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.

◆ lineOffset()

size_t donner::svg::parser::XMLParserContext::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::XMLParserContext::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::XMLParserContext::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::XMLParserContext::setNamespacePrefix ( std::string_view 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: