diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-04 15:07:31 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-04 19:41:25 +0000 |
commit | ee62ba2df7297147cccda472f229a8c82bfc22bc (patch) | |
tree | a45f899363c19589937a0edc92d77b25cc1bbd67 | |
parent | 03d58937248fa244cbf02a3d38d430a513500311 (diff) | |
download | pdfium-ee62ba2df7297147cccda472f229a8c82bfc22bc.tar.xz |
Cleanup CFX_BlockBuffer
This CL cleans up default parameters, return values and bits of code
formatting in the CFX_BlockBuffer code.
Change-Id: Ie7fd7d86046f716d0786213735ad464eefc58dbb
Reviewed-on: https://pdfium-review.googlesource.com/3670
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | core/fxcrt/cfx_blockbuffer.cpp | 138 | ||||
-rw-r--r-- | core/fxcrt/cfx_blockbuffer.h | 31 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlsyntaxparser.cpp | 124 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlsyntaxparser.h | 17 |
4 files changed, 154 insertions, 156 deletions
diff --git a/core/fxcrt/cfx_blockbuffer.cpp b/core/fxcrt/cfx_blockbuffer.cpp index 354f415282..efae014982 100644 --- a/core/fxcrt/cfx_blockbuffer.cpp +++ b/core/fxcrt/cfx_blockbuffer.cpp @@ -7,57 +7,58 @@ #include "core/fxcrt/cfx_blockbuffer.h" #include <algorithm> +#include <utility> #include "third_party/base/stl_util.h" -CFX_BlockBuffer::CFX_BlockBuffer(int32_t iAllocStep) - : m_iDataLength(0), - m_iBufferSize(0), - m_iAllocStep(iAllocStep), - m_iStartPosition(0) {} +namespace { -CFX_BlockBuffer::~CFX_BlockBuffer() { - ClearBuffer(); +const int kAllocStep = 1024 * 1024; + +} // namespace + +CFX_BlockBuffer::CFX_BlockBuffer() + : m_iDataLength(0), m_iBufferSize(0), m_iStartPosition(0) {} + +CFX_BlockBuffer::~CFX_BlockBuffer() {} + +int32_t CFX_BlockBuffer::GetAllocStep() const { + return kAllocStep; } -wchar_t* CFX_BlockBuffer::GetAvailableBlock(int32_t& iIndexInBlock) { - iIndexInBlock = 0; +std::pair<wchar_t*, int32_t> CFX_BlockBuffer::GetAvailableBlock() { if (m_BlockArray.empty()) - return nullptr; + return {nullptr, 0}; int32_t iRealIndex = m_iStartPosition + m_iDataLength; if (iRealIndex == m_iBufferSize) { - m_BlockArray.emplace_back(FX_Alloc(wchar_t, m_iAllocStep)); - m_iBufferSize += m_iAllocStep; - return m_BlockArray.back().get(); + m_BlockArray.emplace_back(FX_Alloc(wchar_t, kAllocStep)); + m_iBufferSize += kAllocStep; + return {m_BlockArray.back().get(), 0}; } - iIndexInBlock = iRealIndex % m_iAllocStep; - return m_BlockArray[iRealIndex / m_iAllocStep].get(); + return {m_BlockArray[iRealIndex / kAllocStep].get(), iRealIndex % kAllocStep}; } -bool CFX_BlockBuffer::InitBuffer(int32_t iBufferSize) { - ClearBuffer(); - int32_t iNumOfBlock = (iBufferSize - 1) / m_iAllocStep + 1; - for (int32_t i = 0; i < iNumOfBlock; i++) - m_BlockArray.emplace_back(FX_Alloc(wchar_t, m_iAllocStep)); - - m_iBufferSize = iNumOfBlock * m_iAllocStep; +bool CFX_BlockBuffer::InitBuffer() { + m_BlockArray.clear(); + m_BlockArray.emplace_back(FX_Alloc(wchar_t, kAllocStep)); + m_iBufferSize = kAllocStep; return true; } void CFX_BlockBuffer::SetTextChar(int32_t iIndex, wchar_t ch) { - if (iIndex < 0) { + if (iIndex < 0) return; - } + int32_t iRealIndex = m_iStartPosition + iIndex; - int32_t iBlockIndex = iRealIndex / m_iAllocStep; - int32_t iInnerIndex = iRealIndex % m_iAllocStep; + int32_t iBlockIndex = iRealIndex / kAllocStep; + int32_t iInnerIndex = iRealIndex % kAllocStep; int32_t iBlockSize = pdfium::CollectionSize<int32_t>(m_BlockArray); if (iBlockIndex >= iBlockSize) { int32_t iNewBlocks = iBlockIndex - iBlockSize + 1; do { - m_BlockArray.emplace_back(FX_Alloc(wchar_t, m_iAllocStep)); - m_iBufferSize += m_iAllocStep; + m_BlockArray.emplace_back(FX_Alloc(wchar_t, kAllocStep)); + m_iBufferSize += kAllocStep; } while (--iNewBlocks); } wchar_t* pTextData = m_BlockArray[iBlockIndex].get(); @@ -65,7 +66,7 @@ void CFX_BlockBuffer::SetTextChar(int32_t iIndex, wchar_t ch) { m_iDataLength = std::max(m_iDataLength, iIndex + 1); } -int32_t CFX_BlockBuffer::DeleteTextChars(int32_t iCount, bool bDirection) { +int32_t CFX_BlockBuffer::DeleteTextChars(int32_t iCount) { if (iCount <= 0) return m_iDataLength; @@ -73,68 +74,57 @@ int32_t CFX_BlockBuffer::DeleteTextChars(int32_t iCount, bool bDirection) { Reset(false); return 0; } - if (bDirection) { - m_iStartPosition += iCount; - m_iDataLength -= iCount; - } else { - m_iDataLength -= iCount; - } + m_iDataLength -= iCount; return m_iDataLength; } -void CFX_BlockBuffer::GetTextData(CFX_WideString& wsTextData, - int32_t iStart, - int32_t iLength) const { - wsTextData.clear(); +CFX_WideString CFX_BlockBuffer::GetTextData(int32_t iStart, + int32_t iLength) const { int32_t iMaybeDataLength = m_iBufferSize - 1 - m_iStartPosition; - if (iStart < 0 || iStart > iMaybeDataLength) { - return; - } - if (iLength == -1 || iLength > iMaybeDataLength) { + if (iStart < 0 || iStart > iMaybeDataLength) + return CFX_WideString(); + if (iLength == -1 || iLength > iMaybeDataLength) iLength = iMaybeDataLength; - } - if (iLength <= 0) { - return; - } + if (iLength <= 0) + return CFX_WideString(); + + CFX_WideString wsTextData; wchar_t* pBuf = wsTextData.GetBuffer(iLength); - if (!pBuf) { - return; - } - int32_t iStartBlockIndex = 0; - int32_t iStartInnerIndex = 0; - TextDataIndex2BufIndex(iStart, iStartBlockIndex, iStartInnerIndex); - int32_t iEndBlockIndex = 0; - int32_t iEndInnerIndex = 0; - TextDataIndex2BufIndex(iStart + iLength, iEndBlockIndex, iEndInnerIndex); + if (!pBuf) + return CFX_WideString(); + + int32_t iStartBlock = 0; + int32_t iStartInner = 0; + std::tie(iStartBlock, iStartInner) = TextDataIndex2BufIndex(iStart); + + int32_t iEndBlock = 0; + int32_t iEndInner = 0; + std::tie(iEndBlock, iEndInner) = TextDataIndex2BufIndex(iStart + iLength); + int32_t iPointer = 0; - for (int32_t i = iStartBlockIndex; i <= iEndBlockIndex; i++) { + for (int32_t i = iStartBlock; i <= iEndBlock; i++) { int32_t iBufferPointer = 0; - int32_t iCopyLength = m_iAllocStep; - if (i == iStartBlockIndex) { - iCopyLength -= iStartInnerIndex; - iBufferPointer = iStartInnerIndex; - } - if (i == iEndBlockIndex) { - iCopyLength -= ((m_iAllocStep - 1) - iEndInnerIndex); + int32_t iCopyLength = kAllocStep; + if (i == iStartBlock) { + iCopyLength -= iStartInner; + iBufferPointer = iStartInner; } + if (i == iEndBlock) + iCopyLength -= ((kAllocStep - 1) - iEndInner); + wchar_t* pBlockBuf = m_BlockArray[i].get(); memcpy(pBuf + iPointer, pBlockBuf + iBufferPointer, iCopyLength * sizeof(wchar_t)); iPointer += iCopyLength; } wsTextData.ReleaseBuffer(iLength); + return wsTextData; } -void CFX_BlockBuffer::TextDataIndex2BufIndex(const int32_t iIndex, - int32_t& iBlockIndex, - int32_t& iInnerIndex) const { +std::pair<int32_t, int32_t> CFX_BlockBuffer::TextDataIndex2BufIndex( + const int32_t iIndex) const { ASSERT(iIndex >= 0); - int32_t iRealIndex = m_iStartPosition + iIndex; - iBlockIndex = iRealIndex / m_iAllocStep; - iInnerIndex = iRealIndex % m_iAllocStep; -} -void CFX_BlockBuffer::ClearBuffer() { - m_iBufferSize = 0; - m_BlockArray.clear(); + int32_t iRealIndex = m_iStartPosition + iIndex; + return {iRealIndex / kAllocStep, iRealIndex % kAllocStep}; } diff --git a/core/fxcrt/cfx_blockbuffer.h b/core/fxcrt/cfx_blockbuffer.h index dbf01a938a..e7e493ca86 100644 --- a/core/fxcrt/cfx_blockbuffer.h +++ b/core/fxcrt/cfx_blockbuffer.h @@ -10,44 +10,43 @@ #include <stdint.h> #include <memory> +#include <utility> #include <vector> #include "core/fxcrt/fx_string.h" class CFX_BlockBuffer { public: - explicit CFX_BlockBuffer(int32_t iAllocStep = 1024 * 1024); + CFX_BlockBuffer(); ~CFX_BlockBuffer(); - bool InitBuffer(int32_t iBufferSize = 1024 * 1024); - bool IsInitialized() { return m_iBufferSize / m_iAllocStep >= 1; } + bool InitBuffer(); + bool IsInitialized() { return m_iBufferSize / GetAllocStep() >= 1; } - wchar_t* GetAvailableBlock(int32_t& iIndexInBlock); - inline int32_t GetAllocStep() const { return m_iAllocStep; } - inline int32_t& GetDataLengthRef() { return m_iDataLength; } + std::pair<wchar_t*, int32_t> GetAvailableBlock(); + int32_t GetAllocStep() const; - inline void Reset(bool bReserveData = true) { + // This is ... scary. This returns a ref, which the XMLSyntaxParser stores + // and modifies. + int32_t& GetDataLengthRef() { return m_iDataLength; } + + void Reset(bool bReserveData) { if (!bReserveData) m_iStartPosition = 0; m_iDataLength = 0; } void SetTextChar(int32_t iIndex, wchar_t ch); - int32_t DeleteTextChars(int32_t iCount, bool bDirection = true); - void GetTextData(CFX_WideString& wsTextData, - int32_t iStart = 0, - int32_t iLength = -1) const; + int32_t DeleteTextChars(int32_t iCount); + CFX_WideString GetTextData(int32_t iStart, int32_t iLength) const; private: - inline void TextDataIndex2BufIndex(const int32_t iIndex, - int32_t& iBlockIndex, - int32_t& iInnerIndex) const; - void ClearBuffer(); + std::pair<int32_t, int32_t> TextDataIndex2BufIndex( + const int32_t iIndex) const; std::vector<std::unique_ptr<wchar_t, FxFreeDeleter>> m_BlockArray; int32_t m_iDataLength; int32_t m_iBufferSize; - int32_t m_iAllocStep; int32_t m_iStartPosition; }; diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser.cpp b/xfa/fde/xml/cfde_xmlsyntaxparser.cpp index 45a1eddb83..b4f9a211a7 100644 --- a/xfa/fde/xml/cfde_xmlsyntaxparser.cpp +++ b/xfa/fde/xml/cfde_xmlsyntaxparser.cpp @@ -126,9 +126,11 @@ void CFDE_XMLSyntaxParser::Init(const CFX_RetainPtr<IFGAS_Stream>& pStream, m_pBuffer = FX_Alloc( wchar_t, pdfium::base::ValueOrDieForType<size_t>(alloc_size_safe)); m_pStart = m_pEnd = m_pBuffer; + ASSERT(!m_BlockBuffer.IsInitialized()); m_BlockBuffer.InitBuffer(); - m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_iParsedBytes = m_iParsedChars = 0; m_iBufferChars = 0; } @@ -174,9 +176,9 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { if (ch == L'<') { if (m_iDataLength > 0) { m_iTextDataLength = m_iDataLength; - m_BlockBuffer.Reset(); - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_iEntityStart = -1; syntaxParserResult = FDE_XmlSyntaxResult::Text; } else { @@ -221,9 +223,9 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { return m_syntaxParserResult; } else { m_iTextDataLength = m_iDataLength; - m_BlockBuffer.Reset(); - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); if (m_syntaxParserState != FDE_XmlSyntaxState::Target) { syntaxParserResult = FDE_XmlSyntaxResult::TagName; } else { @@ -233,8 +235,8 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } } else { if (m_iIndexInBlock == m_iAllocStep) { - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); if (!m_pCurrentBlock) { return FDE_XmlSyntaxResult::Error; } @@ -275,16 +277,16 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } } m_iTextDataLength = m_iDataLength; - m_BlockBuffer.Reset(); - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_syntaxParserState = FDE_XmlSyntaxState::AttriEqualSign; syntaxParserResult = FDE_XmlSyntaxResult::AttriName; } } else { if (m_iIndexInBlock == m_iAllocStep) { - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); if (!m_pCurrentBlock) { return FDE_XmlSyntaxResult::Error; } @@ -333,8 +335,9 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } m_iTextDataLength = m_iDataLength; m_wQuotationMark = 0; - m_BlockBuffer.Reset(); - m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_pStart++; m_syntaxParserState = FDE_XmlSyntaxState::AttriName; syntaxParserResult = FDE_XmlSyntaxResult::AttriValue; @@ -345,8 +348,8 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { case FDE_XmlSyntaxState::CloseInstruction: if (ch != L'>') { if (m_iIndexInBlock == m_iAllocStep) { - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); if (!m_pCurrentBlock) { return FDE_XmlSyntaxResult::Error; } @@ -356,8 +359,9 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { m_syntaxParserState = FDE_XmlSyntaxState::TargetData; } else if (m_iDataLength > 0) { m_iTextDataLength = m_iDataLength; - m_BlockBuffer.Reset(); - m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); syntaxParserResult = FDE_XmlSyntaxResult::TargetData; } else { m_pStart++; @@ -373,8 +377,9 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { m_CurNode.eNodeType = FDE_XMLNODE_Unknown; } m_iCurrentNodeNum = m_CurNode.iNodeNum; - m_BlockBuffer.Reset(); - m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_syntaxParserState = FDE_XmlSyntaxState::Text; syntaxParserResult = FDE_XmlSyntaxResult::InstructionClose; } @@ -407,9 +412,9 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } m_iCurrentNodeNum = m_CurNode.iNodeNum; m_iTextDataLength = m_iDataLength; - m_BlockBuffer.Reset(); - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_syntaxParserState = FDE_XmlSyntaxState::Text; syntaxParserResult = FDE_XmlSyntaxResult::ElementClose; } else if (!IsXMLWhiteSpace(ch)) { @@ -418,8 +423,8 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } } else { if (m_iIndexInBlock == m_iAllocStep) { - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); if (!m_pCurrentBlock) { return FDE_XmlSyntaxResult::Error; } @@ -447,13 +452,14 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { m_pStart += 3; syntaxParserResult = FDE_XmlSyntaxResult::CData; m_iTextDataLength = m_iDataLength; - m_BlockBuffer.Reset(); - m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_syntaxParserState = FDE_XmlSyntaxState::Text; } else { if (m_iIndexInBlock == m_iAllocStep) { - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); if (!m_pCurrentBlock) return FDE_XmlSyntaxResult::Error; } @@ -500,14 +506,13 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { if (ch == m_SkipChar) { m_SkipStack.pop(); if (m_SkipStack.empty()) { - if (m_iDataLength >= 9) { - CFX_WideString wsHeader; - m_BlockBuffer.GetTextData(wsHeader, 0, 7); - } + if (m_iDataLength >= 9) + (void)m_BlockBuffer.GetTextData(0, 7); + m_iTextDataLength = m_iDataLength; - m_BlockBuffer.Reset(); - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_syntaxParserState = FDE_XmlSyntaxState::Text; } else { m_SkipChar = m_SkipStack.top(); @@ -517,8 +522,8 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } if (!m_SkipStack.empty()) { if (m_iIndexInBlock == m_iAllocStep) { - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); if (!m_pCurrentBlock) { return FDE_XmlSyntaxResult::Error; } @@ -545,9 +550,9 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } else if (m_wQuotationMark == 0) { m_iTextDataLength = m_iDataLength; m_wQuotationMark = 0; - m_BlockBuffer.Reset(); - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_pStart++; syntaxParserResult = FDE_XmlSyntaxResult::TargetData; break; @@ -563,9 +568,9 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } else if (ch == m_wQuotationMark) { m_iTextDataLength = m_iDataLength; m_wQuotationMark = 0; - m_BlockBuffer.Reset(); - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.Reset(true); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_pStart++; syntaxParserResult = FDE_XmlSyntaxResult::TargetData; } else { @@ -574,8 +579,8 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } } else { if (m_iIndexInBlock == m_iAllocStep) { - m_pCurrentBlock = - m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); if (!m_pCurrentBlock) { return FDE_XmlSyntaxResult::Error; } @@ -627,17 +632,17 @@ FX_FILESIZE CFDE_XMLSyntaxParser::GetCurrentBinaryPos() const { void CFDE_XMLSyntaxParser::ParseTextChar(wchar_t character) { if (m_iIndexInBlock == m_iAllocStep) { - m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); - if (!m_pCurrentBlock) { + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); + if (!m_pCurrentBlock) return; - } } + m_pCurrentBlock[m_iIndexInBlock++] = character; m_iDataLength++; if (m_iEntityStart > -1 && character == L';') { - CFX_WideString csEntity; - m_BlockBuffer.GetTextData(csEntity, m_iEntityStart + 1, - (m_iDataLength - 1) - m_iEntityStart - 1); + CFX_WideString csEntity = m_BlockBuffer.GetTextData( + m_iEntityStart + 1, (m_iDataLength - 1) - m_iEntityStart - 1); int32_t iLen = csEntity.GetLength(); if (iLen > 0) { if (csEntity[0] == L'#') { @@ -691,13 +696,12 @@ void CFDE_XMLSyntaxParser::ParseTextChar(wchar_t character) { } } } - m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, false); - m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); + m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart); + std::tie(m_pCurrentBlock, m_iIndexInBlock) = + m_BlockBuffer.GetAvailableBlock(); m_iEntityStart = -1; - } else { - if (m_iEntityStart < 0 && character == L'&') { - m_iEntityStart = m_iDataLength - 1; - } + } else if (m_iEntityStart < 0 && character == L'&') { + m_iEntityStart = m_iDataLength - 1; } m_pStart++; } diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser.h b/xfa/fde/xml/cfde_xmlsyntaxparser.h index 9e768d01aa..4f707dc5de 100644 --- a/xfa/fde/xml/cfde_xmlsyntaxparser.h +++ b/xfa/fde/xml/cfde_xmlsyntaxparser.h @@ -53,22 +53,27 @@ class CFDE_XMLSyntaxParser { int32_t GetLastNodeNumber() const { return m_iLastNodeNum; } void GetTargetName(CFX_WideString& wsTarget) const { - m_BlockBuffer.GetTextData(wsTarget, 0, m_iTextDataLength); + wsTarget = m_BlockBuffer.GetTextData(0, m_iTextDataLength); } + void GetTagName(CFX_WideString& wsTag) const { - m_BlockBuffer.GetTextData(wsTag, 0, m_iTextDataLength); + wsTag = m_BlockBuffer.GetTextData(0, m_iTextDataLength); } + void GetAttributeName(CFX_WideString& wsAttriName) const { - m_BlockBuffer.GetTextData(wsAttriName, 0, m_iTextDataLength); + wsAttriName = m_BlockBuffer.GetTextData(0, m_iTextDataLength); } + void GetAttributeValue(CFX_WideString& wsAttriValue) const { - m_BlockBuffer.GetTextData(wsAttriValue, 0, m_iTextDataLength); + wsAttriValue = m_BlockBuffer.GetTextData(0, m_iTextDataLength); } + void GetTextData(CFX_WideString& wsText) const { - m_BlockBuffer.GetTextData(wsText, 0, m_iTextDataLength); + wsText = m_BlockBuffer.GetTextData(0, m_iTextDataLength); } + void GetTargetData(CFX_WideString& wsData) const { - m_BlockBuffer.GetTextData(wsData, 0, m_iTextDataLength); + wsData = m_BlockBuffer.GetTextData(0, m_iTextDataLength); } protected: |