From 4027887ee29a7f4920b03041068bff9bde239782 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 10 Apr 2018 13:01:07 +0000 Subject: Merge CXFA_SimpleParser::{Start|Do}Parse The StartParse and DoParse methods have been merged into a single Parse method. Change-Id: I1310bda90b853c11af8b8d1794de6b5c19e931cf Reviewed-on: https://pdfium-review.googlesource.com/30010 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_dataimporter.cpp | 9 ++++----- xfa/fxfa/parser/cxfa_document_parser.cpp | 4 +--- xfa/fxfa/parser/cxfa_simple_parser.cpp | 14 ++++---------- xfa/fxfa/parser/cxfa_simple_parser.h | 8 +++----- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/xfa/fxfa/parser/cxfa_dataimporter.cpp b/xfa/fxfa/parser/cxfa_dataimporter.cpp index c5c23fcfb9..01e95b1c3a 100644 --- a/xfa/fxfa/parser/cxfa_dataimporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataimporter.cpp @@ -26,13 +26,12 @@ CXFA_DataImporter::~CXFA_DataImporter() {} bool CXFA_DataImporter::ImportData( const RetainPtr& pDataDocument) { - auto pDataDocumentParser = - pdfium::MakeUnique(m_pDocument.Get()); - pDataDocumentParser->StartParse(pDataDocument, XFA_PacketType::Datasets); - if (pDataDocumentParser->DoParse() < XFA_PARSESTATUS_Done) + CXFA_SimpleParser parser(m_pDocument.Get()); + int status = parser.Parse(pDataDocument, XFA_PacketType::Datasets); + if (status < XFA_PARSESTATUS_Done) return false; - CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode(); + CXFA_Node* pImportDataRoot = parser.GetRootNode(); if (!pImportDataRoot) return false; diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index 8df91bc1cc..18f9955210 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -23,12 +23,10 @@ int32_t CXFA_DocumentParser::Parse(const RetainPtr& pStream, m_pDocument.reset(); m_nodeParser.CloseParser(); - m_nodeParser.StartParse(pStream, ePacketID); - m_pDocument = pdfium::MakeUnique(GetNotify()); m_nodeParser.SetFactory(m_pDocument.get()); - int32_t nRetStatus = m_nodeParser.DoParse(); + int32_t nRetStatus = m_nodeParser.Parse(pStream, ePacketID); if (nRetStatus == XFA_PARSESTATUS_Done) { ASSERT(m_pDocument); m_pDocument->SetRoot(m_nodeParser.GetRootNode()); diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index a59ea9d951..7021285dff 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -339,8 +339,8 @@ void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { m_pFactory = pFactory; } -void CXFA_SimpleParser::StartParse(const RetainPtr& pStream, - XFA_PacketType ePacketID) { +int32_t CXFA_SimpleParser::Parse(const RetainPtr& pStream, + XFA_PacketType ePacketID) { CloseParser(); m_pFileRead = pStream; m_pStream = pdfium::MakeRetain(pStream, false); @@ -351,13 +351,7 @@ void CXFA_SimpleParser::StartParse(const RetainPtr& pStream, } m_pXMLDoc = pdfium::MakeUnique(m_pStream); - - m_bParseStarted = true; - m_ePacketID = ePacketID; -} - -int32_t CXFA_SimpleParser::DoParse() { - if (!m_pXMLDoc || !m_bParseStarted) + if (!m_pXMLDoc) return XFA_PARSESTATUS_StatusErr; int32_t iRet = m_pXMLDoc->DoLoad(); @@ -366,7 +360,7 @@ int32_t CXFA_SimpleParser::DoParse() { if (iRet < 100) return iRet / 2; - m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); + m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), ePacketID); m_pXMLDoc->CloseXML(); m_pStream.Reset(); diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h index c5c3eade87..cef9c9af54 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -25,9 +25,9 @@ class CXFA_SimpleParser { explicit CXFA_SimpleParser(CXFA_Document* pFactory); ~CXFA_SimpleParser(); - void StartParse(const RetainPtr& pStream, - XFA_PacketType ePacketID); - int32_t DoParse(); + int32_t Parse(const RetainPtr& pStream, + XFA_PacketType ePacketID); + CFX_XMLNode* ParseXMLData(const ByteString& wsXML); void ConstructXFANode(CXFA_Node* pXFANode, CFX_XMLNode* pXMLNode); CXFA_Node* GetRootNode() const; @@ -77,8 +77,6 @@ class CXFA_SimpleParser { UnownedPtr m_pFactory; // TODO(dsinclair): Figure out who owns this. CXFA_Node* m_pRootNode = nullptr; - XFA_PacketType m_ePacketID = XFA_PacketType::User; - bool m_bParseStarted = false; const bool m_bDocumentParser; }; -- cgit v1.2.3