Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: xfa/fde/xml/fde_xml_imp.h

Issue 2067253002: Cleanup XML parser code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Review feedback Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fde/xml/fde_xml.h ('k') | xfa/fde/xml/fde_xml_imp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef XFA_FDE_XML_FDE_XML_IMP_H_ 7 #ifndef XFA_FDE_XML_FDE_XML_IMP_H_
8 #define XFA_FDE_XML_FDE_XML_IMP_H_ 8 #define XFA_FDE_XML_FDE_XML_IMP_H_
9 9
10 #include "core/fxcrt/include/fx_system.h" 10 #include "core/fxcrt/include/fx_system.h"
11 #include "xfa/fde/xml/fde_xml.h" 11 #include "xfa/fde/xml/fde_xml.h"
12 #include "xfa/fgas/crt/fgas_memory.h" 12 #include "xfa/fgas/crt/fgas_memory.h"
13 #include "xfa/fgas/crt/fgas_stream.h" 13 #include "xfa/fgas/crt/fgas_stream.h"
14 #include "xfa/fgas/crt/fgas_utils.h"
14 15
15 class CFDE_BlockBuffer; 16 class CFDE_BlockBuffer;
16 class CFDE_XMLInstruction; 17 class CFDE_XMLInstruction;
17 class CFDE_XMLElement; 18 class CFDE_XMLElement;
18 class CFDE_XMLText; 19 class CFDE_XMLText;
19 class CFDE_XMLDoc; 20 class CFDE_XMLDoc;
20 class CFDE_XMLDOMParser; 21 class CFDE_XMLDOMParser;
21 class CFDE_XMLParser; 22 class CFDE_XMLParser;
22 class CFDE_XMLSAXParser;
23 class CFDE_XMLSyntaxParser; 23 class CFDE_XMLSyntaxParser;
24 24
25 class CFDE_XMLNode : public CFX_Target { 25 class CFDE_XMLNode : public CFX_Target {
26 public: 26 public:
27 enum NodeItem { 27 enum NodeItem {
28 Root = 0, 28 Root = 0,
29 Parent, 29 Parent,
30 FirstSibling, 30 FirstSibling,
31 PriorSibling, 31 PriorSibling,
32 NextSibling, 32 NextSibling,
33 LastSibling, 33 LastSibling,
34 FirstNeighbor, 34 FirstNeighbor,
35 PriorNeighbor, 35 PriorNeighbor,
36 NextNeighbor, 36 NextNeighbor,
37 LastNeighbor, 37 LastNeighbor,
38 FirstChild, 38 FirstChild,
39 LastChild 39 LastChild
40 }; 40 };
41 41
42 CFDE_XMLNode(); 42 CFDE_XMLNode();
43 virtual ~CFDE_XMLNode();
43 44
44 virtual void Release() { delete this; } 45 virtual void Release() { delete this; }
45 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Unknown; } 46 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Unknown; }
46 virtual int32_t CountChildNodes() const;
47 virtual CFDE_XMLNode* GetChildNode(int32_t index) const;
48 virtual int32_t GetChildNodeIndex(CFDE_XMLNode* pNode) const;
49 virtual CFDE_XMLNode* GetPath(const FX_WCHAR* pPath,
50 int32_t iLength = -1,
51 FX_BOOL bQualifiedName = TRUE) const;
52 virtual int32_t InsertChildNode(CFDE_XMLNode* pNode, int32_t index = -1);
53 virtual void RemoveChildNode(CFDE_XMLNode* pNode);
54 virtual void DeleteChildren();
55 virtual CFDE_XMLNode* GetNodeItem(CFDE_XMLNode::NodeItem eItem) const;
56 virtual int32_t GetNodeLevel() const;
57 virtual FX_BOOL InsertNodeItem(CFDE_XMLNode::NodeItem eItem,
58 CFDE_XMLNode* pNode);
59 virtual CFDE_XMLNode* RemoveNodeItem(CFDE_XMLNode::NodeItem eItem);
60 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive); 47 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive);
61 virtual void SaveXMLNode(IFX_Stream* pXMLStream);
62 48
63 public: 49 int32_t CountChildNodes() const;
64 ~CFDE_XMLNode(); 50 CFDE_XMLNode* GetChildNode(int32_t index) const;
51 int32_t GetChildNodeIndex(CFDE_XMLNode* pNode) const;
52 int32_t InsertChildNode(CFDE_XMLNode* pNode, int32_t index = -1);
53 void RemoveChildNode(CFDE_XMLNode* pNode);
54 void DeleteChildren();
65 void CloneChildren(CFDE_XMLNode* pClone); 55 void CloneChildren(CFDE_XMLNode* pClone);
56
57 CFDE_XMLNode* GetPath(const FX_WCHAR* pPath,
58 int32_t iLength = -1,
59 FX_BOOL bQualifiedName = TRUE) const;
60
61 int32_t GetNodeLevel() const;
62 CFDE_XMLNode* GetNodeItem(CFDE_XMLNode::NodeItem eItem) const;
63 FX_BOOL InsertNodeItem(CFDE_XMLNode::NodeItem eItem, CFDE_XMLNode* pNode);
64 CFDE_XMLNode* RemoveNodeItem(CFDE_XMLNode::NodeItem eItem);
65
66 void SaveXMLNode(IFX_Stream* pXMLStream);
67
66 CFDE_XMLNode* m_pParent; 68 CFDE_XMLNode* m_pParent;
67 CFDE_XMLNode* m_pChild; 69 CFDE_XMLNode* m_pChild;
68 CFDE_XMLNode* m_pPrior; 70 CFDE_XMLNode* m_pPrior;
69 CFDE_XMLNode* m_pNext; 71 CFDE_XMLNode* m_pNext;
70 }; 72 };
73
71 class CFDE_XMLInstruction : public CFDE_XMLNode { 74 class CFDE_XMLInstruction : public CFDE_XMLNode {
72 public: 75 public:
73 CFDE_XMLInstruction(const CFX_WideString& wsTarget); 76 CFDE_XMLInstruction(const CFX_WideString& wsTarget);
74 virtual void Release() { delete this; } 77 ~CFDE_XMLInstruction() override {}
75 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Instruction; }
76 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive);
77 virtual void GetTargetName(CFX_WideString& wsTarget) const {
78 wsTarget = m_wsTarget;
79 }
80 virtual int32_t CountAttributes() const;
81 virtual FX_BOOL GetAttribute(int32_t index,
82 CFX_WideString& wsAttriName,
83 CFX_WideString& wsAttriValue) const;
84 virtual FX_BOOL HasAttribute(const FX_WCHAR* pwsAttriName) const;
85 virtual void GetString(const FX_WCHAR* pwsAttriName,
86 CFX_WideString& wsAttriValue,
87 const FX_WCHAR* pwsDefValue = nullptr) const;
88 virtual void SetString(const CFX_WideString& wsAttriName,
89 const CFX_WideString& wsAttriValue);
90 virtual int32_t GetInteger(const FX_WCHAR* pwsAttriName,
91 int32_t iDefValue = 0) const;
92 virtual void SetInteger(const FX_WCHAR* pwsAttriName, int32_t iAttriValue);
93 virtual FX_FLOAT GetFloat(const FX_WCHAR* pwsAttriName,
94 FX_FLOAT fDefValue = 0) const;
95 virtual void SetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fAttriValue);
96 virtual void RemoveAttribute(const FX_WCHAR* pwsAttriName);
97 virtual int32_t CountData() const;
98 virtual FX_BOOL GetData(int32_t index, CFX_WideString& wsData) const;
99 virtual void AppendData(const CFX_WideString& wsData);
100 virtual void RemoveData(int32_t index);
101 78
102 public: 79 // CFDE_XMLNode
103 ~CFDE_XMLInstruction() {} 80 void Release() override { delete this; }
81 FDE_XMLNODETYPE GetType() const override { return FDE_XMLNODE_Instruction; }
82 CFDE_XMLNode* Clone(FX_BOOL bRecursive) override;
83
84 void GetTargetName(CFX_WideString& wsTarget) const { wsTarget = m_wsTarget; }
85 int32_t CountAttributes() const;
86 FX_BOOL GetAttribute(int32_t index,
87 CFX_WideString& wsAttriName,
88 CFX_WideString& wsAttriValue) const;
89 FX_BOOL HasAttribute(const FX_WCHAR* pwsAttriName) const;
90 void GetString(const FX_WCHAR* pwsAttriName,
91 CFX_WideString& wsAttriValue,
92 const FX_WCHAR* pwsDefValue = nullptr) const;
93 void SetString(const CFX_WideString& wsAttriName,
94 const CFX_WideString& wsAttriValue);
95 int32_t GetInteger(const FX_WCHAR* pwsAttriName, int32_t iDefValue = 0) const;
96 void SetInteger(const FX_WCHAR* pwsAttriName, int32_t iAttriValue);
97 FX_FLOAT GetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fDefValue = 0) const;
98 void SetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fAttriValue);
99 void RemoveAttribute(const FX_WCHAR* pwsAttriName);
100 int32_t CountData() const;
101 FX_BOOL GetData(int32_t index, CFX_WideString& wsData) const;
102 void AppendData(const CFX_WideString& wsData);
103 void RemoveData(int32_t index);
104
104 CFX_WideString m_wsTarget; 105 CFX_WideString m_wsTarget;
105 CFX_WideStringArray m_Attributes; 106 CFX_WideStringArray m_Attributes;
106 CFX_WideStringArray m_TargetData; 107 CFX_WideStringArray m_TargetData;
107 }; 108 };
109
108 class CFDE_XMLElement : public CFDE_XMLNode { 110 class CFDE_XMLElement : public CFDE_XMLNode {
109 public: 111 public:
110 CFDE_XMLElement(const CFX_WideString& wsTag); 112 CFDE_XMLElement(const CFX_WideString& wsTag);
111 virtual void Release() { delete this; } 113 ~CFDE_XMLElement() override;
112 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Element; }
113 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive);
114 virtual void GetTagName(CFX_WideString& wsTag) const;
115 virtual void GetLocalTagName(CFX_WideString& wsTag) const;
116 virtual void GetNamespacePrefix(CFX_WideString& wsPrefix) const;
117 virtual void GetNamespaceURI(CFX_WideString& wsNamespace) const;
118 virtual int32_t CountAttributes() const;
119 virtual FX_BOOL GetAttribute(int32_t index,
120 CFX_WideString& wsAttriName,
121 CFX_WideString& wsAttriValue) const;
122 virtual FX_BOOL HasAttribute(const FX_WCHAR* pwsAttriName) const;
123 virtual void GetString(const FX_WCHAR* pwsAttriName,
124 CFX_WideString& wsAttriValue,
125 const FX_WCHAR* pwsDefValue = nullptr) const;
126 virtual void SetString(const CFX_WideString& wsAttriName,
127 const CFX_WideString& wsAttriValue);
128 virtual int32_t GetInteger(const FX_WCHAR* pwsAttriName,
129 int32_t iDefValue = 0) const;
130 virtual void SetInteger(const FX_WCHAR* pwsAttriName, int32_t iAttriValue);
131 virtual FX_FLOAT GetFloat(const FX_WCHAR* pwsAttriName,
132 FX_FLOAT fDefValue = 0) const;
133 virtual void SetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fAttriValue);
134 virtual void RemoveAttribute(const FX_WCHAR* pwsAttriName);
135 virtual void GetTextData(CFX_WideString& wsText) const;
136 virtual void SetTextData(const CFX_WideString& wsText);
137 114
138 public: 115 // CFDE_XMLNode
139 ~CFDE_XMLElement(); 116 void Release() override { delete this; }
117 FDE_XMLNODETYPE GetType() const override { return FDE_XMLNODE_Element; }
118 CFDE_XMLNode* Clone(FX_BOOL bRecursive) override;
119
120 void GetTagName(CFX_WideString& wsTag) const;
121 void GetLocalTagName(CFX_WideString& wsTag) const;
122
123 void GetNamespacePrefix(CFX_WideString& wsPrefix) const;
124 void GetNamespaceURI(CFX_WideString& wsNamespace) const;
125
126 int32_t CountAttributes() const;
127 FX_BOOL GetAttribute(int32_t index,
128 CFX_WideString& wsAttriName,
129 CFX_WideString& wsAttriValue) const;
130 FX_BOOL HasAttribute(const FX_WCHAR* pwsAttriName) const;
131 void RemoveAttribute(const FX_WCHAR* pwsAttriName);
132
133 void GetString(const FX_WCHAR* pwsAttriName,
134 CFX_WideString& wsAttriValue,
135 const FX_WCHAR* pwsDefValue = nullptr) const;
136 void SetString(const CFX_WideString& wsAttriName,
137 const CFX_WideString& wsAttriValue);
138
139 int32_t GetInteger(const FX_WCHAR* pwsAttriName, int32_t iDefValue = 0) const;
140 void SetInteger(const FX_WCHAR* pwsAttriName, int32_t iAttriValue);
141
142 FX_FLOAT GetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fDefValue = 0) const;
143 void SetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fAttriValue);
144
145 void GetTextData(CFX_WideString& wsText) const;
146 void SetTextData(const CFX_WideString& wsText);
147
140 CFX_WideString m_wsTag; 148 CFX_WideString m_wsTag;
141 CFX_WideStringArray m_Attributes; 149 CFX_WideStringArray m_Attributes;
142 }; 150 };
151
143 class CFDE_XMLText : public CFDE_XMLNode { 152 class CFDE_XMLText : public CFDE_XMLNode {
144 public: 153 public:
145 CFDE_XMLText(const CFX_WideString& wsText); 154 CFDE_XMLText(const CFX_WideString& wsText);
146 virtual void Release() { delete this; } 155 ~CFDE_XMLText() override {}
147 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Text; }
148 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive);
149 virtual void GetText(CFX_WideString& wsText) const { wsText = m_wsText; }
150 virtual void SetText(const CFX_WideString& wsText) { m_wsText = wsText; }
151 156
152 public: 157 // CFDE_XMLNode
153 ~CFDE_XMLText() {} 158 void Release() override { delete this; }
159 FDE_XMLNODETYPE GetType() const override { return FDE_XMLNODE_Text; }
160 CFDE_XMLNode* Clone(FX_BOOL bRecursive) override;
161
162 void GetText(CFX_WideString& wsText) const { wsText = m_wsText; }
163 void SetText(const CFX_WideString& wsText) { m_wsText = wsText; }
164
154 CFX_WideString m_wsText; 165 CFX_WideString m_wsText;
155 }; 166 };
167
156 class CFDE_XMLDeclaration : public CFDE_XMLNode { 168 class CFDE_XMLDeclaration : public CFDE_XMLNode {
157 public: 169 public:
158 CFDE_XMLDeclaration() : CFDE_XMLNode() {} 170 CFDE_XMLDeclaration() : CFDE_XMLNode() {}
171 ~CFDE_XMLDeclaration() override {}
159 }; 172 };
173
160 class CFDE_XMLCharData : public CFDE_XMLDeclaration { 174 class CFDE_XMLCharData : public CFDE_XMLDeclaration {
161 public: 175 public:
162 CFDE_XMLCharData(const CFX_WideString& wsCData); 176 CFDE_XMLCharData(const CFX_WideString& wsCData);
177 ~CFDE_XMLCharData() override {}
163 178
164 virtual void Release() { delete this; } 179 void Release() override { delete this; }
165 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_CharData; } 180 FDE_XMLNODETYPE GetType() const override { return FDE_XMLNODE_CharData; }
166 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive); 181 CFDE_XMLNode* Clone(FX_BOOL bRecursive) override;
167 virtual void GetCharData(CFX_WideString& wsCharData) const { 182
183 void GetCharData(CFX_WideString& wsCharData) const {
168 wsCharData = m_wsCharData; 184 wsCharData = m_wsCharData;
169 } 185 }
170 virtual void SetCharData(const CFX_WideString& wsCData) { 186 void SetCharData(const CFX_WideString& wsCData) { m_wsCharData = wsCData; }
171 m_wsCharData = wsCData;
172 }
173
174 public:
175 ~CFDE_XMLCharData() {}
176 187
177 CFX_WideString m_wsCharData; 188 CFX_WideString m_wsCharData;
178 }; 189 };
190
179 class CFDE_XMLDoc : public CFX_Target { 191 class CFDE_XMLDoc : public CFX_Target {
180 public: 192 public:
181 CFDE_XMLDoc(); 193 CFDE_XMLDoc();
182 ~CFDE_XMLDoc(); 194 ~CFDE_XMLDoc() override;
183 virtual void Release() { delete this; } 195
184 virtual FX_BOOL LoadXML(IFX_Stream* pXMLStream, 196 void Release() { delete this; }
185 int32_t iXMLPlaneSize = 8192, 197 FX_BOOL LoadXML(CFDE_XMLParser* pXMLParser);
186 int32_t iTextDataSize = 256, 198 int32_t DoLoad(IFX_Pause* pPause = nullptr);
187 FDE_XMLREADERHANDLER* pHandler = nullptr); 199 void CloseXML();
188 virtual FX_BOOL LoadXML(CFDE_XMLParser* pXMLParser); 200 CFDE_XMLNode* GetRoot() const { return m_pRoot; }
189 virtual int32_t DoLoad(IFX_Pause* pPause = nullptr); 201 void SaveXML(IFX_Stream* pXMLStream = nullptr, FX_BOOL bSaveBOM = TRUE);
190 virtual void CloseXML(); 202 void SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pNode);
191 virtual CFDE_XMLNode* GetRoot() const { return m_pRoot; }
192 virtual void SaveXML(IFX_Stream* pXMLStream = nullptr,
193 FX_BOOL bSaveBOM = TRUE);
194 virtual void SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pNode);
195 203
196 protected: 204 protected:
205 void Reset(FX_BOOL bInitRoot);
206 void ReleaseParser();
207
197 IFX_Stream* m_pStream; 208 IFX_Stream* m_pStream;
198 int32_t m_iStatus; 209 int32_t m_iStatus;
199 CFDE_XMLNode* m_pRoot; 210 CFDE_XMLNode* m_pRoot;
200 CFDE_XMLSyntaxParser* m_pSyntaxParser; 211 CFDE_XMLSyntaxParser* m_pSyntaxParser;
201 CFDE_XMLParser* m_pXMLParser; 212 CFDE_XMLParser* m_pXMLParser;
202 void Reset(FX_BOOL bInitRoot);
203 void ReleaseParser();
204 }; 213 };
205 typedef CFX_StackTemplate<CFDE_XMLNode*> CFDE_XMLDOMNodeStack;
206 214
207 class CFDE_XMLParser { 215 class CFDE_XMLParser {
208 public: 216 public:
209 virtual ~CFDE_XMLParser() {} 217 virtual ~CFDE_XMLParser() {}
210 218
211 virtual void Release() = 0; 219 virtual void Release() = 0;
212 virtual int32_t DoParser(IFX_Pause* pPause) = 0; 220 virtual int32_t DoParser(IFX_Pause* pPause) = 0;
213 }; 221 };
214 222
215 class CFDE_XMLDOMParser : public CFDE_XMLParser, public CFX_Target {
216 public:
217 CFDE_XMLDOMParser(CFDE_XMLNode* pRoot, CFDE_XMLSyntaxParser* pParser);
218 ~CFDE_XMLDOMParser();
219
220 virtual void Release() { delete this; }
221 virtual int32_t DoParser(IFX_Pause* pPause);
222
223 private:
224 CFDE_XMLSyntaxParser* m_pParser;
225 CFDE_XMLNode* m_pParent;
226 CFDE_XMLNode* m_pChild;
227 CFDE_XMLDOMNodeStack m_NodeStack;
228 CFX_WideString m_ws1;
229 CFX_WideString m_ws2;
230 };
231 class CFDE_XMLTAG : public CFX_Target {
232 public:
233 CFDE_XMLTAG() : eType(FDE_XMLNODE_Unknown) {}
234 CFDE_XMLTAG(const CFDE_XMLTAG& src)
235 : wsTagName(src.wsTagName), eType(src.eType) {}
236 CFX_WideString wsTagName;
237 FDE_XMLNODETYPE eType;
238 };
239 typedef CFX_ObjectStackTemplate<CFDE_XMLTAG> CFDE_XMLTagStack;
240 class CFDE_XMLSAXParser : public CFDE_XMLParser, public CFX_Target {
241 public:
242 CFDE_XMLSAXParser(FDE_XMLREADERHANDLER* pHandler,
243 CFDE_XMLSyntaxParser* pParser);
244 ~CFDE_XMLSAXParser();
245
246 virtual void Release() { delete this; }
247 virtual int32_t DoParser(IFX_Pause* pPause);
248
249 private:
250 void Push(const CFDE_XMLTAG& xmlTag);
251 void Pop();
252 FDE_XMLREADERHANDLER* m_pHandler;
253 CFDE_XMLSyntaxParser* m_pParser;
254 CFDE_XMLTagStack m_TagStack;
255 CFDE_XMLTAG* m_pTagTop;
256 CFX_WideString m_ws1;
257 CFX_WideString m_ws2;
258 };
259
260 class CFDE_BlockBuffer : public CFX_Target { 223 class CFDE_BlockBuffer : public CFX_Target {
261 public: 224 public:
262 CFDE_BlockBuffer(int32_t iAllocStep = 1024 * 1024); 225 CFDE_BlockBuffer(int32_t iAllocStep = 1024 * 1024);
263 ~CFDE_BlockBuffer(); 226 ~CFDE_BlockBuffer();
264 227
265 FX_BOOL InitBuffer(int32_t iBufferSize = 1024 * 1024); 228 FX_BOOL InitBuffer(int32_t iBufferSize = 1024 * 1024);
266 FX_BOOL IsInitialized() { return m_iBufferSize / m_iAllocStep >= 1; } 229 FX_BOOL IsInitialized() { return m_iBufferSize / m_iAllocStep >= 1; }
267 void ReleaseBuffer() { delete this; } 230 void ReleaseBuffer() { delete this; }
268 FX_WCHAR* GetAvailableBlock(int32_t& iIndexInBlock); 231 FX_WCHAR* GetAvailableBlock(int32_t& iIndexInBlock);
269 inline int32_t GetAllocStep() const { return m_iAllocStep; } 232 inline int32_t GetAllocStep() const { return m_iAllocStep; }
270 inline int32_t& GetDataLengthRef() { return m_iDataLength; } 233 inline int32_t& GetDataLengthRef() { return m_iDataLength; }
271 inline void Reset(FX_BOOL bReserveData = TRUE) { 234 inline void Reset(FX_BOOL bReserveData = TRUE) {
272 if (!bReserveData) { 235 if (!bReserveData) {
273 m_iStartPosition = 0; 236 m_iStartPosition = 0;
274 } 237 }
275 m_iDataLength = 0; 238 m_iDataLength = 0;
276 } 239 }
277 void SetTextChar(int32_t iIndex, FX_WCHAR ch); 240 void SetTextChar(int32_t iIndex, FX_WCHAR ch);
278 int32_t DeleteTextChars(int32_t iCount, FX_BOOL bDirection = TRUE); 241 int32_t DeleteTextChars(int32_t iCount, FX_BOOL bDirection = TRUE);
279 void GetTextData(CFX_WideString& wsTextData, 242 void GetTextData(CFX_WideString& wsTextData,
280 int32_t iStart = 0, 243 int32_t iStart = 0,
281 int32_t iLength = -1) const; 244 int32_t iLength = -1) const;
282 245
283 protected: 246 protected:
284 inline void TextDataIndex2BufIndex(const int32_t iIndex, 247 inline void TextDataIndex2BufIndex(const int32_t iIndex,
285 int32_t& iBlockIndex, 248 int32_t& iBlockIndex,
286 int32_t& iInnerIndex) const; 249 int32_t& iInnerIndex) const;
287 void ClearBuffer(); 250 void ClearBuffer();
251
288 CFX_ArrayTemplate<FX_WCHAR*> m_BlockArray; 252 CFX_ArrayTemplate<FX_WCHAR*> m_BlockArray;
289 int32_t m_iDataLength; 253 int32_t m_iDataLength;
290 int32_t m_iBufferSize; 254 int32_t m_iBufferSize;
291 int32_t m_iAllocStep; 255 int32_t m_iAllocStep;
292 int32_t m_iStartPosition; 256 int32_t m_iStartPosition;
293 }; 257 };
294 258
295 class CFDE_XMLSyntaxParser : public CFX_Target { 259 class CFDE_XMLSyntaxParser : public CFX_Target {
296 public: 260 public:
297 CFDE_XMLSyntaxParser(); 261 CFDE_XMLSyntaxParser();
298 ~CFDE_XMLSyntaxParser(); 262 ~CFDE_XMLSyntaxParser();
263
299 void Release() { delete this; } 264 void Release() { delete this; }
300 void Init(IFX_Stream* pStream, 265 void Init(IFX_Stream* pStream,
301 int32_t iXMLPlaneSize, 266 int32_t iXMLPlaneSize,
302 int32_t iTextDataSize = 256); 267 int32_t iTextDataSize = 256);
268
303 FDE_XmlSyntaxResult DoSyntaxParse(); 269 FDE_XmlSyntaxResult DoSyntaxParse();
270
304 int32_t GetStatus() const; 271 int32_t GetStatus() const;
305 int32_t GetCurrentPos() const { 272 int32_t GetCurrentPos() const {
306 return m_iParsedChars + (m_pStart - m_pBuffer); 273 return m_iParsedChars + (m_pStart - m_pBuffer);
307 } 274 }
308 FX_FILESIZE GetCurrentBinaryPos() const; 275 FX_FILESIZE GetCurrentBinaryPos() const;
309 int32_t GetCurrentNodeNumber() const { return m_iCurrentNodeNum; } 276 int32_t GetCurrentNodeNumber() const { return m_iCurrentNodeNum; }
310 int32_t GetLastNodeNumber() const { return m_iLastNodeNum; } 277 int32_t GetLastNodeNumber() const { return m_iLastNodeNum; }
311 278
312 void GetTargetName(CFX_WideString& wsTarget) const { 279 void GetTargetName(CFX_WideString& wsTarget) const {
313 m_BlockBuffer.GetTextData(wsTarget, 0, m_iTextDataLength); 280 m_BlockBuffer.GetTextData(wsTarget, 0, m_iTextDataLength);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 BreakElement, 312 BreakElement,
346 CloseElement, 313 CloseElement,
347 SkipDeclNode, 314 SkipDeclNode,
348 DeclCharData, 315 DeclCharData,
349 SkipComment, 316 SkipComment,
350 SkipCommentOrDecl, 317 SkipCommentOrDecl,
351 SkipCData, 318 SkipCData,
352 TargetData 319 TargetData
353 }; 320 };
354 321
322 void ParseTextChar(FX_WCHAR ch);
323
355 IFX_Stream* m_pStream; 324 IFX_Stream* m_pStream;
356 int32_t m_iXMLPlaneSize; 325 int32_t m_iXMLPlaneSize;
357 int32_t m_iCurrentPos; 326 int32_t m_iCurrentPos;
358 int32_t m_iCurrentNodeNum; 327 int32_t m_iCurrentNodeNum;
359 int32_t m_iLastNodeNum; 328 int32_t m_iLastNodeNum;
360 int32_t m_iParsedChars; 329 int32_t m_iParsedChars;
361 int32_t m_iParsedBytes; 330 int32_t m_iParsedBytes;
362 FX_WCHAR* m_pBuffer; 331 FX_WCHAR* m_pBuffer;
363 int32_t m_iBufferChars; 332 int32_t m_iBufferChars;
364 FX_BOOL m_bEOS; 333 FX_BOOL m_bEOS;
365 FX_WCHAR* m_pStart; 334 FX_WCHAR* m_pStart;
366 FX_WCHAR* m_pEnd; 335 FX_WCHAR* m_pEnd;
367 FDE_XMLNODE m_CurNode; 336 FDE_XMLNODE m_CurNode;
368 CFDE_XMLNodeStack m_XMLNodeStack; 337 CFX_StackTemplate<FDE_XMLNODE> m_XMLNodeStack;
369 CFDE_BlockBuffer m_BlockBuffer; 338 CFDE_BlockBuffer m_BlockBuffer;
370 int32_t m_iAllocStep; 339 int32_t m_iAllocStep;
371 int32_t& m_iDataLength; 340 int32_t& m_iDataLength;
372 FX_WCHAR* m_pCurrentBlock; 341 FX_WCHAR* m_pCurrentBlock;
373 int32_t m_iIndexInBlock; 342 int32_t m_iIndexInBlock;
374 int32_t m_iTextDataLength; 343 int32_t m_iTextDataLength;
375 FDE_XmlSyntaxResult m_syntaxParserResult; 344 FDE_XmlSyntaxResult m_syntaxParserResult;
376 FDE_XmlSyntaxState m_syntaxParserState; 345 FDE_XmlSyntaxState m_syntaxParserState;
377 FX_WCHAR m_wQuotationMark; 346 FX_WCHAR m_wQuotationMark;
378 int32_t m_iEntityStart; 347 int32_t m_iEntityStart;
379 CFX_DWordStack m_SkipStack; 348 CFX_DWordStack m_SkipStack;
380 FX_WCHAR m_SkipChar; 349 FX_WCHAR m_SkipChar;
381 inline void ParseTextChar(FX_WCHAR ch);
382 }; 350 };
383 351
384 #endif // XFA_FDE_XML_FDE_XML_IMP_H_ 352 #endif // XFA_FDE_XML_FDE_XML_IMP_H_
OLDNEW
« no previous file with comments | « xfa/fde/xml/fde_xml.h ('k') | xfa/fde/xml/fde_xml_imp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698