From c6077a0164340fa084be03eb059d608bc2675b2b Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 23 Apr 2018 18:24:56 +0000 Subject: Make CFX_SeekableStreamProxy a subclass of IFX_SeekableReadStream This CL changes CFX_SeekableStreamProxy to be an IFX_SeekableReadStream subclass. Change-Id: I28ccb4771606fd6c9cc60e57297ae2e776fc5a9f Reviewed-on: https://pdfium-review.googlesource.com/30879 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- core/fxcrt/xml/cfx_xmlparser.cpp | 35 ++++++++++------------------------- core/fxcrt/xml/cfx_xmlparser.h | 9 +++------ 2 files changed, 13 insertions(+), 31 deletions(-) (limited to 'core/fxcrt/xml') diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp index 7788a42907..bf578291e6 100644 --- a/core/fxcrt/xml/cfx_xmlparser.cpp +++ b/core/fxcrt/xml/cfx_xmlparser.cpp @@ -11,6 +11,7 @@ #include #include +#include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_safe_types.h" @@ -57,13 +58,10 @@ bool CFX_XMLParser::IsXMLNameChar(wchar_t ch, bool bFirstChar) { } CFX_XMLParser::CFX_XMLParser(CFX_XMLNode* pParent, - const RetainPtr& pStream) + const RetainPtr& pStream) : m_pParent(pParent), m_pChild(nullptr), - m_pStream(pdfium::MakeRetain(pStream)), m_iXMLPlaneSize(1024), - m_iCurrentPos(0), - m_bEOS(false), m_Start(0), m_End(0), m_CurNodeType(FX_XMLNODE_Unknown), @@ -77,18 +75,19 @@ CFX_XMLParser::CFX_XMLParser(CFX_XMLNode* pParent, ASSERT(m_pParent); ASSERT(pStream); - uint16_t wCodePage = m_pStream->GetCodePage(); + auto proxy = pdfium::MakeRetain(pStream); + uint16_t wCodePage = proxy->GetCodePage(); if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && wCodePage != FX_CODEPAGE_UTF8) { - m_pStream->SetCodePage(FX_CODEPAGE_UTF8); + proxy->SetCodePage(FX_CODEPAGE_UTF8); } + m_pStream = proxy; m_NodeStack.push(m_pParent); m_iXMLPlaneSize = std::min(m_iXMLPlaneSize, - pdfium::base::checked_cast(m_pStream->GetLength())); - m_iCurrentPos = m_pStream->GetBOMLength(); + pdfium::base::checked_cast(m_pStream->GetSize())); FX_SAFE_SIZE_T alloc_size_safe = m_iXMLPlaneSize; alloc_size_safe += 1; // For NUL. @@ -217,28 +216,20 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() { return m_syntaxParserResult; } - FX_FILESIZE iStreamLength = m_pStream->GetLength(); - FX_FILESIZE iPos; - FX_XmlSyntaxResult syntaxParserResult = FX_XmlSyntaxResult::None; while (true) { if (m_Start >= m_End) { - if (m_bEOS || m_iCurrentPos >= iStreamLength) { + if (m_pStream->IsEOF()) { m_syntaxParserResult = FX_XmlSyntaxResult::EndOfString; return m_syntaxParserResult; } - if (m_pStream->GetPosition() != m_iCurrentPos) - m_pStream->Seek(CFX_SeekableStreamProxy::From::Begin, m_iCurrentPos); size_t buffer_chars = - m_pStream->ReadString(m_Buffer.data(), m_iXMLPlaneSize, &m_bEOS); - iPos = m_pStream->GetPosition(); + m_pStream->ReadBlock(m_Buffer.data(), m_iXMLPlaneSize); if (buffer_chars == 0) { - m_iCurrentPos = iStreamLength; m_syntaxParserResult = FX_XmlSyntaxResult::EndOfString; return m_syntaxParserResult; } - m_iCurrentPos = iPos; m_Start = 0; m_End = buffer_chars; } @@ -665,13 +656,7 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() { } bool CFX_XMLParser::GetStatus() const { - if (!m_pStream) - return false; - - int32_t iStreamLength = m_pStream->GetLength(); - if (iStreamLength < 1) - return true; - return m_syntaxParserResult != FX_XmlSyntaxResult::Error; + return m_pStream && m_syntaxParserResult != FX_XmlSyntaxResult::Error; } void CFX_XMLParser::ParseTextChar(wchar_t character) { diff --git a/core/fxcrt/xml/cfx_xmlparser.h b/core/fxcrt/xml/cfx_xmlparser.h index f369453de1..6405b61a64 100644 --- a/core/fxcrt/xml/cfx_xmlparser.h +++ b/core/fxcrt/xml/cfx_xmlparser.h @@ -12,14 +12,13 @@ #include #include "core/fxcrt/cfx_blockbuffer.h" -#include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/xml/cfx_xmlnode.h" class CFX_XMLElement; class CFX_XMLNode; -class IFX_SeekableStream; +class IFX_SeekableReadStream; enum class FX_XmlSyntaxResult { None, @@ -44,7 +43,7 @@ class CFX_XMLParser { static bool IsXMLNameChar(wchar_t ch, bool bFirstChar); CFX_XMLParser(CFX_XMLNode* pParent, - const RetainPtr& pStream); + const RetainPtr& pStream); virtual ~CFX_XMLParser(); bool Parse(); @@ -100,11 +99,9 @@ class CFX_XMLParser { std::stack m_NodeStack; WideString m_ws1; - RetainPtr m_pStream; + RetainPtr m_pStream; size_t m_iXMLPlaneSize; - FX_FILESIZE m_iCurrentPos; std::vector m_Buffer; - bool m_bEOS; FX_FILESIZE m_Start; // Start position in m_Buffer FX_FILESIZE m_End; // End position in m_Buffer FX_XMLNODETYPE m_CurNodeType; -- cgit v1.2.3