diff options
author | Dimitri van Heesch <doxygen@gmail.com> | 2020-12-05 10:46:11 (GMT) |
---|---|---|
committer | Dimitri van Heesch <doxygen@gmail.com> | 2020-12-06 20:25:41 (GMT) |
commit | 644997f85f327d3f8456f1c5cf0cde78a3bd1d28 (patch) | |
tree | f6c248faed847719ddb922c98428cd80774d7996 /src/xml.h | |
parent | f673a99a492397b3647ce07eb9537b8d1522a541 (diff) | |
download | Doxygen-644997f85f327d3f8456f1c5cf0cde78a3bd1d28.zip Doxygen-644997f85f327d3f8456f1c5cf0cde78a3bd1d28.tar.gz Doxygen-644997f85f327d3f8456f1c5cf0cde78a3bd1d28.tar.bz2 |
Refactoring: replace QXml by own XML processor
Diffstat (limited to 'src/xml.h')
-rw-r--r-- | src/xml.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/xml.h b/src/xml.h new file mode 100644 index 0000000..6ba36b2 --- /dev/null +++ b/src/xml.h @@ -0,0 +1,64 @@ +#ifndef XML_H +#define XML_H + +#include <memory> +#include <functional> +#include <string> +#include <unordered_map> + +/*! @brief Event handlers that can installed by the client and called while parsing a XML document. + */ +class XMLHandlers +{ + public: + using Attributes = std::unordered_map<std::string,std::string>; + using StartDocType = void(); + using EndDocType = void(); + using StartElementType = void(const std::string &,const Attributes &); + using EndElementType = void(const std::string &); + using ErrorType = void(const std::string,int,const std::string &); + using CharsType = void(const std::string &); + + std::function<StartDocType> startDocument; /**< handler invoked at the start of the document */ + std::function<EndDocType> endDocument; /**< handler invoked at the end of the document */ + std::function<StartElementType> startElement; /**< handler invoked when an opening tag has been found */ + std::function<EndElementType> endElement; /**< handler invoked when a closing tag has been found */ + std::function<CharsType> characters; /**< handler invoked when content between tags has been found */ + std::function<ErrorType> error; /**< handler invoked when the parser encounters an error */ +}; + +class XMLLocator +{ + public: + virtual ~XMLLocator() {} + virtual int lineNr() const = 0; + virtual std::string fileName() const = 0; +}; + +/*! Very basic SAX style parser to parse XML documents. */ +class XMLParser : public XMLLocator +{ + public: + /*! Creates an instance of the parser object. Different instances can run on different + * threads without interference. + * + * @param handlers The event handlers passed by the client. + */ + XMLParser(const XMLHandlers &handlers); + /*! Destructor */ + ~XMLParser(); + + /*! Parses a file gives the contents of the file as a string. + * @param fileName the name of the file, used for error reporting. + * @param inputString the contents of the file as a zero terminated UTF-8 string. + */ + void parse(const char *fileName,const char *inputString); + + private: + virtual int lineNr() const override; + virtual std::string fileName() const override; + struct Private; + std::unique_ptr<Private> p; +}; + +#endif |