Doxygen
Loading...
Searching...
No Matches
XMLParser Class Reference

#include <libxml/xml.h>

+ Inheritance diagram for XMLParser:
+ Collaboration diagram for XMLParser:

Classes

struct  Private
 

Public Types

using Transcode = bool(std::string &,const char *)
 

Public Member Functions

 XMLParser (const XMLHandlers &handlers)
 
 ~XMLParser () override
 
 XMLParser (const XMLParser &)=delete
 
XMLParseroperator= (const XMLParser &)=delete
 
 XMLParser (XMLParser &&)=delete
 
XMLParseroperator= (XMLParser &&)=delete
 
void parse (const char *fileName, const char *inputString, bool debugEnabled, std::function< void()> debugStart, std::function< void()> debugEnd, std::function< Transcode > transcoder=[](std::string &s, const char *){ return true;})
 
- Public Member Functions inherited from XMLLocator
 XMLLocator ()=default
 
 XMLLocator (const XMLLocator &)=delete
 
XMLLocatoroperator= (const XMLLocator &)=delete
 
 XMLLocator (XMLLocator &&)=delete
 
XMLLocatoroperator= (XMLLocator &&)=delete
 
virtual ~XMLLocator ()=default
 

Private Member Functions

int lineNr () const override
 
std::string fileName () const override
 

Private Attributes

std::unique_ptr< Privatep
 

Detailed Description

Very basic SAX style parser to parse XML documents.

Definition at line 70 of file xml.h.

Member Typedef Documentation

◆ Transcode

using XMLParser::Transcode = bool(std::string &,const char *)

Definition at line 86 of file xml.h.

Constructor & Destructor Documentation

◆ XMLParser() [1/3]

XMLParser::XMLParser ( const XMLHandlers & handlers)

Creates an instance of the parser object. Different instances can run on different threads without interference.

Parameters
handlersThe event handlers passed by the client.

Definition at line 436 of file xml.l.

436 : p(new Private)
437{
438 xmlYYlex_init_extra(&p->xmlYY_extra,&p->yyscanner);
439 p->xmlYY_extra.handlers = handlers;
440}
std::unique_ptr< Private > p
Definition xml.h:109

References p.

Referenced by operator=(), operator=(), XMLParser(), and XMLParser().

◆ ~XMLParser()

XMLParser::~XMLParser ( )
override

Destructor

Definition at line 442 of file xml.l.

443{
444 xmlYYlex_destroy(p->yyscanner);
445}

References p.

◆ XMLParser() [2/3]

XMLParser::XMLParser ( const XMLParser & )
delete

References XMLParser().

◆ XMLParser() [3/3]

XMLParser::XMLParser ( XMLParser && )
delete

References XMLParser().

Member Function Documentation

◆ fileName()

std::string XMLParser::fileName ( ) const
overrideprivatevirtual

Implements XMLLocator.

Definition at line 507 of file xml.l.

508{
509 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
510 return yyextra->fileName;
511}

References p.

Referenced by parse().

◆ lineNr()

int XMLParser::lineNr ( ) const
overrideprivatevirtual

Implements XMLLocator.

Definition at line 501 of file xml.l.

502{
503 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
504 return yyextra->lineNr;
505}

References p.

◆ operator=() [1/2]

XMLParser & XMLParser::operator= ( const XMLParser & )
delete

References XMLParser().

◆ operator=() [2/2]

XMLParser & XMLParser::operator= ( XMLParser && )
delete

References XMLParser().

◆ parse()

void XMLParser::parse ( const char * fileName,
const char * inputString,
bool debugEnabled,
std::function< void()> debugStart,
std::function< void()> debugEnd,
std::function< Transcode > transcoder = [](std::string&s,const char *){ return true; } )

Parses a file gives the contents of the file as a string.

Parameters
fileNamethe name of the file, used for error reporting.
inputStringthe contents of the file as a zero terminated UTF-8 string.
debugEnabledindicates if debugging via -d lex is enabled or not.
debugStarthook that is to be called before starting with parsing
debugEndhook that is to be called after finishing with parsing
transcoderhook that is to be called when transcoding text to UTF-8

Definition at line 447 of file xml.l.

453{
454 yyscan_t yyscanner = p->yyscanner;
455 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
456
457#ifdef FLEX_DEBUG
458 xmlYYset_debug(debugEnabled?1:0,p->yyscanner);
459#endif
460
461 if (inputStr==nullptr || inputStr[0]=='\0') return; // empty input
462
463 debugStart();
464
465 BEGIN(Initial);
466 yyextra->fileName = fileName;
467 yyextra->lineNr = 1;
468 yyextra->inputString = inputStr;
469 yyextra->inputPosition = 0;
470 yyextra->transcodeFunc = transcodeFunc;
471
472 if (static_cast<unsigned char>(inputStr[0])==0xEF &&
473 static_cast<unsigned char>(inputStr[1])==0xBB &&
474 static_cast<unsigned char>(inputStr[2])==0xBF)
475 {
476 yyextra->inputPosition = 3; // remove UTF-8 BOM
477 }
478
479 xmlYYrestart( 0, yyscanner );
480
481 if (yyextra->handlers.startDocument)
482 {
483 yyextra->handlers.startDocument();
484 }
485 xmlYYlex(yyscanner);
486 if (yyextra->handlers.endDocument)
487 {
488 yyextra->handlers.endDocument();
489 }
490
491 if (!yyextra->xpath.empty())
492 {
493 std::string tagName = yyextra->xpath.back();
494 std::string msg = "End of file reached while expecting closing tag '"+tagName+"'";
495 reportError(yyscanner,msg);
496 }
497
498 debugEnd();
499}
std::string fileName() const override
Definition xml.l:507
yyguts_t * yyscan_t
Definition code.l:24
void msg(const char *fmt,...)
Definition message.cpp:98
static void reportError(yyscan_t yyscanner, const std::string &msg)
Definition xml.l:361

References fileName(), msg(), p, and reportError().

Referenced by LayoutDocManager::init(), LayoutDocManager::parse(), and parseTagFile().

Member Data Documentation

◆ p

std::unique_ptr<Private> XMLParser::p
private

Definition at line 109 of file xml.h.

Referenced by fileName(), lineNr(), parse(), XMLParser(), and ~XMLParser().


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