/src/CMake/Source/cmXMLParser.h
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying | 
| 2 |  |    file Copyright.txt or https://cmake.org/licensing for details.  */ | 
| 3 |  | #pragma once | 
| 4 |  |  | 
| 5 |  | #include "cmConfigure.h" // IWYU pragma: keep | 
| 6 |  |  | 
| 7 |  | #include <string> | 
| 8 |  |  | 
| 9 |  | extern "C" { | 
| 10 |  | void cmXMLParserStartElement(void*, const char*, const char**); | 
| 11 |  | void cmXMLParserEndElement(void*, const char*); | 
| 12 |  | void cmXMLParserCharacterDataHandler(void*, const char*, int); | 
| 13 |  | } | 
| 14 |  |  | 
| 15 |  | /** \class cmXMLParser | 
| 16 |  |  * \brief Helper class for performing XML parsing | 
| 17 |  |  * | 
| 18 |  |  * Superclass for all XML parsers. | 
| 19 |  |  */ | 
| 20 |  | class cmXMLParser | 
| 21 |  | { | 
| 22 |  | public: | 
| 23 |  |   cmXMLParser(); | 
| 24 |  |   cmXMLParser(const cmXMLParser& /*other*/) = default; | 
| 25 |  |   virtual ~cmXMLParser(); | 
| 26 |  |  | 
| 27 |  |   //! Parse given XML string | 
| 28 |  |   virtual int Parse(const char* string); | 
| 29 |  |  | 
| 30 |  |   //! Parse given XML file | 
| 31 |  |   virtual int ParseFile(const char* file); | 
| 32 |  |  | 
| 33 |  |   /** | 
| 34 |  |    * When parsing fragments of XML or streaming XML, use the following | 
| 35 |  |    * three methods.  InitializeParser method initialize parser but does | 
| 36 |  |    * not perform any actual parsing.  ParseChunk parses framgent of | 
| 37 |  |    * XML. This has to match to what was already parsed. CleanupParser | 
| 38 |  |    * finishes parsing. If there were errors, CleanupParser will report | 
| 39 |  |    * them. | 
| 40 |  |    */ | 
| 41 |  |   virtual int InitializeParser(); | 
| 42 |  |   virtual int ParseChunk(const char* inputString, | 
| 43 |  |                          std::string::size_type length); | 
| 44 |  |   virtual int CleanupParser(); | 
| 45 |  |   using ReportFunction = void (*)(int, const char*, void*); | 
| 46 |  |   void SetErrorCallback(ReportFunction f, void* d) | 
| 47 | 0 |   { | 
| 48 | 0 |     this->ReportCallback = f; | 
| 49 | 0 |     this->ReportCallbackData = d; | 
| 50 | 0 |   } | 
| 51 |  |  | 
| 52 |  | protected: | 
| 53 |  |   //! This variable is true if there was a parse error while parsing in | 
| 54 |  |   // chunks. | 
| 55 |  |   int ParseError; | 
| 56 |  |   ReportFunction ReportCallback; | 
| 57 |  |   void* ReportCallbackData; | 
| 58 |  |  | 
| 59 |  |   // 1 Expat parser structure.  Exists only during call to Parse(). | 
| 60 |  |   void* Parser; | 
| 61 |  |  | 
| 62 |  |   /** | 
| 63 |  |    * Called before each block of input is read from the stream to check if | 
| 64 |  |    * parsing is complete.  Can be replaced by subclasses to change the | 
| 65 |  |    * terminating condition for parsing.  Parsing always stops when the end of | 
| 66 |  |    * file is reached in the stream. | 
| 67 |  |    */ | 
| 68 |  |  | 
| 69 |  |   virtual int ParsingComplete(); | 
| 70 |  |  | 
| 71 |  |   /** | 
| 72 |  |    * Called when a new element is opened in the XML source.  Should be | 
| 73 |  |    * replaced by subclasses to handle each element.  name = Name of new | 
| 74 |  |    * element.  atts = Null-terminated array of attribute name/value pairs. | 
| 75 |  |    * Even indices are attribute names, and odd indices are values. | 
| 76 |  |    */ | 
| 77 |  |   virtual void StartElement(const std::string& name, const char** atts); | 
| 78 |  |  | 
| 79 |  |   //! Called at the end of an element in the XML source opened when | 
| 80 |  |   // StartElement was called. | 
| 81 |  |   virtual void EndElement(const std::string& name); | 
| 82 |  |  | 
| 83 |  |   //! Called when there is character data to handle. | 
| 84 |  |   virtual void CharacterDataHandler(const char* data, int length); | 
| 85 |  |  | 
| 86 |  |   //! Called by Parse to report an XML syntax error. | 
| 87 |  |   virtual void ReportXmlParseError(); | 
| 88 |  |  | 
| 89 |  |   /** Called by ReportXmlParseError with basic error info.  */ | 
| 90 |  |   virtual void ReportError(int line, int column, const char* msg); | 
| 91 |  |  | 
| 92 |  |   //! Send the given buffer to the XML parser. | 
| 93 |  |   virtual int ParseBuffer(const char* buffer, std::string::size_type length); | 
| 94 |  |  | 
| 95 |  |   //! Send the given c-style string to the XML parser. | 
| 96 |  |   int ParseBuffer(const char* buffer); | 
| 97 |  |  | 
| 98 |  |   /** Helps subclasses search for attributes on elements.  */ | 
| 99 |  |   static const char* FindAttribute(const char** atts, const char* attribute); | 
| 100 |  |  | 
| 101 |  |   //! Callbacks for the expat | 
| 102 |  |   friend void cmXMLParserStartElement(void*, const char*, const char**); | 
| 103 |  |   friend void cmXMLParserEndElement(void*, const char*); | 
| 104 |  |   friend void cmXMLParserCharacterDataHandler(void*, const char*, int); | 
| 105 |  | }; |