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 <thestig@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp index b2b4747..3084783 100644 --- a/xfa/fxfa/cxfa_textparser.cpp +++ b/xfa/fxfa/cxfa_textparser.cpp
@@ -41,6 +41,18 @@ 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 @@ 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 {};