summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml/cfx_xmlparser.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-04-12 13:14:49 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 13:14:49 +0000
commit6d503b875e6f75f0d8b5f29fcf811a89f12ad12d (patch)
treedfe3e6f2125e327e57b6688c9020f698f3accbfa /core/fxcrt/xml/cfx_xmlparser.cpp
parente1a41afbe146c9a976d96828a3a09a8a384741d9 (diff)
downloadpdfium-6d503b875e6f75f0d8b5f29fcf811a89f12ad12d.tar.xz
Cleanup some CFX_XMLParser code
This CL cleans up minor nits in the CFX_XMLParser code. Change-Id: Ie19d12d3dcce16c9ce6088160ecdec3d9855c11f Reviewed-on: https://pdfium-review.googlesource.com/30170 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/xml/cfx_xmlparser.cpp')
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.cpp87
1 files changed, 35 insertions, 52 deletions
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 05e52015bd..76ea32df6c 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -15,58 +15,46 @@
CFX_XMLParser::CFX_XMLParser(CFX_XMLNode* pParent,
const RetainPtr<CFX_SeekableStreamProxy>& pStream)
- : m_pStream(pStream),
- m_pParser(pdfium::MakeUnique<CFX_XMLSyntaxParser>(m_pStream)),
+ : m_pParser(pdfium::MakeUnique<CFX_XMLSyntaxParser>(pStream)),
m_pParent(pParent),
- m_pChild(nullptr),
- m_syntaxParserResult(FX_XmlSyntaxResult::None) {
- ASSERT(m_pParent && m_pStream);
+ m_pChild(nullptr) {
+ ASSERT(m_pParent && pStream);
m_NodeStack.push(m_pParent);
}
CFX_XMLParser::~CFX_XMLParser() {}
-int32_t CFX_XMLParser::DoParser() {
- if (m_syntaxParserResult == FX_XmlSyntaxResult::Error)
- return -1;
- if (m_syntaxParserResult == FX_XmlSyntaxResult::EndOfString)
- return 100;
-
+int32_t CFX_XMLParser::Parse() {
int32_t iCount = 0;
while (true) {
- m_syntaxParserResult = m_pParser->DoSyntaxParse();
- switch (m_syntaxParserResult) {
- case FX_XmlSyntaxResult::InstructionOpen:
- break;
+ FX_XmlSyntaxResult result = m_pParser->DoSyntaxParse();
+ if (result == FX_XmlSyntaxResult::Error)
+ return -1;
+ if (result == FX_XmlSyntaxResult::EndOfString)
+ break;
+
+ switch (result) {
case FX_XmlSyntaxResult::InstructionClose:
- if (m_pChild) {
- if (m_pChild->GetType() != FX_XMLNODE_Instruction) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- break;
- }
- }
+ if (m_pChild && m_pChild->GetType() != FX_XMLNODE_Instruction)
+ return -1;
+
m_pChild = m_pParent;
break;
- case FX_XmlSyntaxResult::ElementOpen:
- case FX_XmlSyntaxResult::ElementBreak:
- break;
case FX_XmlSyntaxResult::ElementClose:
- if (m_pChild->GetType() != FX_XMLNODE_Element) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- break;
- }
+ if (m_pChild->GetType() != FX_XMLNODE_Element)
+ return -1;
+
m_ws1 = m_pParser->GetTagName();
- m_ws2 = static_cast<CFX_XMLElement*>(m_pChild)->GetName();
- if (m_ws1.GetLength() > 0 && m_ws1 != m_ws2) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- break;
+ if (m_ws1.GetLength() > 0 &&
+ m_ws1 != static_cast<CFX_XMLElement*>(m_pChild)->GetName()) {
+ return -1;
}
+
if (!m_NodeStack.empty())
m_NodeStack.pop();
- if (m_NodeStack.empty()) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- break;
- }
+ if (m_NodeStack.empty())
+ return -1;
+
m_pParent = m_NodeStack.top();
m_pChild = m_pParent;
iCount++;
@@ -92,10 +80,9 @@ int32_t CFX_XMLParser::DoParser() {
m_ws1 = m_pParser->GetAttributeName();
break;
case FX_XmlSyntaxResult::AttriValue:
- if (m_pChild) {
- m_ws2 = m_pParser->GetAttributeName();
- if (m_pChild->GetType() == FX_XMLNODE_Element)
- static_cast<CFX_XMLElement*>(m_pChild)->SetString(m_ws1, m_ws2);
+ if (m_pChild && m_pChild->GetType() == FX_XMLNODE_Element) {
+ static_cast<CFX_XMLElement*>(m_pChild)->SetString(
+ m_ws1, m_pParser->GetAttributeName());
}
m_ws1.clear();
break;
@@ -113,27 +100,23 @@ int32_t CFX_XMLParser::DoParser() {
break;
case FX_XmlSyntaxResult::TargetData:
if (m_pChild) {
- if (m_pChild->GetType() != FX_XMLNODE_Instruction) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- break;
- }
+ if (m_pChild->GetType() != FX_XMLNODE_Instruction)
+ return -1;
+
auto* instruction = static_cast<CFX_XMLInstruction*>(m_pChild);
if (!m_ws1.IsEmpty())
instruction->AppendData(m_ws1);
+
instruction->AppendData(m_pParser->GetTargetData());
}
m_ws1.clear();
break;
+ case FX_XmlSyntaxResult::ElementOpen:
+ case FX_XmlSyntaxResult::ElementBreak:
+ case FX_XmlSyntaxResult::InstructionOpen:
default:
break;
}
- if (m_syntaxParserResult == FX_XmlSyntaxResult::Error ||
- m_syntaxParserResult == FX_XmlSyntaxResult::EndOfString) {
- break;
- }
}
- return (m_syntaxParserResult == FX_XmlSyntaxResult::Error ||
- m_NodeStack.size() != 1)
- ? -1
- : m_pParser->GetStatus();
+ return m_NodeStack.size() != 1 ? -1 : m_pParser->GetStatus();
}