From b9509d740966e16a94dc456c634b3f1005e8be95 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 22 Aug 2018 15:21:52 +0000 Subject: Add GetLowerCaseElementAttributeOrDefault() helper function. CXFA_TextParser::GetEmbeddedObj() does the same thing twice in a row. Change-Id: Ia46a0a697ff667b2884cea82258399889dbb5dc6 Reviewed-on: https://pdfium-review.googlesource.com/40775 Commit-Queue: Lei Zhang Reviewed-by: Ryan Harrison --- xfa/fxfa/cxfa_textparser.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp index b2b47474bf..3084783a83 100644 --- a/xfa/fxfa/cxfa_textparser.cpp +++ b/xfa/fxfa/cxfa_textparser.cpp @@ -41,6 +41,18 @@ enum class TabStopStatus { Location, }; +WideString GetLowerCaseElementAttributeOrDefault( + const CFX_XMLElement* pElement, + const WideString& wsName, + const WideString& wsDefaultValue) { + WideString ws = pElement->GetAttribute(wsName); + if (ws.IsEmpty()) + ws = wsDefaultValue; + else + ws.MakeLower(); + return ws; +} + } // namespace CXFA_TextParser::CXFA_TextParser() @@ -512,19 +524,13 @@ Optional CXFA_TextParser::GetEmbeddedObj( if (wsAttr[0] == L'#') wsAttr.Delete(0); - WideString ws = pElement->GetAttribute(L"xfa:embedType"); - if (ws.IsEmpty()) - ws = L"som"; - else - ws.MakeLower(); + WideString ws = + GetLowerCaseElementAttributeOrDefault(pElement, L"xfa:embedType", L"som"); if (ws != L"uri") return {}; - ws = pElement->GetAttribute(L"xfa:embedMode"); - if (ws.IsEmpty()) - ws = L"formatted"; - else - ws.MakeLower(); + ws = GetLowerCaseElementAttributeOrDefault(pElement, L"xfa:embedMode", + L"formatted"); if (ws != L"raw" && ws != L"formatted") return {}; -- cgit v1.2.3