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 #ifndef _FXCRT_XML_INT_ | 7 #ifndef _FXCRT_XML_INT_ |
8 #define _FXCRT_XML_INT_ | 8 #define _FXCRT_XML_INT_ |
9 class CXML_DataBufAcc : public IFX_BufferRead, public CFX_Object | 9 class CXML_DataBufAcc : public IFX_BufferRead, public CFX_Object |
10 { | 10 { |
11 public: | 11 public: |
12 CXML_DataBufAcc(FX_LPCBYTE pBuffer, size_t size, IFX_Allocator* pAllocator =
NULL) | 12 CXML_DataBufAcc(FX_LPCBYTE pBuffer, size_t size) |
13 : m_pAllocator(pAllocator) | 13 : m_pBuffer(pBuffer) |
14 , m_pBuffer(pBuffer) | |
15 , m_dwSize(size) | 14 , m_dwSize(size) |
16 , m_dwCurPos(0) | 15 , m_dwCurPos(0) |
17 { | 16 { |
18 } | 17 } |
19 virtual ~CXML_DataBufAcc() {} | 18 virtual ~CXML_DataBufAcc() {} |
20 virtual void Release() | 19 virtual void Release() |
21 { | 20 { |
22 if (m_pAllocator) { | 21 delete this; |
23 FX_DeleteAtAllocator(this, m_pAllocator, CXML_DataBufAcc); | |
24 } else { | |
25 delete this; | |
26 } | |
27 } | 22 } |
28 virtual FX_BOOL IsEOF() | 23 virtual FX_BOOL IsEOF() |
29 { | 24 { |
30 return m_dwCurPos >= m_dwSize; | 25 return m_dwCurPos >= m_dwSize; |
31 } | 26 } |
32 virtual FX_FILESIZE GetPosition() | 27 virtual FX_FILESIZE GetPosition() |
33 { | 28 { |
34 return (FX_FILESIZE)m_dwCurPos; | 29 return (FX_FILESIZE)m_dwCurPos; |
35 } | 30 } |
36 virtual size_t ReadBlock(void* buffer, size_t size) | 31 virtual size_t ReadBlock(void* buffer, size_t size) |
(...skipping 17 matching lines...) Expand all Loading... |
54 } | 49 } |
55 virtual size_t GetBlockSize() | 50 virtual size_t GetBlockSize() |
56 { | 51 { |
57 return m_dwSize; | 52 return m_dwSize; |
58 } | 53 } |
59 virtual FX_FILESIZE GetBlockOffset() | 54 virtual FX_FILESIZE GetBlockOffset() |
60 { | 55 { |
61 return 0; | 56 return 0; |
62 } | 57 } |
63 protected: | 58 protected: |
64 IFX_Allocator* m_pAllocator; | |
65 FX_LPCBYTE m_pBuffer; | 59 FX_LPCBYTE m_pBuffer; |
66 size_t m_dwSize; | 60 size_t m_dwSize; |
67 size_t m_dwCurPos; | 61 size_t m_dwCurPos; |
68 }; | 62 }; |
69 #define FX_XMLDATASTREAM_BufferSize (32 * 1024) | 63 #define FX_XMLDATASTREAM_BufferSize (32 * 1024) |
70 class CXML_DataStmAcc : public IFX_BufferRead, public CFX_Object | 64 class CXML_DataStmAcc : public IFX_BufferRead, public CFX_Object |
71 { | 65 { |
72 public: | 66 public: |
73 CXML_DataStmAcc(IFX_FileRead *pFileRead, IFX_Allocator* pAllocator = NULL) | 67 CXML_DataStmAcc(IFX_FileRead *pFileRead) |
74 : m_pAllocator(pAllocator) | 68 : m_pFileRead(pFileRead) |
75 , m_pFileRead(pFileRead) | |
76 , m_pBuffer(NULL) | 69 , m_pBuffer(NULL) |
77 , m_nStart(0) | 70 , m_nStart(0) |
78 , m_dwSize(0) | 71 , m_dwSize(0) |
79 { | 72 { |
80 FXSYS_assert(m_pFileRead != NULL); | 73 FXSYS_assert(m_pFileRead != NULL); |
81 } | 74 } |
82 virtual ~CXML_DataStmAcc() | 75 virtual ~CXML_DataStmAcc() |
83 { | 76 { |
84 if (m_pBuffer) { | 77 if (m_pBuffer) { |
85 FX_Allocator_Free(m_pAllocator, m_pBuffer); | 78 FX_Free(m_pBuffer); |
86 } | 79 } |
87 } | 80 } |
88 virtual void Release() | 81 virtual void Release() |
89 { | 82 { |
90 if (m_pAllocator) { | 83 delete this; |
91 FX_DeleteAtAllocator(this, m_pAllocator, CXML_DataStmAcc); | |
92 } else { | |
93 delete this; | |
94 } | |
95 } | 84 } |
96 virtual FX_BOOL IsEOF() | 85 virtual FX_BOOL IsEOF() |
97 { | 86 { |
98 return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize(); | 87 return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize(); |
99 } | 88 } |
100 virtual FX_FILESIZE GetPosition() | 89 virtual FX_FILESIZE GetPosition() |
101 { | 90 { |
102 return m_nStart + (FX_FILESIZE)m_dwSize; | 91 return m_nStart + (FX_FILESIZE)m_dwSize; |
103 } | 92 } |
104 virtual size_t ReadBlock(void* buffer, size_t size) | 93 virtual size_t ReadBlock(void* buffer, size_t size) |
105 { | 94 { |
106 return 0; | 95 return 0; |
107 } | 96 } |
108 virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) | 97 virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) |
109 { | 98 { |
110 if (bRestart) { | 99 if (bRestart) { |
111 m_nStart = 0; | 100 m_nStart = 0; |
112 } | 101 } |
113 FX_FILESIZE nLength = m_pFileRead->GetSize(); | 102 FX_FILESIZE nLength = m_pFileRead->GetSize(); |
114 m_nStart += (FX_FILESIZE)m_dwSize; | 103 m_nStart += (FX_FILESIZE)m_dwSize; |
115 if (m_nStart >= nLength) { | 104 if (m_nStart >= nLength) { |
116 return FALSE; | 105 return FALSE; |
117 } | 106 } |
118 m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStar
t); | 107 m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStar
t); |
119 if (!m_pBuffer) { | 108 if (!m_pBuffer) { |
120 m_pBuffer = FX_Allocator_Alloc(m_pAllocator, FX_BYTE, m_dwSize); | 109 m_pBuffer = FX_Alloc(FX_BYTE, m_dwSize); |
121 if (!m_pBuffer) { | 110 if (!m_pBuffer) { |
122 return FALSE; | 111 return FALSE; |
123 } | 112 } |
124 } | 113 } |
125 return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize); | 114 return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize); |
126 } | 115 } |
127 virtual FX_LPCBYTE GetBlockBuffer() | 116 virtual FX_LPCBYTE GetBlockBuffer() |
128 { | 117 { |
129 return (FX_LPCBYTE)m_pBuffer; | 118 return (FX_LPCBYTE)m_pBuffer; |
130 } | 119 } |
131 virtual size_t GetBlockSize() | 120 virtual size_t GetBlockSize() |
132 { | 121 { |
133 return m_dwSize; | 122 return m_dwSize; |
134 } | 123 } |
135 virtual FX_FILESIZE GetBlockOffset() | 124 virtual FX_FILESIZE GetBlockOffset() |
136 { | 125 { |
137 return m_nStart; | 126 return m_nStart; |
138 } | 127 } |
139 protected: | 128 protected: |
140 IFX_Allocator* m_pAllocator; | |
141 IFX_FileRead *m_pFileRead; | 129 IFX_FileRead *m_pFileRead; |
142 FX_LPBYTE m_pBuffer; | 130 FX_LPBYTE m_pBuffer; |
143 FX_FILESIZE m_nStart; | 131 FX_FILESIZE m_nStart; |
144 size_t m_dwSize; | 132 size_t m_dwSize; |
145 }; | 133 }; |
146 class CXML_Parser | 134 class CXML_Parser |
147 { | 135 { |
148 public: | 136 public: |
149 CXML_Parser(IFX_Allocator* pAllocator = NULL) : m_pAllocator(pAllocator) {} | |
150 ~CXML_Parser(); | 137 ~CXML_Parser(); |
151 IFX_Allocator* m_pAllocator; | |
152 IFX_BufferRead* m_pDataAcc; | 138 IFX_BufferRead* m_pDataAcc; |
153 FX_BOOL m_bOwnedStream; | 139 FX_BOOL m_bOwnedStream; |
154 FX_FILESIZE m_nOffset; | 140 FX_FILESIZE m_nOffset; |
155 FX_BOOL m_bSaveSpaceChars; | 141 FX_BOOL m_bSaveSpaceChars; |
156 FX_LPCBYTE m_pBuffer; | 142 FX_LPCBYTE m_pBuffer; |
157 size_t m_dwBufferSize; | 143 size_t m_dwBufferSize; |
158 FX_FILESIZE m_nBufferOffset; | 144 FX_FILESIZE m_nBufferOffset; |
159 size_t m_dwIndex; | 145 size_t m_dwIndex; |
160 FX_BOOL Init(FX_LPBYTE pBuffer, size_t size); | 146 FX_BOOL Init(FX_LPBYTE pBuffer, size_t size); |
161 FX_BOOL Init(IFX_FileRead *pFileRead); | 147 FX_BOOL Init(IFX_FileRead *pFileRead); |
162 FX_BOOL Init(IFX_BufferRead *pBuffer); | 148 FX_BOOL Init(IFX_BufferRead *pBuffer); |
163 FX_BOOL Init(FX_BOOL bOwndedStream); | 149 FX_BOOL Init(FX_BOOL bOwndedStream); |
164 FX_BOOL ReadNextBlock(); | 150 FX_BOOL ReadNextBlock(); |
165 FX_BOOL IsEOF(); | 151 FX_BOOL IsEOF(); |
166 FX_BOOL HaveAvailData(); | 152 FX_BOOL HaveAvailData(); |
167 void SkipWhiteSpaces(); | 153 void SkipWhiteSpaces(); |
168 void» » » GetName(CFX_ByteStringL &space, CFX_ByteStringL
&name); | 154 void» » » GetName(CFX_ByteString& space, CFX_ByteString& n
ame); |
169 void» » » GetAttrValue(CFX_WideStringL &value); | 155 void» » » GetAttrValue(CFX_WideString &value); |
170 FX_DWORD GetCharRef(); | 156 FX_DWORD GetCharRef(); |
171 void» » » GetTagName(CFX_ByteStringL &space, CFX_ByteStrin
gL &name, FX_BOOL &bEndTag, FX_BOOL bStartTag = FALSE); | 157 void» » » GetTagName(CFX_ByteString &space, CFX_ByteString
&name, FX_BOOL &bEndTag, FX_BOOL bStartTag = FALSE); |
172 void SkipLiterals(FX_BSTR str); | 158 void SkipLiterals(FX_BSTR str); |
173 CXML_Element* ParseElement(CXML_Element* pParent, FX_BOOL bStartTag =
FALSE); | 159 CXML_Element* ParseElement(CXML_Element* pParent, FX_BOOL bStartTag =
FALSE); |
174 void InsertContentSegment(FX_BOOL bCDATA, FX_WSTR con
tent, CXML_Element* pElement); | 160 void InsertContentSegment(FX_BOOL bCDATA, FX_WSTR con
tent, CXML_Element* pElement); |
175 void InsertCDATASegment(CFX_UTF8Decoder& decoder, CXM
L_Element* pElement); | 161 void InsertCDATASegment(CFX_UTF8Decoder& decoder, CXM
L_Element* pElement); |
176 }; | 162 }; |
177 void FX_XML_SplitQualifiedName(FX_BSTR bsFullName, CFX_ByteStringC &bsSpace, CFX
_ByteStringC &bsName); | 163 void FX_XML_SplitQualifiedName(FX_BSTR bsFullName, CFX_ByteStringC &bsSpace, CFX
_ByteStringC &bsName); |
178 #endif | 164 #endif |
OLD | NEW |