| 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 XFA_FGAS_XML_FGAS_SAX_H_ | 7 #ifndef XFA_FDE_XML_CFX_SAXREADER_H_ |
| 8 #define XFA_FGAS_XML_FGAS_SAX_H_ | 8 #define XFA_FDE_XML_CFX_SAXREADER_H_ |
| 9 | 9 |
| 10 #include "core/fxcrt/include/fx_basic.h" | 10 #include "core/fxcrt/include/fx_basic.h" |
| 11 | 11 |
| 12 #define FX_SAXPARSEMODE_NotConvert_amp 0x0001 | 12 class CFX_SAXItem { |
| 13 #define FX_SAXPARSEMODE_NotConvert_lt 0x0002 | 13 public: |
| 14 #define FX_SAXPARSEMODE_NotConvert_gt 0x0004 | 14 enum class Type { |
| 15 #define FX_SAXPARSEMODE_NotConvert_apos 0x0008 | 15 Unknown = 0, |
| 16 #define FX_SAXPARSEMODE_NotConvert_quot 0x0010 | 16 Instruction, |
| 17 #define FX_SAXPARSEMODE_NotConvert_sharp 0x0020 | 17 Declaration, |
| 18 #define FX_SAXPARSEMODE_NotSkipSpace 0x0100 | 18 Comment, |
| 19 Tag, |
| 20 Text, |
| 21 CharData, |
| 22 }; |
| 19 | 23 |
| 20 enum FX_SAXNODE { | 24 CFX_SAXItem() |
| 21 FX_SAXNODE_Unknown = 0, | 25 : m_pNode(nullptr), |
| 22 FX_SAXNODE_Instruction, | 26 m_eNode(Type::Unknown), |
| 23 FX_SAXNODE_Declaration, | 27 m_dwID(0), |
| 24 FX_SAXNODE_Comment, | 28 m_bSkip(FALSE), |
| 25 FX_SAXNODE_Tag, | 29 m_pPrev(nullptr), |
| 26 FX_SAXNODE_Text, | 30 m_pNext(nullptr) {} |
| 27 FX_SAXNODE_CharData, | 31 |
| 32 void* m_pNode; |
| 33 Type m_eNode; |
| 34 uint32_t m_dwID; |
| 35 FX_BOOL m_bSkip; |
| 36 CFX_SAXItem* m_pPrev; |
| 37 CFX_SAXItem* m_pNext; |
| 28 }; | 38 }; |
| 29 | 39 |
| 30 enum FX_SAXMODE { | |
| 31 FX_SAXMODE_Text = 0, | |
| 32 FX_SAXMODE_NodeStart, | |
| 33 FX_SAXMODE_DeclOrComment, | |
| 34 FX_SAXMODE_DeclNode, | |
| 35 FX_SAXMODE_Comment, | |
| 36 FX_SAXMODE_CommentContent, | |
| 37 FX_SAXMODE_TagName, | |
| 38 FX_SAXMODE_TagAttributeName, | |
| 39 FX_SAXMODE_TagAttributeEqual, | |
| 40 FX_SAXMODE_TagAttributeValue, | |
| 41 FX_SAXMODE_TagMaybeClose, | |
| 42 FX_SAXMODE_TagClose, | |
| 43 FX_SAXMODE_TagEnd, | |
| 44 FX_SAXMODE_TargetData, | |
| 45 FX_SAXMODE_MAX, | |
| 46 }; | |
| 47 | |
| 48 class CXFA_SAXReaderHandler; | |
| 49 | |
| 50 class CFX_SAXFile { | 40 class CFX_SAXFile { |
| 51 public: | 41 public: |
| 52 CFX_SAXFile(); | 42 CFX_SAXFile(); |
| 53 FX_BOOL StartFile(IFX_FileRead* pFile, uint32_t dwStart, uint32_t dwLen); | 43 FX_BOOL StartFile(IFX_FileRead* pFile, uint32_t dwStart, uint32_t dwLen); |
| 54 FX_BOOL ReadNextBlock(); | 44 FX_BOOL ReadNextBlock(); |
| 55 void Reset(); | 45 void Reset(); |
| 56 IFX_FileRead* m_pFile; | 46 IFX_FileRead* m_pFile; |
| 57 uint32_t m_dwStart; | 47 uint32_t m_dwStart; |
| 58 uint32_t m_dwEnd; | 48 uint32_t m_dwEnd; |
| 59 uint32_t m_dwCur; | 49 uint32_t m_dwCur; |
| 60 uint8_t* m_pBuf; | 50 uint8_t* m_pBuf; |
| 61 uint32_t m_dwBufSize; | 51 uint32_t m_dwBufSize; |
| 62 uint32_t m_dwBufIndex; | 52 uint32_t m_dwBufIndex; |
| 63 }; | 53 }; |
| 64 | 54 |
| 65 class CFX_SAXItem { | 55 class CFX_SAXCommentContext; |
| 66 public: | 56 enum class CFX_SaxMode; |
| 67 CFX_SAXItem() | 57 |
| 68 : m_pNode(NULL), | 58 enum CFX_SaxParseMode { |
| 69 m_eNode(FX_SAXNODE_Unknown), | 59 CFX_SaxParseMode_NotConvert_amp = 1 << 0, |
| 70 m_dwID(0), | 60 CFX_SaxParseMode_NotConvert_lt = 1 << 1, |
| 71 m_bSkip(FALSE), | 61 CFX_SaxParseMode_NotConvert_gt = 1 << 2, |
| 72 m_pPrev(NULL), | 62 CFX_SaxParseMode_NotConvert_apos = 1 << 3, |
| 73 m_pNext(NULL) {} | 63 CFX_SaxParseMode_NotConvert_quot = 1 << 4, |
| 74 void* m_pNode; | 64 CFX_SaxParseMode_NotConvert_sharp = 1 << 5, |
| 75 FX_SAXNODE m_eNode; | 65 CFX_SaxParseMode_NotSkipSpace = 1 << 6 |
| 76 uint32_t m_dwID; | |
| 77 FX_BOOL m_bSkip; | |
| 78 CFX_SAXItem* m_pPrev; | |
| 79 CFX_SAXItem* m_pNext; | |
| 80 }; | 66 }; |
| 81 | 67 |
| 82 class CFX_SAXCommentContext { | 68 class CXFA_SAXReaderHandler; |
| 83 public: | |
| 84 CFX_SAXCommentContext() : m_iHeaderCount(0), m_iTailCount(0) {} | |
| 85 int32_t m_iHeaderCount; | |
| 86 int32_t m_iTailCount; | |
| 87 }; | |
| 88 | 69 |
| 89 class CFX_SAXReader { | 70 class CFX_SAXReader { |
| 90 public: | 71 public: |
| 91 CFX_SAXReader(); | 72 CFX_SAXReader(); |
| 92 ~CFX_SAXReader(); | 73 ~CFX_SAXReader(); |
| 93 | 74 |
| 94 int32_t StartParse(IFX_FileRead* pFile, | 75 int32_t StartParse(IFX_FileRead* pFile, |
| 95 uint32_t dwStart = 0, | 76 uint32_t dwStart = 0, |
| 96 uint32_t dwLen = -1, | 77 uint32_t dwLen = -1, |
| 97 uint32_t dwParseMode = 0); | 78 uint32_t dwParseMode = 0); |
| 98 int32_t ContinueParse(IFX_Pause* pPause = NULL); | 79 int32_t ContinueParse(IFX_Pause* pPause = nullptr); |
| 99 void SkipCurrentNode(); | 80 void SkipCurrentNode(); |
| 100 void SetHandler(CXFA_SAXReaderHandler* pHandler); | 81 void SetHandler(CXFA_SAXReaderHandler* pHandler); |
| 101 void AppendData(uint8_t ch); | 82 void AppendData(uint8_t ch); |
| 102 void AppendName(uint8_t ch); | 83 void AppendName(uint8_t ch); |
| 103 void ParseText(); | 84 void ParseText(); |
| 104 void ParseNodeStart(); | 85 void ParseNodeStart(); |
| 105 void ParseInstruction(); | 86 void ParseInstruction(); |
| 106 void ParseDeclOrComment(); | 87 void ParseDeclOrComment(); |
| 107 void ParseDeclNode(); | 88 void ParseDeclNode(); |
| 108 void ParseComment(); | 89 void ParseComment(); |
| 109 void ParseCommentContent(); | 90 void ParseCommentContent(); |
| 110 void ParseTagName(); | 91 void ParseTagName(); |
| 111 void ParseTagAttributeName(); | 92 void ParseTagAttributeName(); |
| 112 void ParseTagAttributeEqual(); | 93 void ParseTagAttributeEqual(); |
| 113 void ParseTagAttributeValue(); | 94 void ParseTagAttributeValue(); |
| 114 void ParseMaybeClose(); | 95 void ParseMaybeClose(); |
| 115 void ParseTagClose(); | 96 void ParseTagClose(); |
| 116 void ParseTagEnd(); | 97 void ParseTagEnd(); |
| 117 void ParseTargetData(); | 98 void ParseTargetData(); |
| 118 | 99 |
| 119 protected: | 100 private: |
| 120 void Reset(); | 101 void Reset(); |
| 121 void Push(); | 102 void Push(); |
| 122 void Pop(); | 103 void Pop(); |
| 123 FX_BOOL SkipSpace(uint8_t ch); | 104 FX_BOOL SkipSpace(uint8_t ch); |
| 124 void SkipNode(); | 105 void SkipNode(); |
| 125 void NotifyData(); | 106 void NotifyData(); |
| 126 void NotifyEnter(); | 107 void NotifyEnter(); |
| 127 void NotifyAttribute(); | 108 void NotifyAttribute(); |
| 128 void NotifyBreak(); | 109 void NotifyBreak(); |
| 129 void NotifyClose(); | 110 void NotifyClose(); |
| 130 void NotifyEnd(); | 111 void NotifyEnd(); |
| 131 void NotifyTargetData(); | 112 void NotifyTargetData(); |
| 132 void ReallocDataBuffer(); | 113 void ReallocDataBuffer(); |
| 133 void ReallocNameBuffer(); | 114 void ReallocNameBuffer(); |
| 134 void ParseChar(uint8_t ch); | 115 void ParseChar(uint8_t ch); |
| 135 | 116 |
| 136 CFX_SAXFile m_File; | 117 CFX_SAXFile m_File; |
| 137 CXFA_SAXReaderHandler* m_pHandler; | 118 CXFA_SAXReaderHandler* m_pHandler; |
| 138 int32_t m_iState; | 119 int32_t m_iState; |
| 139 CFX_SAXItem* m_pRoot; | 120 CFX_SAXItem* m_pRoot; |
| 140 CFX_SAXItem* m_pCurItem; | 121 CFX_SAXItem* m_pCurItem; |
| 141 uint32_t m_dwItemID; | 122 uint32_t m_dwItemID; |
| 142 FX_SAXMODE m_eMode; | 123 CFX_SaxMode m_eMode; |
| 143 FX_SAXMODE m_ePrevMode; | 124 CFX_SaxMode m_ePrevMode; |
| 144 FX_BOOL m_bCharData; | 125 FX_BOOL m_bCharData; |
| 145 uint8_t m_CurByte; | 126 uint8_t m_CurByte; |
| 146 uint32_t m_dwDataOffset; | 127 uint32_t m_dwDataOffset; |
| 147 CFX_ByteArray m_SkipStack; | 128 CFX_ByteArray m_SkipStack; |
| 148 uint8_t m_SkipChar; | 129 uint8_t m_SkipChar; |
| 149 uint32_t m_dwNodePos; | 130 uint32_t m_dwNodePos; |
| 150 uint8_t* m_pszData; | 131 uint8_t* m_pszData; |
| 151 int32_t m_iDataSize; | 132 int32_t m_iDataSize; |
| 152 int32_t m_iDataLength; | 133 int32_t m_iDataLength; |
| 153 int32_t m_iEntityStart; | 134 int32_t m_iEntityStart; |
| 154 int32_t m_iDataPos; | 135 int32_t m_iDataPos; |
| 155 uint8_t* m_pszName; | 136 uint8_t* m_pszName; |
| 156 int32_t m_iNameSize; | 137 int32_t m_iNameSize; |
| 157 int32_t m_iNameLength; | 138 int32_t m_iNameLength; |
| 158 uint32_t m_dwParseMode; | 139 uint32_t m_dwParseMode; |
| 159 CFX_SAXCommentContext* m_pCommentContext; | 140 CFX_SAXCommentContext* m_pCommentContext; |
| 160 }; | 141 }; |
| 161 | 142 |
| 162 #endif // XFA_FGAS_XML_FGAS_SAX_H_ | 143 #endif // XFA_FDE_XML_CFX_SAXREADER_H_ |
| OLD | NEW |