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 |
11 #include "core/fxcrt/include/fx_ext.h" | 11 #include "core/fxcrt/include/fx_ext.h" |
12 #include "core/fxcrt/include/fx_xml.h" | 12 #include "core/fxcrt/include/fx_xml.h" |
13 #include "third_party/base/stl_util.h" | 13 #include "third_party/base/stl_util.h" |
14 | 14 |
| 15 CXML_DataBufAcc::CXML_DataBufAcc(const uint8_t* pBuffer, size_t size) |
| 16 : m_pBuffer(pBuffer), m_dwSize(size), m_dwCurPos(0) {} |
| 17 |
| 18 CXML_DataBufAcc::~CXML_DataBufAcc() {} |
| 19 |
| 20 void CXML_DataBufAcc::Release() { |
| 21 delete this; |
| 22 } |
| 23 |
| 24 FX_BOOL CXML_DataBufAcc::IsEOF() { |
| 25 return m_dwCurPos >= m_dwSize; |
| 26 } |
| 27 |
| 28 FX_FILESIZE CXML_DataBufAcc::GetPosition() { |
| 29 return (FX_FILESIZE)m_dwCurPos; |
| 30 } |
| 31 |
| 32 size_t CXML_DataBufAcc::ReadBlock(void* buffer, size_t size) { |
| 33 return 0; |
| 34 } |
| 35 |
| 36 FX_BOOL CXML_DataBufAcc::ReadNextBlock(FX_BOOL bRestart) { |
| 37 if (bRestart) { |
| 38 m_dwCurPos = 0; |
| 39 } |
| 40 if (m_dwCurPos < m_dwSize) { |
| 41 m_dwCurPos = m_dwSize; |
| 42 return TRUE; |
| 43 } |
| 44 return FALSE; |
| 45 } |
| 46 |
| 47 const uint8_t* CXML_DataBufAcc::GetBlockBuffer() { |
| 48 return m_pBuffer; |
| 49 } |
| 50 |
| 51 size_t CXML_DataBufAcc::GetBlockSize() { |
| 52 return m_dwSize; |
| 53 } |
| 54 |
| 55 FX_FILESIZE CXML_DataBufAcc::GetBlockOffset() { |
| 56 return 0; |
| 57 } |
| 58 |
| 59 CXML_DataStmAcc::CXML_DataStmAcc(IFX_FileRead* pFileRead) |
| 60 : m_pFileRead(pFileRead), m_pBuffer(nullptr), m_nStart(0), m_dwSize(0) { |
| 61 ASSERT(m_pFileRead); |
| 62 } |
| 63 |
| 64 CXML_DataStmAcc::~CXML_DataStmAcc() { |
| 65 FX_Free(m_pBuffer); |
| 66 } |
| 67 |
| 68 void CXML_DataStmAcc::Release() { |
| 69 delete this; |
| 70 } |
| 71 |
| 72 FX_BOOL CXML_DataStmAcc::IsEOF() { |
| 73 return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize(); |
| 74 } |
| 75 |
| 76 FX_FILESIZE CXML_DataStmAcc::GetPosition() { |
| 77 return m_nStart + (FX_FILESIZE)m_dwSize; |
| 78 } |
| 79 |
| 80 size_t CXML_DataStmAcc::ReadBlock(void* buffer, size_t size) { |
| 81 return 0; |
| 82 } |
| 83 |
| 84 FX_BOOL CXML_DataStmAcc::ReadNextBlock(FX_BOOL bRestart) { |
| 85 if (bRestart) { |
| 86 m_nStart = 0; |
| 87 } |
| 88 FX_FILESIZE nLength = m_pFileRead->GetSize(); |
| 89 m_nStart += (FX_FILESIZE)m_dwSize; |
| 90 if (m_nStart >= nLength) { |
| 91 return FALSE; |
| 92 } |
| 93 static const FX_FILESIZE FX_XMLDATASTREAM_BufferSize = 32 * 1024; |
| 94 m_dwSize = static_cast<size_t>( |
| 95 std::min(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart)); |
| 96 if (!m_pBuffer) { |
| 97 m_pBuffer = FX_Alloc(uint8_t, m_dwSize); |
| 98 } |
| 99 return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize); |
| 100 } |
| 101 |
| 102 const uint8_t* CXML_DataStmAcc::GetBlockBuffer() { |
| 103 return (const uint8_t*)m_pBuffer; |
| 104 } |
| 105 |
| 106 size_t CXML_DataStmAcc::GetBlockSize() { |
| 107 return m_dwSize; |
| 108 } |
| 109 |
| 110 FX_FILESIZE CXML_DataStmAcc::GetBlockOffset() { |
| 111 return m_nStart; |
| 112 } |
| 113 |
| 114 CXML_Parser::CXML_Parser() |
| 115 : m_pDataAcc(nullptr), |
| 116 m_bOwnedStream(FALSE), |
| 117 m_nOffset(0), |
| 118 m_bSaveSpaceChars(FALSE), |
| 119 m_pBuffer(nullptr), |
| 120 m_dwBufferSize(0), |
| 121 m_nBufferOffset(0), |
| 122 m_dwIndex(0) {} |
| 123 |
15 CXML_Parser::~CXML_Parser() { | 124 CXML_Parser::~CXML_Parser() { |
16 if (m_bOwnedStream) { | 125 if (m_bOwnedStream) { |
17 m_pDataAcc->Release(); | 126 m_pDataAcc->Release(); |
18 } | 127 } |
19 } | 128 } |
| 129 |
20 FX_BOOL CXML_Parser::Init(uint8_t* pBuffer, size_t size) { | 130 FX_BOOL CXML_Parser::Init(uint8_t* pBuffer, size_t size) { |
21 m_pDataAcc = new CXML_DataBufAcc(pBuffer, size); | 131 m_pDataAcc = new CXML_DataBufAcc(pBuffer, size); |
22 return Init(TRUE); | 132 return Init(TRUE); |
23 } | 133 } |
24 FX_BOOL CXML_Parser::Init(IFX_FileRead* pFileRead) { | 134 FX_BOOL CXML_Parser::Init(IFX_FileRead* pFileRead) { |
25 m_pDataAcc = new CXML_DataStmAcc(pFileRead); | 135 m_pDataAcc = new CXML_DataStmAcc(pFileRead); |
26 return Init(TRUE); | 136 return Init(TRUE); |
27 } | 137 } |
28 FX_BOOL CXML_Parser::Init(IFX_BufferRead* pBuffer) { | 138 FX_BOOL CXML_Parser::Init(IFX_BufferRead* pBuffer) { |
29 if (!pBuffer) { | 139 if (!pBuffer) { |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 ++index; | 867 ++index; |
758 } | 868 } |
759 return (uint32_t)-1; | 869 return (uint32_t)-1; |
760 } | 870 } |
761 | 871 |
762 bool CXML_AttrItem::Matches(const CFX_ByteString& space, | 872 bool CXML_AttrItem::Matches(const CFX_ByteString& space, |
763 const CFX_ByteString& name) const { | 873 const CFX_ByteString& name) const { |
764 return (space.IsEmpty() || m_QSpaceName == space) && m_AttrName == name; | 874 return (space.IsEmpty() || m_QSpaceName == space) && m_AttrName == name; |
765 } | 875 } |
766 | 876 |
| 877 CXML_AttrMap::CXML_AttrMap() {} |
| 878 |
| 879 CXML_AttrMap::~CXML_AttrMap() {} |
| 880 |
767 const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteString& space, | 881 const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteString& space, |
768 const CFX_ByteString& name) const { | 882 const CFX_ByteString& name) const { |
769 if (!m_pMap) | 883 if (!m_pMap) |
770 return nullptr; | 884 return nullptr; |
771 | 885 |
772 for (const auto& item : *m_pMap) { | 886 for (const auto& item : *m_pMap) { |
773 if (item.Matches(space, name)) | 887 if (item.Matches(space, name)) |
774 return &item.m_Value; | 888 return &item.m_Value; |
775 } | 889 } |
776 return nullptr; | 890 return nullptr; |
(...skipping 15 matching lines...) Expand all Loading... |
792 m_pMap->push_back({space, name, CFX_WideString(value)}); | 906 m_pMap->push_back({space, name, CFX_WideString(value)}); |
793 } | 907 } |
794 | 908 |
795 int CXML_AttrMap::GetSize() const { | 909 int CXML_AttrMap::GetSize() const { |
796 return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0; | 910 return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0; |
797 } | 911 } |
798 | 912 |
799 CXML_AttrItem& CXML_AttrMap::GetAt(int index) const { | 913 CXML_AttrItem& CXML_AttrMap::GetAt(int index) const { |
800 return (*m_pMap)[index]; | 914 return (*m_pMap)[index]; |
801 } | 915 } |
OLD | NEW |