From c9171e16d9d4477501d326d8d456fdc03e0f832e Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 26 Jul 2018 19:34:26 +0000 Subject: Use moar ToXMLElement() in place of static_cast<>. Introduces checks in a few new places, but mainly just consolidates checking/casting logic. Change-Id: I634a03060d254db099972c6978249992367e146c Reviewed-on: https://pdfium-review.googlesource.com/38900 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- xfa/fxfa/cxfa_textparser.cpp | 70 ++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'xfa/fxfa/cxfa_textparser.cpp') diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp index f0a6dd2af1..c60b774051 100644 --- a/xfa/fxfa/cxfa_textparser.cpp +++ b/xfa/fxfa/cxfa_textparser.cpp @@ -276,18 +276,18 @@ bool CXFA_TextParser::TagValidate(const WideString& wsName) const { std::unique_ptr CXFA_TextParser::ParseTagInfo( CFX_XMLNode* pXMLNode) { auto tagProvider = pdfium::MakeUnique(); - - WideString wsName; - if (pXMLNode->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pXMLElement = static_cast(pXMLNode); - wsName = pXMLElement->GetLocalTagName(); + CFX_XMLElement* pXMLElement = ToXMLElement(pXMLNode); + if (pXMLElement) { + WideString wsName = pXMLElement->GetLocalTagName(); tagProvider->SetTagName(wsName); tagProvider->m_bTagAvailable = TagValidate(wsName); - WideString wsValue = pXMLElement->GetAttribute(L"style"); if (!wsValue.IsEmpty()) tagProvider->SetAttribute(L"style", wsValue); - } else if (pXMLNode->GetType() == FX_XMLNODE_Text) { + + return tagProvider; + } + if (pXMLNode->GetType() == FX_XMLNODE_Text) { tagProvider->m_bTagAvailable = true; tagProvider->m_bContent = true; } @@ -502,38 +502,38 @@ bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, if (!pXMLNode) return false; - bool bRet = false; - if (pXMLNode->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pElement = static_cast(pXMLNode); - WideString wsAttr = pElement->GetAttribute(L"xfa:embed"); - if (wsAttr.IsEmpty()) - return false; - if (wsAttr[0] == L'#') - wsAttr.Delete(0); - - WideString ws = pElement->GetAttribute(L"xfa:embedType"); - if (ws.IsEmpty()) - ws = L"som"; - else - ws.MakeLower(); + CFX_XMLElement* pElement = ToXMLElement(pXMLNode); + if (!pElement) + return false; + + WideString wsAttr = pElement->GetAttribute(L"xfa:embed"); + if (wsAttr.IsEmpty()) + return false; - bool bURI = (ws == L"uri"); - if (!bURI && ws != L"som") - return false; + if (wsAttr[0] == L'#') + wsAttr.Delete(0); - ws = pElement->GetAttribute(L"xfa:embedMode"); - if (ws.IsEmpty()) - ws = L"formatted"; - else - ws.MakeLower(); + WideString ws = pElement->GetAttribute(L"xfa:embedType"); + if (ws.IsEmpty()) + ws = L"som"; + else + ws.MakeLower(); - bool bRaw = (ws == L"raw"); - if (!bRaw && ws != L"formatted") - return false; + bool bURI = (ws == L"uri"); + if (!bURI && ws != L"som") + return false; - bRet = pTextProvider->GetEmbbedObj(bURI, bRaw, wsAttr, wsValue); - } - return bRet; + ws = pElement->GetAttribute(L"xfa:embedMode"); + if (ws.IsEmpty()) + ws = L"formatted"; + else + ws.MakeLower(); + + bool bRaw = (ws == L"raw"); + if (!bRaw && ws != L"formatted") + return false; + + return pTextProvider->GetEmbbedObj(bURI, bRaw, wsAttr, wsValue); } CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( -- cgit v1.2.3