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; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 while (++iCount != index && pFind->m_pNext) { | 210 while (++iCount != index && pFind->m_pNext) { |
203 pFind = pFind->m_pNext; | 211 pFind = pFind->m_pNext; |
204 } | 212 } |
205 pNode->m_pPrior = pFind; | 213 pNode->m_pPrior = pFind; |
206 pNode->m_pNext = pFind->m_pNext; | 214 pNode->m_pNext = pFind->m_pNext; |
207 if (pFind->m_pNext) | 215 if (pFind->m_pNext) |
208 pFind->m_pNext->m_pPrior = pNode; | 216 pFind->m_pNext->m_pPrior = pNode; |
209 pFind->m_pNext = pNode; | 217 pFind->m_pNext = pNode; |
210 return iCount; | 218 return iCount; |
211 } | 219 } |
220 | |
212 void CFDE_XMLNode::RemoveChildNode(CFDE_XMLNode* pNode) { | 221 void CFDE_XMLNode::RemoveChildNode(CFDE_XMLNode* pNode) { |
213 ASSERT(m_pChild && pNode); | 222 ASSERT(m_pChild && pNode); |
214 if (m_pChild == pNode) { | 223 if (m_pChild == pNode) { |
215 m_pChild = pNode->m_pNext; | 224 m_pChild = pNode->m_pNext; |
216 } else { | 225 } else { |
217 pNode->m_pPrior->m_pNext = pNode->m_pNext; | 226 pNode->m_pPrior->m_pNext = pNode->m_pNext; |
218 } | 227 } |
219 if (pNode->m_pNext) | 228 if (pNode->m_pNext) |
220 pNode->m_pNext->m_pPrior = pNode->m_pPrior; | 229 pNode->m_pNext->m_pPrior = pNode->m_pPrior; |
221 pNode->m_pParent = nullptr; | 230 pNode->m_pParent = nullptr; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 } | 377 } |
369 break; | 378 break; |
370 default: | 379 default: |
371 break; | 380 break; |
372 } | 381 } |
373 return pNode; | 382 return pNode; |
374 } | 383 } |
375 CFDE_XMLNode* CFDE_XMLNode::Clone(FX_BOOL bRecursive) { | 384 CFDE_XMLNode* CFDE_XMLNode::Clone(FX_BOOL bRecursive) { |
376 return nullptr; | 385 return nullptr; |
377 } | 386 } |
387 | |
378 void CFDE_XMLNode::SaveXMLNode(IFX_Stream* pXMLStream) { | 388 void CFDE_XMLNode::SaveXMLNode(IFX_Stream* pXMLStream) { |
379 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; | 389 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; |
380 switch (pNode->GetType()) { | 390 switch (pNode->GetType()) { |
381 case FDE_XMLNODE_Instruction: { | 391 case FDE_XMLNODE_Instruction: { |
382 CFX_WideString ws; | 392 CFX_WideString ws; |
383 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; | 393 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; |
384 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { | 394 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { |
385 ws = L"<?xml version=\"1.0\" encoding=\""; | 395 ws = L"<?xml version=\"1.0\" encoding=\""; |
386 uint16_t wCodePage = pXMLStream->GetCodePage(); | 396 uint16_t wCodePage = pXMLStream->GetCodePage(); |
387 if (wCodePage == FX_CODEPAGE_UTF16LE) { | 397 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; | 487 ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; |
478 ws += L"]]>"; | 488 ws += L"]]>"; |
479 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 489 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
480 } break; | 490 } break; |
481 case FDE_XMLNODE_Unknown: | 491 case FDE_XMLNODE_Unknown: |
482 break; | 492 break; |
483 default: | 493 default: |
484 break; | 494 break; |
485 } | 495 } |
486 } | 496 } |
497 | |
487 void CFDE_XMLNode::CloneChildren(CFDE_XMLNode* pClone) { | 498 void CFDE_XMLNode::CloneChildren(CFDE_XMLNode* pClone) { |
488 if (!m_pChild) { | 499 if (!m_pChild) { |
489 return; | 500 return; |
490 } | 501 } |
491 CFDE_XMLNode* pNext = m_pChild; | 502 CFDE_XMLNode* pNext = m_pChild; |
492 CFDE_XMLNode* pCloneNext = pNext->Clone(TRUE); | 503 CFDE_XMLNode* pCloneNext = pNext->Clone(TRUE); |
493 pClone->InsertChildNode(pCloneNext); | 504 pClone->InsertChildNode(pCloneNext); |
494 pNext = pNext->m_pNext; | 505 pNext = pNext->m_pNext; |
495 while (pNext) { | 506 while (pNext) { |
496 CFDE_XMLNode* pChild = pNext->Clone(TRUE); | 507 CFDE_XMLNode* pChild = pNext->Clone(TRUE); |
497 pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild); | 508 pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild); |
498 pCloneNext = pChild; | 509 pCloneNext = pChild; |
499 pNext = pNext->m_pNext; | 510 pNext = pNext->m_pNext; |
500 } | 511 } |
501 } | 512 } |
502 | 513 |
503 CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) | 514 CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) |
504 : m_wsTarget(wsTarget) { | 515 : m_wsTarget(wsTarget) { |
505 ASSERT(m_wsTarget.GetLength() > 0); | 516 ASSERT(m_wsTarget.GetLength() > 0); |
506 } | 517 } |
518 | |
519 void CFDE_XMLInstruction::Release() { | |
520 delete this; | |
521 } | |
Lei Zhang
2016/06/17 03:10:05
blank line after
Wei Li
2016/06/17 21:47:44
Done.
| |
522 FDE_XMLNODETYPE CFDE_XMLInstruction::GetType() const { | |
523 return FDE_XMLNODE_Instruction; | |
524 } | |
507 CFDE_XMLNode* CFDE_XMLInstruction::Clone(FX_BOOL bRecursive) { | 525 CFDE_XMLNode* CFDE_XMLInstruction::Clone(FX_BOOL bRecursive) { |
508 CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget); | 526 CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget); |
509 if (!pClone) { | 527 if (!pClone) { |
510 return pClone; | 528 return pClone; |
511 } | 529 } |
512 pClone->m_Attributes.Copy(m_Attributes); | 530 pClone->m_Attributes.Copy(m_Attributes); |
513 pClone->m_TargetData.Copy(m_TargetData); | 531 pClone->m_TargetData.Copy(m_TargetData); |
514 if (bRecursive) { | 532 if (bRecursive) { |
515 CloneChildren(pClone); | 533 CloneChildren(pClone); |
516 } | 534 } |
517 return pClone; | 535 return pClone; |
518 } | 536 } |
537 | |
538 void CFDE_XMLInstruction::GetTargetName(CFX_WideString& wsTarget) const { | |
539 wsTarget = m_wsTarget; | |
540 } | |
Lei Zhang
2016/06/17 03:10:05
blank line after
Wei Li
2016/06/17 21:47:44
Done.
| |
519 int32_t CFDE_XMLInstruction::CountAttributes() const { | 541 int32_t CFDE_XMLInstruction::CountAttributes() const { |
520 return m_Attributes.GetSize() / 2; | 542 return m_Attributes.GetSize() / 2; |
521 } | 543 } |
522 FX_BOOL CFDE_XMLInstruction::GetAttribute(int32_t index, | 544 FX_BOOL CFDE_XMLInstruction::GetAttribute(int32_t index, |
523 CFX_WideString& wsAttriName, | 545 CFX_WideString& wsAttriName, |
524 CFX_WideString& wsAttriValue) const { | 546 CFX_WideString& wsAttriValue) const { |
525 int32_t iCount = m_Attributes.GetSize(); | 547 int32_t iCount = m_Attributes.GetSize(); |
526 ASSERT(index > -1 && index < iCount / 2); | 548 ASSERT(index > -1 && index < iCount / 2); |
527 for (int32_t i = 0; i < iCount; i += 2) { | 549 for (int32_t i = 0; i < iCount; i += 2) { |
528 if (index == 0) { | 550 if (index == 0) { |
529 wsAttriName = m_Attributes[i]; | 551 wsAttriName = m_Attributes[i]; |
530 wsAttriValue = m_Attributes[i + 1]; | 552 wsAttriValue = m_Attributes[i + 1]; |
531 return TRUE; | 553 return TRUE; |
532 } | 554 } |
533 index--; | 555 index--; |
534 } | 556 } |
535 return FALSE; | 557 return FALSE; |
536 } | 558 } |
537 FX_BOOL CFDE_XMLInstruction::HasAttribute(const FX_WCHAR* pwsAttriName) const { | 559 FX_BOOL CFDE_XMLInstruction::HasAttribute(const FX_WCHAR* pwsAttriName) const { |
538 int32_t iCount = m_Attributes.GetSize(); | 560 int32_t iCount = m_Attributes.GetSize(); |
539 for (int32_t i = 0; i < iCount; i += 2) { | 561 for (int32_t i = 0; i < iCount; i += 2) { |
540 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 562 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
541 return TRUE; | 563 return TRUE; |
542 } | 564 } |
543 } | 565 } |
544 return FALSE; | 566 return FALSE; |
545 } | 567 } |
568 | |
546 void CFDE_XMLInstruction::GetString(const FX_WCHAR* pwsAttriName, | 569 void CFDE_XMLInstruction::GetString(const FX_WCHAR* pwsAttriName, |
547 CFX_WideString& wsAttriValue, | 570 CFX_WideString& wsAttriValue, |
548 const FX_WCHAR* pwsDefValue) const { | 571 const FX_WCHAR* pwsDefValue) const { |
549 int32_t iCount = m_Attributes.GetSize(); | 572 int32_t iCount = m_Attributes.GetSize(); |
550 for (int32_t i = 0; i < iCount; i += 2) { | 573 for (int32_t i = 0; i < iCount; i += 2) { |
551 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 574 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
552 wsAttriValue = m_Attributes[i + 1]; | 575 wsAttriValue = m_Attributes[i + 1]; |
553 return; | 576 return; |
554 } | 577 } |
555 } | 578 } |
556 wsAttriValue = pwsDefValue; | 579 wsAttriValue = pwsDefValue; |
557 } | 580 } |
581 | |
558 void CFDE_XMLInstruction::SetString(const CFX_WideString& wsAttriName, | 582 void CFDE_XMLInstruction::SetString(const CFX_WideString& wsAttriName, |
559 const CFX_WideString& wsAttriValue) { | 583 const CFX_WideString& wsAttriValue) { |
560 ASSERT(wsAttriName.GetLength() > 0); | 584 ASSERT(wsAttriName.GetLength() > 0); |
561 int32_t iCount = m_Attributes.GetSize(); | 585 int32_t iCount = m_Attributes.GetSize(); |
562 for (int32_t i = 0; i < iCount; i += 2) { | 586 for (int32_t i = 0; i < iCount; i += 2) { |
563 if (m_Attributes[i].Compare(wsAttriName) == 0) { | 587 if (m_Attributes[i].Compare(wsAttriName) == 0) { |
564 m_Attributes[i] = wsAttriName; | 588 m_Attributes[i] = wsAttriName; |
565 m_Attributes[i + 1] = wsAttriValue; | 589 m_Attributes[i + 1] = wsAttriValue; |
566 return; | 590 return; |
567 } | 591 } |
568 } | 592 } |
569 m_Attributes.Add(wsAttriName); | 593 m_Attributes.Add(wsAttriName); |
570 m_Attributes.Add(wsAttriValue); | 594 m_Attributes.Add(wsAttriValue); |
571 } | 595 } |
572 int32_t CFDE_XMLInstruction::GetInteger(const FX_WCHAR* pwsAttriName, | 596 int32_t CFDE_XMLInstruction::GetInteger(const FX_WCHAR* pwsAttriName, |
573 int32_t iDefValue) const { | 597 int32_t iDefValue) const { |
574 int32_t iCount = m_Attributes.GetSize(); | 598 int32_t iCount = m_Attributes.GetSize(); |
575 for (int32_t i = 0; i < iCount; i += 2) { | 599 for (int32_t i = 0; i < iCount; i += 2) { |
576 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 600 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
577 return FXSYS_wtoi(m_Attributes[i + 1].c_str()); | 601 return FXSYS_wtoi(m_Attributes[i + 1].c_str()); |
578 } | 602 } |
579 } | 603 } |
580 return iDefValue; | 604 return iDefValue; |
581 } | 605 } |
606 | |
582 void CFDE_XMLInstruction::SetInteger(const FX_WCHAR* pwsAttriName, | 607 void CFDE_XMLInstruction::SetInteger(const FX_WCHAR* pwsAttriName, |
583 int32_t iAttriValue) { | 608 int32_t iAttriValue) { |
584 CFX_WideString wsValue; | 609 CFX_WideString wsValue; |
585 wsValue.Format(L"%d", iAttriValue); | 610 wsValue.Format(L"%d", iAttriValue); |
586 SetString(pwsAttriName, wsValue); | 611 SetString(pwsAttriName, wsValue); |
587 } | 612 } |
588 FX_FLOAT CFDE_XMLInstruction::GetFloat(const FX_WCHAR* pwsAttriName, | 613 FX_FLOAT CFDE_XMLInstruction::GetFloat(const FX_WCHAR* pwsAttriName, |
589 FX_FLOAT fDefValue) const { | 614 FX_FLOAT fDefValue) const { |
590 int32_t iCount = m_Attributes.GetSize(); | 615 int32_t iCount = m_Attributes.GetSize(); |
591 for (int32_t i = 0; i < iCount; i += 2) { | 616 for (int32_t i = 0; i < iCount; i += 2) { |
592 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 617 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
593 return FX_wcstof(m_Attributes[i + 1].c_str()); | 618 return FX_wcstof(m_Attributes[i + 1].c_str()); |
594 } | 619 } |
595 } | 620 } |
596 return fDefValue; | 621 return fDefValue; |
597 } | 622 } |
623 | |
598 void CFDE_XMLInstruction::SetFloat(const FX_WCHAR* pwsAttriName, | 624 void CFDE_XMLInstruction::SetFloat(const FX_WCHAR* pwsAttriName, |
599 FX_FLOAT fAttriValue) { | 625 FX_FLOAT fAttriValue) { |
600 CFX_WideString wsValue; | 626 CFX_WideString wsValue; |
601 wsValue.Format(L"%f", fAttriValue); | 627 wsValue.Format(L"%f", fAttriValue); |
602 SetString(pwsAttriName, wsValue); | 628 SetString(pwsAttriName, wsValue); |
603 } | 629 } |
630 | |
604 void CFDE_XMLInstruction::RemoveAttribute(const FX_WCHAR* pwsAttriName) { | 631 void CFDE_XMLInstruction::RemoveAttribute(const FX_WCHAR* pwsAttriName) { |
605 int32_t iCount = m_Attributes.GetSize(); | 632 int32_t iCount = m_Attributes.GetSize(); |
606 for (int32_t i = 0; i < iCount; i += 2) { | 633 for (int32_t i = 0; i < iCount; i += 2) { |
607 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 634 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
608 m_Attributes.RemoveAt(i + 1); | 635 m_Attributes.RemoveAt(i + 1); |
609 m_Attributes.RemoveAt(i); | 636 m_Attributes.RemoveAt(i); |
610 return; | 637 return; |
611 } | 638 } |
612 } | 639 } |
613 } | 640 } |
614 int32_t CFDE_XMLInstruction::CountData() const { | 641 int32_t CFDE_XMLInstruction::CountData() const { |
615 return m_TargetData.GetSize(); | 642 return m_TargetData.GetSize(); |
616 } | 643 } |
617 FX_BOOL CFDE_XMLInstruction::GetData(int32_t index, | 644 FX_BOOL CFDE_XMLInstruction::GetData(int32_t index, |
618 CFX_WideString& wsData) const { | 645 CFX_WideString& wsData) const { |
619 if (index < 0 || index >= m_TargetData.GetSize()) { | 646 if (index < 0 || index >= m_TargetData.GetSize()) { |
620 return FALSE; | 647 return FALSE; |
621 } | 648 } |
622 wsData = m_TargetData[index]; | 649 wsData = m_TargetData[index]; |
623 return TRUE; | 650 return TRUE; |
624 } | 651 } |
652 | |
625 void CFDE_XMLInstruction::AppendData(const CFX_WideString& wsData) { | 653 void CFDE_XMLInstruction::AppendData(const CFX_WideString& wsData) { |
626 m_TargetData.Add(wsData); | 654 m_TargetData.Add(wsData); |
627 } | 655 } |
656 | |
628 void CFDE_XMLInstruction::RemoveData(int32_t index) { | 657 void CFDE_XMLInstruction::RemoveData(int32_t index) { |
629 m_TargetData.RemoveAt(index); | 658 m_TargetData.RemoveAt(index); |
630 } | 659 } |
631 | 660 |
661 CFDE_XMLInstruction::~CFDE_XMLInstruction() {} | |
662 | |
632 CFDE_XMLElement::CFDE_XMLElement(const CFX_WideString& wsTag) | 663 CFDE_XMLElement::CFDE_XMLElement(const CFX_WideString& wsTag) |
633 : CFDE_XMLNode(), m_wsTag(wsTag), m_Attributes() { | 664 : CFDE_XMLNode(), m_wsTag(wsTag), m_Attributes() { |
634 ASSERT(m_wsTag.GetLength() > 0); | 665 ASSERT(m_wsTag.GetLength() > 0); |
635 } | 666 } |
636 CFDE_XMLElement::~CFDE_XMLElement() { | 667 CFDE_XMLElement::~CFDE_XMLElement() { |
637 m_Attributes.RemoveAll(); | 668 m_Attributes.RemoveAll(); |
638 } | 669 } |
670 | |
671 void CFDE_XMLElement::Release() { | |
672 delete this; | |
673 } | |
674 | |
675 FDE_XMLNODETYPE CFDE_XMLElement::GetType() const { | |
676 return FDE_XMLNODE_Element; | |
677 } | |
678 | |
639 CFDE_XMLNode* CFDE_XMLElement::Clone(FX_BOOL bRecursive) { | 679 CFDE_XMLNode* CFDE_XMLElement::Clone(FX_BOOL bRecursive) { |
640 CFDE_XMLElement* pClone = new CFDE_XMLElement(m_wsTag); | 680 CFDE_XMLElement* pClone = new CFDE_XMLElement(m_wsTag); |
641 if (!pClone) { | 681 if (!pClone) { |
642 return nullptr; | 682 return nullptr; |
643 } | 683 } |
644 pClone->m_Attributes.Copy(m_Attributes); | 684 pClone->m_Attributes.Copy(m_Attributes); |
645 if (bRecursive) { | 685 if (bRecursive) { |
646 CloneChildren(pClone); | 686 CloneChildren(pClone); |
647 } else { | 687 } else { |
648 CFX_WideString wsText; | 688 CFX_WideString wsText; |
649 CFDE_XMLNode* pChild = m_pChild; | 689 CFDE_XMLNode* pChild = m_pChild; |
650 while (pChild) { | 690 while (pChild) { |
651 switch (pChild->GetType()) { | 691 switch (pChild->GetType()) { |
652 case FDE_XMLNODE_Text: | 692 case FDE_XMLNODE_Text: |
653 wsText += ((CFDE_XMLText*)pChild)->m_wsText; | 693 wsText += ((CFDE_XMLText*)pChild)->m_wsText; |
654 break; | 694 break; |
655 default: | 695 default: |
656 break; | 696 break; |
657 } | 697 } |
658 pChild = pChild->m_pNext; | 698 pChild = pChild->m_pNext; |
659 } | 699 } |
660 pClone->SetTextData(wsText); | 700 pClone->SetTextData(wsText); |
661 } | 701 } |
662 return pClone; | 702 return pClone; |
663 } | 703 } |
704 | |
664 void CFDE_XMLElement::GetTagName(CFX_WideString& wsTag) const { | 705 void CFDE_XMLElement::GetTagName(CFX_WideString& wsTag) const { |
665 wsTag = m_wsTag; | 706 wsTag = m_wsTag; |
666 } | 707 } |
708 | |
667 void CFDE_XMLElement::GetLocalTagName(CFX_WideString& wsTag) const { | 709 void CFDE_XMLElement::GetLocalTagName(CFX_WideString& wsTag) const { |
668 FX_STRSIZE iFind = m_wsTag.Find(L':', 0); | 710 FX_STRSIZE iFind = m_wsTag.Find(L':', 0); |
669 if (iFind < 0) { | 711 if (iFind < 0) { |
670 wsTag = m_wsTag; | 712 wsTag = m_wsTag; |
671 } else { | 713 } else { |
672 wsTag = m_wsTag.Right(m_wsTag.GetLength() - iFind - 1); | 714 wsTag = m_wsTag.Right(m_wsTag.GetLength() - iFind - 1); |
673 } | 715 } |
674 } | 716 } |
717 | |
675 void CFDE_XMLElement::GetNamespacePrefix(CFX_WideString& wsPrefix) const { | 718 void CFDE_XMLElement::GetNamespacePrefix(CFX_WideString& wsPrefix) const { |
676 FX_STRSIZE iFind = m_wsTag.Find(L':', 0); | 719 FX_STRSIZE iFind = m_wsTag.Find(L':', 0); |
677 if (iFind < 0) { | 720 if (iFind < 0) { |
678 wsPrefix.clear(); | 721 wsPrefix.clear(); |
679 } else { | 722 } else { |
680 wsPrefix = m_wsTag.Left(iFind); | 723 wsPrefix = m_wsTag.Left(iFind); |
681 } | 724 } |
682 } | 725 } |
726 | |
683 void CFDE_XMLElement::GetNamespaceURI(CFX_WideString& wsNamespace) const { | 727 void CFDE_XMLElement::GetNamespaceURI(CFX_WideString& wsNamespace) const { |
684 CFX_WideString wsAttri(L"xmlns"), wsPrefix; | 728 CFX_WideString wsAttri(L"xmlns"), wsPrefix; |
685 GetNamespacePrefix(wsPrefix); | 729 GetNamespacePrefix(wsPrefix); |
686 if (wsPrefix.GetLength() > 0) { | 730 if (wsPrefix.GetLength() > 0) { |
687 wsAttri += L":"; | 731 wsAttri += L":"; |
688 wsAttri += wsPrefix; | 732 wsAttri += wsPrefix; |
689 } | 733 } |
690 wsNamespace.clear(); | 734 wsNamespace.clear(); |
691 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; | 735 CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; |
692 while (pNode) { | 736 while (pNode) { |
693 if (pNode->GetType() != FDE_XMLNODE_Element) { | 737 if (pNode->GetType() != FDE_XMLNODE_Element) { |
694 break; | 738 break; |
695 } | 739 } |
696 CFDE_XMLElement* pElement = (CFDE_XMLElement*)pNode; | 740 CFDE_XMLElement* pElement = (CFDE_XMLElement*)pNode; |
697 if (!pElement->HasAttribute(wsAttri.c_str())) { | 741 if (!pElement->HasAttribute(wsAttri.c_str())) { |
698 pNode = pNode->GetNodeItem(CFDE_XMLNode::Parent); | 742 pNode = pNode->GetNodeItem(CFDE_XMLNode::Parent); |
699 continue; | 743 continue; |
700 } | 744 } |
701 pElement->GetString(wsAttri.c_str(), wsNamespace); | 745 pElement->GetString(wsAttri.c_str(), wsNamespace); |
702 break; | 746 break; |
703 } | 747 } |
704 } | 748 } |
749 | |
705 int32_t CFDE_XMLElement::CountAttributes() const { | 750 int32_t CFDE_XMLElement::CountAttributes() const { |
706 return m_Attributes.GetSize() / 2; | 751 return m_Attributes.GetSize() / 2; |
707 } | 752 } |
708 FX_BOOL CFDE_XMLElement::GetAttribute(int32_t index, | 753 FX_BOOL CFDE_XMLElement::GetAttribute(int32_t index, |
709 CFX_WideString& wsAttriName, | 754 CFX_WideString& wsAttriName, |
710 CFX_WideString& wsAttriValue) const { | 755 CFX_WideString& wsAttriValue) const { |
711 int32_t iCount = m_Attributes.GetSize(); | 756 int32_t iCount = m_Attributes.GetSize(); |
712 ASSERT(index > -1 && index < iCount / 2); | 757 ASSERT(index > -1 && index < iCount / 2); |
713 for (int32_t i = 0; i < iCount; i += 2) { | 758 for (int32_t i = 0; i < iCount; i += 2) { |
714 if (index == 0) { | 759 if (index == 0) { |
715 wsAttriName = m_Attributes[i]; | 760 wsAttriName = m_Attributes[i]; |
716 wsAttriValue = m_Attributes[i + 1]; | 761 wsAttriValue = m_Attributes[i + 1]; |
717 return TRUE; | 762 return TRUE; |
718 } | 763 } |
719 index--; | 764 index--; |
720 } | 765 } |
721 return FALSE; | 766 return FALSE; |
722 } | 767 } |
768 | |
723 FX_BOOL CFDE_XMLElement::HasAttribute(const FX_WCHAR* pwsAttriName) const { | 769 FX_BOOL CFDE_XMLElement::HasAttribute(const FX_WCHAR* pwsAttriName) const { |
724 int32_t iCount = m_Attributes.GetSize(); | 770 int32_t iCount = m_Attributes.GetSize(); |
725 for (int32_t i = 0; i < iCount; i += 2) { | 771 for (int32_t i = 0; i < iCount; i += 2) { |
726 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 772 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
727 return TRUE; | 773 return TRUE; |
728 } | 774 } |
729 } | 775 } |
730 return FALSE; | 776 return FALSE; |
731 } | 777 } |
778 | |
732 void CFDE_XMLElement::GetString(const FX_WCHAR* pwsAttriName, | 779 void CFDE_XMLElement::GetString(const FX_WCHAR* pwsAttriName, |
733 CFX_WideString& wsAttriValue, | 780 CFX_WideString& wsAttriValue, |
734 const FX_WCHAR* pwsDefValue) const { | 781 const FX_WCHAR* pwsDefValue) const { |
735 int32_t iCount = m_Attributes.GetSize(); | 782 int32_t iCount = m_Attributes.GetSize(); |
736 for (int32_t i = 0; i < iCount; i += 2) { | 783 for (int32_t i = 0; i < iCount; i += 2) { |
737 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 784 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
738 wsAttriValue = m_Attributes[i + 1]; | 785 wsAttriValue = m_Attributes[i + 1]; |
739 return; | 786 return; |
740 } | 787 } |
741 } | 788 } |
742 wsAttriValue = pwsDefValue; | 789 wsAttriValue = pwsDefValue; |
743 } | 790 } |
791 | |
744 void CFDE_XMLElement::SetString(const CFX_WideString& wsAttriName, | 792 void CFDE_XMLElement::SetString(const CFX_WideString& wsAttriName, |
745 const CFX_WideString& wsAttriValue) { | 793 const CFX_WideString& wsAttriValue) { |
746 ASSERT(wsAttriName.GetLength() > 0); | 794 ASSERT(wsAttriName.GetLength() > 0); |
747 int32_t iCount = m_Attributes.GetSize(); | 795 int32_t iCount = m_Attributes.GetSize(); |
748 for (int32_t i = 0; i < iCount; i += 2) { | 796 for (int32_t i = 0; i < iCount; i += 2) { |
749 if (m_Attributes[i].Compare(wsAttriName) == 0) { | 797 if (m_Attributes[i].Compare(wsAttriName) == 0) { |
750 m_Attributes[i] = wsAttriName; | 798 m_Attributes[i] = wsAttriName; |
751 m_Attributes[i + 1] = wsAttriValue; | 799 m_Attributes[i + 1] = wsAttriValue; |
752 return; | 800 return; |
753 } | 801 } |
754 } | 802 } |
755 m_Attributes.Add(wsAttriName); | 803 m_Attributes.Add(wsAttriName); |
756 m_Attributes.Add(wsAttriValue); | 804 m_Attributes.Add(wsAttriValue); |
757 } | 805 } |
758 int32_t CFDE_XMLElement::GetInteger(const FX_WCHAR* pwsAttriName, | 806 int32_t CFDE_XMLElement::GetInteger(const FX_WCHAR* pwsAttriName, |
759 int32_t iDefValue) const { | 807 int32_t iDefValue) const { |
760 int32_t iCount = m_Attributes.GetSize(); | 808 int32_t iCount = m_Attributes.GetSize(); |
761 for (int32_t i = 0; i < iCount; i += 2) { | 809 for (int32_t i = 0; i < iCount; i += 2) { |
762 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 810 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
763 return FXSYS_wtoi(m_Attributes[i + 1].c_str()); | 811 return FXSYS_wtoi(m_Attributes[i + 1].c_str()); |
764 } | 812 } |
765 } | 813 } |
766 return iDefValue; | 814 return iDefValue; |
767 } | 815 } |
816 | |
768 void CFDE_XMLElement::SetInteger(const FX_WCHAR* pwsAttriName, | 817 void CFDE_XMLElement::SetInteger(const FX_WCHAR* pwsAttriName, |
769 int32_t iAttriValue) { | 818 int32_t iAttriValue) { |
770 CFX_WideString wsValue; | 819 CFX_WideString wsValue; |
771 wsValue.Format(L"%d", iAttriValue); | 820 wsValue.Format(L"%d", iAttriValue); |
772 SetString(pwsAttriName, wsValue); | 821 SetString(pwsAttriName, wsValue); |
773 } | 822 } |
823 | |
774 FX_FLOAT CFDE_XMLElement::GetFloat(const FX_WCHAR* pwsAttriName, | 824 FX_FLOAT CFDE_XMLElement::GetFloat(const FX_WCHAR* pwsAttriName, |
775 FX_FLOAT fDefValue) const { | 825 FX_FLOAT fDefValue) const { |
776 int32_t iCount = m_Attributes.GetSize(); | 826 int32_t iCount = m_Attributes.GetSize(); |
777 for (int32_t i = 0; i < iCount; i += 2) { | 827 for (int32_t i = 0; i < iCount; i += 2) { |
778 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 828 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
779 return FX_wcstof(m_Attributes[i + 1].c_str()); | 829 return FX_wcstof(m_Attributes[i + 1].c_str()); |
780 } | 830 } |
781 } | 831 } |
782 return fDefValue; | 832 return fDefValue; |
783 } | 833 } |
834 | |
784 void CFDE_XMLElement::SetFloat(const FX_WCHAR* pwsAttriName, | 835 void CFDE_XMLElement::SetFloat(const FX_WCHAR* pwsAttriName, |
785 FX_FLOAT fAttriValue) { | 836 FX_FLOAT fAttriValue) { |
786 CFX_WideString wsValue; | 837 CFX_WideString wsValue; |
787 wsValue.Format(L"%f", fAttriValue); | 838 wsValue.Format(L"%f", fAttriValue); |
788 SetString(pwsAttriName, wsValue); | 839 SetString(pwsAttriName, wsValue); |
789 } | 840 } |
841 | |
790 void CFDE_XMLElement::RemoveAttribute(const FX_WCHAR* pwsAttriName) { | 842 void CFDE_XMLElement::RemoveAttribute(const FX_WCHAR* pwsAttriName) { |
791 int32_t iCount = m_Attributes.GetSize(); | 843 int32_t iCount = m_Attributes.GetSize(); |
792 for (int32_t i = 0; i < iCount; i += 2) { | 844 for (int32_t i = 0; i < iCount; i += 2) { |
793 if (m_Attributes[i].Compare(pwsAttriName) == 0) { | 845 if (m_Attributes[i].Compare(pwsAttriName) == 0) { |
794 m_Attributes.RemoveAt(i + 1); | 846 m_Attributes.RemoveAt(i + 1); |
795 m_Attributes.RemoveAt(i); | 847 m_Attributes.RemoveAt(i); |
796 return; | 848 return; |
797 } | 849 } |
798 } | 850 } |
799 } | 851 } |
852 | |
800 void CFDE_XMLElement::GetTextData(CFX_WideString& wsText) const { | 853 void CFDE_XMLElement::GetTextData(CFX_WideString& wsText) const { |
801 CFX_WideTextBuf buffer; | 854 CFX_WideTextBuf buffer; |
802 CFDE_XMLNode* pChild = m_pChild; | 855 CFDE_XMLNode* pChild = m_pChild; |
803 while (pChild) { | 856 while (pChild) { |
804 switch (pChild->GetType()) { | 857 switch (pChild->GetType()) { |
805 case FDE_XMLNODE_Text: | 858 case FDE_XMLNODE_Text: |
806 buffer << ((CFDE_XMLText*)pChild)->m_wsText; | 859 buffer << ((CFDE_XMLText*)pChild)->m_wsText; |
807 break; | 860 break; |
808 case FDE_XMLNODE_CharData: | 861 case FDE_XMLNODE_CharData: |
809 buffer << ((CFDE_XMLCharData*)pChild)->m_wsCharData; | 862 buffer << ((CFDE_XMLCharData*)pChild)->m_wsCharData; |
810 break; | 863 break; |
811 default: | 864 default: |
812 break; | 865 break; |
813 } | 866 } |
814 pChild = pChild->m_pNext; | 867 pChild = pChild->m_pNext; |
815 } | 868 } |
816 wsText = buffer.AsStringC(); | 869 wsText = buffer.AsStringC(); |
817 } | 870 } |
871 | |
818 void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) { | 872 void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) { |
819 if (wsText.GetLength() < 1) { | 873 if (wsText.GetLength() < 1) { |
820 return; | 874 return; |
821 } | 875 } |
822 InsertChildNode(new CFDE_XMLText(wsText)); | 876 InsertChildNode(new CFDE_XMLText(wsText)); |
823 } | 877 } |
824 CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) | 878 CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) |
825 : CFDE_XMLNode(), m_wsText(wsText) {} | 879 : CFDE_XMLNode(), m_wsText(wsText) {} |
880 | |
881 void CFDE_XMLText::Release() { | |
882 delete this; | |
883 } | |
884 FDE_XMLNODETYPE CFDE_XMLText::GetType() const { | |
885 return FDE_XMLNODE_Text; | |
886 } | |
Lei Zhang
2016/06/17 03:10:05
blank line after
Wei Li
2016/06/17 21:47:44
Done.
| |
826 CFDE_XMLNode* CFDE_XMLText::Clone(FX_BOOL bRecursive) { | 887 CFDE_XMLNode* CFDE_XMLText::Clone(FX_BOOL bRecursive) { |
827 CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText); | 888 CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText); |
828 return pClone; | 889 return pClone; |
829 } | 890 } |
830 | 891 |
892 void CFDE_XMLText::GetText(CFX_WideString& wsText) const { | |
893 wsText = m_wsText; | |
894 } | |
895 | |
896 void CFDE_XMLText::SetText(const CFX_WideString& wsText) { | |
897 m_wsText = wsText; | |
898 } | |
899 | |
900 CFDE_XMLText::~CFDE_XMLText() {} | |
901 | |
831 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) | 902 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) |
832 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} | 903 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} |
904 | |
905 void CFDE_XMLCharData::Release() { | |
906 delete this; | |
907 } | |
908 FDE_XMLNODETYPE CFDE_XMLCharData::GetType() const { | |
909 return FDE_XMLNODE_CharData; | |
910 } | |
833 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { | 911 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { |
834 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); | 912 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); |
835 return pClone; | 913 return pClone; |
836 } | 914 } |
837 | 915 |
916 void CFDE_XMLCharData::GetCharData(CFX_WideString& wsCharData) const { | |
917 wsCharData = m_wsCharData; | |
918 } | |
919 | |
920 void CFDE_XMLCharData::SetCharData(const CFX_WideString& wsCData) { | |
921 m_wsCharData = wsCData; | |
922 } | |
923 | |
924 CFDE_XMLCharData::~CFDE_XMLCharData() {} | |
925 | |
838 CFDE_XMLDoc::CFDE_XMLDoc() | 926 CFDE_XMLDoc::CFDE_XMLDoc() |
839 : m_pRoot(nullptr), m_pSyntaxParser(nullptr), m_pXMLParser(nullptr) { | 927 : m_pRoot(nullptr), m_pSyntaxParser(nullptr), m_pXMLParser(nullptr) { |
840 Reset(TRUE); | 928 Reset(TRUE); |
841 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); | 929 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); |
842 m_pRoot->InsertChildNode(pXML); | 930 m_pRoot->InsertChildNode(pXML); |
843 } | 931 } |
844 CFDE_XMLDoc::~CFDE_XMLDoc() { | 932 CFDE_XMLDoc::~CFDE_XMLDoc() { |
845 Reset(FALSE); | 933 Reset(FALSE); |
846 } | 934 } |
935 | |
847 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { | 936 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { |
848 m_iStatus = 0; | 937 m_iStatus = 0; |
849 m_pStream = nullptr; | 938 m_pStream = nullptr; |
850 if (bInitRoot) { | 939 if (bInitRoot) { |
851 if (m_pRoot) | 940 if (m_pRoot) |
852 m_pRoot->DeleteChildren(); | 941 m_pRoot->DeleteChildren(); |
853 else | 942 else |
854 m_pRoot = new CFDE_XMLNode; | 943 m_pRoot = new CFDE_XMLNode; |
855 } else { | 944 } else { |
856 if (m_pRoot) { | 945 if (m_pRoot) { |
857 m_pRoot->Release(); | 946 m_pRoot->Release(); |
858 m_pRoot = nullptr; | 947 m_pRoot = nullptr; |
859 } | 948 } |
860 } | 949 } |
861 ReleaseParser(); | 950 ReleaseParser(); |
862 } | 951 } |
952 | |
863 void CFDE_XMLDoc::ReleaseParser() { | 953 void CFDE_XMLDoc::ReleaseParser() { |
864 if (m_pXMLParser) { | 954 if (m_pXMLParser) { |
865 m_pXMLParser->Release(); | 955 m_pXMLParser->Release(); |
866 m_pXMLParser = nullptr; | 956 m_pXMLParser = nullptr; |
867 } | 957 } |
868 if (m_pSyntaxParser) { | 958 if (m_pSyntaxParser) { |
869 m_pSyntaxParser->Release(); | 959 m_pSyntaxParser->Release(); |
870 m_pSyntaxParser = nullptr; | 960 m_pSyntaxParser = nullptr; |
871 } | 961 } |
872 } | 962 } |
873 | 963 |
964 void CFDE_XMLDoc::Release() { | |
965 delete this; | |
966 } | |
967 | |
874 FX_BOOL CFDE_XMLDoc::LoadXML(CFDE_XMLParser* pXMLParser) { | 968 FX_BOOL CFDE_XMLDoc::LoadXML(CFDE_XMLParser* pXMLParser) { |
875 if (!pXMLParser) | 969 if (!pXMLParser) |
876 return FALSE; | 970 return FALSE; |
877 | 971 |
878 Reset(TRUE); | 972 Reset(TRUE); |
879 m_pXMLParser = pXMLParser; | 973 m_pXMLParser = pXMLParser; |
880 return !!m_pXMLParser; | 974 return !!m_pXMLParser; |
881 } | 975 } |
882 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { | 976 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { |
883 if (m_iStatus >= 100) | 977 if (m_iStatus >= 100) |
884 return m_iStatus; | 978 return m_iStatus; |
885 return m_iStatus = m_pXMLParser->DoParser(pPause); | 979 return m_iStatus = m_pXMLParser->DoParser(pPause); |
886 } | 980 } |
981 | |
887 void CFDE_XMLDoc::CloseXML() { | 982 void CFDE_XMLDoc::CloseXML() { |
888 ReleaseParser(); | 983 ReleaseParser(); |
889 } | 984 } |
985 | |
986 CFDE_XMLNode* CFDE_XMLDoc::GetRoot() const { | |
987 return m_pRoot; | |
988 } | |
989 | |
890 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { | 990 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { |
891 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; | 991 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; |
892 switch (pNode->GetType()) { | 992 switch (pNode->GetType()) { |
893 case FDE_XMLNODE_Instruction: { | 993 case FDE_XMLNODE_Instruction: { |
894 CFX_WideString ws; | 994 CFX_WideString ws; |
895 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; | 995 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; |
896 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { | 996 if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { |
897 ws = L"<?xml version=\"1.0\" encoding=\""; | 997 ws = L"<?xml version=\"1.0\" encoding=\""; |
898 uint16_t wCodePage = pXMLStream->GetCodePage(); | 998 uint16_t wCodePage = pXMLStream->GetCodePage(); |
899 if (wCodePage == FX_CODEPAGE_UTF16LE) { | 999 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; | 1089 ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; |
990 ws += L"]]>"; | 1090 ws += L"]]>"; |
991 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); | 1091 pXMLStream->WriteString(ws.c_str(), ws.GetLength()); |
992 } break; | 1092 } break; |
993 case FDE_XMLNODE_Unknown: | 1093 case FDE_XMLNODE_Unknown: |
994 break; | 1094 break; |
995 default: | 1095 default: |
996 break; | 1096 break; |
997 } | 1097 } |
998 } | 1098 } |
1099 | |
999 void CFDE_XMLDoc::SaveXML(IFX_Stream* pXMLStream, FX_BOOL bSaveBOM) { | 1100 void CFDE_XMLDoc::SaveXML(IFX_Stream* pXMLStream, FX_BOOL bSaveBOM) { |
1000 if (!pXMLStream || pXMLStream == m_pStream) { | 1101 if (!pXMLStream || pXMLStream == m_pStream) { |
1001 m_pStream->Seek(FX_STREAMSEEK_Begin, 0); | 1102 m_pStream->Seek(FX_STREAMSEEK_Begin, 0); |
1002 pXMLStream = m_pStream; | 1103 pXMLStream = m_pStream; |
1003 } | 1104 } |
1004 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Text) != 0); | 1105 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Text) != 0); |
1005 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 1106 ASSERT((pXMLStream->GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
1006 uint16_t wCodePage = pXMLStream->GetCodePage(); | 1107 uint16_t wCodePage = pXMLStream->GetCodePage(); |
1007 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && | 1108 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && |
1008 wCodePage != FX_CODEPAGE_UTF8) { | 1109 wCodePage != FX_CODEPAGE_UTF8) { |
(...skipping 12 matching lines...) Expand all Loading... | |
1021 int32_t iPos = pXMLStream->GetPosition(); | 1122 int32_t iPos = pXMLStream->GetPosition(); |
1022 pXMLStream->SetLength(iPos); | 1123 pXMLStream->SetLength(iPos); |
1023 } | 1124 } |
1024 } | 1125 } |
1025 | 1126 |
1026 CFDE_BlockBuffer::CFDE_BlockBuffer(int32_t iAllocStep) | 1127 CFDE_BlockBuffer::CFDE_BlockBuffer(int32_t iAllocStep) |
1027 : m_iDataLength(0), | 1128 : m_iDataLength(0), |
1028 m_iBufferSize(0), | 1129 m_iBufferSize(0), |
1029 m_iAllocStep(iAllocStep), | 1130 m_iAllocStep(iAllocStep), |
1030 m_iStartPosition(0) {} | 1131 m_iStartPosition(0) {} |
1132 | |
1031 CFDE_BlockBuffer::~CFDE_BlockBuffer() { | 1133 CFDE_BlockBuffer::~CFDE_BlockBuffer() { |
1032 ClearBuffer(); | 1134 ClearBuffer(); |
1033 } | 1135 } |
1136 | |
1034 FX_WCHAR* CFDE_BlockBuffer::GetAvailableBlock(int32_t& iIndexInBlock) { | 1137 FX_WCHAR* CFDE_BlockBuffer::GetAvailableBlock(int32_t& iIndexInBlock) { |
1035 iIndexInBlock = 0; | 1138 iIndexInBlock = 0; |
1036 if (!m_BlockArray.GetSize()) { | 1139 if (!m_BlockArray.GetSize()) { |
1037 return nullptr; | 1140 return nullptr; |
1038 } | 1141 } |
1039 int32_t iRealIndex = m_iStartPosition + m_iDataLength; | 1142 int32_t iRealIndex = m_iStartPosition + m_iDataLength; |
1040 if (iRealIndex == m_iBufferSize) { | 1143 if (iRealIndex == m_iBufferSize) { |
1041 FX_WCHAR* pBlock = FX_Alloc(FX_WCHAR, m_iAllocStep); | 1144 FX_WCHAR* pBlock = FX_Alloc(FX_WCHAR, m_iAllocStep); |
1042 m_BlockArray.Add(pBlock); | 1145 m_BlockArray.Add(pBlock); |
1043 m_iBufferSize += m_iAllocStep; | 1146 m_iBufferSize += m_iAllocStep; |
1044 return pBlock; | 1147 return pBlock; |
1045 } | 1148 } |
1046 iIndexInBlock = iRealIndex % m_iAllocStep; | 1149 iIndexInBlock = iRealIndex % m_iAllocStep; |
1047 return m_BlockArray[iRealIndex / m_iAllocStep]; | 1150 return m_BlockArray[iRealIndex / m_iAllocStep]; |
1048 } | 1151 } |
1152 | |
1049 FX_BOOL CFDE_BlockBuffer::InitBuffer(int32_t iBufferSize) { | 1153 FX_BOOL CFDE_BlockBuffer::InitBuffer(int32_t iBufferSize) { |
1050 ClearBuffer(); | 1154 ClearBuffer(); |
1051 int32_t iNumOfBlock = (iBufferSize - 1) / m_iAllocStep + 1; | 1155 int32_t iNumOfBlock = (iBufferSize - 1) / m_iAllocStep + 1; |
1052 for (int32_t i = 0; i < iNumOfBlock; i++) { | 1156 for (int32_t i = 0; i < iNumOfBlock; i++) { |
1053 m_BlockArray.Add(FX_Alloc(FX_WCHAR, m_iAllocStep)); | 1157 m_BlockArray.Add(FX_Alloc(FX_WCHAR, m_iAllocStep)); |
1054 } | 1158 } |
1055 m_iBufferSize = iNumOfBlock * m_iAllocStep; | 1159 m_iBufferSize = iNumOfBlock * m_iAllocStep; |
1056 return TRUE; | 1160 return TRUE; |
1057 } | 1161 } |
1162 | |
1058 void CFDE_BlockBuffer::SetTextChar(int32_t iIndex, FX_WCHAR ch) { | 1163 void CFDE_BlockBuffer::SetTextChar(int32_t iIndex, FX_WCHAR ch) { |
1059 if (iIndex < 0) { | 1164 if (iIndex < 0) { |
1060 return; | 1165 return; |
1061 } | 1166 } |
1062 int32_t iRealIndex = m_iStartPosition + iIndex; | 1167 int32_t iRealIndex = m_iStartPosition + iIndex; |
1063 int32_t iBlockIndex = iRealIndex / m_iAllocStep; | 1168 int32_t iBlockIndex = iRealIndex / m_iAllocStep; |
1064 int32_t iInnerIndex = iRealIndex % m_iAllocStep; | 1169 int32_t iInnerIndex = iRealIndex % m_iAllocStep; |
1065 int32_t iBlockSize = m_BlockArray.GetSize(); | 1170 int32_t iBlockSize = m_BlockArray.GetSize(); |
1066 if (iBlockIndex >= iBlockSize) { | 1171 if (iBlockIndex >= iBlockSize) { |
1067 int32_t iNewBlocks = iBlockIndex - iBlockSize + 1; | 1172 int32_t iNewBlocks = iBlockIndex - iBlockSize + 1; |
(...skipping 18 matching lines...) Expand all Loading... | |
1086 return 0; | 1191 return 0; |
1087 } | 1192 } |
1088 if (bDirection) { | 1193 if (bDirection) { |
1089 m_iStartPosition += iCount; | 1194 m_iStartPosition += iCount; |
1090 m_iDataLength -= iCount; | 1195 m_iDataLength -= iCount; |
1091 } else { | 1196 } else { |
1092 m_iDataLength -= iCount; | 1197 m_iDataLength -= iCount; |
1093 } | 1198 } |
1094 return m_iDataLength; | 1199 return m_iDataLength; |
1095 } | 1200 } |
1201 | |
1096 void CFDE_BlockBuffer::GetTextData(CFX_WideString& wsTextData, | 1202 void CFDE_BlockBuffer::GetTextData(CFX_WideString& wsTextData, |
1097 int32_t iStart, | 1203 int32_t iStart, |
1098 int32_t iLength) const { | 1204 int32_t iLength) const { |
1099 wsTextData.clear(); | 1205 wsTextData.clear(); |
1100 int32_t iMaybeDataLength = m_iBufferSize - 1 - m_iStartPosition; | 1206 int32_t iMaybeDataLength = m_iBufferSize - 1 - m_iStartPosition; |
1101 if (iStart < 0 || iStart > iMaybeDataLength) { | 1207 if (iStart < 0 || iStart > iMaybeDataLength) { |
1102 return; | 1208 return; |
1103 } | 1209 } |
1104 if (iLength == -1 || iLength > iMaybeDataLength) { | 1210 if (iLength == -1 || iLength > iMaybeDataLength) { |
1105 iLength = iMaybeDataLength; | 1211 iLength = iMaybeDataLength; |
(...skipping 22 matching lines...) Expand all Loading... | |
1128 if (i == iEndBlockIndex) { | 1234 if (i == iEndBlockIndex) { |
1129 iCopyLength -= ((m_iAllocStep - 1) - iEndInnerIndex); | 1235 iCopyLength -= ((m_iAllocStep - 1) - iEndInnerIndex); |
1130 } | 1236 } |
1131 FX_WCHAR* pBlockBuf = m_BlockArray[i]; | 1237 FX_WCHAR* pBlockBuf = m_BlockArray[i]; |
1132 FXSYS_memcpy(pBuf + iPointer, pBlockBuf + iBufferPointer, | 1238 FXSYS_memcpy(pBuf + iPointer, pBlockBuf + iBufferPointer, |
1133 iCopyLength * sizeof(FX_WCHAR)); | 1239 iCopyLength * sizeof(FX_WCHAR)); |
1134 iPointer += iCopyLength; | 1240 iPointer += iCopyLength; |
1135 } | 1241 } |
1136 wsTextData.ReleaseBuffer(iLength); | 1242 wsTextData.ReleaseBuffer(iLength); |
1137 } | 1243 } |
1244 | |
1138 void CFDE_BlockBuffer::TextDataIndex2BufIndex(const int32_t iIndex, | 1245 void CFDE_BlockBuffer::TextDataIndex2BufIndex(const int32_t iIndex, |
1139 int32_t& iBlockIndex, | 1246 int32_t& iBlockIndex, |
1140 int32_t& iInnerIndex) const { | 1247 int32_t& iInnerIndex) const { |
1141 ASSERT(iIndex >= 0); | 1248 ASSERT(iIndex >= 0); |
1142 int32_t iRealIndex = m_iStartPosition + iIndex; | 1249 int32_t iRealIndex = m_iStartPosition + iIndex; |
1143 iBlockIndex = iRealIndex / m_iAllocStep; | 1250 iBlockIndex = iRealIndex / m_iAllocStep; |
1144 iInnerIndex = iRealIndex % m_iAllocStep; | 1251 iInnerIndex = iRealIndex % m_iAllocStep; |
1145 } | 1252 } |
1253 | |
1146 void CFDE_BlockBuffer::ClearBuffer() { | 1254 void CFDE_BlockBuffer::ClearBuffer() { |
1147 m_iBufferSize = 0; | 1255 m_iBufferSize = 0; |
1148 int32_t iSize = m_BlockArray.GetSize(); | 1256 int32_t iSize = m_BlockArray.GetSize(); |
1149 for (int32_t i = 0; i < iSize; i++) { | 1257 for (int32_t i = 0; i < iSize; i++) { |
1150 FX_Free(m_BlockArray[i]); | 1258 FX_Free(m_BlockArray[i]); |
1151 } | 1259 } |
1152 m_BlockArray.RemoveAll(); | 1260 m_BlockArray.RemoveAll(); |
1153 } | 1261 } |
1154 | 1262 |
1155 CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser() | 1263 CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser() |
(...skipping 16 matching lines...) Expand all Loading... | |
1172 m_iIndexInBlock(0), | 1280 m_iIndexInBlock(0), |
1173 m_iTextDataLength(0), | 1281 m_iTextDataLength(0), |
1174 m_syntaxParserResult(FDE_XmlSyntaxResult::None), | 1282 m_syntaxParserResult(FDE_XmlSyntaxResult::None), |
1175 m_syntaxParserState(FDE_XmlSyntaxState::Text), | 1283 m_syntaxParserState(FDE_XmlSyntaxState::Text), |
1176 m_wQuotationMark(0), | 1284 m_wQuotationMark(0), |
1177 m_iEntityStart(-1), | 1285 m_iEntityStart(-1), |
1178 m_SkipStack(16) { | 1286 m_SkipStack(16) { |
1179 m_CurNode.iNodeNum = -1; | 1287 m_CurNode.iNodeNum = -1; |
1180 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; | 1288 m_CurNode.eNodeType = FDE_XMLNODE_Unknown; |
1181 } | 1289 } |
1290 | |
1182 void CFDE_XMLSyntaxParser::Init(IFX_Stream* pStream, | 1291 void CFDE_XMLSyntaxParser::Init(IFX_Stream* pStream, |
1183 int32_t iXMLPlaneSize, | 1292 int32_t iXMLPlaneSize, |
1184 int32_t iTextDataSize) { | 1293 int32_t iTextDataSize) { |
1185 ASSERT(!m_pStream && !m_pBuffer); | 1294 ASSERT(!m_pStream && !m_pBuffer); |
1186 ASSERT(pStream && iXMLPlaneSize > 0); | 1295 ASSERT(pStream && iXMLPlaneSize > 0); |
1187 int32_t iStreamLength = pStream->GetLength(); | 1296 int32_t iStreamLength = pStream->GetLength(); |
1188 ASSERT(iStreamLength > 0); | 1297 ASSERT(iStreamLength > 0); |
1189 m_pStream = pStream; | 1298 m_pStream = pStream; |
1190 m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength); | 1299 m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength); |
1191 uint8_t bom[4]; | 1300 uint8_t bom[4]; |
(...skipping 603 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 |