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 "core/fxcrt/xml_int.h" | 7 #include "core/fxcrt/xml_int.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 if (m_pBuffer[m_dwIndex] != '=') { | 390 if (m_pBuffer[m_dwIndex] != '=') { |
391 break; | 391 break; |
392 } | 392 } |
393 m_dwIndex++; | 393 m_dwIndex++; |
394 SkipWhiteSpaces(); | 394 SkipWhiteSpaces(); |
395 if (IsEOF()) { | 395 if (IsEOF()) { |
396 break; | 396 break; |
397 } | 397 } |
398 CFX_WideString attr_value; | 398 CFX_WideString attr_value; |
399 GetAttrValue(attr_value); | 399 GetAttrValue(attr_value); |
400 pElement->m_AttrMap.SetAt(attr_space.AsStringC(), attr_name.AsStringC(), | 400 pElement->m_AttrMap.SetAt(attr_space, attr_name, attr_value); |
401 attr_value.AsStringC()); | |
402 } | 401 } |
403 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 402 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
404 if (m_dwIndex < m_dwBufferSize || IsEOF()) { | 403 if (m_dwIndex < m_dwBufferSize || IsEOF()) { |
405 break; | 404 break; |
406 } | 405 } |
407 } while (ReadNextBlock()); | 406 } while (ReadNextBlock()); |
408 SkipWhiteSpaces(); | 407 SkipWhiteSpaces(); |
409 if (IsEOF()) { | 408 if (IsEOF()) { |
410 return pElement; | 409 return pElement; |
411 } | 410 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 589 } |
591 CFX_ByteString CXML_Element::GetTagName(FX_BOOL bQualified) const { | 590 CFX_ByteString CXML_Element::GetTagName(FX_BOOL bQualified) const { |
592 if (!bQualified || m_QSpaceName.IsEmpty()) { | 591 if (!bQualified || m_QSpaceName.IsEmpty()) { |
593 return m_TagName; | 592 return m_TagName; |
594 } | 593 } |
595 CFX_ByteString bsTag = m_QSpaceName; | 594 CFX_ByteString bsTag = m_QSpaceName; |
596 bsTag += ":"; | 595 bsTag += ":"; |
597 bsTag += m_TagName; | 596 bsTag += m_TagName; |
598 return bsTag; | 597 return bsTag; |
599 } | 598 } |
| 599 |
600 CFX_ByteString CXML_Element::GetNamespace(FX_BOOL bQualified) const { | 600 CFX_ByteString CXML_Element::GetNamespace(FX_BOOL bQualified) const { |
601 if (bQualified) { | 601 return bQualified ? m_QSpaceName : GetNamespaceURI(m_QSpaceName); |
602 return m_QSpaceName; | |
603 } | |
604 return GetNamespaceURI(m_QSpaceName.AsStringC()); | |
605 } | 602 } |
| 603 |
606 CFX_ByteString CXML_Element::GetNamespaceURI( | 604 CFX_ByteString CXML_Element::GetNamespaceURI( |
607 const CFX_ByteStringC& qName) const { | 605 const CFX_ByteString& qName) const { |
608 const CFX_WideString* pwsSpace; | 606 const CFX_WideString* pwsSpace; |
609 const CXML_Element* pElement = this; | 607 const CXML_Element* pElement = this; |
610 do { | 608 do { |
611 if (qName.IsEmpty()) { | 609 if (qName.IsEmpty()) { |
612 pwsSpace = pElement->m_AttrMap.Lookup("", "xmlns"); | 610 pwsSpace = pElement->m_AttrMap.Lookup("", "xmlns"); |
613 } else { | 611 } else { |
614 pwsSpace = pElement->m_AttrMap.Lookup("xmlns", qName); | 612 pwsSpace = pElement->m_AttrMap.Lookup("xmlns", qName); |
615 } | 613 } |
616 if (pwsSpace) { | 614 if (pwsSpace) { |
617 break; | 615 break; |
618 } | 616 } |
619 pElement = pElement->GetParent(); | 617 pElement = pElement->GetParent(); |
620 } while (pElement); | 618 } while (pElement); |
621 return pwsSpace ? FX_UTF8Encode(*pwsSpace) : CFX_ByteString(); | 619 return pwsSpace ? FX_UTF8Encode(*pwsSpace) : CFX_ByteString(); |
622 } | 620 } |
623 void CXML_Element::GetAttrByIndex(int index, | 621 void CXML_Element::GetAttrByIndex(int index, |
624 CFX_ByteString& space, | 622 CFX_ByteString& space, |
625 CFX_ByteString& name, | 623 CFX_ByteString& name, |
626 CFX_WideString& value) const { | 624 CFX_WideString& value) const { |
627 if (index < 0 || index >= m_AttrMap.GetSize()) { | 625 if (index < 0 || index >= m_AttrMap.GetSize()) { |
628 return; | 626 return; |
629 } | 627 } |
630 CXML_AttrItem& item = m_AttrMap.GetAt(index); | 628 CXML_AttrItem& item = m_AttrMap.GetAt(index); |
631 space = item.m_QSpaceName; | 629 space = item.m_QSpaceName; |
632 name = item.m_AttrName; | 630 name = item.m_AttrName; |
633 value = item.m_Value; | 631 value = item.m_Value; |
634 } | 632 } |
635 FX_BOOL CXML_Element::HasAttr(const CFX_ByteStringC& name) const { | 633 FX_BOOL CXML_Element::HasAttr(const CFX_ByteStringC& name) const { |
636 CFX_ByteStringC bsSpace, bsName; | 634 CFX_ByteStringC bsSpace; |
| 635 CFX_ByteStringC bsName; |
637 FX_XML_SplitQualifiedName(name, bsSpace, bsName); | 636 FX_XML_SplitQualifiedName(name, bsSpace, bsName); |
638 return !!m_AttrMap.Lookup(bsSpace, bsName); | 637 return !!m_AttrMap.Lookup(CFX_ByteString(bsSpace), CFX_ByteString(bsName)); |
639 } | 638 } |
640 FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& name, | 639 FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& name, |
641 CFX_WideString& attribute) const { | 640 CFX_WideString& attribute) const { |
642 CFX_ByteStringC bsSpace, bsName; | 641 CFX_ByteStringC bsSpace; |
| 642 CFX_ByteStringC bsName; |
643 FX_XML_SplitQualifiedName(name, bsSpace, bsName); | 643 FX_XML_SplitQualifiedName(name, bsSpace, bsName); |
644 return GetAttrValue(bsSpace, bsName, attribute); | 644 return GetAttrValue(bsSpace, bsName, attribute); |
645 } | 645 } |
646 FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& space, | 646 FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& space, |
647 const CFX_ByteStringC& name, | 647 const CFX_ByteStringC& name, |
648 CFX_WideString& attribute) const { | 648 CFX_WideString& attribute) const { |
649 const CFX_WideString* pValue = m_AttrMap.Lookup(space, name); | 649 const CFX_WideString* pValue = |
| 650 m_AttrMap.Lookup(CFX_ByteString(space), CFX_ByteString(name)); |
650 if (pValue) { | 651 if (pValue) { |
651 attribute = *pValue; | 652 attribute = *pValue; |
652 return TRUE; | 653 return TRUE; |
653 } | 654 } |
654 return FALSE; | 655 return FALSE; |
655 } | 656 } |
656 FX_BOOL CXML_Element::GetAttrInteger(const CFX_ByteStringC& name, | 657 FX_BOOL CXML_Element::GetAttrInteger(const CFX_ByteStringC& name, |
657 int& attribute) const { | 658 int& attribute) const { |
658 CFX_ByteStringC bsSpace, bsName; | 659 CFX_ByteStringC bsSpace; |
| 660 CFX_ByteStringC bsName; |
659 FX_XML_SplitQualifiedName(name, bsSpace, bsName); | 661 FX_XML_SplitQualifiedName(name, bsSpace, bsName); |
660 const CFX_WideString* pwsValue = m_AttrMap.Lookup(bsSpace, bsName); | 662 const CFX_WideString* pwsValue = |
| 663 m_AttrMap.Lookup(CFX_ByteString(bsSpace), CFX_ByteString(bsName)); |
661 if (pwsValue) { | 664 if (pwsValue) { |
662 attribute = pwsValue->GetInteger(); | 665 attribute = pwsValue->GetInteger(); |
663 return TRUE; | 666 return TRUE; |
664 } | 667 } |
665 return FALSE; | 668 return FALSE; |
666 } | 669 } |
667 FX_BOOL CXML_Element::GetAttrInteger(const CFX_ByteStringC& space, | 670 FX_BOOL CXML_Element::GetAttrInteger(const CFX_ByteStringC& space, |
668 const CFX_ByteStringC& name, | 671 const CFX_ByteStringC& name, |
669 int& attribute) const { | 672 int& attribute) const { |
670 const CFX_WideString* pwsValue = m_AttrMap.Lookup(space, name); | 673 const CFX_WideString* pwsValue = |
| 674 m_AttrMap.Lookup(CFX_ByteString(space), CFX_ByteString(name)); |
671 if (pwsValue) { | 675 if (pwsValue) { |
672 attribute = pwsValue->GetInteger(); | 676 attribute = pwsValue->GetInteger(); |
673 return TRUE; | 677 return TRUE; |
674 } | 678 } |
675 return FALSE; | 679 return FALSE; |
676 } | 680 } |
677 FX_BOOL CXML_Element::GetAttrFloat(const CFX_ByteStringC& name, | 681 FX_BOOL CXML_Element::GetAttrFloat(const CFX_ByteStringC& name, |
678 FX_FLOAT& attribute) const { | 682 FX_FLOAT& attribute) const { |
679 CFX_ByteStringC bsSpace, bsName; | 683 CFX_ByteStringC bsSpace, bsName; |
680 FX_XML_SplitQualifiedName(name, bsSpace, bsName); | 684 FX_XML_SplitQualifiedName(name, bsSpace, bsName); |
681 return GetAttrFloat(bsSpace, bsName, attribute); | 685 return GetAttrFloat(bsSpace, bsName, attribute); |
682 } | 686 } |
683 FX_BOOL CXML_Element::GetAttrFloat(const CFX_ByteStringC& space, | 687 FX_BOOL CXML_Element::GetAttrFloat(const CFX_ByteStringC& space, |
684 const CFX_ByteStringC& name, | 688 const CFX_ByteStringC& name, |
685 FX_FLOAT& attribute) const { | 689 FX_FLOAT& attribute) const { |
686 const CFX_WideString* pValue = m_AttrMap.Lookup(space, name); | 690 const CFX_WideString* pValue = |
| 691 m_AttrMap.Lookup(CFX_ByteString(space), CFX_ByteString(name)); |
687 if (pValue) { | 692 if (pValue) { |
688 attribute = pValue->GetFloat(); | 693 attribute = pValue->GetFloat(); |
689 return TRUE; | 694 return TRUE; |
690 } | 695 } |
691 return FALSE; | 696 return FALSE; |
692 } | 697 } |
693 CXML_Element::ChildType CXML_Element::GetChildType(uint32_t index) const { | 698 CXML_Element::ChildType CXML_Element::GetChildType(uint32_t index) const { |
694 return index < m_Children.size() ? m_Children[index].type : Invalid; | 699 return index < m_Children.size() ? m_Children[index].type : Invalid; |
695 } | 700 } |
696 CFX_WideString CXML_Element::GetContent(uint32_t index) const { | 701 CFX_WideString CXML_Element::GetContent(uint32_t index) const { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 for (const ChildRecord& record : m_Children) { | 752 for (const ChildRecord& record : m_Children) { |
748 if (record.type == Element && | 753 if (record.type == Element && |
749 static_cast<CXML_Element*>(record.child) == pChild) { | 754 static_cast<CXML_Element*>(record.child) == pChild) { |
750 return index; | 755 return index; |
751 } | 756 } |
752 ++index; | 757 ++index; |
753 } | 758 } |
754 return (uint32_t)-1; | 759 return (uint32_t)-1; |
755 } | 760 } |
756 | 761 |
757 bool CXML_AttrItem::Matches(const CFX_ByteStringC& space, | 762 bool CXML_AttrItem::Matches(const CFX_ByteString& space, |
758 const CFX_ByteStringC& name) const { | 763 const CFX_ByteString& name) const { |
759 return (space.IsEmpty() || m_QSpaceName == space) && m_AttrName == name; | 764 return (space.IsEmpty() || m_QSpaceName == space) && m_AttrName == name; |
760 } | 765 } |
761 | 766 |
762 const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteStringC& space, | 767 const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteString& space, |
763 const CFX_ByteStringC& name) const { | 768 const CFX_ByteString& name) const { |
764 if (!m_pMap) | 769 if (!m_pMap) |
765 return nullptr; | 770 return nullptr; |
766 | 771 |
767 for (const auto& item : *m_pMap) { | 772 for (const auto& item : *m_pMap) { |
768 if (item.Matches(space, name)) | 773 if (item.Matches(space, name)) |
769 return &item.m_Value; | 774 return &item.m_Value; |
770 } | 775 } |
771 return nullptr; | 776 return nullptr; |
772 } | 777 } |
773 | 778 |
774 void CXML_AttrMap::SetAt(const CFX_ByteStringC& space, | 779 void CXML_AttrMap::SetAt(const CFX_ByteString& space, |
775 const CFX_ByteStringC& name, | 780 const CFX_ByteString& name, |
776 const CFX_WideStringC& value) { | 781 const CFX_WideString& value) { |
777 if (!m_pMap) | 782 if (!m_pMap) |
778 m_pMap.reset(new std::vector<CXML_AttrItem>); | 783 m_pMap.reset(new std::vector<CXML_AttrItem>); |
779 | 784 |
780 for (CXML_AttrItem& item : *m_pMap) { | 785 for (CXML_AttrItem& item : *m_pMap) { |
781 if (item.Matches(space, name)) { | 786 if (item.Matches(space, name)) { |
782 item.m_Value = value; | 787 item.m_Value = value; |
783 return; | 788 return; |
784 } | 789 } |
785 } | 790 } |
786 | 791 |
787 m_pMap->push_back({space, name, CFX_WideString(value)}); | 792 m_pMap->push_back({space, name, CFX_WideString(value)}); |
788 } | 793 } |
789 | 794 |
790 int CXML_AttrMap::GetSize() const { | 795 int CXML_AttrMap::GetSize() const { |
791 return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0; | 796 return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0; |
792 } | 797 } |
793 | 798 |
794 CXML_AttrItem& CXML_AttrMap::GetAt(int index) const { | 799 CXML_AttrItem& CXML_AttrMap::GetAt(int index) const { |
795 return (*m_pMap)[index]; | 800 return (*m_pMap)[index]; |
796 } | 801 } |
OLD | NEW |