From c8a17e550d4d4a6f68598f8eed70eb6f8f301442 Mon Sep 17 00:00:00 2001 From: Jane Liu Date: Thu, 13 Jul 2017 10:37:59 -0400 Subject: Changed CPDF_FileSpec::GetFileName() to directly return CFX_WideString Changed CPDF_FileSpec::GetFileName() to directly return CFX_WideString, instead of taking in a CFX_WideString* and returning a bool. Also fixed test calls in the unit test. Bug=pdfium:808 Change-Id: Ie081fc9f4f1c15d23c86d7222d8480ab9cb56056 Reviewed-on: https://pdfium-review.googlesource.com/7671 Commit-Queue: Jane Liu Commit-Queue: dsinclair Reviewed-by: dsinclair Reviewed-by: Lei Zhang --- core/fpdfdoc/cpdf_filespec.cpp | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'core/fpdfdoc/cpdf_filespec.cpp') diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp index 7d1f0e68b9..5ef6f466c5 100644 --- a/core/fpdfdoc/cpdf_filespec.cpp +++ b/core/fpdfdoc/cpdf_filespec.cpp @@ -89,36 +89,31 @@ CFX_WideString CPDF_FileSpec::DecodeFileName(const CFX_WideString& filepath) { #endif } -bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const { +CFX_WideString CPDF_FileSpec::GetFileName() const { + CFX_WideString csFileName; if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { - *csFileName = pDict->GetUnicodeTextFor("UF"); - if (csFileName->IsEmpty()) { - *csFileName = + csFileName = pDict->GetUnicodeTextFor("UF"); + if (csFileName.IsEmpty()) { + csFileName = CFX_WideString::FromLocal(pDict->GetStringFor("F").AsStringC()); } if (pDict->GetStringFor("FS") == "URL") - return true; - if (csFileName->IsEmpty()) { - if (pDict->KeyExist("DOS")) { - *csFileName = - CFX_WideString::FromLocal(pDict->GetStringFor("DOS").AsStringC()); - } else if (pDict->KeyExist("Mac")) { - *csFileName = - CFX_WideString::FromLocal(pDict->GetStringFor("Mac").AsStringC()); - } else if (pDict->KeyExist("Unix")) { - *csFileName = - CFX_WideString::FromLocal(pDict->GetStringFor("Unix").AsStringC()); - } else { - return false; + return csFileName; + + if (csFileName.IsEmpty()) { + constexpr const char* keys[] = {"DOS", "Mac", "Unix"}; + for (const auto* key : keys) { + if (pDict->KeyExist(key)) { + csFileName = + CFX_WideString::FromLocal(pDict->GetStringFor(key).AsStringC()); + break; + } } } } else if (m_pObj->IsString()) { - *csFileName = CFX_WideString::FromLocal(m_pObj->GetString().AsStringC()); - } else { - return false; + csFileName = CFX_WideString::FromLocal(m_pObj->GetString().AsStringC()); } - *csFileName = DecodeFileName(*csFileName); - return true; + return DecodeFileName(csFileName); } CPDF_Stream* CPDF_FileSpec::GetFileStream() const { -- cgit v1.2.3