• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef IMAGE_IO_XML_XML_ELEMENT_RULES_H_  // NOLINT
2 #define IMAGE_IO_XML_XML_ELEMENT_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 XmlElementRule parses the following syntax:
10 /// Element ::= EmptyElemTag  | STag content ETag
11 /// EmptyElemTag ::=  '<' Name (S Attribute)* S? '/>'
12 /// STag         ::=  '<' Name (S Attribute)* S? '>'
13 /// ETag         ::=  '</' Name S? '>'
14 /// The Attribute syntax is parsed by XmlAttributeRule, which this rule
15 /// delegates to as a child rule. The EmptyElemTag type syntax is handled by
16 /// this rule. The STag part of the syntax is handled by this rule, but the
17 /// element contents and the ETag syntax is handled by the XmlElementContentRule
18 /// that is chained to by this rule.
19 class XmlElementRule : public XmlRule {
20  public:
21   XmlElementRule();
22   explicit XmlElementRule(StartPoint start_point);
23 
24  private:
25   /// Builds an XmlTokenContext from the XmlActionContext and calls the
26   /// handler's StartElement() function.
27   /// @param context The action context from the rule's terminal.
28   /// @return The result value from the handler's function.
29   DataMatchResult HandleName(const XmlActionContext& context);
30 
31   /// Handles the book keeping after parsing the whitespace following the name
32   /// of the element, basically looking ahead to see if an XmlAttributeRule has
33   /// to be delegated to as a child rule, or if the element ends.
34   /// @param context The action context from the rule's terminal.
35   /// @return The result value action context.
36   DataMatchResult HandlePostWhitespaceChar(const XmlActionContext& context);
37 
38   /// Builds an XmlTokenContext from the XmlActionContext and calls the
39   /// handler's FinishElement() function in response to the final literal in
40   /// the EmptyElemTag type sytax. As written in the comment for the XmlHandler
41   /// FinishElement() function, the token context passed to the handler in this
42   /// case will have an invalid range and a XmlPortion value of kNone - i.e.,
43   /// the element name is not available tfor this form of the element syntax.
44   /// @param context The action context from the rule's terminal.
45   /// @return The result value from the handler's function.
46   DataMatchResult HandleEmptyElemTagEnd(const XmlActionContext& context);
47 
48   /// Handles the book keeping after parsing the final ">" literal of the STag
49   /// syntax of the rule, creating an XmlElementContentRule for use as a chained
50   /// to rule.
51   /// @param context The action context from the rule's terminal.
52   /// @return The result value action context.
53   DataMatchResult HandleSTagEnd(const XmlActionContext& context);
54 };
55 
56 /// The XmlElementContentRule parses the following syntax:
57 /// (c? Element | PI | CDATA | Comment )+ ETag
58 /// The "c?" syntax represents the character data passed to the XmlHandler's
59 /// ElementContent() function. The syntax for Element, PI, CDATA and Comment
60 /// all cause a child rule to be created and delegated to. The ETag syntax will
61 /// cause this element to be finished with a DataMatchResult type of kFull.
62 class XmlElementContentRule : public XmlRule {
63  public:
64   XmlElementContentRule();
65 
66  private:
67   /// Builds an XmlTokenContext from the XmlActionContext and calls the
68   /// handler's ElementContent() function.
69   /// @param context The action context from the rule's terminal.
70   /// @return The result value from the handler's function.
71   DataMatchResult HandleContent(const XmlActionContext& context);
72 
73   /// Handles the book keeping after parsing the element's content characters,
74   /// and the first character literal ("<") of the Element, PI, CDATA or Comment
75   /// syntax, creating an appropriate child rule to delegate the processing to.
76   /// @param context The action context from the rule's terminal.
77   /// @return The result value action context.
78   DataMatchResult HandlePostOpenChar(const XmlActionContext& context);
79 
80   /// Builds an XmlTokenContext from the XmlActionContext and calls the
81   /// handler's FinishElement() function. No check is done by the rule to verify
82   /// that the element name matches the one that was passed to the handler's
83   /// StartElement.
84   /// @param context The action context from the rule's terminal.
85   /// @return The result value from the handler's function.
86   DataMatchResult HandleEndTag(const XmlActionContext& context);
87 };
88 
89 }  // namespace image_io
90 }  // namespace photos_editing_formats
91 
92 #endif // IMAGE_IO_XML_XML_ELEMENT_RULES_H_  // NOLINT
93