OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef XFA_FGAS_XML_FGAS_SAX_H_ | |
8 #define XFA_FGAS_XML_FGAS_SAX_H_ | |
9 | |
10 #include "core/fxcrt/include/fx_basic.h" | |
11 | |
12 #define FX_SAXPARSEMODE_NotConvert_amp 0x0001 | |
13 #define FX_SAXPARSEMODE_NotConvert_lt 0x0002 | |
14 #define FX_SAXPARSEMODE_NotConvert_gt 0x0004 | |
15 #define FX_SAXPARSEMODE_NotConvert_apos 0x0008 | |
16 #define FX_SAXPARSEMODE_NotConvert_quot 0x0010 | |
17 #define FX_SAXPARSEMODE_NotConvert_sharp 0x0020 | |
18 #define FX_SAXPARSEMODE_NotSkipSpace 0x0100 | |
19 | |
20 enum FX_SAXNODE { | |
21 FX_SAXNODE_Unknown = 0, | |
22 FX_SAXNODE_Instruction, | |
23 FX_SAXNODE_Declaration, | |
24 FX_SAXNODE_Comment, | |
25 FX_SAXNODE_Tag, | |
26 FX_SAXNODE_Text, | |
27 FX_SAXNODE_CharData, | |
28 }; | |
29 | |
30 enum FX_SAXMODE { | |
31 FX_SAXMODE_Text = 0, | |
32 FX_SAXMODE_NodeStart, | |
33 FX_SAXMODE_DeclOrComment, | |
34 FX_SAXMODE_DeclNode, | |
35 FX_SAXMODE_Comment, | |
36 FX_SAXMODE_CommentContent, | |
37 FX_SAXMODE_TagName, | |
38 FX_SAXMODE_TagAttributeName, | |
39 FX_SAXMODE_TagAttributeEqual, | |
40 FX_SAXMODE_TagAttributeValue, | |
41 FX_SAXMODE_TagMaybeClose, | |
42 FX_SAXMODE_TagClose, | |
43 FX_SAXMODE_TagEnd, | |
44 FX_SAXMODE_TargetData, | |
45 FX_SAXMODE_MAX, | |
46 }; | |
47 | |
48 class CXFA_SAXReaderHandler; | |
49 | |
50 class CFX_SAXFile { | |
51 public: | |
52 CFX_SAXFile(); | |
53 FX_BOOL StartFile(IFX_FileRead* pFile, uint32_t dwStart, uint32_t dwLen); | |
54 FX_BOOL ReadNextBlock(); | |
55 void Reset(); | |
56 IFX_FileRead* m_pFile; | |
57 uint32_t m_dwStart; | |
58 uint32_t m_dwEnd; | |
59 uint32_t m_dwCur; | |
60 uint8_t* m_pBuf; | |
61 uint32_t m_dwBufSize; | |
62 uint32_t m_dwBufIndex; | |
63 }; | |
64 | |
65 class CFX_SAXItem { | |
66 public: | |
67 CFX_SAXItem() | |
68 : m_pNode(NULL), | |
69 m_eNode(FX_SAXNODE_Unknown), | |
70 m_dwID(0), | |
71 m_bSkip(FALSE), | |
72 m_pPrev(NULL), | |
73 m_pNext(NULL) {} | |
74 void* m_pNode; | |
75 FX_SAXNODE m_eNode; | |
76 uint32_t m_dwID; | |
77 FX_BOOL m_bSkip; | |
78 CFX_SAXItem* m_pPrev; | |
79 CFX_SAXItem* m_pNext; | |
80 }; | |
81 | |
82 class CFX_SAXCommentContext { | |
83 public: | |
84 CFX_SAXCommentContext() : m_iHeaderCount(0), m_iTailCount(0) {} | |
85 int32_t m_iHeaderCount; | |
86 int32_t m_iTailCount; | |
87 }; | |
88 | |
89 class CFX_SAXReader { | |
90 public: | |
91 CFX_SAXReader(); | |
92 ~CFX_SAXReader(); | |
93 | |
94 int32_t StartParse(IFX_FileRead* pFile, | |
95 uint32_t dwStart = 0, | |
96 uint32_t dwLen = -1, | |
97 uint32_t dwParseMode = 0); | |
98 int32_t ContinueParse(IFX_Pause* pPause = NULL); | |
99 void SkipCurrentNode(); | |
100 void SetHandler(CXFA_SAXReaderHandler* pHandler); | |
101 void AppendData(uint8_t ch); | |
102 void AppendName(uint8_t ch); | |
103 void ParseText(); | |
104 void ParseNodeStart(); | |
105 void ParseInstruction(); | |
106 void ParseDeclOrComment(); | |
107 void ParseDeclNode(); | |
108 void ParseComment(); | |
109 void ParseCommentContent(); | |
110 void ParseTagName(); | |
111 void ParseTagAttributeName(); | |
112 void ParseTagAttributeEqual(); | |
113 void ParseTagAttributeValue(); | |
114 void ParseMaybeClose(); | |
115 void ParseTagClose(); | |
116 void ParseTagEnd(); | |
117 void ParseTargetData(); | |
118 | |
119 protected: | |
120 void Reset(); | |
121 void Push(); | |
122 void Pop(); | |
123 FX_BOOL SkipSpace(uint8_t ch); | |
124 void SkipNode(); | |
125 void NotifyData(); | |
126 void NotifyEnter(); | |
127 void NotifyAttribute(); | |
128 void NotifyBreak(); | |
129 void NotifyClose(); | |
130 void NotifyEnd(); | |
131 void NotifyTargetData(); | |
132 void ReallocDataBuffer(); | |
133 void ReallocNameBuffer(); | |
134 void ParseChar(uint8_t ch); | |
135 | |
136 CFX_SAXFile m_File; | |
137 CXFA_SAXReaderHandler* m_pHandler; | |
138 int32_t m_iState; | |
139 CFX_SAXItem* m_pRoot; | |
140 CFX_SAXItem* m_pCurItem; | |
141 uint32_t m_dwItemID; | |
142 FX_SAXMODE m_eMode; | |
143 FX_SAXMODE m_ePrevMode; | |
144 FX_BOOL m_bCharData; | |
145 uint8_t m_CurByte; | |
146 uint32_t m_dwDataOffset; | |
147 CFX_ByteArray m_SkipStack; | |
148 uint8_t m_SkipChar; | |
149 uint32_t m_dwNodePos; | |
150 uint8_t* m_pszData; | |
151 int32_t m_iDataSize; | |
152 int32_t m_iDataLength; | |
153 int32_t m_iEntityStart; | |
154 int32_t m_iDataPos; | |
155 uint8_t* m_pszName; | |
156 int32_t m_iNameSize; | |
157 int32_t m_iNameLength; | |
158 uint32_t m_dwParseMode; | |
159 CFX_SAXCommentContext* m_pCommentContext; | |
160 }; | |
161 | |
162 #endif // XFA_FGAS_XML_FGAS_SAX_H_ | |
OLD | NEW |