OLD | NEW |
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 #include "xfa/fde/xml/fde_xml_imp.h" | 7 #include "xfa/fde/xml/fde_xml_imp.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (bFirstChar) { | 67 if (bFirstChar) { |
68 return g_XMLNameChars[iMid].bStartChar; | 68 return g_XMLNameChars[iMid].bStartChar; |
69 } | 69 } |
70 return TRUE; | 70 return TRUE; |
71 } | 71 } |
72 } | 72 } |
73 return FALSE; | 73 return FALSE; |
74 } | 74 } |
75 | 75 |
76 CFDE_XMLNode::CFDE_XMLNode() | 76 CFDE_XMLNode::CFDE_XMLNode() |
77 : m_pParent(NULL), m_pChild(NULL), m_pPrior(NULL), m_pNext(NULL) {} | 77 : m_pParent(nullptr), |
| 78 m_pChild(nullptr), |
| 79 m_pPrior(nullptr), |
| 80 m_pNext(nullptr) {} |
78 CFDE_XMLNode::~CFDE_XMLNode() { | 81 CFDE_XMLNode::~CFDE_XMLNode() { |
79 DeleteChildren(); | 82 DeleteChildren(); |
80 } | 83 } |
81 void CFDE_XMLNode::DeleteChildren() { | 84 void CFDE_XMLNode::DeleteChildren() { |
82 CFDE_XMLNode *pChild = m_pChild, *pTemp; | 85 CFDE_XMLNode *pChild = m_pChild, *pTemp; |
83 while (pChild != NULL) { | 86 while (pChild) { |
84 pTemp = pChild->m_pNext; | 87 pTemp = pChild->m_pNext; |
85 pChild->Release(); | 88 pChild->Release(); |
86 pChild = pTemp; | 89 pChild = pTemp; |
87 } | 90 } |
88 m_pChild = NULL; | 91 m_pChild = nullptr; |
89 } | 92 } |
90 int32_t CFDE_XMLNode::CountChildNodes() const { | 93 int32_t CFDE_XMLNode::CountChildNodes() const { |
91 int32_t iCount = 0; | 94 int32_t iCount = 0; |
92 CFDE_XMLNode* pChild = m_pChild; | 95 CFDE_XMLNode* pChild = m_pChild; |
93 while (pChild != NULL) { | 96 while (pChild) { |
94 iCount++; | 97 iCount++; |
95 pChild = pChild->m_pNext; | 98 pChild = pChild->m_pNext; |
96 } | 99 } |
97 return iCount; | 100 return iCount; |
98 } | 101 } |
99 CFDE_XMLNode* CFDE_XMLNode::GetChildNode(int32_t index) const { | 102 CFDE_XMLNode* CFDE_XMLNode::GetChildNode(int32_t index) const { |
100 CFDE_XMLNode* pChild = m_pChild; | 103 CFDE_XMLNode* pChild = m_pChild; |
101 while (pChild != NULL) { | 104 while (pChild) { |
102 if (index == 0) { | 105 if (index == 0) { |
103 return pChild; | 106 return pChild; |
104 } | 107 } |
105 index--; | 108 index--; |
106 pChild = pChild->m_pNext; | 109 pChild = pChild->m_pNext; |
107 } | 110 } |
108 return NULL; | 111 return nullptr; |
109 } | 112 } |
110 int32_t CFDE_XMLNode::GetChildNodeIndex(CFDE_XMLNode* pNode) const { | 113 int32_t CFDE_XMLNode::GetChildNodeIndex(CFDE_XMLNode* pNode) const { |
111 int32_t index = 0; | 114 int32_t index = 0; |
112 CFDE_XMLNode* pChild = m_pChild; | 115 CFDE_XMLNode* pChild = m_pChild; |
113 while (pChild != NULL) { | 116 while (pChild) { |
114 if (pChild == pNode) { | 117 if (pChild == pNode) { |
115 return index; | 118 return index; |
116 } | 119 } |
117 index++; | 120 index++; |
118 pChild = pChild->m_pNext; | 121 pChild = pChild->m_pNext; |
119 } | 122 } |
120 return -1; | 123 return -1; |
121 } | 124 } |
122 CFDE_XMLNode* CFDE_XMLNode::GetPath(const FX_WCHAR* pPath, | 125 CFDE_XMLNode* CFDE_XMLNode::GetPath(const FX_WCHAR* pPath, |
123 int32_t iLength, | 126 int32_t iLength, |
124 FX_BOOL bQualifiedName) const { | 127 FX_BOOL bQualifiedName) const { |
125 ASSERT(pPath != NULL); | 128 ASSERT(pPath); |
126 if (iLength < 0) { | 129 if (iLength < 0) { |
127 iLength = FXSYS_wcslen(pPath); | 130 iLength = FXSYS_wcslen(pPath); |
128 } | 131 } |
129 if (iLength == 0) { | 132 if (iLength == 0) { |
130 return NULL; | 133 return nullptr; |
131 } | 134 } |
132 CFX_WideString csPath; | 135 CFX_WideString csPath; |
133 const FX_WCHAR* pStart = pPath; | 136 const FX_WCHAR* pStart = pPath; |
134 const FX_WCHAR* pEnd = pPath + iLength; | 137 const FX_WCHAR* pEnd = pPath + iLength; |
135 FX_WCHAR ch; | 138 FX_WCHAR ch; |
136 while (pStart < pEnd) { | 139 while (pStart < pEnd) { |
137 ch = *pStart++; | 140 ch = *pStart++; |
138 if (ch == L'/') { | 141 if (ch == L'/') { |
139 break; | 142 break; |
140 } else { | 143 } else { |
141 csPath += ch; | 144 csPath += ch; |
142 } | 145 } |
143 } | 146 } |
144 iLength -= pStart - pPath; | 147 iLength -= pStart - pPath; |
145 CFDE_XMLNode* pFind = NULL; | 148 CFDE_XMLNode* pFind = nullptr; |
146 if (csPath.GetLength() < 1) { | 149 if (csPath.GetLength() < 1) { |
147 pFind = GetNodeItem(CFDE_XMLNode::Root); | 150 pFind = GetNodeItem(CFDE_XMLNode::Root); |
148 } else if (csPath.Compare(L"..") == 0) { | 151 } else if (csPath.Compare(L"..") == 0) { |
149 pFind = m_pParent; | 152 pFind = m_pParent; |
150 } else if (csPath.Compare(L".") == 0) { | 153 } else if (csPath.Compare(L".") == 0) { |
151 pFind = (CFDE_XMLNode*)this; | 154 pFind = (CFDE_XMLNode*)this; |
152 } else { | 155 } else { |
153 CFX_WideString wsTag; | 156 CFX_WideString wsTag; |
154 CFDE_XMLNode* pNode = m_pChild; | 157 CFDE_XMLNode* pNode = m_pChild; |
155 while (pNode != NULL) { | 158 while (pNode) { |
156 if (pNode->GetType() == FDE_XMLNODE_Element) { | 159 if (pNode->GetType() == FDE_XMLNODE_Element) { |
157 if (bQualifiedName) { | 160 if (bQualifiedName) { |
158 ((CFDE_XMLElement*)pNode)->GetTagName(wsTag); | 161 ((CFDE_XMLElement*)pNode)->GetTagName(wsTag); |
159 } else { | 162 } else { |
160 ((CFDE_XMLElement*)pNode)->GetLocalTagName(wsTag); | 163 ((CFDE_XMLElement*)pNode)->GetLocalTagName(wsTag); |
161 } | 164 } |
162 if (wsTag.Compare(csPath) == 0) { | 165 if (wsTag.Compare(csPath) == 0) { |
163 if (iLength < 1) { | 166 if (iLength < 1) { |
164 pFind = pNode; | 167 pFind = pNode; |
165 } else { | 168 } else { |
166 pFind = pNode->GetPath(pStart, iLength, bQualifiedName); | 169 pFind = pNode->GetPath(pStart, iLength, bQualifiedName); |
167 } | 170 } |
168 if (pFind != NULL) { | 171 if (pFind) |
169 return pFind; | 172 return pFind; |
170 } | |
171 } | 173 } |
172 } | 174 } |
173 pNode = pNode->m_pNext; | 175 pNode = pNode->m_pNext; |
174 } | 176 } |
175 } | 177 } |
176 if (pFind == NULL || iLength < 1) { | 178 if (!pFind || iLength < 1) |
177 return pFind; | 179 return pFind; |
178 } | |
179 return pFind->GetPath(pStart, iLength, bQualifiedName); | 180 return pFind->GetPath(pStart, iLength, bQualifiedName); |
180 } | 181 } |
181 int32_t CFDE_XMLNode::InsertChildNode(CFDE_XMLNode* pNode, int32_t index) { | 182 int32_t CFDE_XMLNode::InsertChildNode(CFDE_XMLNode* pNode, int32_t index) { |
182 ASSERT(pNode != NULL); | |
183 pNode->m_pParent = this; | 183 pNode->m_pParent = this; |
184 if (m_pChild == NULL) { | 184 if (!m_pChild) { |
185 m_pChild = pNode; | 185 m_pChild = pNode; |
186 pNode->m_pPrior = NULL; | 186 pNode->m_pPrior = nullptr; |
187 pNode->m_pNext = NULL; | 187 pNode->m_pNext = nullptr; |
188 return 0; | 188 return 0; |
189 } else if (index == 0) { | 189 } |
| 190 if (index == 0) { |
190 pNode->m_pNext = m_pChild; | 191 pNode->m_pNext = m_pChild; |
191 pNode->m_pPrior = NULL; | 192 pNode->m_pPrior = nullptr; |
192 m_pChild->m_pPrior = pNode; | 193 m_pChild->m_pPrior = pNode; |
193 m_pChild = pNode; | 194 m_pChild = pNode; |
194 return 0; | 195 return 0; |
195 } | 196 } |
196 int32_t iCount = 0; | 197 int32_t iCount = 0; |
197 CFDE_XMLNode* pFind = m_pChild; | 198 CFDE_XMLNode* pFind = m_pChild; |
198 while (++iCount != index && pFind->m_pNext != NULL) { | 199 while (++iCount != index && pFind->m_pNext) { |
199 pFind = pFind->m_pNext; | 200 pFind = pFind->m_pNext; |
200 } | 201 } |
201 pNode->m_pPrior = pFind; | 202 pNode->m_pPrior = pFind; |
202 pNode->m_pNext = pFind->m_pNext; | 203 pNode->m_pNext = pFind->m_pNext; |
203 if (pFind->m_pNext != NULL) { | 204 if (pFind->m_pNext) |
204 pFind->m_pNext->m_pPrior = pNode; | 205 pFind->m_pNext->m_pPrior = pNode; |
205 } | |
206 pFind->m_pNext = pNode; | 206 pFind->m_pNext = pNode; |
207 return iCount; | 207 return iCount; |
208 } | 208 } |
209 void CFDE_XMLNode::RemoveChildNode(CFDE_XMLNode* pNode) { | 209 void CFDE_XMLNode::RemoveChildNode(CFDE_XMLNode* pNode) { |
210 ASSERT(m_pChild != NULL && pNode != NULL); | 210 ASSERT(m_pChild && pNode); |
211 if (m_pChild == pNode) { | 211 if (m_pChild == pNode) { |
212 m_pChild = pNode->m_pNext; | 212 m_pChild = pNode->m_pNext; |
213 } else { | 213 } else { |
214 pNode->m_pPrior->m_pNext = pNode->m_pNext; | 214 pNode->m_pPrior->m_pNext = pNode->m_pNext; |
215 } | 215 } |
216 if (pNode->m_pNext != NULL) { | 216 if (pNode->m_pNext) |
217 pNode->m_pNext->m_pPrior = pNode->m_pPrior; | 217 pNode->m_pNext->m_pPrior = pNode->m_pPrior; |
218 } | 218 pNode->m_pParent = nullptr; |
219 pNode->m_pParent = NULL; | 219 pNode->m_pNext = nullptr; |
220 pNode->m_pNext = NULL; | 220 pNode->m_pPrior = nullptr; |
221 pNode->m_pPrior = NULL; | |
222 } | 221 } |
223 CFDE_XMLNode* CFDE_XMLNode::GetNodeItem(CFDE_XMLNode::NodeItem eItem) const { | 222 CFDE_XMLNode* CFDE_XMLNode::GetNodeItem(CFDE_XMLNode::NodeItem eItem) const { |
224 switch (eItem) { | 223 switch (eItem) { |
225 case CFDE_XMLNode::Root: { | 224 case CFDE_XMLNode::Root: { |
226 CFDE_XMLNode* pParent = (CFDE_XMLNode*)this; | 225 CFDE_XMLNode* pParent = (CFDE_XMLNode*)this; |
227 while (pParent->m_pParent != NULL) { | 226 while (pParent->m_pParent) { |
228 pParent = pParent->m_pParent; | 227 pParent = pParent->m_pParent; |
229 } | 228 } |
230 return pParent; | 229 return pParent; |
231 } | 230 } |
232 case CFDE_XMLNode::Parent: | 231 case CFDE_XMLNode::Parent: |
233 return m_pParent; | 232 return m_pParent; |
234 case CFDE_XMLNode::FirstSibling: { | 233 case CFDE_XMLNode::FirstSibling: { |
235 CFDE_XMLNode* pItem = (CFDE_XMLNode*)this; | 234 CFDE_XMLNode* pItem = (CFDE_XMLNode*)this; |
236 while (pItem->m_pPrior != NULL) { | 235 while (pItem->m_pPrior) { |
237 pItem = pItem->m_pPrior; | 236 pItem = pItem->m_pPrior; |
238 } | 237 } |
239 return pItem == (CFDE_XMLNode*)this ? NULL : pItem; | 238 return pItem == (CFDE_XMLNode*)this ? nullptr : pItem; |
240 } | 239 } |
241 case CFDE_XMLNode::PriorSibling: | 240 case CFDE_XMLNode::PriorSibling: |
242 return m_pPrior; | 241 return m_pPrior; |
243 case CFDE_XMLNode::NextSibling: | 242 case CFDE_XMLNode::NextSibling: |
244 return m_pNext; | 243 return m_pNext; |
245 case CFDE_XMLNode::LastSibling: { | 244 case CFDE_XMLNode::LastSibling: { |
246 CFDE_XMLNode* pItem = (CFDE_XMLNode*)this; | 245 CFDE_XMLNode* pItem = (CFDE_XMLNode*)this; |
247 while (pItem->m_pNext != NULL) { | 246 while (pItem->m_pNext) |
248 pItem = pItem->m_pNext; | 247 pItem = pItem->m_pNext; |
249 } | 248 return pItem == (CFDE_XMLNode*)this ? nullptr : pItem; |
250 return pItem == (CFDE_XMLNode*)this ? NULL : pItem; | |
251 } | 249 } |
252 case CFDE_XMLNode::FirstNeighbor: { | 250 case CFDE_XMLNode::FirstNeighbor: { |
253 CFDE_XMLNode* pParent = (CFDE_XMLNode*)this; | 251 CFDE_XMLNode* pParent = (CFDE_XMLNode*)this; |
254 while (pParent->m_pParent != NULL) { | 252 while (pParent->m_pParent) |
255 pParent = pParent->m_pParent; | 253 pParent = pParent->m_pParent; |
256 } | 254 return pParent == (CFDE_XMLNode*)this ? nullptr : pParent; |
257 return pParent == (CFDE_XMLNode*)this ? NULL : pParent; | |
258 } | 255 } |
259 case CFDE_XMLNode::PriorNeighbor: { | 256 case CFDE_XMLNode::PriorNeighbor: { |
260 if (m_pPrior == NULL) { | 257 if (!m_pPrior) |
261 return m_pParent; | 258 return m_pParent; |
262 } | 259 |
263 CFDE_XMLNode* pItem = m_pPrior; | 260 CFDE_XMLNode* pItem = m_pPrior; |
264 while (CFDE_XMLNode* pTemp = pItem->m_pChild) { | 261 while (pItem->m_pChild) { |
265 pItem = pTemp; | 262 pItem = pItem->m_pChild; |
266 while ((pTemp = pItem->m_pNext) != NULL) { | 263 while (pItem->m_pNext) |
267 pItem = pTemp; | 264 pItem = pItem->m_pNext; |
268 } | |
269 } | 265 } |
270 return pItem; | 266 return pItem; |
271 } | 267 } |
272 case CFDE_XMLNode::NextNeighbor: { | 268 case CFDE_XMLNode::NextNeighbor: { |
273 if (m_pChild != NULL) { | 269 if (m_pChild) |
274 return m_pChild; | 270 return m_pChild; |
275 } | 271 if (m_pNext) |
276 if (m_pNext != NULL) { | |
277 return m_pNext; | 272 return m_pNext; |
278 } | |
279 CFDE_XMLNode* pItem = m_pParent; | 273 CFDE_XMLNode* pItem = m_pParent; |
280 while (pItem != NULL) { | 274 while (pItem) { |
281 if (pItem->m_pNext != NULL) { | 275 if (pItem->m_pNext) |
282 return pItem->m_pNext; | 276 return pItem->m_pNext; |
283 } | |
284 pItem = pItem->m_pParent; | 277 pItem = pItem->m_pParent; |
285 } | 278 } |
286 return NULL; | 279 return nullptr; |
287 } | 280 } |
288 case CFDE_XMLNode::LastNeighbor: { | 281 case CFDE_XMLNode::LastNeighbor: { |
289 CFDE_XMLNode* pItem = (CFDE_XMLNode*)this; | 282 CFDE_XMLNode* pItem = (CFDE_XMLNode*)this; |
290 while (pItem->m_pParent != NULL) { | 283 while (pItem->m_pParent) { |
291 pItem = pItem->m_pParent; | 284 pItem = pItem->m_pParent; |
292 } | 285 } |
293 while (TRUE) { | 286 while (TRUE) { |
294 while (pItem->m_pNext != NULL) { | 287 while (pItem->m_pNext) |
295 pItem = pItem->m_pNext; | 288 pItem = pItem->m_pNext; |
296 } | 289 if (!pItem->m_pChild) |
297 if (pItem->m_pChild == NULL) { | |
298 break; | 290 break; |
299 } | |
300 pItem = pItem->m_pChild; | 291 pItem = pItem->m_pChild; |
301 } | 292 } |
302 return pItem == (CFDE_XMLNode*)this ? NULL : pItem; | 293 return pItem == (CFDE_XMLNode*)this ? nullptr : pItem; |
303 } | 294 } |
304 case CFDE_XMLNode::FirstChild: | 295 case CFDE_XMLNode::FirstChild: |
305 return m_pChild; | 296 return m_pChild; |
306 case CFDE_XMLNode::LastChild: { | 297 case CFDE_XMLNode::LastChild: { |
307 if (m_pChild == NULL) { | 298 if (!m_pChild) |
308 return NULL; | 299 return nullptr; |
309 } | 300 |
310 CFDE_XMLNode* pChild = m_pChild; | 301 CFDE_XMLNode* pChild = m_pChild; |
311 while (pChild->m_pNext != NULL) { | 302 while (pChild->m_pNext) |
312 pChild = pChild->m_pNext; | 303 pChild = pChild->m_pNext; |
313 } | |
314 return pChild; | 304 return pChild; |
315 } | 305 } |
316 default: | 306 default: |
317 break; | 307 break; |
318 } | 308 } |
319 return NULL; | 309 return nullptr; |
320 } | 310 } |
321 int32_t CFDE_XMLNode::GetNodeLevel() const { | 311 int32_t CFDE_XMLNode::GetNodeLevel() const { |
322 int32_t iLevel = 0; | 312 int32_t iLevel = 0; |
323 CFDE_XMLNode* pItem = (CFDE_XMLNode*)this; | 313 CFDE_XMLNode* pItem = (CFDE_XMLNode*)this; |
324 while ((pItem = pItem->m_pParent) != NULL) { | 314 while ((pItem = pItem->m_pParent) != nullptr) { |
325 iLevel++; | 315 iLevel++; |
326 } | 316 } |
327 return iLevel; | 317 return iLevel; |
328 } | 318 } |
329 FX_BOOL CFDE_XMLNode::InsertNodeItem(CFDE_XMLNode::NodeItem eItem, | 319 FX_BOOL CFDE_XMLNode::InsertNodeItem(CFDE_XMLNode::NodeItem eItem, |
330 CFDE_XMLNode* pNode) { | 320 CFDE_XMLNode* pNode) { |
331 ASSERT(pNode != NULL); | |
332 switch (eItem) { | 321 switch (eItem) { |
333 case CFDE_XMLNode::NextSibling: { | 322 case CFDE_XMLNode::NextSibling: { |
334 pNode->m_pParent = m_pParent; | 323 pNode->m_pParent = m_pParent; |
335 pNode->m_pNext = m_pNext; | 324 pNode->m_pNext = m_pNext; |
336 pNode->m_pPrior = this; | 325 pNode->m_pPrior = this; |
337 if (m_pNext) { | 326 if (m_pNext) { |
338 m_pNext->m_pPrior = pNode; | 327 m_pNext->m_pPrior = pNode; |
339 } | 328 } |
340 m_pNext = pNode; | 329 m_pNext = pNode; |
341 return TRUE; | 330 return TRUE; |
342 } | 331 } |
343 case CFDE_XMLNode::PriorSibling: { | 332 case CFDE_XMLNode::PriorSibling: { |
344 pNode->m_pParent = m_pParent; | 333 pNode->m_pParent = m_pParent; |
345 pNode->m_pNext = this; | 334 pNode->m_pNext = this; |
346 pNode->m_pPrior = m_pPrior; | 335 pNode->m_pPrior = m_pPrior; |
347 if (m_pPrior) { | 336 if (m_pPrior) { |
348 m_pPrior->m_pNext = pNode; | 337 m_pPrior->m_pNext = pNode; |
349 } else if (m_pParent) { | 338 } else if (m_pParent) { |
350 m_pParent->m_pChild = pNode; | 339 m_pParent->m_pChild = pNode; |
351 } | 340 } |
352 m_pPrior = pNode; | 341 m_pPrior = pNode; |
353 return TRUE; | 342 return TRUE; |
354 } | 343 } |
355 default: | 344 default: |
356 return FALSE; | 345 return FALSE; |
357 } | 346 } |
358 } | 347 } |
359 CFDE_XMLNode* CFDE_XMLNode::RemoveNodeItem(CFDE_XMLNode::NodeItem eItem) { | 348 CFDE_XMLNode* CFDE_XMLNode::RemoveNodeItem(CFDE_XMLNode::NodeItem eItem) { |
360 CFDE_XMLNode* pNode = NULL; | 349 CFDE_XMLNode* pNode = nullptr; |
361 switch (eItem) { | 350 switch (eItem) { |
362 case CFDE_XMLNode::NextSibling: | 351 case CFDE_XMLNode::NextSibling: |
363 if (m_pNext) { | 352 if (m_pNext) { |
364 pNode = m_pNext; | 353 pNode = m_pNext; |
365 m_pNext = pNode->m_pNext; | 354 m_pNext = pNode->m_pNext; |
366 if (m_pNext) { | 355 if (m_pNext) { |
367 m_pNext->m_pPrior = this; | 356 m_pNext->m_pPrior = this; |
368 } | 357 } |
369 pNode->m_pParent = NULL; | 358 pNode->m_pParent = nullptr; |
370 pNode->m_pNext = NULL; | 359 pNode->m_pNext = nullptr; |
371 pNode->m_pPrior = NULL; | 360 pNode->m_pPrior = nullptr; |
372 } | 361 } |
373 break; | 362 break; |
374 default: | 363 default: |
375 break; | 364 break; |
376 } | 365 } |
377 return pNode; | 366 return pNode; |
378 } | 367 } |
379 CFDE_XMLNode* CFDE_XMLNode::Clone(FX_BOOL bRecursive) { | 368 CFDE_XMLNode* CFDE_XMLNode::Clone(FX_BOOL bRecursive) { |
380 return NULL; | 369 return nullptr; |
381 } | 370 } |
382 void CFDE_XMLNode::SaveXMLNode(IFX_Stream* pXMLStream) { | 371 void CFDE_XMLNode::SaveXMLNode(IFX_Stream* pXMLStream) { |
383 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; | 372 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; |
384 ASSERT(pXMLStream != NULL && pNode != NULL); | |
385 switch (pNode->GetType()) { | 373 switch (pNode->GetType()) { |
386 case FDE_XMLNODE_Instruction: { | 374 case FDE_XMLNODE_Instruction: { |
387 CFX_WideString ws; | 375 CFX_WideString ws; |
388 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; | 376 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; |
389 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { | 377 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { |
390 ws = L"<?xml version=\"1.0\" encoding=\""; | 378 ws = L"<?xml version=\"1.0\" encoding=\""; |
391 uint16_t wCodePage = pXMLStream->GetCodePage(); | 379 uint16_t wCodePage = pXMLStream->GetCodePage(); |
392 if (wCodePage == FX_CODEPAGE_UTF16LE) { | 380 if (wCodePage == FX_CODEPAGE_UTF16LE) { |
393 ws += L"UTF-16"; | 381 ws += L"UTF-16"; |
394 } else if (wCodePage == FX_CODEPAGE_UTF16BE) { | 382 } else if (wCodePage == FX_CODEPAGE_UTF16BE) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 wsValue = attributes[i + 1]; | 433 wsValue = attributes[i + 1]; |
446 wsValue.Replace(L"&", L"&"); | 434 wsValue.Replace(L"&", L"&"); |
447 wsValue.Replace(L"<", L"<"); | 435 wsValue.Replace(L"<", L"<"); |
448 wsValue.Replace(L">", L">"); | 436 wsValue.Replace(L">", L">"); |
449 wsValue.Replace(L"\'", L"'"); | 437 wsValue.Replace(L"\'", L"'"); |
450 wsValue.Replace(L"\"", L"""); | 438 wsValue.Replace(L"\"", L"""); |
451 ws += wsValue; | 439 ws += wsValue; |
452 ws += L"\""; | 440 ws += L"\""; |
453 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 441 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
454 } | 442 } |
455 if (pNode->m_pChild == NULL) { | 443 if (pNode->m_pChild) { |
456 ws = L"\n/>"; | |
457 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | |
458 } else { | |
459 ws = L"\n>"; | 444 ws = L"\n>"; |
460 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 445 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
461 CFDE_XMLNode* pChild = pNode->m_pChild; | 446 CFDE_XMLNode* pChild = pNode->m_pChild; |
462 while (pChild != NULL) { | 447 while (pChild) { |
463 pChild->SaveXMLNode(pXMLStream); | 448 pChild->SaveXMLNode(pXMLStream); |
464 pChild = pChild->m_pNext; | 449 pChild = pChild->m_pNext; |
465 } | 450 } |
466 ws = L"</"; | 451 ws = L"</"; |
467 ws += ((CFDE_XMLElement*)pNode)->m_wsTag; | 452 ws += ((CFDE_XMLElement*)pNode)->m_wsTag; |
468 ws += L"\n>"; | 453 ws += L"\n>"; |
469 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 454 } else { |
| 455 ws = L"\n/>"; |
470 } | 456 } |
| 457 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
471 } break; | 458 } break; |
472 case FDE_XMLNODE_Text: { | 459 case FDE_XMLNODE_Text: { |
473 CFX_WideString ws = ((CFDE_XMLText*)pNode)->m_wsText; | 460 CFX_WideString ws = ((CFDE_XMLText*)pNode)->m_wsText; |
474 ws.Replace(L"&", L"&"); | 461 ws.Replace(L"&", L"&"); |
475 ws.Replace(L"<", L"<"); | 462 ws.Replace(L"<", L"<"); |
476 ws.Replace(L">", L">"); | 463 ws.Replace(L">", L">"); |
477 ws.Replace(L"\'", L"'"); | 464 ws.Replace(L"\'", L"'"); |
478 ws.Replace(L"\"", L"""); | 465 ws.Replace(L"\"", L"""); |
479 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 466 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
480 } break; | 467 } break; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 CFDE_XMLElement::CFDE_XMLElement(const CFX_WideString& wsTag) | 625 CFDE_XMLElement::CFDE_XMLElement(const CFX_WideString& wsTag) |
639 : CFDE_XMLNode(), m_wsTag(wsTag), m_Attributes() { | 626 : CFDE_XMLNode(), m_wsTag(wsTag), m_Attributes() { |
640 ASSERT(m_wsTag.GetLength() > 0); | 627 ASSERT(m_wsTag.GetLength() > 0); |
641 } | 628 } |
642 CFDE_XMLElement::~CFDE_XMLElement() { | 629 CFDE_XMLElement::~CFDE_XMLElement() { |
643 m_Attributes.RemoveAll(); | 630 m_Attributes.RemoveAll(); |
644 } | 631 } |
645 CFDE_XMLNode* CFDE_XMLElement::Clone(FX_BOOL bRecursive) { | 632 CFDE_XMLNode* CFDE_XMLElement::Clone(FX_BOOL bRecursive) { |
646 CFDE_XMLElement* pClone = new CFDE_XMLElement(m_wsTag); | 633 CFDE_XMLElement* pClone = new CFDE_XMLElement(m_wsTag); |
647 if (!pClone) { | 634 if (!pClone) { |
648 return NULL; | 635 return nullptr; |
649 } | 636 } |
650 pClone->m_Attributes.Copy(m_Attributes); | 637 pClone->m_Attributes.Copy(m_Attributes); |
651 if (bRecursive) { | 638 if (bRecursive) { |
652 CloneChildren(pClone); | 639 CloneChildren(pClone); |
653 } else { | 640 } else { |
654 CFX_WideString wsText; | 641 CFX_WideString wsText; |
655 CFDE_XMLNode* pChild = m_pChild; | 642 CFDE_XMLNode* pChild = m_pChild; |
656 while (pChild != NULL) { | 643 while (pChild) { |
657 switch (pChild->GetType()) { | 644 switch (pChild->GetType()) { |
658 case FDE_XMLNODE_Text: | 645 case FDE_XMLNODE_Text: |
659 wsText += ((CFDE_XMLText*)pChild)->m_wsText; | 646 wsText += ((CFDE_XMLText*)pChild)->m_wsText; |
660 break; | 647 break; |
661 default: | 648 default: |
662 break; | 649 break; |
663 } | 650 } |
664 pChild = pChild->m_pNext; | 651 pChild = pChild->m_pNext; |
665 } | 652 } |
666 pClone->SetTextData(wsText); | 653 pClone->SetTextData(wsText); |
(...skipping 21 matching lines...) Expand all Loading... |
688 } | 675 } |
689 void CFDE_XMLElement::GetNamespaceURI(CFX_WideString& wsNamespace) const { | 676 void CFDE_XMLElement::GetNamespaceURI(CFX_WideString& wsNamespace) const { |
690 CFX_WideString wsAttri(L"xmlns"), wsPrefix; | 677 CFX_WideString wsAttri(L"xmlns"), wsPrefix; |
691 GetNamespacePrefix(wsPrefix); | 678 GetNamespacePrefix(wsPrefix); |
692 if (wsPrefix.GetLength() > 0) { | 679 if (wsPrefix.GetLength() > 0) { |
693 wsAttri += L":"; | 680 wsAttri += L":"; |
694 wsAttri += wsPrefix; | 681 wsAttri += wsPrefix; |
695 } | 682 } |
696 wsNamespace.clear(); | 683 wsNamespace.clear(); |
697 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; | 684 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; |
698 while (pNode != NULL) { | 685 while (pNode) { |
699 if (pNode->GetType() != FDE_XMLNODE_Element) { | 686 if (pNode->GetType() != FDE_XMLNODE_Element) { |
700 break; | 687 break; |
701 } | 688 } |
702 CFDE_XMLElement* pElement = (CFDE_XMLElement*)pNode; | 689 CFDE_XMLElement* pElement = (CFDE_XMLElement*)pNode; |
703 if (!pElement->HasAttribute(wsAttri.c_str())) { | 690 if (!pElement->HasAttribute(wsAttri.c_str())) { |
704 pNode = pNode->GetNodeItem(CFDE_XMLNode::Parent); | 691 pNode = pNode->GetNodeItem(CFDE_XMLNode::Parent); |
705 continue; | 692 continue; |
706 } | 693 } |
707 pElement->GetString(wsAttri.c_str(), wsNamespace); | 694 pElement->GetString(wsAttri.c_str(), wsNamespace); |
708 break; | 695 break; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 786 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
800 m_Attributes.RemoveAt(i + 1); | 787 m_Attributes.RemoveAt(i + 1); |
801 m_Attributes.RemoveAt(i); | 788 m_Attributes.RemoveAt(i); |
802 return; | 789 return; |
803 } | 790 } |
804 } | 791 } |
805 } | 792 } |
806 void CFDE_XMLElement::GetTextData(CFX_WideString& wsText) const { | 793 void CFDE_XMLElement::GetTextData(CFX_WideString& wsText) const { |
807 CFX_WideTextBuf buffer; | 794 CFX_WideTextBuf buffer; |
808 CFDE_XMLNode* pChild = m_pChild; | 795 CFDE_XMLNode* pChild = m_pChild; |
809 while (pChild != NULL) { | 796 while (pChild) { |
810 switch (pChild->GetType()) { | 797 switch (pChild->GetType()) { |
811 case FDE_XMLNODE_Text: | 798 case FDE_XMLNODE_Text: |
812 buffer << ((CFDE_XMLText*)pChild)->m_wsText; | 799 buffer << ((CFDE_XMLText*)pChild)->m_wsText; |
813 break; | 800 break; |
814 case FDE_XMLNODE_CharData: | 801 case FDE_XMLNODE_CharData: |
815 buffer << ((CFDE_XMLCharData*)pChild)->m_wsCharData; | 802 buffer << ((CFDE_XMLCharData*)pChild)->m_wsCharData; |
816 break; | 803 break; |
817 default: | 804 default: |
818 break; | 805 break; |
819 } | 806 } |
(...skipping 15 matching lines...) Expand all Loading... |
835 } | 822 } |
836 | 823 |
837 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) | 824 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) |
838 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} | 825 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} |
839 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { | 826 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { |
840 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); | 827 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); |
841 return pClone; | 828 return pClone; |
842 } | 829 } |
843 | 830 |
844 CFDE_XMLDoc::CFDE_XMLDoc() | 831 CFDE_XMLDoc::CFDE_XMLDoc() |
845 : m_pRoot(NULL), m_pSyntaxParser(NULL), m_pXMLParser(NULL) { | 832 : m_pRoot(nullptr), m_pSyntaxParser(nullptr), m_pXMLParser(nullptr) { |
846 Reset(TRUE); | 833 Reset(TRUE); |
847 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); | 834 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); |
848 m_pRoot->InsertChildNode(pXML); | 835 m_pRoot->InsertChildNode(pXML); |
849 } | 836 } |
850 CFDE_XMLDoc::~CFDE_XMLDoc() { | 837 CFDE_XMLDoc::~CFDE_XMLDoc() { |
851 Reset(FALSE); | 838 Reset(FALSE); |
852 } | 839 } |
853 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { | 840 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { |
854 m_iStatus = 0; | 841 m_iStatus = 0; |
855 m_pStream = NULL; | 842 m_pStream = nullptr; |
856 if (bInitRoot) { | 843 if (bInitRoot) { |
857 if (m_pRoot == NULL) { | 844 if (m_pRoot) |
| 845 m_pRoot->DeleteChildren(); |
| 846 else |
858 m_pRoot = new CFDE_XMLNode; | 847 m_pRoot = new CFDE_XMLNode; |
859 } else { | |
860 m_pRoot->DeleteChildren(); | |
861 } | |
862 } else { | 848 } else { |
863 if (m_pRoot != NULL) { | 849 if (m_pRoot) { |
864 m_pRoot->Release(); | 850 m_pRoot->Release(); |
865 m_pRoot = NULL; | 851 m_pRoot = nullptr; |
866 } | 852 } |
867 } | 853 } |
868 ReleaseParser(); | 854 ReleaseParser(); |
869 } | 855 } |
870 void CFDE_XMLDoc::ReleaseParser() { | 856 void CFDE_XMLDoc::ReleaseParser() { |
871 if (m_pXMLParser != NULL) { | 857 if (m_pXMLParser) { |
872 m_pXMLParser->Release(); | 858 m_pXMLParser->Release(); |
873 m_pXMLParser = NULL; | 859 m_pXMLParser = nullptr; |
874 } | 860 } |
875 if (m_pSyntaxParser != NULL) { | 861 if (m_pSyntaxParser) { |
876 m_pSyntaxParser->Release(); | 862 m_pSyntaxParser->Release(); |
877 m_pSyntaxParser = NULL; | 863 m_pSyntaxParser = nullptr; |
878 } | 864 } |
879 } | 865 } |
880 FX_BOOL CFDE_XMLDoc::LoadXML(IFX_Stream* pXMLStream, | 866 FX_BOOL CFDE_XMLDoc::LoadXML(IFX_Stream* pXMLStream, |
881 int32_t iXMLPlaneSize, | 867 int32_t iXMLPlaneSize, |
882 int32_t iTextDataSize, | 868 int32_t iTextDataSize, |
883 FDE_XMLREADERHANDLER* pHandler) { | 869 FDE_XMLREADERHANDLER* pHandler) { |
884 if (pXMLStream == NULL) { | 870 if (!pXMLStream) |
885 return FALSE; | 871 return FALSE; |
886 } | 872 |
887 Reset(TRUE); | 873 Reset(TRUE); |
888 iXMLPlaneSize = iXMLPlaneSize / 1024; | 874 iXMLPlaneSize = iXMLPlaneSize / 1024; |
889 if (iXMLPlaneSize < 1) { | 875 if (iXMLPlaneSize < 1) { |
890 iXMLPlaneSize = 1; | 876 iXMLPlaneSize = 1; |
891 } | 877 } |
892 iXMLPlaneSize *= 1024; | 878 iXMLPlaneSize *= 1024; |
893 if (iXMLPlaneSize < 4096) { | 879 if (iXMLPlaneSize < 4096) { |
894 iXMLPlaneSize = 4096; | 880 iXMLPlaneSize = 4096; |
895 } | 881 } |
896 iTextDataSize = iTextDataSize / 128; | 882 iTextDataSize = iTextDataSize / 128; |
897 if (iTextDataSize < 1) { | 883 if (iTextDataSize < 1) { |
898 iTextDataSize = 1; | 884 iTextDataSize = 1; |
899 } | 885 } |
900 iTextDataSize *= 128; | 886 iTextDataSize *= 128; |
901 if (iTextDataSize < 128) { | 887 if (iTextDataSize < 128) { |
902 iTextDataSize = 128; | 888 iTextDataSize = 128; |
903 } | 889 } |
904 m_pStream = pXMLStream; | 890 m_pStream = pXMLStream; |
905 uint16_t wCodePage = m_pStream->GetCodePage(); | 891 uint16_t wCodePage = m_pStream->GetCodePage(); |
906 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && | 892 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && |
907 wCodePage != FX_CODEPAGE_UTF8) { | 893 wCodePage != FX_CODEPAGE_UTF8) { |
908 m_pStream->SetCodePage(FX_CODEPAGE_UTF8); | 894 m_pStream->SetCodePage(FX_CODEPAGE_UTF8); |
909 } | 895 } |
910 m_pSyntaxParser = new CFDE_XMLSyntaxParser; | 896 m_pSyntaxParser = new CFDE_XMLSyntaxParser; |
911 if (m_pSyntaxParser == NULL) { | 897 |
912 return FALSE; | |
913 } | |
914 m_pSyntaxParser->Init(m_pStream, iXMLPlaneSize, iTextDataSize); | 898 m_pSyntaxParser->Init(m_pStream, iXMLPlaneSize, iTextDataSize); |
915 if (pHandler == NULL) { | 899 if (pHandler) |
| 900 m_pXMLParser = new CFDE_XMLSAXParser(pHandler, m_pSyntaxParser); |
| 901 else |
916 m_pXMLParser = new CFDE_XMLDOMParser(m_pRoot, m_pSyntaxParser); | 902 m_pXMLParser = new CFDE_XMLDOMParser(m_pRoot, m_pSyntaxParser); |
917 } else { | |
918 m_pXMLParser = new CFDE_XMLSAXParser(pHandler, m_pSyntaxParser); | |
919 } | |
920 return TRUE; | 903 return TRUE; |
921 } | 904 } |
922 FX_BOOL CFDE_XMLDoc::LoadXML(CFDE_XMLParser* pXMLParser) { | 905 FX_BOOL CFDE_XMLDoc::LoadXML(CFDE_XMLParser* pXMLParser) { |
923 if (pXMLParser == NULL) { | 906 if (!pXMLParser) |
924 return FALSE; | 907 return FALSE; |
925 } | 908 |
926 Reset(TRUE); | 909 Reset(TRUE); |
927 m_pXMLParser = pXMLParser; | 910 m_pXMLParser = pXMLParser; |
928 return m_pXMLParser != NULL; | 911 return !!m_pXMLParser; |
929 } | 912 } |
930 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { | 913 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { |
931 if (m_iStatus >= 100) { | 914 if (m_iStatus >= 100) |
932 return m_iStatus; | 915 return m_iStatus; |
933 } | |
934 ASSERT(m_pXMLParser != NULL); | |
935 return m_iStatus = m_pXMLParser->DoParser(pPause); | 916 return m_iStatus = m_pXMLParser->DoParser(pPause); |
936 } | 917 } |
937 void CFDE_XMLDoc::CloseXML() { | 918 void CFDE_XMLDoc::CloseXML() { |
938 ReleaseParser(); | 919 ReleaseParser(); |
939 } | 920 } |
940 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { | 921 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { |
941 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; | 922 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; |
942 ASSERT(pXMLStream != NULL && pNode != NULL); | |
943 switch (pNode->GetType()) { | 923 switch (pNode->GetType()) { |
944 case FDE_XMLNODE_Instruction: { | 924 case FDE_XMLNODE_Instruction: { |
945 CFX_WideString ws; | 925 CFX_WideString ws; |
946 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; | 926 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; |
947 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { | 927 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { |
948 ws = L"<?xml version=\"1.0\" encoding=\""; | 928 ws = L"<?xml version=\"1.0\" encoding=\""; |
949 uint16_t wCodePage = pXMLStream->GetCodePage(); | 929 uint16_t wCodePage = pXMLStream->GetCodePage(); |
950 if (wCodePage == FX_CODEPAGE_UTF16LE) { | 930 if (wCodePage == FX_CODEPAGE_UTF16LE) { |
951 ws += L"UTF-16"; | 931 ws += L"UTF-16"; |
952 } else if (wCodePage == FX_CODEPAGE_UTF16BE) { | 932 } else if (wCodePage == FX_CODEPAGE_UTF16BE) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 wsValue = attributes[i + 1]; | 983 wsValue = attributes[i + 1]; |
1004 wsValue.Replace(L"&", L"&"); | 984 wsValue.Replace(L"&", L"&"); |
1005 wsValue.Replace(L"<", L"<"); | 985 wsValue.Replace(L"<", L"<"); |
1006 wsValue.Replace(L">", L">"); | 986 wsValue.Replace(L">", L">"); |
1007 wsValue.Replace(L"\'", L"'"); | 987 wsValue.Replace(L"\'", L"'"); |
1008 wsValue.Replace(L"\"", L"""); | 988 wsValue.Replace(L"\"", L"""); |
1009 ws += wsValue; | 989 ws += wsValue; |
1010 ws += L"\""; | 990 ws += L"\""; |
1011 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 991 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
1012 } | 992 } |
1013 if (pNode->m_pChild == NULL) { | 993 if (pNode->m_pChild) { |
1014 ws = L"\n/>"; | |
1015 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | |
1016 } else { | |
1017 ws = L"\n>"; | 994 ws = L"\n>"; |
1018 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 995 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
1019 CFDE_XMLNode* pChild = pNode->m_pChild; | 996 CFDE_XMLNode* pChild = pNode->m_pChild; |
1020 while (pChild != NULL) { | 997 while (pChild) { |
1021 SaveXMLNode(pXMLStream, static_cast<CFDE_XMLNode*>(pChild)); | 998 SaveXMLNode(pXMLStream, static_cast<CFDE_XMLNode*>(pChild)); |
1022 pChild = pChild->m_pNext; | 999 pChild = pChild->m_pNext; |
1023 } | 1000 } |
1024 ws = L"</"; | 1001 ws = L"</"; |
1025 ws += ((CFDE_XMLElement*)pNode)->m_wsTag; | 1002 ws += ((CFDE_XMLElement*)pNode)->m_wsTag; |
1026 ws += L"\n>"; | 1003 ws += L"\n>"; |
1027 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 1004 } else { |
| 1005 ws = L"\n/>"; |
1028 } | 1006 } |
| 1007 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
1029 } break; | 1008 } break; |
1030 case FDE_XMLNODE_Text: { | 1009 case FDE_XMLNODE_Text: { |
1031 CFX_WideString ws = ((CFDE_XMLText*)pNode)->m_wsText; | 1010 CFX_WideString ws = ((CFDE_XMLText*)pNode)->m_wsText; |
1032 ws.Replace(L"&", L"&"); | 1011 ws.Replace(L"&", L"&"); |
1033 ws.Replace(L"<", L"<"); | 1012 ws.Replace(L"<", L"<"); |
1034 ws.Replace(L">", L">"); | 1013 ws.Replace(L">", L">"); |
1035 ws.Replace(L"\'", L"'"); | 1014 ws.Replace(L"\'", L"'"); |
1036 ws.Replace(L"\"", L"""); | 1015 ws.Replace(L"\"", L"""); |
1037 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 1016 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
1038 } break; | 1017 } break; |
1039 case FDE_XMLNODE_CharData: { | 1018 case FDE_XMLNODE_CharData: { |
1040 CFX_WideString ws = L"<![CDATA["; | 1019 CFX_WideString ws = L"<![CDATA["; |
1041 ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; | 1020 ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; |
1042 ws += L"]]>"; | 1021 ws += L"]]>"; |
1043 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 1022 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
1044 } break; | 1023 } break; |
1045 case FDE_XMLNODE_Unknown: | 1024 case FDE_XMLNODE_Unknown: |
1046 break; | 1025 break; |
1047 default: | 1026 default: |
1048 break; | 1027 break; |
1049 } | 1028 } |
1050 } | 1029 } |
1051 void CFDE_XMLDoc::SaveXML(IFX_Stream* pXMLStream, FX_BOOL bSaveBOM) { | 1030 void CFDE_XMLDoc::SaveXML(IFX_Stream* pXMLStream, FX_BOOL bSaveBOM) { |
1052 if (pXMLStream == NULL || pXMLStream == m_pStream) { | 1031 if (!pXMLStream || pXMLStream == m_pStream) { |
1053 m_pStream->Seek(FX_STREAMSEEK_Begin, 0); | 1032 m_pStream->Seek(FX_STREAMSEEK_Begin, 0); |
1054 pXMLStream = m_pStream; | 1033 pXMLStream = m_pStream; |
1055 } | 1034 } |
1056 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Text) != 0); | 1035 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Text) != 0); |
1057 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 1036 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
1058 uint16_t wCodePage = pXMLStream->GetCodePage(); | 1037 uint16_t wCodePage = pXMLStream->GetCodePage(); |
1059 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && | 1038 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && |
1060 wCodePage != FX_CODEPAGE_UTF8) { | 1039 wCodePage != FX_CODEPAGE_UTF8) { |
1061 wCodePage = FX_CODEPAGE_UTF8; | 1040 wCodePage = FX_CODEPAGE_UTF8; |
1062 pXMLStream->SetCodePage(wCodePage); | 1041 pXMLStream->SetCodePage(wCodePage); |
1063 } | 1042 } |
1064 if (bSaveBOM) { | 1043 if (bSaveBOM) { |
1065 pXMLStream->WriteString(L"\xFEFF", 1); | 1044 pXMLStream->WriteString(L"\xFEFF", 1); |
1066 } | 1045 } |
1067 CFDE_XMLNode* pNode = m_pRoot->m_pChild; | 1046 CFDE_XMLNode* pNode = m_pRoot->m_pChild; |
1068 while (pNode != NULL) { | 1047 while (pNode) { |
1069 SaveXMLNode(pXMLStream, static_cast<CFDE_XMLNode*>(pNode)); | 1048 SaveXMLNode(pXMLStream, static_cast<CFDE_XMLNode*>(pNode)); |
1070 pNode = pNode->m_pNext; | 1049 pNode = pNode->m_pNext; |
1071 } | 1050 } |
1072 if (pXMLStream == m_pStream) { | 1051 if (pXMLStream == m_pStream) { |
1073 int32_t iPos = pXMLStream->GetPosition(); | 1052 int32_t iPos = pXMLStream->GetPosition(); |
1074 pXMLStream->SetLength(iPos); | 1053 pXMLStream->SetLength(iPos); |
1075 } | 1054 } |
1076 } | 1055 } |
1077 CFDE_XMLDOMParser::CFDE_XMLDOMParser(CFDE_XMLNode* pRoot, | 1056 CFDE_XMLDOMParser::CFDE_XMLDOMParser(CFDE_XMLNode* pRoot, |
1078 CFDE_XMLSyntaxParser* pParser) | 1057 CFDE_XMLSyntaxParser* pParser) |
1079 : m_pParser(pParser), | 1058 : m_pParser(pParser), |
1080 m_pParent(pRoot), | 1059 m_pParent(pRoot), |
1081 m_pChild(NULL), | 1060 m_pChild(nullptr), |
1082 m_NodeStack(16), | 1061 m_NodeStack(16), |
1083 m_ws1(), | 1062 m_ws1(), |
1084 m_ws2() { | 1063 m_ws2() { |
1085 m_NodeStack.Push(m_pParent); | 1064 m_NodeStack.Push(m_pParent); |
1086 } | 1065 } |
1087 CFDE_XMLDOMParser::~CFDE_XMLDOMParser() { | 1066 CFDE_XMLDOMParser::~CFDE_XMLDOMParser() { |
1088 m_NodeStack.RemoveAll(); | 1067 m_NodeStack.RemoveAll(); |
1089 m_ws1.clear(); | 1068 m_ws1.clear(); |
1090 m_ws2.clear(); | 1069 m_ws2.clear(); |
1091 } | 1070 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 m_pParser->GetTagName(m_ws1); | 1117 m_pParser->GetTagName(m_ws1); |
1139 m_pChild = new CFDE_XMLElement(m_ws1); | 1118 m_pChild = new CFDE_XMLElement(m_ws1); |
1140 m_pParent->InsertChildNode(m_pChild); | 1119 m_pParent->InsertChildNode(m_pChild); |
1141 m_NodeStack.Push(m_pChild); | 1120 m_NodeStack.Push(m_pChild); |
1142 m_pParent = m_pChild; | 1121 m_pParent = m_pChild; |
1143 break; | 1122 break; |
1144 case FDE_XmlSyntaxResult::AttriName: | 1123 case FDE_XmlSyntaxResult::AttriName: |
1145 m_pParser->GetAttributeName(m_ws1); | 1124 m_pParser->GetAttributeName(m_ws1); |
1146 break; | 1125 break; |
1147 case FDE_XmlSyntaxResult::AttriValue: | 1126 case FDE_XmlSyntaxResult::AttriValue: |
1148 if (m_pChild == NULL) { | 1127 if (!m_pChild) { |
1149 syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1128 syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1150 break; | 1129 break; |
1151 } | 1130 } |
1152 m_pParser->GetAttributeName(m_ws2); | 1131 m_pParser->GetAttributeName(m_ws2); |
1153 if (m_pChild->GetType() == FDE_XMLNODE_Element) { | 1132 if (m_pChild->GetType() == FDE_XMLNODE_Element) { |
1154 ((CFDE_XMLElement*)m_pChild)->SetString(m_ws1, m_ws2); | 1133 ((CFDE_XMLElement*)m_pChild)->SetString(m_ws1, m_ws2); |
1155 } else if (m_pChild->GetType() == FDE_XMLNODE_Instruction) { | 1134 } else if (m_pChild->GetType() == FDE_XMLNODE_Instruction) { |
1156 ((CFDE_XMLInstruction*)m_pChild)->SetString(m_ws1, m_ws2); | 1135 ((CFDE_XMLInstruction*)m_pChild)->SetString(m_ws1, m_ws2); |
1157 } | 1136 } |
1158 m_ws1.clear(); | 1137 m_ws1.clear(); |
1159 break; | 1138 break; |
1160 case FDE_XmlSyntaxResult::Text: | 1139 case FDE_XmlSyntaxResult::Text: |
1161 m_pParser->GetTextData(m_ws1); | 1140 m_pParser->GetTextData(m_ws1); |
1162 m_pChild = new CFDE_XMLText(m_ws1); | 1141 m_pChild = new CFDE_XMLText(m_ws1); |
1163 m_pParent->InsertChildNode(m_pChild); | 1142 m_pParent->InsertChildNode(m_pChild); |
1164 m_pChild = m_pParent; | 1143 m_pChild = m_pParent; |
1165 break; | 1144 break; |
1166 case FDE_XmlSyntaxResult::CData: | 1145 case FDE_XmlSyntaxResult::CData: |
1167 m_pParser->GetTextData(m_ws1); | 1146 m_pParser->GetTextData(m_ws1); |
1168 m_pChild = new CFDE_XMLCharData(m_ws1); | 1147 m_pChild = new CFDE_XMLCharData(m_ws1); |
1169 m_pParent->InsertChildNode(m_pChild); | 1148 m_pParent->InsertChildNode(m_pChild); |
1170 m_pChild = m_pParent; | 1149 m_pChild = m_pParent; |
1171 break; | 1150 break; |
1172 case FDE_XmlSyntaxResult::TargetData: | 1151 case FDE_XmlSyntaxResult::TargetData: |
1173 if (m_pChild == NULL || | 1152 if (!m_pChild || m_pChild->GetType() != FDE_XMLNODE_Instruction) { |
1174 m_pChild->GetType() != FDE_XMLNODE_Instruction) { | |
1175 syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1153 syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1176 break; | 1154 break; |
1177 } | 1155 } |
1178 if (!m_ws1.IsEmpty()) { | 1156 if (!m_ws1.IsEmpty()) { |
1179 ((CFDE_XMLInstruction*)m_pChild)->AppendData(m_ws1); | 1157 ((CFDE_XMLInstruction*)m_pChild)->AppendData(m_ws1); |
1180 } | 1158 } |
1181 m_pParser->GetTargetData(m_ws1); | 1159 m_pParser->GetTargetData(m_ws1); |
1182 ((CFDE_XMLInstruction*)m_pChild)->AppendData(m_ws1); | 1160 ((CFDE_XMLInstruction*)m_pChild)->AppendData(m_ws1); |
1183 m_ws1.clear(); | 1161 m_ws1.clear(); |
1184 break; | 1162 break; |
1185 default: | 1163 default: |
1186 break; | 1164 break; |
1187 } | 1165 } |
1188 if (syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1166 if (syntaxParserResult == FDE_XmlSyntaxResult::Error || |
1189 syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { | 1167 syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { |
1190 break; | 1168 break; |
1191 } | 1169 } |
1192 if (pPause != NULL && iCount > 500 && pPause->NeedToPauseNow()) { | 1170 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { |
1193 break; | 1171 break; |
1194 } | 1172 } |
1195 } | 1173 } |
1196 return m_pParser->GetStatus(); | 1174 return m_pParser->GetStatus(); |
1197 } | 1175 } |
1198 CFDE_XMLSAXParser::CFDE_XMLSAXParser(FDE_XMLREADERHANDLER* pHandler, | 1176 CFDE_XMLSAXParser::CFDE_XMLSAXParser(FDE_XMLREADERHANDLER* pHandler, |
1199 CFDE_XMLSyntaxParser* pParser) | 1177 CFDE_XMLSyntaxParser* pParser) |
1200 : m_pHandler(pHandler), | 1178 : m_pHandler(pHandler), |
1201 m_pParser(pParser), | 1179 m_pParser(pParser), |
1202 m_TagStack(16), | 1180 m_TagStack(16), |
1203 m_pTagTop(NULL), | 1181 m_pTagTop(nullptr), |
1204 m_ws1(), | 1182 m_ws1(), |
1205 m_ws2() {} | 1183 m_ws2() {} |
1206 CFDE_XMLSAXParser::~CFDE_XMLSAXParser() { | 1184 CFDE_XMLSAXParser::~CFDE_XMLSAXParser() { |
1207 m_TagStack.RemoveAll(); | 1185 m_TagStack.RemoveAll(); |
1208 m_ws1.clear(); | 1186 m_ws1.clear(); |
1209 m_ws2.clear(); | 1187 m_ws2.clear(); |
1210 } | 1188 } |
1211 int32_t CFDE_XMLSAXParser::DoParser(IFX_Pause* pPause) { | 1189 int32_t CFDE_XMLSAXParser::DoParser(IFX_Pause* pPause) { |
1212 FDE_XmlSyntaxResult syntaxParserResult; | 1190 FDE_XmlSyntaxResult syntaxParserResult; |
1213 int32_t iCount = 0; | 1191 int32_t iCount = 0; |
1214 while (TRUE) { | 1192 while (TRUE) { |
1215 syntaxParserResult = m_pParser->DoSyntaxParse(); | 1193 syntaxParserResult = m_pParser->DoSyntaxParse(); |
1216 switch (syntaxParserResult) { | 1194 switch (syntaxParserResult) { |
1217 case FDE_XmlSyntaxResult::ElementBreak: | 1195 case FDE_XmlSyntaxResult::ElementBreak: |
1218 if (m_pTagTop == NULL) { | 1196 if (!m_pTagTop) { |
1219 syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1197 syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1220 break; | 1198 break; |
1221 } | 1199 } |
1222 if (m_pTagTop->eType == FDE_XMLNODE_Element) { | 1200 if (m_pTagTop->eType == FDE_XMLNODE_Element) { |
1223 m_pHandler->OnTagBreak(m_pHandler, m_pTagTop->wsTagName); | 1201 m_pHandler->OnTagBreak(m_pHandler, m_pTagTop->wsTagName); |
1224 } | 1202 } |
1225 break; | 1203 break; |
1226 case FDE_XmlSyntaxResult::ElementClose: | 1204 case FDE_XmlSyntaxResult::ElementClose: |
1227 if (m_pTagTop == NULL || m_pTagTop->eType != FDE_XMLNODE_Element) { | 1205 if (!m_pTagTop || m_pTagTop->eType != FDE_XMLNODE_Element) { |
1228 syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1206 syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1229 break; | 1207 break; |
1230 } | 1208 } |
1231 m_pParser->GetTagName(m_ws1); | 1209 m_pParser->GetTagName(m_ws1); |
1232 if (m_ws1.GetLength() > 0 && m_ws1.Compare(m_pTagTop->wsTagName) != 0) { | 1210 if (m_ws1.GetLength() > 0 && m_ws1.Compare(m_pTagTop->wsTagName) != 0) { |
1233 syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1211 syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1234 break; | 1212 break; |
1235 } else if (m_ws1.GetLength() == 0) { | 1213 } else if (m_ws1.GetLength() == 0) { |
1236 m_pHandler->OnTagBreak(m_pHandler, m_pTagTop->wsTagName); | 1214 m_pHandler->OnTagBreak(m_pHandler, m_pTagTop->wsTagName); |
1237 } | 1215 } |
(...skipping 18 matching lines...) Expand all Loading... |
1256 xmlTag.eType = FDE_XMLNODE_Element; | 1234 xmlTag.eType = FDE_XMLNODE_Element; |
1257 Push(xmlTag); | 1235 Push(xmlTag); |
1258 m_pHandler->OnTagEnter(m_pHandler, FDE_XMLNODE_Element, | 1236 m_pHandler->OnTagEnter(m_pHandler, FDE_XMLNODE_Element, |
1259 m_pTagTop->wsTagName); | 1237 m_pTagTop->wsTagName); |
1260 } break; | 1238 } break; |
1261 case FDE_XmlSyntaxResult::AttriName: | 1239 case FDE_XmlSyntaxResult::AttriName: |
1262 m_pParser->GetTargetName(m_ws1); | 1240 m_pParser->GetTargetName(m_ws1); |
1263 break; | 1241 break; |
1264 case FDE_XmlSyntaxResult::AttriValue: | 1242 case FDE_XmlSyntaxResult::AttriValue: |
1265 m_pParser->GetAttributeName(m_ws2); | 1243 m_pParser->GetAttributeName(m_ws2); |
1266 if (m_pTagTop == NULL) { | 1244 if (!m_pTagTop) { |
1267 syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1245 syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1268 break; | 1246 break; |
1269 } | 1247 } |
1270 if (m_pTagTop->eType == FDE_XMLNODE_Element) { | 1248 if (m_pTagTop->eType == FDE_XMLNODE_Element) { |
1271 m_pHandler->OnAttribute(m_pHandler, m_ws1, m_ws2); | 1249 m_pHandler->OnAttribute(m_pHandler, m_ws1, m_ws2); |
1272 } | 1250 } |
1273 m_ws1.clear(); | 1251 m_ws1.clear(); |
1274 break; | 1252 break; |
1275 case FDE_XmlSyntaxResult::CData: | 1253 case FDE_XmlSyntaxResult::CData: |
1276 m_pParser->GetTextData(m_ws1); | 1254 m_pParser->GetTextData(m_ws1); |
1277 m_pHandler->OnData(m_pHandler, FDE_XMLNODE_CharData, m_ws1); | 1255 m_pHandler->OnData(m_pHandler, FDE_XMLNODE_CharData, m_ws1); |
1278 break; | 1256 break; |
1279 case FDE_XmlSyntaxResult::Text: | 1257 case FDE_XmlSyntaxResult::Text: |
1280 m_pParser->GetTextData(m_ws1); | 1258 m_pParser->GetTextData(m_ws1); |
1281 m_pHandler->OnData(m_pHandler, FDE_XMLNODE_Text, m_ws1); | 1259 m_pHandler->OnData(m_pHandler, FDE_XMLNODE_Text, m_ws1); |
1282 break; | 1260 break; |
1283 case FDE_XmlSyntaxResult::TargetData: | 1261 case FDE_XmlSyntaxResult::TargetData: |
1284 m_pParser->GetTargetData(m_ws1); | 1262 m_pParser->GetTargetData(m_ws1); |
1285 m_pHandler->OnData(m_pHandler, FDE_XMLNODE_Instruction, m_ws1); | 1263 m_pHandler->OnData(m_pHandler, FDE_XMLNODE_Instruction, m_ws1); |
1286 m_ws1.clear(); | 1264 m_ws1.clear(); |
1287 break; | 1265 break; |
1288 default: | 1266 default: |
1289 break; | 1267 break; |
1290 } | 1268 } |
1291 if (syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1269 if (syntaxParserResult == FDE_XmlSyntaxResult::Error || |
1292 syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { | 1270 syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { |
1293 break; | 1271 break; |
1294 } | 1272 } |
1295 if (pPause != NULL && iCount > 500 && pPause->NeedToPauseNow()) { | 1273 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { |
1296 break; | 1274 break; |
1297 } | 1275 } |
1298 } | 1276 } |
1299 return m_pParser->GetStatus(); | 1277 return m_pParser->GetStatus(); |
1300 } | 1278 } |
1301 inline void CFDE_XMLSAXParser::Push(const CFDE_XMLTAG& xmlTag) { | 1279 inline void CFDE_XMLSAXParser::Push(const CFDE_XMLTAG& xmlTag) { |
1302 m_TagStack.Push(xmlTag); | 1280 m_TagStack.Push(xmlTag); |
1303 m_pTagTop = m_TagStack.GetTopElement(); | 1281 m_pTagTop = m_TagStack.GetTopElement(); |
1304 } | 1282 } |
1305 inline void CFDE_XMLSAXParser::Pop() { | 1283 inline void CFDE_XMLSAXParser::Pop() { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 m_syntaxParserState(FDE_XmlSyntaxState::Text), | 1437 m_syntaxParserState(FDE_XmlSyntaxState::Text), |
1460 m_wQuotationMark(0), | 1438 m_wQuotationMark(0), |
1461 m_iEntityStart(-1), | 1439 m_iEntityStart(-1), |
1462 m_SkipStack(16) { | 1440 m_SkipStack(16) { |
1463 m_CurNode.iNodeNum = -1; | 1441 m_CurNode.iNodeNum = -1; |
1464 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; | 1442 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; |
1465 } | 1443 } |
1466 void CFDE_XMLSyntaxParser::Init(IFX_Stream* pStream, | 1444 void CFDE_XMLSyntaxParser::Init(IFX_Stream* pStream, |
1467 int32_t iXMLPlaneSize, | 1445 int32_t iXMLPlaneSize, |
1468 int32_t iTextDataSize) { | 1446 int32_t iTextDataSize) { |
1469 ASSERT(m_pStream == NULL && m_pBuffer == NULL); | 1447 ASSERT(!m_pStream && !m_pBuffer); |
1470 ASSERT(pStream != NULL && iXMLPlaneSize > 0); | 1448 ASSERT(pStream && iXMLPlaneSize > 0); |
1471 int32_t iStreamLength = pStream->GetLength(); | 1449 int32_t iStreamLength = pStream->GetLength(); |
1472 ASSERT(iStreamLength > 0); | 1450 ASSERT(iStreamLength > 0); |
1473 m_pStream = pStream; | 1451 m_pStream = pStream; |
1474 m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength); | 1452 m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength); |
1475 uint8_t bom[4]; | 1453 uint8_t bom[4]; |
1476 m_iCurrentPos = m_pStream->GetBOM(bom); | 1454 m_iCurrentPos = m_pStream->GetBOM(bom); |
1477 ASSERT(m_pBuffer == NULL); | 1455 ASSERT(!m_pBuffer); |
1478 | 1456 |
1479 FX_SAFE_INT32 alloc_size_safe = m_iXMLPlaneSize; | 1457 FX_SAFE_INT32 alloc_size_safe = m_iXMLPlaneSize; |
1480 alloc_size_safe += 1; // For NUL. | 1458 alloc_size_safe += 1; // For NUL. |
1481 if (!alloc_size_safe.IsValid() || alloc_size_safe.ValueOrDie() <= 0) { | 1459 if (!alloc_size_safe.IsValid() || alloc_size_safe.ValueOrDie() <= 0) { |
1482 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1460 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1483 return; | 1461 return; |
1484 } | 1462 } |
1485 | 1463 |
1486 m_pBuffer = FX_Alloc(FX_WCHAR, alloc_size_safe.ValueOrDie()); | 1464 m_pBuffer = FX_Alloc(FX_WCHAR, alloc_size_safe.ValueOrDie()); |
1487 m_pStart = m_pEnd = m_pBuffer; | 1465 m_pStart = m_pEnd = m_pBuffer; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 m_iDataLength++; | 1692 m_iDataLength++; |
1715 m_syntaxParserState = FDE_XmlSyntaxState::TargetData; | 1693 m_syntaxParserState = FDE_XmlSyntaxState::TargetData; |
1716 } else if (m_iDataLength > 0) { | 1694 } else if (m_iDataLength > 0) { |
1717 m_iTextDataLength = m_iDataLength; | 1695 m_iTextDataLength = m_iDataLength; |
1718 m_BlockBuffer.Reset(); | 1696 m_BlockBuffer.Reset(); |
1719 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 1697 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
1720 syntaxParserResult = FDE_XmlSyntaxResult::TargetData; | 1698 syntaxParserResult = FDE_XmlSyntaxResult::TargetData; |
1721 } else { | 1699 } else { |
1722 m_pStart++; | 1700 m_pStart++; |
1723 FDE_XMLNODE* pXMLNode = m_XMLNodeStack.GetTopElement(); | 1701 FDE_XMLNODE* pXMLNode = m_XMLNodeStack.GetTopElement(); |
1724 if (pXMLNode == NULL) { | 1702 if (!pXMLNode) { |
1725 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1703 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1726 return m_syntaxParserResult; | 1704 return m_syntaxParserResult; |
1727 } | 1705 } |
1728 m_XMLNodeStack.Pop(); | 1706 m_XMLNodeStack.Pop(); |
1729 pXMLNode = m_XMLNodeStack.GetTopElement(); | 1707 pXMLNode = m_XMLNodeStack.GetTopElement(); |
1730 if (pXMLNode == NULL) { | 1708 if (pXMLNode) { |
| 1709 m_CurNode = *pXMLNode; |
| 1710 } else { |
1731 m_CurNode.iNodeNum = -1; | 1711 m_CurNode.iNodeNum = -1; |
1732 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; | 1712 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; |
1733 } else { | |
1734 m_CurNode = *pXMLNode; | |
1735 } | 1713 } |
1736 m_iCurrentNodeNum = m_CurNode.iNodeNum; | 1714 m_iCurrentNodeNum = m_CurNode.iNodeNum; |
1737 m_BlockBuffer.Reset(); | 1715 m_BlockBuffer.Reset(); |
1738 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 1716 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
1739 m_syntaxParserState = FDE_XmlSyntaxState::Text; | 1717 m_syntaxParserState = FDE_XmlSyntaxState::Text; |
1740 syntaxParserResult = FDE_XmlSyntaxResult::InstructionClose; | 1718 syntaxParserResult = FDE_XmlSyntaxResult::InstructionClose; |
1741 } | 1719 } |
1742 break; | 1720 break; |
1743 case FDE_XmlSyntaxState::BreakElement: | 1721 case FDE_XmlSyntaxState::BreakElement: |
1744 if (ch == L'>') { | 1722 if (ch == L'>') { |
1745 m_syntaxParserState = FDE_XmlSyntaxState::Text; | 1723 m_syntaxParserState = FDE_XmlSyntaxState::Text; |
1746 syntaxParserResult = FDE_XmlSyntaxResult::ElementBreak; | 1724 syntaxParserResult = FDE_XmlSyntaxResult::ElementBreak; |
1747 } else if (ch == L'/') { | 1725 } else if (ch == L'/') { |
1748 m_syntaxParserState = FDE_XmlSyntaxState::CloseElement; | 1726 m_syntaxParserState = FDE_XmlSyntaxState::CloseElement; |
1749 } else { | 1727 } else { |
1750 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1728 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1751 return m_syntaxParserResult; | 1729 return m_syntaxParserResult; |
1752 } | 1730 } |
1753 m_pStart++; | 1731 m_pStart++; |
1754 break; | 1732 break; |
1755 case FDE_XmlSyntaxState::CloseElement: | 1733 case FDE_XmlSyntaxState::CloseElement: |
1756 if (!FDE_IsXMLNameChar(ch, m_iDataLength < 1)) { | 1734 if (!FDE_IsXMLNameChar(ch, m_iDataLength < 1)) { |
1757 if (ch == L'>') { | 1735 if (ch == L'>') { |
1758 FDE_XMLNODE* pXMLNode = m_XMLNodeStack.GetTopElement(); | 1736 FDE_XMLNODE* pXMLNode = m_XMLNodeStack.GetTopElement(); |
1759 if (pXMLNode == NULL) { | 1737 if (!pXMLNode) { |
1760 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1738 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; |
1761 return m_syntaxParserResult; | 1739 return m_syntaxParserResult; |
1762 } | 1740 } |
1763 m_XMLNodeStack.Pop(); | 1741 m_XMLNodeStack.Pop(); |
1764 pXMLNode = m_XMLNodeStack.GetTopElement(); | 1742 pXMLNode = m_XMLNodeStack.GetTopElement(); |
1765 if (pXMLNode == NULL) { | 1743 if (pXMLNode) { |
| 1744 m_CurNode = *pXMLNode; |
| 1745 } else { |
1766 m_CurNode.iNodeNum = -1; | 1746 m_CurNode.iNodeNum = -1; |
1767 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; | 1747 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; |
1768 } else { | |
1769 m_CurNode = *pXMLNode; | |
1770 } | 1748 } |
1771 m_iCurrentNodeNum = m_CurNode.iNodeNum; | 1749 m_iCurrentNodeNum = m_CurNode.iNodeNum; |
1772 m_iTextDataLength = m_iDataLength; | 1750 m_iTextDataLength = m_iDataLength; |
1773 m_BlockBuffer.Reset(); | 1751 m_BlockBuffer.Reset(); |
1774 m_pCurrentBlock = | 1752 m_pCurrentBlock = |
1775 m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 1753 m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
1776 m_syntaxParserState = FDE_XmlSyntaxState::Text; | 1754 m_syntaxParserState = FDE_XmlSyntaxState::Text; |
1777 syntaxParserResult = FDE_XmlSyntaxResult::ElementClose; | 1755 syntaxParserResult = FDE_XmlSyntaxResult::ElementClose; |
1778 } else if (!FDE_IsXMLWhiteSpace(ch)) { | 1756 } else if (!FDE_IsXMLWhiteSpace(ch)) { |
1779 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; | 1757 m_syntaxParserResult = FDE_XmlSyntaxResult::Error; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1955 } | 1933 } |
1956 if (syntaxParserResult != FDE_XmlSyntaxResult::None) | 1934 if (syntaxParserResult != FDE_XmlSyntaxResult::None) |
1957 return syntaxParserResult; | 1935 return syntaxParserResult; |
1958 } | 1936 } |
1959 } | 1937 } |
1960 return FDE_XmlSyntaxResult::Text; | 1938 return FDE_XmlSyntaxResult::Text; |
1961 } | 1939 } |
1962 | 1940 |
1963 CFDE_XMLSyntaxParser::~CFDE_XMLSyntaxParser() { | 1941 CFDE_XMLSyntaxParser::~CFDE_XMLSyntaxParser() { |
1964 if (m_pCurrentBlock) { | 1942 if (m_pCurrentBlock) { |
1965 m_pCurrentBlock = NULL; | 1943 m_pCurrentBlock = nullptr; |
1966 } | 1944 } |
1967 FX_Free(m_pBuffer); | 1945 FX_Free(m_pBuffer); |
1968 } | 1946 } |
1969 | 1947 |
1970 int32_t CFDE_XMLSyntaxParser::GetStatus() const { | 1948 int32_t CFDE_XMLSyntaxParser::GetStatus() const { |
1971 if (m_pStream == NULL) { | 1949 if (!m_pStream) |
1972 return -1; | 1950 return -1; |
1973 } | 1951 |
1974 int32_t iStreamLength = m_pStream->GetLength(); | 1952 int32_t iStreamLength = m_pStream->GetLength(); |
1975 if (iStreamLength < 1) { | 1953 if (iStreamLength < 1) { |
1976 return 100; | 1954 return 100; |
1977 } | 1955 } |
1978 if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) { | 1956 if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) { |
1979 return -1; | 1957 return -1; |
1980 } | 1958 } |
1981 if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { | 1959 if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { |
1982 return 100; | 1960 return 100; |
1983 } | 1961 } |
(...skipping 16 matching lines...) Expand all Loading... |
2000 } else if ((uint32_t)unicode < 0x4000000) { | 1978 } else if ((uint32_t)unicode < 0x4000000) { |
2001 nbytes = 5; | 1979 nbytes = 5; |
2002 } else { | 1980 } else { |
2003 nbytes = 6; | 1981 nbytes = 6; |
2004 } | 1982 } |
2005 iDstNum += nbytes; | 1983 iDstNum += nbytes; |
2006 } | 1984 } |
2007 return iDstNum; | 1985 return iDstNum; |
2008 } | 1986 } |
2009 FX_FILESIZE CFDE_XMLSyntaxParser::GetCurrentBinaryPos() const { | 1987 FX_FILESIZE CFDE_XMLSyntaxParser::GetCurrentBinaryPos() const { |
2010 if (m_pStream == NULL) { | 1988 if (!m_pStream) |
2011 return 0; | 1989 return 0; |
2012 } | 1990 |
2013 int32_t nSrcLen = m_pStart - m_pBuffer; | 1991 int32_t nSrcLen = m_pStart - m_pBuffer; |
2014 int32_t nDstLen = FX_GetUTF8EncodeLength(m_pBuffer, nSrcLen); | 1992 int32_t nDstLen = FX_GetUTF8EncodeLength(m_pBuffer, nSrcLen); |
2015 return m_iParsedBytes + nDstLen; | 1993 return m_iParsedBytes + nDstLen; |
2016 } | 1994 } |
2017 | 1995 |
2018 void CFDE_XMLSyntaxParser::ParseTextChar(FX_WCHAR ch) { | 1996 void CFDE_XMLSyntaxParser::ParseTextChar(FX_WCHAR ch) { |
2019 if (m_iIndexInBlock == m_iAllocStep) { | 1997 if (m_iIndexInBlock == m_iAllocStep) { |
2020 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 1998 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
2021 if (!m_pCurrentBlock) { | 1999 if (!m_pCurrentBlock) { |
2022 return; | 2000 return; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2081 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); | 2059 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); |
2082 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 2060 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
2083 m_iEntityStart = -1; | 2061 m_iEntityStart = -1; |
2084 } else { | 2062 } else { |
2085 if (m_iEntityStart < 0 && ch == L'&') { | 2063 if (m_iEntityStart < 0 && ch == L'&') { |
2086 m_iEntityStart = m_iDataLength - 1; | 2064 m_iEntityStart = m_iDataLength - 1; |
2087 } | 2065 } |
2088 } | 2066 } |
2089 m_pStart++; | 2067 m_pStart++; |
2090 } | 2068 } |
OLD | NEW |