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 CORE_SRC_FXCRT_XML_INT_H_ | 7 #ifndef CORE_SRC_FXCRT_XML_INT_H_ |
8 #define CORE_SRC_FXCRT_XML_INT_H_ | 8 #define CORE_SRC_FXCRT_XML_INT_H_ |
9 | 9 |
10 #include "../../include/fxcrt/fx_stream.h" | 10 #include "../../include/fxcrt/fx_stream.h" |
11 | 11 |
12 class CXML_DataBufAcc : public IFX_BufferRead { | 12 class CXML_DataBufAcc : public IFX_BufferRead { |
13 public: | 13 public: |
14 CXML_DataBufAcc(const uint8_t* pBuffer, size_t size) | 14 CXML_DataBufAcc(const uint8_t* pBuffer, size_t size) |
15 : m_pBuffer(pBuffer), m_dwSize(size), m_dwCurPos(0) {} | 15 : m_pBuffer(pBuffer), m_dwSize(size), m_dwCurPos(0) {} |
16 virtual ~CXML_DataBufAcc() {} | 16 ~CXML_DataBufAcc() override {} |
17 virtual void Release() { delete this; } | 17 |
18 virtual FX_BOOL IsEOF() { return m_dwCurPos >= m_dwSize; } | 18 // IFX_BufferRead |
19 virtual FX_FILESIZE GetPosition() { return (FX_FILESIZE)m_dwCurPos; } | 19 void Release() override { delete this; } |
20 virtual size_t ReadBlock(void* buffer, size_t size) { return 0; } | 20 FX_BOOL IsEOF() override { return m_dwCurPos >= m_dwSize; } |
21 virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) { | 21 FX_FILESIZE GetPosition() override { return (FX_FILESIZE)m_dwCurPos; } |
| 22 size_t ReadBlock(void* buffer, size_t size) override { return 0; } |
| 23 FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) override { |
22 if (bRestart) { | 24 if (bRestart) { |
23 m_dwCurPos = 0; | 25 m_dwCurPos = 0; |
24 } | 26 } |
25 if (m_dwCurPos < m_dwSize) { | 27 if (m_dwCurPos < m_dwSize) { |
26 m_dwCurPos = m_dwSize; | 28 m_dwCurPos = m_dwSize; |
27 return TRUE; | 29 return TRUE; |
28 } | 30 } |
29 return FALSE; | 31 return FALSE; |
30 } | 32 } |
31 virtual const uint8_t* GetBlockBuffer() { return m_pBuffer; } | 33 const uint8_t* GetBlockBuffer() override { return m_pBuffer; } |
32 virtual size_t GetBlockSize() { return m_dwSize; } | 34 size_t GetBlockSize() override { return m_dwSize; } |
33 virtual FX_FILESIZE GetBlockOffset() { return 0; } | 35 FX_FILESIZE GetBlockOffset() override { return 0; } |
34 | 36 |
35 protected: | 37 protected: |
36 const uint8_t* m_pBuffer; | 38 const uint8_t* m_pBuffer; |
37 size_t m_dwSize; | 39 size_t m_dwSize; |
38 size_t m_dwCurPos; | 40 size_t m_dwCurPos; |
39 }; | 41 }; |
| 42 |
40 #define FX_XMLDATASTREAM_BufferSize (32 * 1024) | 43 #define FX_XMLDATASTREAM_BufferSize (32 * 1024) |
41 class CXML_DataStmAcc : public IFX_BufferRead { | 44 class CXML_DataStmAcc : public IFX_BufferRead { |
42 public: | 45 public: |
43 CXML_DataStmAcc(IFX_FileRead* pFileRead) | 46 CXML_DataStmAcc(IFX_FileRead* pFileRead) |
44 : m_pFileRead(pFileRead), m_pBuffer(NULL), m_nStart(0), m_dwSize(0) { | 47 : m_pFileRead(pFileRead), m_pBuffer(NULL), m_nStart(0), m_dwSize(0) { |
45 FXSYS_assert(m_pFileRead != NULL); | 48 FXSYS_assert(m_pFileRead != NULL); |
46 } | 49 } |
47 virtual ~CXML_DataStmAcc() { | 50 ~CXML_DataStmAcc() override { |
48 if (m_pBuffer) { | 51 if (m_pBuffer) { |
49 FX_Free(m_pBuffer); | 52 FX_Free(m_pBuffer); |
50 } | 53 } |
51 } | 54 } |
52 virtual void Release() { delete this; } | 55 |
53 virtual FX_BOOL IsEOF() { | 56 void Release() override { delete this; } |
| 57 FX_BOOL IsEOF() override { |
54 return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize(); | 58 return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize(); |
55 } | 59 } |
56 virtual FX_FILESIZE GetPosition() { return m_nStart + (FX_FILESIZE)m_dwSize; } | 60 FX_FILESIZE GetPosition() override { |
57 virtual size_t ReadBlock(void* buffer, size_t size) { return 0; } | 61 return m_nStart + (FX_FILESIZE)m_dwSize; |
58 virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) { | 62 } |
| 63 size_t ReadBlock(void* buffer, size_t size) override { return 0; } |
| 64 FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) override { |
59 if (bRestart) { | 65 if (bRestart) { |
60 m_nStart = 0; | 66 m_nStart = 0; |
61 } | 67 } |
62 FX_FILESIZE nLength = m_pFileRead->GetSize(); | 68 FX_FILESIZE nLength = m_pFileRead->GetSize(); |
63 m_nStart += (FX_FILESIZE)m_dwSize; | 69 m_nStart += (FX_FILESIZE)m_dwSize; |
64 if (m_nStart >= nLength) { | 70 if (m_nStart >= nLength) { |
65 return FALSE; | 71 return FALSE; |
66 } | 72 } |
67 m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart); | 73 m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart); |
68 if (!m_pBuffer) { | 74 if (!m_pBuffer) { |
69 m_pBuffer = FX_Alloc(uint8_t, m_dwSize); | 75 m_pBuffer = FX_Alloc(uint8_t, m_dwSize); |
70 } | 76 } |
71 return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize); | 77 return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize); |
72 } | 78 } |
73 virtual const uint8_t* GetBlockBuffer() { return (const uint8_t*)m_pBuffer; } | 79 const uint8_t* GetBlockBuffer() override { return (const uint8_t*)m_pBuffer; } |
74 virtual size_t GetBlockSize() { return m_dwSize; } | 80 size_t GetBlockSize() override { return m_dwSize; } |
75 virtual FX_FILESIZE GetBlockOffset() { return m_nStart; } | 81 FX_FILESIZE GetBlockOffset() override { return m_nStart; } |
76 | 82 |
77 protected: | 83 protected: |
78 IFX_FileRead* m_pFileRead; | 84 IFX_FileRead* m_pFileRead; |
79 uint8_t* m_pBuffer; | 85 uint8_t* m_pBuffer; |
80 FX_FILESIZE m_nStart; | 86 FX_FILESIZE m_nStart; |
81 size_t m_dwSize; | 87 size_t m_dwSize; |
82 }; | 88 }; |
| 89 |
83 class CXML_Parser { | 90 class CXML_Parser { |
84 public: | 91 public: |
85 ~CXML_Parser(); | 92 ~CXML_Parser(); |
86 IFX_BufferRead* m_pDataAcc; | 93 IFX_BufferRead* m_pDataAcc; |
87 FX_BOOL m_bOwnedStream; | 94 FX_BOOL m_bOwnedStream; |
88 FX_FILESIZE m_nOffset; | 95 FX_FILESIZE m_nOffset; |
89 FX_BOOL m_bSaveSpaceChars; | 96 FX_BOOL m_bSaveSpaceChars; |
90 const uint8_t* m_pBuffer; | 97 const uint8_t* m_pBuffer; |
91 size_t m_dwBufferSize; | 98 size_t m_dwBufferSize; |
92 FX_FILESIZE m_nBufferOffset; | 99 FX_FILESIZE m_nBufferOffset; |
(...skipping 13 matching lines...) Expand all Loading... |
106 CFX_ByteString& name, | 113 CFX_ByteString& name, |
107 FX_BOOL& bEndTag, | 114 FX_BOOL& bEndTag, |
108 FX_BOOL bStartTag = FALSE); | 115 FX_BOOL bStartTag = FALSE); |
109 void SkipLiterals(const CFX_ByteStringC& str); | 116 void SkipLiterals(const CFX_ByteStringC& str); |
110 CXML_Element* ParseElement(CXML_Element* pParent, FX_BOOL bStartTag = FALSE); | 117 CXML_Element* ParseElement(CXML_Element* pParent, FX_BOOL bStartTag = FALSE); |
111 void InsertContentSegment(FX_BOOL bCDATA, | 118 void InsertContentSegment(FX_BOOL bCDATA, |
112 const CFX_WideStringC& content, | 119 const CFX_WideStringC& content, |
113 CXML_Element* pElement); | 120 CXML_Element* pElement); |
114 void InsertCDATASegment(CFX_UTF8Decoder& decoder, CXML_Element* pElement); | 121 void InsertCDATASegment(CFX_UTF8Decoder& decoder, CXML_Element* pElement); |
115 }; | 122 }; |
| 123 |
116 void FX_XML_SplitQualifiedName(const CFX_ByteStringC& bsFullName, | 124 void FX_XML_SplitQualifiedName(const CFX_ByteStringC& bsFullName, |
117 CFX_ByteStringC& bsSpace, | 125 CFX_ByteStringC& bsSpace, |
118 CFX_ByteStringC& bsName); | 126 CFX_ByteStringC& bsName); |
119 | 127 |
120 #endif // CORE_SRC_FXCRT_XML_INT_H_ | 128 #endif // CORE_SRC_FXCRT_XML_INT_H_ |
OLD | NEW |