summaryrefslogtreecommitdiff
path: root/xfa/fde
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-04 15:07:31 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 19:41:25 +0000
commitee62ba2df7297147cccda472f229a8c82bfc22bc (patch)
treea45f899363c19589937a0edc92d77b25cc1bbd67 /xfa/fde
parent03d58937248fa244cbf02a3d38d430a513500311 (diff)
downloadpdfium-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>
Diffstat (limited to 'xfa/fde')
-rw-r--r--xfa/fde/xml/cfde_xmlsyntaxparser.cpp124
-rw-r--r--xfa/fde/xml/cfde_xmlsyntaxparser.h17
2 files changed, 75 insertions, 66 deletions
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: