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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 return FALSE; | 74 return FALSE; |
75 } | 75 } |
76 | 76 |
77 CFDE_XMLNode::CFDE_XMLNode() | 77 CFDE_XMLNode::CFDE_XMLNode() |
78 : m_pParent(nullptr), | 78 : m_pParent(nullptr), |
79 m_pChild(nullptr), | 79 m_pChild(nullptr), |
80 m_pPrior(nullptr), | 80 m_pPrior(nullptr), |
81 m_pNext(nullptr) {} | 81 m_pNext(nullptr) {} |
82 | 82 |
| 83 void CFDE_XMLNode::Release() { |
| 84 delete this; |
| 85 } |
| 86 |
| 87 FDE_XMLNODETYPE CFDE_XMLNode::GetType() const { |
| 88 return FDE_XMLNODE_Unknown; |
| 89 } |
| 90 |
83 CFDE_XMLNode::~CFDE_XMLNode() { | 91 CFDE_XMLNode::~CFDE_XMLNode() { |
84 DeleteChildren(); | 92 DeleteChildren(); |
85 } | 93 } |
86 | 94 |
87 void CFDE_XMLNode::DeleteChildren() { | 95 void CFDE_XMLNode::DeleteChildren() { |
88 CFDE_XMLNode* pChild = m_pChild; | 96 CFDE_XMLNode* pChild = m_pChild; |
89 while (pChild) { | 97 while (pChild) { |
90 CFDE_XMLNode* pTemp = pChild->m_pNext; | 98 CFDE_XMLNode* pTemp = pChild->m_pNext; |
91 pChild->Release(); | 99 pChild->Release(); |
92 pChild = pTemp; | 100 pChild = pTemp; |
93 } | 101 } |
94 m_pChild = nullptr; | 102 m_pChild = nullptr; |
95 } | 103 } |
| 104 |
96 int32_t CFDE_XMLNode::CountChildNodes() const { | 105 int32_t CFDE_XMLNode::CountChildNodes() const { |
97 int32_t iCount = 0; | 106 int32_t iCount = 0; |
98 CFDE_XMLNode* pChild = m_pChild; | 107 CFDE_XMLNode* pChild = m_pChild; |
99 while (pChild) { | 108 while (pChild) { |
100 iCount++; | 109 iCount++; |
101 pChild = pChild->m_pNext; | 110 pChild = pChild->m_pNext; |
102 } | 111 } |
103 return iCount; | 112 return iCount; |
104 } | 113 } |
| 114 |
105 CFDE_XMLNode* CFDE_XMLNode::GetChildNode(int32_t index) const { | 115 CFDE_XMLNode* CFDE_XMLNode::GetChildNode(int32_t index) const { |
106 CFDE_XMLNode* pChild = m_pChild; | 116 CFDE_XMLNode* pChild = m_pChild; |
107 while (pChild) { | 117 while (pChild) { |
108 if (index == 0) { | 118 if (index == 0) { |
109 return pChild; | 119 return pChild; |
110 } | 120 } |
111 index--; | 121 index--; |
112 pChild = pChild->m_pNext; | 122 pChild = pChild->m_pNext; |
113 } | 123 } |
114 return nullptr; | 124 return nullptr; |
115 } | 125 } |
| 126 |
116 int32_t CFDE_XMLNode::GetChildNodeIndex(CFDE_XMLNode* pNode) const { | 127 int32_t CFDE_XMLNode::GetChildNodeIndex(CFDE_XMLNode* pNode) const { |
117 int32_t index = 0; | 128 int32_t index = 0; |
118 CFDE_XMLNode* pChild = m_pChild; | 129 CFDE_XMLNode* pChild = m_pChild; |
119 while (pChild) { | 130 while (pChild) { |
120 if (pChild == pNode) { | 131 if (pChild == pNode) { |
121 return index; | 132 return index; |
122 } | 133 } |
123 index++; | 134 index++; |
124 pChild = pChild->m_pNext; | 135 pChild = pChild->m_pNext; |
125 } | 136 } |
126 return -1; | 137 return -1; |
127 } | 138 } |
| 139 |
128 CFDE_XMLNode* CFDE_XMLNode::GetPath(const FX_WCHAR* pPath, | 140 CFDE_XMLNode* CFDE_XMLNode::GetPath(const FX_WCHAR* pPath, |
129 int32_t iLength, | 141 int32_t iLength, |
130 FX_BOOL bQualifiedName) const { | 142 FX_BOOL bQualifiedName) const { |
131 ASSERT(pPath); | 143 ASSERT(pPath); |
132 if (iLength < 0) { | 144 if (iLength < 0) { |
133 iLength = FXSYS_wcslen(pPath); | 145 iLength = FXSYS_wcslen(pPath); |
134 } | 146 } |
135 if (iLength == 0) { | 147 if (iLength == 0) { |
136 return nullptr; | 148 return nullptr; |
137 } | 149 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return pFind; | 187 return pFind; |
176 } | 188 } |
177 } | 189 } |
178 pNode = pNode->m_pNext; | 190 pNode = pNode->m_pNext; |
179 } | 191 } |
180 } | 192 } |
181 if (!pFind || iLength < 1) | 193 if (!pFind || iLength < 1) |
182 return pFind; | 194 return pFind; |
183 return pFind->GetPath(pStart, iLength, bQualifiedName); | 195 return pFind->GetPath(pStart, iLength, bQualifiedName); |
184 } | 196 } |
| 197 |
185 int32_t CFDE_XMLNode::InsertChildNode(CFDE_XMLNode* pNode, int32_t index) { | 198 int32_t CFDE_XMLNode::InsertChildNode(CFDE_XMLNode* pNode, int32_t index) { |
186 pNode->m_pParent = this; | 199 pNode->m_pParent = this; |
187 if (!m_pChild) { | 200 if (!m_pChild) { |
188 m_pChild = pNode; | 201 m_pChild = pNode; |
189 pNode->m_pPrior = nullptr; | 202 pNode->m_pPrior = nullptr; |
190 pNode->m_pNext = nullptr; | 203 pNode->m_pNext = nullptr; |
191 return 0; | 204 return 0; |
192 } | 205 } |
193 if (index == 0) { | 206 if (index == 0) { |
194 pNode->m_pNext = m_pChild; | 207 pNode->m_pNext = m_pChild; |
195 pNode->m_pPrior = nullptr; | 208 pNode->m_pPrior = nullptr; |
196 m_pChild->m_pPrior = pNode; | 209 m_pChild->m_pPrior = pNode; |
197 m_pChild = pNode; | 210 m_pChild = pNode; |
198 return 0; | 211 return 0; |
199 } | 212 } |
200 int32_t iCount = 0; | 213 int32_t iCount = 0; |
201 CFDE_XMLNode* pFind = m_pChild; | 214 CFDE_XMLNode* pFind = m_pChild; |
202 while (++iCount != index && pFind->m_pNext) { | 215 while (++iCount != index && pFind->m_pNext) { |
203 pFind = pFind->m_pNext; | 216 pFind = pFind->m_pNext; |
204 } | 217 } |
205 pNode->m_pPrior = pFind; | 218 pNode->m_pPrior = pFind; |
206 pNode->m_pNext = pFind->m_pNext; | 219 pNode->m_pNext = pFind->m_pNext; |
207 if (pFind->m_pNext) | 220 if (pFind->m_pNext) |
208 pFind->m_pNext->m_pPrior = pNode; | 221 pFind->m_pNext->m_pPrior = pNode; |
209 pFind->m_pNext = pNode; | 222 pFind->m_pNext = pNode; |
210 return iCount; | 223 return iCount; |
211 } | 224 } |
| 225 |
212 void CFDE_XMLNode::RemoveChildNode(CFDE_XMLNode* pNode) { | 226 void CFDE_XMLNode::RemoveChildNode(CFDE_XMLNode* pNode) { |
213 ASSERT(m_pChild && pNode); | 227 ASSERT(m_pChild && pNode); |
214 if (m_pChild == pNode) { | 228 if (m_pChild == pNode) { |
215 m_pChild = pNode->m_pNext; | 229 m_pChild = pNode->m_pNext; |
216 } else { | 230 } else { |
217 pNode->m_pPrior->m_pNext = pNode->m_pNext; | 231 pNode->m_pPrior->m_pNext = pNode->m_pNext; |
218 } | 232 } |
219 if (pNode->m_pNext) | 233 if (pNode->m_pNext) |
220 pNode->m_pNext->m_pPrior = pNode->m_pPrior; | 234 pNode->m_pNext->m_pPrior = pNode->m_pPrior; |
221 pNode->m_pParent = nullptr; | 235 pNode->m_pParent = nullptr; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } else if (m_pParent) { | 359 } else if (m_pParent) { |
346 m_pParent->m_pChild = pNode; | 360 m_pParent->m_pChild = pNode; |
347 } | 361 } |
348 m_pPrior = pNode; | 362 m_pPrior = pNode; |
349 return TRUE; | 363 return TRUE; |
350 } | 364 } |
351 default: | 365 default: |
352 return FALSE; | 366 return FALSE; |
353 } | 367 } |
354 } | 368 } |
| 369 |
355 CFDE_XMLNode* CFDE_XMLNode::RemoveNodeItem(CFDE_XMLNode::NodeItem eItem) { | 370 CFDE_XMLNode* CFDE_XMLNode::RemoveNodeItem(CFDE_XMLNode::NodeItem eItem) { |
356 CFDE_XMLNode* pNode = nullptr; | 371 CFDE_XMLNode* pNode = nullptr; |
357 switch (eItem) { | 372 switch (eItem) { |
358 case CFDE_XMLNode::NextSibling: | 373 case CFDE_XMLNode::NextSibling: |
359 if (m_pNext) { | 374 if (m_pNext) { |
360 pNode = m_pNext; | 375 pNode = m_pNext; |
361 m_pNext = pNode->m_pNext; | 376 m_pNext = pNode->m_pNext; |
362 if (m_pNext) { | 377 if (m_pNext) { |
363 m_pNext->m_pPrior = this; | 378 m_pNext->m_pPrior = this; |
364 } | 379 } |
365 pNode->m_pParent = nullptr; | 380 pNode->m_pParent = nullptr; |
366 pNode->m_pNext = nullptr; | 381 pNode->m_pNext = nullptr; |
367 pNode->m_pPrior = nullptr; | 382 pNode->m_pPrior = nullptr; |
368 } | 383 } |
369 break; | 384 break; |
370 default: | 385 default: |
371 break; | 386 break; |
372 } | 387 } |
373 return pNode; | 388 return pNode; |
374 } | 389 } |
| 390 |
375 CFDE_XMLNode* CFDE_XMLNode::Clone(FX_BOOL bRecursive) { | 391 CFDE_XMLNode* CFDE_XMLNode::Clone(FX_BOOL bRecursive) { |
376 return nullptr; | 392 return nullptr; |
377 } | 393 } |
| 394 |
378 void CFDE_XMLNode::SaveXMLNode(IFX_Stream* pXMLStream) { | 395 void CFDE_XMLNode::SaveXMLNode(IFX_Stream* pXMLStream) { |
379 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; | 396 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; |
380 switch (pNode->GetType()) { | 397 switch (pNode->GetType()) { |
381 case FDE_XMLNODE_Instruction: { | 398 case FDE_XMLNODE_Instruction: { |
382 CFX_WideString ws; | 399 CFX_WideString ws; |
383 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; | 400 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; |
384 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { | 401 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { |
385 ws = L"<?xml version=\"1.0\" encoding=\""; | 402 ws = L"<?xml version=\"1.0\" encoding=\""; |
386 uint16_t wCodePage = pXMLStream->GetCodePage(); | 403 uint16_t wCodePage = pXMLStream->GetCodePage(); |
387 if (wCodePage == FX_CODEPAGE_UTF16LE) { | 404 if (wCodePage == FX_CODEPAGE_UTF16LE) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; | 494 ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; |
478 ws += L"]]>"; | 495 ws += L"]]>"; |
479 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 496 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
480 } break; | 497 } break; |
481 case FDE_XMLNODE_Unknown: | 498 case FDE_XMLNODE_Unknown: |
482 break; | 499 break; |
483 default: | 500 default: |
484 break; | 501 break; |
485 } | 502 } |
486 } | 503 } |
| 504 |
487 void CFDE_XMLNode::CloneChildren(CFDE_XMLNode* pClone) { | 505 void CFDE_XMLNode::CloneChildren(CFDE_XMLNode* pClone) { |
488 if (!m_pChild) { | 506 if (!m_pChild) { |
489 return; | 507 return; |
490 } | 508 } |
491 CFDE_XMLNode* pNext = m_pChild; | 509 CFDE_XMLNode* pNext = m_pChild; |
492 CFDE_XMLNode* pCloneNext = pNext->Clone(TRUE); | 510 CFDE_XMLNode* pCloneNext = pNext->Clone(TRUE); |
493 pClone->InsertChildNode(pCloneNext); | 511 pClone->InsertChildNode(pCloneNext); |
494 pNext = pNext->m_pNext; | 512 pNext = pNext->m_pNext; |
495 while (pNext) { | 513 while (pNext) { |
496 CFDE_XMLNode* pChild = pNext->Clone(TRUE); | 514 CFDE_XMLNode* pChild = pNext->Clone(TRUE); |
497 pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild); | 515 pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild); |
498 pCloneNext = pChild; | 516 pCloneNext = pChild; |
499 pNext = pNext->m_pNext; | 517 pNext = pNext->m_pNext; |
500 } | 518 } |
501 } | 519 } |
502 | 520 |
503 CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) | 521 CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) |
504 : m_wsTarget(wsTarget) { | 522 : m_wsTarget(wsTarget) { |
505 ASSERT(m_wsTarget.GetLength() > 0); | 523 ASSERT(m_wsTarget.GetLength() > 0); |
506 } | 524 } |
| 525 |
| 526 void CFDE_XMLInstruction::Release() { |
| 527 delete this; |
| 528 } |
| 529 |
| 530 FDE_XMLNODETYPE CFDE_XMLInstruction::GetType() const { |
| 531 return FDE_XMLNODE_Instruction; |
| 532 } |
| 533 |
507 CFDE_XMLNode* CFDE_XMLInstruction::Clone(FX_BOOL bRecursive) { | 534 CFDE_XMLNode* CFDE_XMLInstruction::Clone(FX_BOOL bRecursive) { |
508 CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget); | 535 CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget); |
509 if (!pClone) { | 536 if (!pClone) { |
510 return pClone; | 537 return pClone; |
511 } | 538 } |
512 pClone->m_Attributes.Copy(m_Attributes); | 539 pClone->m_Attributes.Copy(m_Attributes); |
513 pClone->m_TargetData.Copy(m_TargetData); | 540 pClone->m_TargetData.Copy(m_TargetData); |
514 if (bRecursive) { | 541 if (bRecursive) { |
515 CloneChildren(pClone); | 542 CloneChildren(pClone); |
516 } | 543 } |
517 return pClone; | 544 return pClone; |
518 } | 545 } |
| 546 |
519 int32_t CFDE_XMLInstruction::CountAttributes() const { | 547 int32_t CFDE_XMLInstruction::CountAttributes() const { |
520 return m_Attributes.GetSize() / 2; | 548 return m_Attributes.GetSize() / 2; |
521 } | 549 } |
| 550 |
522 FX_BOOL CFDE_XMLInstruction::GetAttribute(int32_t index, | 551 FX_BOOL CFDE_XMLInstruction::GetAttribute(int32_t index, |
523 CFX_WideString& wsAttriName, | 552 CFX_WideString& wsAttriName, |
524 CFX_WideString& wsAttriValue) const { | 553 CFX_WideString& wsAttriValue) const { |
525 int32_t iCount = m_Attributes.GetSize(); | 554 int32_t iCount = m_Attributes.GetSize(); |
526 ASSERT(index > -1 && index < iCount / 2); | 555 ASSERT(index > -1 && index < iCount / 2); |
527 for (int32_t i = 0; i < iCount; i += 2) { | 556 for (int32_t i = 0; i < iCount; i += 2) { |
528 if (index == 0) { | 557 if (index == 0) { |
529 wsAttriName = m_Attributes[i]; | 558 wsAttriName = m_Attributes[i]; |
530 wsAttriValue = m_Attributes[i + 1]; | 559 wsAttriValue = m_Attributes[i + 1]; |
531 return TRUE; | 560 return TRUE; |
532 } | 561 } |
533 index--; | 562 index--; |
534 } | 563 } |
535 return FALSE; | 564 return FALSE; |
536 } | 565 } |
| 566 |
537 FX_BOOL CFDE_XMLInstruction::HasAttribute(const FX_WCHAR* pwsAttriName) const { | 567 FX_BOOL CFDE_XMLInstruction::HasAttribute(const FX_WCHAR* pwsAttriName) const { |
538 int32_t iCount = m_Attributes.GetSize(); | 568 int32_t iCount = m_Attributes.GetSize(); |
539 for (int32_t i = 0; i < iCount; i += 2) { | 569 for (int32_t i = 0; i < iCount; i += 2) { |
540 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 570 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
541 return TRUE; | 571 return TRUE; |
542 } | 572 } |
543 } | 573 } |
544 return FALSE; | 574 return FALSE; |
545 } | 575 } |
| 576 |
546 void CFDE_XMLInstruction::GetString(const FX_WCHAR* pwsAttriName, | 577 void CFDE_XMLInstruction::GetString(const FX_WCHAR* pwsAttriName, |
547 CFX_WideString& wsAttriValue, | 578 CFX_WideString& wsAttriValue, |
548 const FX_WCHAR* pwsDefValue) const { | 579 const FX_WCHAR* pwsDefValue) const { |
549 int32_t iCount = m_Attributes.GetSize(); | 580 int32_t iCount = m_Attributes.GetSize(); |
550 for (int32_t i = 0; i < iCount; i += 2) { | 581 for (int32_t i = 0; i < iCount; i += 2) { |
551 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 582 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
552 wsAttriValue = m_Attributes[i + 1]; | 583 wsAttriValue = m_Attributes[i + 1]; |
553 return; | 584 return; |
554 } | 585 } |
555 } | 586 } |
556 wsAttriValue = pwsDefValue; | 587 wsAttriValue = pwsDefValue; |
557 } | 588 } |
| 589 |
558 void CFDE_XMLInstruction::SetString(const CFX_WideString& wsAttriName, | 590 void CFDE_XMLInstruction::SetString(const CFX_WideString& wsAttriName, |
559 const CFX_WideString& wsAttriValue) { | 591 const CFX_WideString& wsAttriValue) { |
560 ASSERT(wsAttriName.GetLength() > 0); | 592 ASSERT(wsAttriName.GetLength() > 0); |
561 int32_t iCount = m_Attributes.GetSize(); | 593 int32_t iCount = m_Attributes.GetSize(); |
562 for (int32_t i = 0; i < iCount; i += 2) { | 594 for (int32_t i = 0; i < iCount; i += 2) { |
563 if (m_Attributes[i].Compare(wsAttriName) == 0) { | 595 if (m_Attributes[i].Compare(wsAttriName) == 0) { |
564 m_Attributes[i] = wsAttriName; | 596 m_Attributes[i] = wsAttriName; |
565 m_Attributes[i + 1] = wsAttriValue; | 597 m_Attributes[i + 1] = wsAttriValue; |
566 return; | 598 return; |
567 } | 599 } |
568 } | 600 } |
569 m_Attributes.Add(wsAttriName); | 601 m_Attributes.Add(wsAttriName); |
570 m_Attributes.Add(wsAttriValue); | 602 m_Attributes.Add(wsAttriValue); |
571 } | 603 } |
| 604 |
572 int32_t CFDE_XMLInstruction::GetInteger(const FX_WCHAR* pwsAttriName, | 605 int32_t CFDE_XMLInstruction::GetInteger(const FX_WCHAR* pwsAttriName, |
573 int32_t iDefValue) const { | 606 int32_t iDefValue) const { |
574 int32_t iCount = m_Attributes.GetSize(); | 607 int32_t iCount = m_Attributes.GetSize(); |
575 for (int32_t i = 0; i < iCount; i += 2) { | 608 for (int32_t i = 0; i < iCount; i += 2) { |
576 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 609 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
577 return FXSYS_wtoi(m_Attributes[i + 1].c_str()); | 610 return FXSYS_wtoi(m_Attributes[i + 1].c_str()); |
578 } | 611 } |
579 } | 612 } |
580 return iDefValue; | 613 return iDefValue; |
581 } | 614 } |
| 615 |
582 void CFDE_XMLInstruction::SetInteger(const FX_WCHAR* pwsAttriName, | 616 void CFDE_XMLInstruction::SetInteger(const FX_WCHAR* pwsAttriName, |
583 int32_t iAttriValue) { | 617 int32_t iAttriValue) { |
584 CFX_WideString wsValue; | 618 CFX_WideString wsValue; |
585 wsValue.Format(L"%d", iAttriValue); | 619 wsValue.Format(L"%d", iAttriValue); |
586 SetString(pwsAttriName, wsValue); | 620 SetString(pwsAttriName, wsValue); |
587 } | 621 } |
| 622 |
588 FX_FLOAT CFDE_XMLInstruction::GetFloat(const FX_WCHAR* pwsAttriName, | 623 FX_FLOAT CFDE_XMLInstruction::GetFloat(const FX_WCHAR* pwsAttriName, |
589 FX_FLOAT fDefValue) const { | 624 FX_FLOAT fDefValue) const { |
590 int32_t iCount = m_Attributes.GetSize(); | 625 int32_t iCount = m_Attributes.GetSize(); |
591 for (int32_t i = 0; i < iCount; i += 2) { | 626 for (int32_t i = 0; i < iCount; i += 2) { |
592 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 627 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
593 return FX_wcstof(m_Attributes[i + 1].c_str()); | 628 return FX_wcstof(m_Attributes[i + 1].c_str()); |
594 } | 629 } |
595 } | 630 } |
596 return fDefValue; | 631 return fDefValue; |
597 } | 632 } |
| 633 |
598 void CFDE_XMLInstruction::SetFloat(const FX_WCHAR* pwsAttriName, | 634 void CFDE_XMLInstruction::SetFloat(const FX_WCHAR* pwsAttriName, |
599 FX_FLOAT fAttriValue) { | 635 FX_FLOAT fAttriValue) { |
600 CFX_WideString wsValue; | 636 CFX_WideString wsValue; |
601 wsValue.Format(L"%f", fAttriValue); | 637 wsValue.Format(L"%f", fAttriValue); |
602 SetString(pwsAttriName, wsValue); | 638 SetString(pwsAttriName, wsValue); |
603 } | 639 } |
| 640 |
604 void CFDE_XMLInstruction::RemoveAttribute(const FX_WCHAR* pwsAttriName) { | 641 void CFDE_XMLInstruction::RemoveAttribute(const FX_WCHAR* pwsAttriName) { |
605 int32_t iCount = m_Attributes.GetSize(); | 642 int32_t iCount = m_Attributes.GetSize(); |
606 for (int32_t i = 0; i < iCount; i += 2) { | 643 for (int32_t i = 0; i < iCount; i += 2) { |
607 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 644 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
608 m_Attributes.RemoveAt(i + 1); | 645 m_Attributes.RemoveAt(i + 1); |
609 m_Attributes.RemoveAt(i); | 646 m_Attributes.RemoveAt(i); |
610 return; | 647 return; |
611 } | 648 } |
612 } | 649 } |
613 } | 650 } |
| 651 |
614 int32_t CFDE_XMLInstruction::CountData() const { | 652 int32_t CFDE_XMLInstruction::CountData() const { |
615 return m_TargetData.GetSize(); | 653 return m_TargetData.GetSize(); |
616 } | 654 } |
| 655 |
617 FX_BOOL CFDE_XMLInstruction::GetData(int32_t index, | 656 FX_BOOL CFDE_XMLInstruction::GetData(int32_t index, |
618 CFX_WideString& wsData) const { | 657 CFX_WideString& wsData) const { |
619 if (index < 0 || index >= m_TargetData.GetSize()) { | 658 if (index < 0 || index >= m_TargetData.GetSize()) { |
620 return FALSE; | 659 return FALSE; |
621 } | 660 } |
622 wsData = m_TargetData[index]; | 661 wsData = m_TargetData[index]; |
623 return TRUE; | 662 return TRUE; |
624 } | 663 } |
| 664 |
625 void CFDE_XMLInstruction::AppendData(const CFX_WideString& wsData) { | 665 void CFDE_XMLInstruction::AppendData(const CFX_WideString& wsData) { |
626 m_TargetData.Add(wsData); | 666 m_TargetData.Add(wsData); |
627 } | 667 } |
| 668 |
628 void CFDE_XMLInstruction::RemoveData(int32_t index) { | 669 void CFDE_XMLInstruction::RemoveData(int32_t index) { |
629 m_TargetData.RemoveAt(index); | 670 m_TargetData.RemoveAt(index); |
630 } | 671 } |
631 | 672 |
| 673 CFDE_XMLInstruction::~CFDE_XMLInstruction() {} |
| 674 |
632 CFDE_XMLElement::CFDE_XMLElement(const CFX_WideString& wsTag) | 675 CFDE_XMLElement::CFDE_XMLElement(const CFX_WideString& wsTag) |
633 : CFDE_XMLNode(), m_wsTag(wsTag), m_Attributes() { | 676 : CFDE_XMLNode(), m_wsTag(wsTag), m_Attributes() { |
634 ASSERT(m_wsTag.GetLength() > 0); | 677 ASSERT(m_wsTag.GetLength() > 0); |
635 } | 678 } |
| 679 |
636 CFDE_XMLElement::~CFDE_XMLElement() { | 680 CFDE_XMLElement::~CFDE_XMLElement() { |
637 m_Attributes.RemoveAll(); | 681 m_Attributes.RemoveAll(); |
638 } | 682 } |
| 683 |
| 684 void CFDE_XMLElement::Release() { |
| 685 delete this; |
| 686 } |
| 687 |
| 688 FDE_XMLNODETYPE CFDE_XMLElement::GetType() const { |
| 689 return FDE_XMLNODE_Element; |
| 690 } |
| 691 |
639 CFDE_XMLNode* CFDE_XMLElement::Clone(FX_BOOL bRecursive) { | 692 CFDE_XMLNode* CFDE_XMLElement::Clone(FX_BOOL bRecursive) { |
640 CFDE_XMLElement* pClone = new CFDE_XMLElement(m_wsTag); | 693 CFDE_XMLElement* pClone = new CFDE_XMLElement(m_wsTag); |
641 if (!pClone) { | 694 if (!pClone) { |
642 return nullptr; | 695 return nullptr; |
643 } | 696 } |
644 pClone->m_Attributes.Copy(m_Attributes); | 697 pClone->m_Attributes.Copy(m_Attributes); |
645 if (bRecursive) { | 698 if (bRecursive) { |
646 CloneChildren(pClone); | 699 CloneChildren(pClone); |
647 } else { | 700 } else { |
648 CFX_WideString wsText; | 701 CFX_WideString wsText; |
649 CFDE_XMLNode* pChild = m_pChild; | 702 CFDE_XMLNode* pChild = m_pChild; |
650 while (pChild) { | 703 while (pChild) { |
651 switch (pChild->GetType()) { | 704 switch (pChild->GetType()) { |
652 case FDE_XMLNODE_Text: | 705 case FDE_XMLNODE_Text: |
653 wsText += ((CFDE_XMLText*)pChild)->m_wsText; | 706 wsText += ((CFDE_XMLText*)pChild)->m_wsText; |
654 break; | 707 break; |
655 default: | 708 default: |
656 break; | 709 break; |
657 } | 710 } |
658 pChild = pChild->m_pNext; | 711 pChild = pChild->m_pNext; |
659 } | 712 } |
660 pClone->SetTextData(wsText); | 713 pClone->SetTextData(wsText); |
661 } | 714 } |
662 return pClone; | 715 return pClone; |
663 } | 716 } |
| 717 |
664 void CFDE_XMLElement::GetTagName(CFX_WideString& wsTag) const { | 718 void CFDE_XMLElement::GetTagName(CFX_WideString& wsTag) const { |
665 wsTag = m_wsTag; | 719 wsTag = m_wsTag; |
666 } | 720 } |
| 721 |
667 void CFDE_XMLElement::GetLocalTagName(CFX_WideString& wsTag) const { | 722 void CFDE_XMLElement::GetLocalTagName(CFX_WideString& wsTag) const { |
668 FX_STRSIZE iFind = m_wsTag.Find(L':', 0); | 723 FX_STRSIZE iFind = m_wsTag.Find(L':', 0); |
669 if (iFind < 0) { | 724 if (iFind < 0) { |
670 wsTag = m_wsTag; | 725 wsTag = m_wsTag; |
671 } else { | 726 } else { |
672 wsTag = m_wsTag.Right(m_wsTag.GetLength() - iFind - 1); | 727 wsTag = m_wsTag.Right(m_wsTag.GetLength() - iFind - 1); |
673 } | 728 } |
674 } | 729 } |
| 730 |
675 void CFDE_XMLElement::GetNamespacePrefix(CFX_WideString& wsPrefix) const { | 731 void CFDE_XMLElement::GetNamespacePrefix(CFX_WideString& wsPrefix) const { |
676 FX_STRSIZE iFind = m_wsTag.Find(L':', 0); | 732 FX_STRSIZE iFind = m_wsTag.Find(L':', 0); |
677 if (iFind < 0) { | 733 if (iFind < 0) { |
678 wsPrefix.clear(); | 734 wsPrefix.clear(); |
679 } else { | 735 } else { |
680 wsPrefix = m_wsTag.Left(iFind); | 736 wsPrefix = m_wsTag.Left(iFind); |
681 } | 737 } |
682 } | 738 } |
| 739 |
683 void CFDE_XMLElement::GetNamespaceURI(CFX_WideString& wsNamespace) const { | 740 void CFDE_XMLElement::GetNamespaceURI(CFX_WideString& wsNamespace) const { |
684 CFX_WideString wsAttri(L"xmlns"), wsPrefix; | 741 CFX_WideString wsAttri(L"xmlns"), wsPrefix; |
685 GetNamespacePrefix(wsPrefix); | 742 GetNamespacePrefix(wsPrefix); |
686 if (wsPrefix.GetLength() > 0) { | 743 if (wsPrefix.GetLength() > 0) { |
687 wsAttri += L":"; | 744 wsAttri += L":"; |
688 wsAttri += wsPrefix; | 745 wsAttri += wsPrefix; |
689 } | 746 } |
690 wsNamespace.clear(); | 747 wsNamespace.clear(); |
691 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; | 748 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; |
692 while (pNode) { | 749 while (pNode) { |
693 if (pNode->GetType() != FDE_XMLNODE_Element) { | 750 if (pNode->GetType() != FDE_XMLNODE_Element) { |
694 break; | 751 break; |
695 } | 752 } |
696 CFDE_XMLElement* pElement = (CFDE_XMLElement*)pNode; | 753 CFDE_XMLElement* pElement = (CFDE_XMLElement*)pNode; |
697 if (!pElement->HasAttribute(wsAttri.c_str())) { | 754 if (!pElement->HasAttribute(wsAttri.c_str())) { |
698 pNode = pNode->GetNodeItem(CFDE_XMLNode::Parent); | 755 pNode = pNode->GetNodeItem(CFDE_XMLNode::Parent); |
699 continue; | 756 continue; |
700 } | 757 } |
701 pElement->GetString(wsAttri.c_str(), wsNamespace); | 758 pElement->GetString(wsAttri.c_str(), wsNamespace); |
702 break; | 759 break; |
703 } | 760 } |
704 } | 761 } |
| 762 |
705 int32_t CFDE_XMLElement::CountAttributes() const { | 763 int32_t CFDE_XMLElement::CountAttributes() const { |
706 return m_Attributes.GetSize() / 2; | 764 return m_Attributes.GetSize() / 2; |
707 } | 765 } |
| 766 |
708 FX_BOOL CFDE_XMLElement::GetAttribute(int32_t index, | 767 FX_BOOL CFDE_XMLElement::GetAttribute(int32_t index, |
709 CFX_WideString& wsAttriName, | 768 CFX_WideString& wsAttriName, |
710 CFX_WideString& wsAttriValue) const { | 769 CFX_WideString& wsAttriValue) const { |
711 int32_t iCount = m_Attributes.GetSize(); | 770 int32_t iCount = m_Attributes.GetSize(); |
712 ASSERT(index > -1 && index < iCount / 2); | 771 ASSERT(index > -1 && index < iCount / 2); |
713 for (int32_t i = 0; i < iCount; i += 2) { | 772 for (int32_t i = 0; i < iCount; i += 2) { |
714 if (index == 0) { | 773 if (index == 0) { |
715 wsAttriName = m_Attributes[i]; | 774 wsAttriName = m_Attributes[i]; |
716 wsAttriValue = m_Attributes[i + 1]; | 775 wsAttriValue = m_Attributes[i + 1]; |
717 return TRUE; | 776 return TRUE; |
718 } | 777 } |
719 index--; | 778 index--; |
720 } | 779 } |
721 return FALSE; | 780 return FALSE; |
722 } | 781 } |
| 782 |
723 FX_BOOL CFDE_XMLElement::HasAttribute(const FX_WCHAR* pwsAttriName) const { | 783 FX_BOOL CFDE_XMLElement::HasAttribute(const FX_WCHAR* pwsAttriName) const { |
724 int32_t iCount = m_Attributes.GetSize(); | 784 int32_t iCount = m_Attributes.GetSize(); |
725 for (int32_t i = 0; i < iCount; i += 2) { | 785 for (int32_t i = 0; i < iCount; i += 2) { |
726 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 786 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
727 return TRUE; | 787 return TRUE; |
728 } | 788 } |
729 } | 789 } |
730 return FALSE; | 790 return FALSE; |
731 } | 791 } |
| 792 |
732 void CFDE_XMLElement::GetString(const FX_WCHAR* pwsAttriName, | 793 void CFDE_XMLElement::GetString(const FX_WCHAR* pwsAttriName, |
733 CFX_WideString& wsAttriValue, | 794 CFX_WideString& wsAttriValue, |
734 const FX_WCHAR* pwsDefValue) const { | 795 const FX_WCHAR* pwsDefValue) const { |
735 int32_t iCount = m_Attributes.GetSize(); | 796 int32_t iCount = m_Attributes.GetSize(); |
736 for (int32_t i = 0; i < iCount; i += 2) { | 797 for (int32_t i = 0; i < iCount; i += 2) { |
737 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 798 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
738 wsAttriValue = m_Attributes[i + 1]; | 799 wsAttriValue = m_Attributes[i + 1]; |
739 return; | 800 return; |
740 } | 801 } |
741 } | 802 } |
742 wsAttriValue = pwsDefValue; | 803 wsAttriValue = pwsDefValue; |
743 } | 804 } |
| 805 |
744 void CFDE_XMLElement::SetString(const CFX_WideString& wsAttriName, | 806 void CFDE_XMLElement::SetString(const CFX_WideString& wsAttriName, |
745 const CFX_WideString& wsAttriValue) { | 807 const CFX_WideString& wsAttriValue) { |
746 ASSERT(wsAttriName.GetLength() > 0); | 808 ASSERT(wsAttriName.GetLength() > 0); |
747 int32_t iCount = m_Attributes.GetSize(); | 809 int32_t iCount = m_Attributes.GetSize(); |
748 for (int32_t i = 0; i < iCount; i += 2) { | 810 for (int32_t i = 0; i < iCount; i += 2) { |
749 if (m_Attributes[i].Compare(wsAttriName) == 0) { | 811 if (m_Attributes[i].Compare(wsAttriName) == 0) { |
750 m_Attributes[i] = wsAttriName; | 812 m_Attributes[i] = wsAttriName; |
751 m_Attributes[i + 1] = wsAttriValue; | 813 m_Attributes[i + 1] = wsAttriValue; |
752 return; | 814 return; |
753 } | 815 } |
754 } | 816 } |
755 m_Attributes.Add(wsAttriName); | 817 m_Attributes.Add(wsAttriName); |
756 m_Attributes.Add(wsAttriValue); | 818 m_Attributes.Add(wsAttriValue); |
757 } | 819 } |
| 820 |
758 int32_t CFDE_XMLElement::GetInteger(const FX_WCHAR* pwsAttriName, | 821 int32_t CFDE_XMLElement::GetInteger(const FX_WCHAR* pwsAttriName, |
759 int32_t iDefValue) const { | 822 int32_t iDefValue) const { |
760 int32_t iCount = m_Attributes.GetSize(); | 823 int32_t iCount = m_Attributes.GetSize(); |
761 for (int32_t i = 0; i < iCount; i += 2) { | 824 for (int32_t i = 0; i < iCount; i += 2) { |
762 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 825 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
763 return FXSYS_wtoi(m_Attributes[i + 1].c_str()); | 826 return FXSYS_wtoi(m_Attributes[i + 1].c_str()); |
764 } | 827 } |
765 } | 828 } |
766 return iDefValue; | 829 return iDefValue; |
767 } | 830 } |
| 831 |
768 void CFDE_XMLElement::SetInteger(const FX_WCHAR* pwsAttriName, | 832 void CFDE_XMLElement::SetInteger(const FX_WCHAR* pwsAttriName, |
769 int32_t iAttriValue) { | 833 int32_t iAttriValue) { |
770 CFX_WideString wsValue; | 834 CFX_WideString wsValue; |
771 wsValue.Format(L"%d", iAttriValue); | 835 wsValue.Format(L"%d", iAttriValue); |
772 SetString(pwsAttriName, wsValue); | 836 SetString(pwsAttriName, wsValue); |
773 } | 837 } |
| 838 |
774 FX_FLOAT CFDE_XMLElement::GetFloat(const FX_WCHAR* pwsAttriName, | 839 FX_FLOAT CFDE_XMLElement::GetFloat(const FX_WCHAR* pwsAttriName, |
775 FX_FLOAT fDefValue) const { | 840 FX_FLOAT fDefValue) const { |
776 int32_t iCount = m_Attributes.GetSize(); | 841 int32_t iCount = m_Attributes.GetSize(); |
777 for (int32_t i = 0; i < iCount; i += 2) { | 842 for (int32_t i = 0; i < iCount; i += 2) { |
778 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 843 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
779 return FX_wcstof(m_Attributes[i + 1].c_str()); | 844 return FX_wcstof(m_Attributes[i + 1].c_str()); |
780 } | 845 } |
781 } | 846 } |
782 return fDefValue; | 847 return fDefValue; |
783 } | 848 } |
| 849 |
784 void CFDE_XMLElement::SetFloat(const FX_WCHAR* pwsAttriName, | 850 void CFDE_XMLElement::SetFloat(const FX_WCHAR* pwsAttriName, |
785 FX_FLOAT fAttriValue) { | 851 FX_FLOAT fAttriValue) { |
786 CFX_WideString wsValue; | 852 CFX_WideString wsValue; |
787 wsValue.Format(L"%f", fAttriValue); | 853 wsValue.Format(L"%f", fAttriValue); |
788 SetString(pwsAttriName, wsValue); | 854 SetString(pwsAttriName, wsValue); |
789 } | 855 } |
| 856 |
790 void CFDE_XMLElement::RemoveAttribute(const FX_WCHAR* pwsAttriName) { | 857 void CFDE_XMLElement::RemoveAttribute(const FX_WCHAR* pwsAttriName) { |
791 int32_t iCount = m_Attributes.GetSize(); | 858 int32_t iCount = m_Attributes.GetSize(); |
792 for (int32_t i = 0; i < iCount; i += 2) { | 859 for (int32_t i = 0; i < iCount; i += 2) { |
793 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 860 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
794 m_Attributes.RemoveAt(i + 1); | 861 m_Attributes.RemoveAt(i + 1); |
795 m_Attributes.RemoveAt(i); | 862 m_Attributes.RemoveAt(i); |
796 return; | 863 return; |
797 } | 864 } |
798 } | 865 } |
799 } | 866 } |
| 867 |
800 void CFDE_XMLElement::GetTextData(CFX_WideString& wsText) const { | 868 void CFDE_XMLElement::GetTextData(CFX_WideString& wsText) const { |
801 CFX_WideTextBuf buffer; | 869 CFX_WideTextBuf buffer; |
802 CFDE_XMLNode* pChild = m_pChild; | 870 CFDE_XMLNode* pChild = m_pChild; |
803 while (pChild) { | 871 while (pChild) { |
804 switch (pChild->GetType()) { | 872 switch (pChild->GetType()) { |
805 case FDE_XMLNODE_Text: | 873 case FDE_XMLNODE_Text: |
806 buffer << ((CFDE_XMLText*)pChild)->m_wsText; | 874 buffer << ((CFDE_XMLText*)pChild)->m_wsText; |
807 break; | 875 break; |
808 case FDE_XMLNODE_CharData: | 876 case FDE_XMLNODE_CharData: |
809 buffer << ((CFDE_XMLCharData*)pChild)->m_wsCharData; | 877 buffer << ((CFDE_XMLCharData*)pChild)->m_wsCharData; |
810 break; | 878 break; |
811 default: | 879 default: |
812 break; | 880 break; |
813 } | 881 } |
814 pChild = pChild->m_pNext; | 882 pChild = pChild->m_pNext; |
815 } | 883 } |
816 wsText = buffer.AsStringC(); | 884 wsText = buffer.AsStringC(); |
817 } | 885 } |
| 886 |
818 void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) { | 887 void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) { |
819 if (wsText.GetLength() < 1) { | 888 if (wsText.GetLength() < 1) { |
820 return; | 889 return; |
821 } | 890 } |
822 InsertChildNode(new CFDE_XMLText(wsText)); | 891 InsertChildNode(new CFDE_XMLText(wsText)); |
823 } | 892 } |
| 893 |
824 CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) | 894 CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) |
825 : CFDE_XMLNode(), m_wsText(wsText) {} | 895 : CFDE_XMLNode(), m_wsText(wsText) {} |
| 896 |
| 897 void CFDE_XMLText::Release() { |
| 898 delete this; |
| 899 } |
| 900 |
| 901 FDE_XMLNODETYPE CFDE_XMLText::GetType() const { |
| 902 return FDE_XMLNODE_Text; |
| 903 } |
| 904 |
826 CFDE_XMLNode* CFDE_XMLText::Clone(FX_BOOL bRecursive) { | 905 CFDE_XMLNode* CFDE_XMLText::Clone(FX_BOOL bRecursive) { |
827 CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText); | 906 CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText); |
828 return pClone; | 907 return pClone; |
829 } | 908 } |
830 | 909 |
| 910 CFDE_XMLText::~CFDE_XMLText() {} |
| 911 |
831 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) | 912 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) |
832 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} | 913 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} |
| 914 |
| 915 void CFDE_XMLCharData::Release() { |
| 916 delete this; |
| 917 } |
| 918 |
| 919 FDE_XMLNODETYPE CFDE_XMLCharData::GetType() const { |
| 920 return FDE_XMLNODE_CharData; |
| 921 } |
| 922 |
833 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { | 923 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { |
834 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); | 924 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); |
835 return pClone; | 925 return pClone; |
836 } | 926 } |
837 | 927 |
| 928 CFDE_XMLCharData::~CFDE_XMLCharData() {} |
| 929 |
838 CFDE_XMLDoc::CFDE_XMLDoc() | 930 CFDE_XMLDoc::CFDE_XMLDoc() |
839 : m_pRoot(nullptr), m_pSyntaxParser(nullptr), m_pXMLParser(nullptr) { | 931 : m_pRoot(nullptr), m_pSyntaxParser(nullptr), m_pXMLParser(nullptr) { |
840 Reset(TRUE); | 932 Reset(TRUE); |
841 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); | 933 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); |
842 m_pRoot->InsertChildNode(pXML); | 934 m_pRoot->InsertChildNode(pXML); |
843 } | 935 } |
| 936 |
844 CFDE_XMLDoc::~CFDE_XMLDoc() { | 937 CFDE_XMLDoc::~CFDE_XMLDoc() { |
845 Reset(FALSE); | 938 Reset(FALSE); |
846 } | 939 } |
| 940 |
847 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { | 941 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { |
848 m_iStatus = 0; | 942 m_iStatus = 0; |
849 m_pStream = nullptr; | 943 m_pStream = nullptr; |
850 if (bInitRoot) { | 944 if (bInitRoot) { |
851 if (m_pRoot) | 945 if (m_pRoot) |
852 m_pRoot->DeleteChildren(); | 946 m_pRoot->DeleteChildren(); |
853 else | 947 else |
854 m_pRoot = new CFDE_XMLNode; | 948 m_pRoot = new CFDE_XMLNode; |
855 } else { | 949 } else { |
856 if (m_pRoot) { | 950 if (m_pRoot) { |
857 m_pRoot->Release(); | 951 m_pRoot->Release(); |
858 m_pRoot = nullptr; | 952 m_pRoot = nullptr; |
859 } | 953 } |
860 } | 954 } |
861 ReleaseParser(); | 955 ReleaseParser(); |
862 } | 956 } |
| 957 |
863 void CFDE_XMLDoc::ReleaseParser() { | 958 void CFDE_XMLDoc::ReleaseParser() { |
864 if (m_pXMLParser) { | 959 if (m_pXMLParser) { |
865 m_pXMLParser->Release(); | 960 m_pXMLParser->Release(); |
866 m_pXMLParser = nullptr; | 961 m_pXMLParser = nullptr; |
867 } | 962 } |
868 if (m_pSyntaxParser) { | 963 if (m_pSyntaxParser) { |
869 m_pSyntaxParser->Release(); | 964 m_pSyntaxParser->Release(); |
870 m_pSyntaxParser = nullptr; | 965 m_pSyntaxParser = nullptr; |
871 } | 966 } |
872 } | 967 } |
873 | 968 |
874 FX_BOOL CFDE_XMLDoc::LoadXML(CFDE_XMLParser* pXMLParser) { | 969 FX_BOOL CFDE_XMLDoc::LoadXML(CFDE_XMLParser* pXMLParser) { |
875 if (!pXMLParser) | 970 if (!pXMLParser) |
876 return FALSE; | 971 return FALSE; |
877 | 972 |
878 Reset(TRUE); | 973 Reset(TRUE); |
879 m_pXMLParser = pXMLParser; | 974 m_pXMLParser = pXMLParser; |
880 return !!m_pXMLParser; | 975 return !!m_pXMLParser; |
881 } | 976 } |
| 977 |
882 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { | 978 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { |
883 if (m_iStatus >= 100) | 979 if (m_iStatus >= 100) |
884 return m_iStatus; | 980 return m_iStatus; |
885 return m_iStatus = m_pXMLParser->DoParser(pPause); | 981 return m_iStatus = m_pXMLParser->DoParser(pPause); |
886 } | 982 } |
| 983 |
887 void CFDE_XMLDoc::CloseXML() { | 984 void CFDE_XMLDoc::CloseXML() { |
888 ReleaseParser(); | 985 ReleaseParser(); |
889 } | 986 } |
| 987 |
890 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { | 988 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { |
891 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; | 989 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; |
892 switch (pNode->GetType()) { | 990 switch (pNode->GetType()) { |
893 case FDE_XMLNODE_Instruction: { | 991 case FDE_XMLNODE_Instruction: { |
894 CFX_WideString ws; | 992 CFX_WideString ws; |
895 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; | 993 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; |
896 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { | 994 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { |
897 ws = L"<?xml version=\"1.0\" encoding=\""; | 995 ws = L"<?xml version=\"1.0\" encoding=\""; |
898 uint16_t wCodePage = pXMLStream->GetCodePage(); | 996 uint16_t wCodePage = pXMLStream->GetCodePage(); |
899 if (wCodePage == FX_CODEPAGE_UTF16LE) { | 997 if (wCodePage == FX_CODEPAGE_UTF16LE) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; | 1087 ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; |
990 ws += L"]]>"; | 1088 ws += L"]]>"; |
991 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 1089 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
992 } break; | 1090 } break; |
993 case FDE_XMLNODE_Unknown: | 1091 case FDE_XMLNODE_Unknown: |
994 break; | 1092 break; |
995 default: | 1093 default: |
996 break; | 1094 break; |
997 } | 1095 } |
998 } | 1096 } |
| 1097 |
999 void CFDE_XMLDoc::SaveXML(IFX_Stream* pXMLStream, FX_BOOL bSaveBOM) { | 1098 void CFDE_XMLDoc::SaveXML(IFX_Stream* pXMLStream, FX_BOOL bSaveBOM) { |
1000 if (!pXMLStream || pXMLStream == m_pStream) { | 1099 if (!pXMLStream || pXMLStream == m_pStream) { |
1001 m_pStream->Seek(FX_STREAMSEEK_Begin, 0); | 1100 m_pStream->Seek(FX_STREAMSEEK_Begin, 0); |
1002 pXMLStream = m_pStream; | 1101 pXMLStream = m_pStream; |
1003 } | 1102 } |
1004 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Text) != 0); | 1103 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Text) != 0); |
1005 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 1104 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
1006 uint16_t wCodePage = pXMLStream->GetCodePage(); | 1105 uint16_t wCodePage = pXMLStream->GetCodePage(); |
1007 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && | 1106 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && |
1008 wCodePage != FX_CODEPAGE_UTF8) { | 1107 wCodePage != FX_CODEPAGE_UTF8) { |
(...skipping 12 matching lines...) Expand all Loading... |
1021 int32_t iPos = pXMLStream->GetPosition(); | 1120 int32_t iPos = pXMLStream->GetPosition(); |
1022 pXMLStream->SetLength(iPos); | 1121 pXMLStream->SetLength(iPos); |
1023 } | 1122 } |
1024 } | 1123 } |
1025 | 1124 |
1026 CFDE_BlockBuffer::CFDE_BlockBuffer(int32_t iAllocStep) | 1125 CFDE_BlockBuffer::CFDE_BlockBuffer(int32_t iAllocStep) |
1027 : m_iDataLength(0), | 1126 : m_iDataLength(0), |
1028 m_iBufferSize(0), | 1127 m_iBufferSize(0), |
1029 m_iAllocStep(iAllocStep), | 1128 m_iAllocStep(iAllocStep), |
1030 m_iStartPosition(0) {} | 1129 m_iStartPosition(0) {} |
| 1130 |
1031 CFDE_BlockBuffer::~CFDE_BlockBuffer() { | 1131 CFDE_BlockBuffer::~CFDE_BlockBuffer() { |
1032 ClearBuffer(); | 1132 ClearBuffer(); |
1033 } | 1133 } |
| 1134 |
1034 FX_WCHAR* CFDE_BlockBuffer::GetAvailableBlock(int32_t& iIndexInBlock) { | 1135 FX_WCHAR* CFDE_BlockBuffer::GetAvailableBlock(int32_t& iIndexInBlock) { |
1035 iIndexInBlock = 0; | 1136 iIndexInBlock = 0; |
1036 if (!m_BlockArray.GetSize()) { | 1137 if (!m_BlockArray.GetSize()) { |
1037 return nullptr; | 1138 return nullptr; |
1038 } | 1139 } |
1039 int32_t iRealIndex = m_iStartPosition + m_iDataLength; | 1140 int32_t iRealIndex = m_iStartPosition + m_iDataLength; |
1040 if (iRealIndex == m_iBufferSize) { | 1141 if (iRealIndex == m_iBufferSize) { |
1041 FX_WCHAR* pBlock = FX_Alloc(FX_WCHAR, m_iAllocStep); | 1142 FX_WCHAR* pBlock = FX_Alloc(FX_WCHAR, m_iAllocStep); |
1042 m_BlockArray.Add(pBlock); | 1143 m_BlockArray.Add(pBlock); |
1043 m_iBufferSize += m_iAllocStep; | 1144 m_iBufferSize += m_iAllocStep; |
1044 return pBlock; | 1145 return pBlock; |
1045 } | 1146 } |
1046 iIndexInBlock = iRealIndex % m_iAllocStep; | 1147 iIndexInBlock = iRealIndex % m_iAllocStep; |
1047 return m_BlockArray[iRealIndex / m_iAllocStep]; | 1148 return m_BlockArray[iRealIndex / m_iAllocStep]; |
1048 } | 1149 } |
| 1150 |
1049 FX_BOOL CFDE_BlockBuffer::InitBuffer(int32_t iBufferSize) { | 1151 FX_BOOL CFDE_BlockBuffer::InitBuffer(int32_t iBufferSize) { |
1050 ClearBuffer(); | 1152 ClearBuffer(); |
1051 int32_t iNumOfBlock = (iBufferSize - 1) / m_iAllocStep + 1; | 1153 int32_t iNumOfBlock = (iBufferSize - 1) / m_iAllocStep + 1; |
1052 for (int32_t i = 0; i < iNumOfBlock; i++) { | 1154 for (int32_t i = 0; i < iNumOfBlock; i++) { |
1053 m_BlockArray.Add(FX_Alloc(FX_WCHAR, m_iAllocStep)); | 1155 m_BlockArray.Add(FX_Alloc(FX_WCHAR, m_iAllocStep)); |
1054 } | 1156 } |
1055 m_iBufferSize = iNumOfBlock * m_iAllocStep; | 1157 m_iBufferSize = iNumOfBlock * m_iAllocStep; |
1056 return TRUE; | 1158 return TRUE; |
1057 } | 1159 } |
| 1160 |
1058 void CFDE_BlockBuffer::SetTextChar(int32_t iIndex, FX_WCHAR ch) { | 1161 void CFDE_BlockBuffer::SetTextChar(int32_t iIndex, FX_WCHAR ch) { |
1059 if (iIndex < 0) { | 1162 if (iIndex < 0) { |
1060 return; | 1163 return; |
1061 } | 1164 } |
1062 int32_t iRealIndex = m_iStartPosition + iIndex; | 1165 int32_t iRealIndex = m_iStartPosition + iIndex; |
1063 int32_t iBlockIndex = iRealIndex / m_iAllocStep; | 1166 int32_t iBlockIndex = iRealIndex / m_iAllocStep; |
1064 int32_t iInnerIndex = iRealIndex % m_iAllocStep; | 1167 int32_t iInnerIndex = iRealIndex % m_iAllocStep; |
1065 int32_t iBlockSize = m_BlockArray.GetSize(); | 1168 int32_t iBlockSize = m_BlockArray.GetSize(); |
1066 if (iBlockIndex >= iBlockSize) { | 1169 if (iBlockIndex >= iBlockSize) { |
1067 int32_t iNewBlocks = iBlockIndex - iBlockSize + 1; | 1170 int32_t iNewBlocks = iBlockIndex - iBlockSize + 1; |
1068 do { | 1171 do { |
1069 FX_WCHAR* pBlock = FX_Alloc(FX_WCHAR, m_iAllocStep); | 1172 FX_WCHAR* pBlock = FX_Alloc(FX_WCHAR, m_iAllocStep); |
1070 m_BlockArray.Add(pBlock); | 1173 m_BlockArray.Add(pBlock); |
1071 m_iBufferSize += m_iAllocStep; | 1174 m_iBufferSize += m_iAllocStep; |
1072 } while (--iNewBlocks); | 1175 } while (--iNewBlocks); |
1073 } | 1176 } |
1074 FX_WCHAR* pTextData = m_BlockArray[iBlockIndex]; | 1177 FX_WCHAR* pTextData = m_BlockArray[iBlockIndex]; |
1075 *(pTextData + iInnerIndex) = ch; | 1178 *(pTextData + iInnerIndex) = ch; |
1076 if (m_iDataLength <= iIndex) { | 1179 if (m_iDataLength <= iIndex) { |
1077 m_iDataLength = iIndex + 1; | 1180 m_iDataLength = iIndex + 1; |
1078 } | 1181 } |
1079 } | 1182 } |
| 1183 |
1080 int32_t CFDE_BlockBuffer::DeleteTextChars(int32_t iCount, FX_BOOL bDirection) { | 1184 int32_t CFDE_BlockBuffer::DeleteTextChars(int32_t iCount, FX_BOOL bDirection) { |
1081 if (iCount <= 0) { | 1185 if (iCount <= 0) { |
1082 return m_iDataLength; | 1186 return m_iDataLength; |
1083 } | 1187 } |
1084 if (iCount >= m_iDataLength) { | 1188 if (iCount >= m_iDataLength) { |
1085 Reset(FALSE); | 1189 Reset(FALSE); |
1086 return 0; | 1190 return 0; |
1087 } | 1191 } |
1088 if (bDirection) { | 1192 if (bDirection) { |
1089 m_iStartPosition += iCount; | 1193 m_iStartPosition += iCount; |
1090 m_iDataLength -= iCount; | 1194 m_iDataLength -= iCount; |
1091 } else { | 1195 } else { |
1092 m_iDataLength -= iCount; | 1196 m_iDataLength -= iCount; |
1093 } | 1197 } |
1094 return m_iDataLength; | 1198 return m_iDataLength; |
1095 } | 1199 } |
| 1200 |
1096 void CFDE_BlockBuffer::GetTextData(CFX_WideString& wsTextData, | 1201 void CFDE_BlockBuffer::GetTextData(CFX_WideString& wsTextData, |
1097 int32_t iStart, | 1202 int32_t iStart, |
1098 int32_t iLength) const { | 1203 int32_t iLength) const { |
1099 wsTextData.clear(); | 1204 wsTextData.clear(); |
1100 int32_t iMaybeDataLength = m_iBufferSize - 1 - m_iStartPosition; | 1205 int32_t iMaybeDataLength = m_iBufferSize - 1 - m_iStartPosition; |
1101 if (iStart < 0 || iStart > iMaybeDataLength) { | 1206 if (iStart < 0 || iStart > iMaybeDataLength) { |
1102 return; | 1207 return; |
1103 } | 1208 } |
1104 if (iLength == -1 || iLength > iMaybeDataLength) { | 1209 if (iLength == -1 || iLength > iMaybeDataLength) { |
1105 iLength = iMaybeDataLength; | 1210 iLength = iMaybeDataLength; |
(...skipping 22 matching lines...) Expand all Loading... |
1128 if (i == iEndBlockIndex) { | 1233 if (i == iEndBlockIndex) { |
1129 iCopyLength -= ((m_iAllocStep - 1) - iEndInnerIndex); | 1234 iCopyLength -= ((m_iAllocStep - 1) - iEndInnerIndex); |
1130 } | 1235 } |
1131 FX_WCHAR* pBlockBuf = m_BlockArray[i]; | 1236 FX_WCHAR* pBlockBuf = m_BlockArray[i]; |
1132 FXSYS_memcpy(pBuf + iPointer, pBlockBuf + iBufferPointer, | 1237 FXSYS_memcpy(pBuf + iPointer, pBlockBuf + iBufferPointer, |
1133 iCopyLength * sizeof(FX_WCHAR)); | 1238 iCopyLength * sizeof(FX_WCHAR)); |
1134 iPointer += iCopyLength; | 1239 iPointer += iCopyLength; |
1135 } | 1240 } |
1136 wsTextData.ReleaseBuffer(iLength); | 1241 wsTextData.ReleaseBuffer(iLength); |
1137 } | 1242 } |
| 1243 |
1138 void CFDE_BlockBuffer::TextDataIndex2BufIndex(const int32_t iIndex, | 1244 void CFDE_BlockBuffer::TextDataIndex2BufIndex(const int32_t iIndex, |
1139 int32_t& iBlockIndex, | 1245 int32_t& iBlockIndex, |
1140 int32_t& iInnerIndex) const { | 1246 int32_t& iInnerIndex) const { |
1141 ASSERT(iIndex >= 0); | 1247 ASSERT(iIndex >= 0); |
1142 int32_t iRealIndex = m_iStartPosition + iIndex; | 1248 int32_t iRealIndex = m_iStartPosition + iIndex; |
1143 iBlockIndex = iRealIndex / m_iAllocStep; | 1249 iBlockIndex = iRealIndex / m_iAllocStep; |
1144 iInnerIndex = iRealIndex % m_iAllocStep; | 1250 iInnerIndex = iRealIndex % m_iAllocStep; |
1145 } | 1251 } |
| 1252 |
1146 void CFDE_BlockBuffer::ClearBuffer() { | 1253 void CFDE_BlockBuffer::ClearBuffer() { |
1147 m_iBufferSize = 0; | 1254 m_iBufferSize = 0; |
1148 int32_t iSize = m_BlockArray.GetSize(); | 1255 int32_t iSize = m_BlockArray.GetSize(); |
1149 for (int32_t i = 0; i < iSize; i++) { | 1256 for (int32_t i = 0; i < iSize; i++) { |
1150 FX_Free(m_BlockArray[i]); | 1257 FX_Free(m_BlockArray[i]); |
1151 } | 1258 } |
1152 m_BlockArray.RemoveAll(); | 1259 m_BlockArray.RemoveAll(); |
1153 } | 1260 } |
1154 | 1261 |
1155 CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser() | 1262 CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser() |
(...skipping 16 matching lines...) Expand all Loading... |
1172 m_iIndexInBlock(0), | 1279 m_iIndexInBlock(0), |
1173 m_iTextDataLength(0), | 1280 m_iTextDataLength(0), |
1174 m_syntaxParserResult(FDE_XmlSyntaxResult::None), | 1281 m_syntaxParserResult(FDE_XmlSyntaxResult::None), |
1175 m_syntaxParserState(FDE_XmlSyntaxState::Text), | 1282 m_syntaxParserState(FDE_XmlSyntaxState::Text), |
1176 m_wQuotationMark(0), | 1283 m_wQuotationMark(0), |
1177 m_iEntityStart(-1), | 1284 m_iEntityStart(-1), |
1178 m_SkipStack(16) { | 1285 m_SkipStack(16) { |
1179 m_CurNode.iNodeNum = -1; | 1286 m_CurNode.iNodeNum = -1; |
1180 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; | 1287 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; |
1181 } | 1288 } |
| 1289 |
1182 void CFDE_XMLSyntaxParser::Init(IFX_Stream* pStream, | 1290 void CFDE_XMLSyntaxParser::Init(IFX_Stream* pStream, |
1183 int32_t iXMLPlaneSize, | 1291 int32_t iXMLPlaneSize, |
1184 int32_t iTextDataSize) { | 1292 int32_t iTextDataSize) { |
1185 ASSERT(!m_pStream && !m_pBuffer); | 1293 ASSERT(!m_pStream && !m_pBuffer); |
1186 ASSERT(pStream && iXMLPlaneSize > 0); | 1294 ASSERT(pStream && iXMLPlaneSize > 0); |
1187 int32_t iStreamLength = pStream->GetLength(); | 1295 int32_t iStreamLength = pStream->GetLength(); |
1188 ASSERT(iStreamLength > 0); | 1296 ASSERT(iStreamLength > 0); |
1189 m_pStream = pStream; | 1297 m_pStream = pStream; |
1190 m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength); | 1298 m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength); |
1191 uint8_t bom[4]; | 1299 uint8_t bom[4]; |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 nbytes = 4; | 1821 nbytes = 4; |
1714 } else if ((uint32_t)unicode < 0x4000000) { | 1822 } else if ((uint32_t)unicode < 0x4000000) { |
1715 nbytes = 5; | 1823 nbytes = 5; |
1716 } else { | 1824 } else { |
1717 nbytes = 6; | 1825 nbytes = 6; |
1718 } | 1826 } |
1719 iDstNum += nbytes; | 1827 iDstNum += nbytes; |
1720 } | 1828 } |
1721 return iDstNum; | 1829 return iDstNum; |
1722 } | 1830 } |
| 1831 |
1723 FX_FILESIZE CFDE_XMLSyntaxParser::GetCurrentBinaryPos() const { | 1832 FX_FILESIZE CFDE_XMLSyntaxParser::GetCurrentBinaryPos() const { |
1724 if (!m_pStream) | 1833 if (!m_pStream) |
1725 return 0; | 1834 return 0; |
1726 | 1835 |
1727 int32_t nSrcLen = m_pStart - m_pBuffer; | 1836 int32_t nSrcLen = m_pStart - m_pBuffer; |
1728 int32_t nDstLen = FX_GetUTF8EncodeLength(m_pBuffer, nSrcLen); | 1837 int32_t nDstLen = FX_GetUTF8EncodeLength(m_pBuffer, nSrcLen); |
1729 return m_iParsedBytes + nDstLen; | 1838 return m_iParsedBytes + nDstLen; |
1730 } | 1839 } |
1731 | 1840 |
1732 void CFDE_XMLSyntaxParser::ParseTextChar(FX_WCHAR ch) { | 1841 void CFDE_XMLSyntaxParser::ParseTextChar(FX_WCHAR ch) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); | 1904 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); |
1796 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 1905 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
1797 m_iEntityStart = -1; | 1906 m_iEntityStart = -1; |
1798 } else { | 1907 } else { |
1799 if (m_iEntityStart < 0 && ch == L'&') { | 1908 if (m_iEntityStart < 0 && ch == L'&') { |
1800 m_iEntityStart = m_iDataLength - 1; | 1909 m_iEntityStart = m_iDataLength - 1; |
1801 } | 1910 } |
1802 } | 1911 } |
1803 m_pStart++; | 1912 m_pStart++; |
1804 } | 1913 } |
OLD | NEW |