1 #ifndef IMAGE_IO_XML_XML_CDATA_AND_COMMENT_RULES_H_ // NOLINT 2 #define IMAGE_IO_XML_XML_CDATA_AND_COMMENT_RULES_H_ // NOLINT 3 4 #include "image_io/xml/xml_rule.h" 5 6 namespace photos_editing_formats { 7 namespace image_io { 8 9 /// The XmlCdataRule parses the following syntax "<![CDATA[ ... ]]>". 10 /// As mentioned in the comments for the XmlHandler::Cdata() function, the token 11 /// value that is passed to the handler never includes the leading "<![CDATA[" 12 /// syntax and always includes the trailing "]]>" syntax. This considerably 13 /// simplifies the parsing task. The alternate start point constructor is used 14 /// by the XmlCdataOrCommentRule. 15 class XmlCdataRule : public XmlRule { 16 public: 17 XmlCdataRule(); 18 explicit XmlCdataRule(StartPoint start_point); 19 20 private: 21 /// Builds an XmlTokenContext from the XmlActionContext and calls the 22 /// handler's Cdata() function. 23 /// @param context The action context from the rule's terminal. 24 /// @return The result value from the handler's function. 25 DataMatchResult HandleCdataValue(const XmlActionContext& context); 26 }; 27 28 /// The XmlCommentRule parses the following syntax "<!-- ... -->". 29 /// As mentioned in the comments for the XmlHandler::Comment() function, the 30 /// token value that is passed to the handler never includes the leading "<!--" 31 /// syntax and always includes the trailing "-->" syntax. This considerably 32 /// simplifies the parsing task. The alternate start point constructor is used 33 /// by the XmlCdataOrCommentRule. 34 class XmlCommentRule : public XmlRule { 35 public: 36 XmlCommentRule(); 37 explicit XmlCommentRule(StartPoint start_point); 38 39 private: 40 /// Builds an XmlTokenContext from the XmlActionContext and calls the 41 /// handler's Comment() function. 42 /// @param context The action context from the rule's terminal. 43 /// @return The result value from the handler's function. 44 DataMatchResult HandleCommentValue(const XmlActionContext& context); 45 }; 46 47 /// This rule will use chain delegation to start either the XmlCdataRule or the 48 /// XmlCommentRule, depending on the text being parsed. The syntax for XML is 49 /// pretty poor here - the parser needs to look ahead two characters from the < 50 /// character to determine what to do. The alternate start point constructor is 51 /// used by the XmlElementContentRule. 52 class XmlCdataOrCommentRule : public XmlRule { 53 public: 54 XmlCdataOrCommentRule(); 55 explicit XmlCdataOrCommentRule(StartPoint start_point); 56 57 private: 58 /// Builds an XmlTokenContext from the XmlActionContext and creates the 59 /// XmlCdataRule or XmlCommentRule to chain to depending on what character 60 /// follows the exclamation point of the "<!" syntax. 61 /// @param context The action context from the rule's terminal. 62 /// @return The result value from the action context. 63 DataMatchResult HandlePostBangChar(const XmlActionContext& context); 64 }; 65 66 } // namespace image_io 67 } // namespace photos_editing_formats 68 69 #endif // IMAGE_IO_XML_XML_CDATA_AND_COMMENT_RULES_H_ // NOLINT 70