From 8a3aa459fc5284f51bcd7e98e95bf6214f47bb67 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 16 Nov 2016 12:26:06 -0800 Subject: Make CPDF_Array take unique_ptrs BUG= Review-Url: https://codereview.chromium.org/2498223005 --- core/fpdfdoc/cpdf_dest_unittest.cpp | 19 ++++++++++--------- core/fpdfdoc/cpdf_formfield.cpp | 17 ++++++++--------- core/fpdfdoc/cpdf_interform.cpp | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'core/fpdfdoc') diff --git a/core/fpdfdoc/cpdf_dest_unittest.cpp b/core/fpdfdoc/cpdf_dest_unittest.cpp index d427ab66a0..bc83ecacfc 100644 --- a/core/fpdfdoc/cpdf_dest_unittest.cpp +++ b/core/fpdfdoc/cpdf_dest_unittest.cpp @@ -4,6 +4,7 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_null.h" +#include "core/fpdfapi/parser/cpdf_name.h" #include "core/fpdfapi/parser/cpdf_number.h" #include "core/fpdfdoc/cpdf_dest.h" #include "testing/gtest/include/gtest/gtest.h" @@ -22,16 +23,16 @@ TEST(cpdf_dest, GetXYZ) { EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); auto array = pdfium::MakeUnique(); - array->AddInteger(0); // Page Index. - array->AddName("XYZ"); - array->AddNumber(4); // X + array->AddNew(0); // Page Index. + array->AddNew("XYZ"); + array->AddNew(4); // X // Not enough entries. dest = pdfium::MakeUnique(array.get()); EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); - array->AddNumber(5); // Y - array->AddNumber(6); // Zoom. + array->AddNew(5); // Y + array->AddNew(6); // Zoom. dest = pdfium::MakeUnique(array.get()); EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); @@ -43,15 +44,15 @@ TEST(cpdf_dest, GetXYZ) { EXPECT_EQ(6, zoom); // Set zoom to 0. - array->SetAt(4, new CPDF_Number(0)); + array->SetNewAt(4, 0); dest = pdfium::MakeUnique(array.get()); EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); EXPECT_FALSE(hasZoom); // Set values to null. - array->SetAt(2, new CPDF_Null); - array->SetAt(3, new CPDF_Null); - array->SetAt(4, new CPDF_Null); + array->SetNewAt(2); + array->SetNewAt(3); + array->SetNewAt(4); dest = pdfium::MakeUnique(array.get()); EXPECT_TRUE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom)); EXPECT_FALSE(hasX); diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index 4999f2d6b8..3a2213f1ae 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -555,7 +555,7 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) { for (int i = 0; i < CountOptions(); i++) { if (i == index || IsItemSelected(i)) { opt_value = GetOptionValue(i); - pArray->AddString(PDF_EncodeText(opt_value)); + pArray->AddNew(PDF_EncodeText(opt_value), false); } } m_pDict->SetFor("V", pArray); @@ -563,7 +563,7 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) { } else { m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); CPDF_Array* pI = new CPDF_Array; - pI->AddInteger(index); + pI->AddNew(index); m_pDict->SetFor("I", pI); } } else { @@ -579,7 +579,7 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) { for (int i = 0; i < CountOptions(); i++) { if (i != index && IsItemSelected(i)) { opt_value = GetOptionValue(i); - pArray->AddString(PDF_EncodeText(opt_value)); + pArray->AddNew(PDF_EncodeText(opt_value), false); } } if (pArray->GetCount() > 0) @@ -684,11 +684,10 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, int iCount = pdfium::base::checked_cast(pOpt->GetCount()); if (index >= iCount) { - pOpt->AddString(csStr); + pOpt->AddNew(csStr, false); index = iCount; } else { - CPDF_String* pString = new CPDF_String(csStr, false); - pOpt->InsertAt(index, pString); + pOpt->InsertNewAt(index, csStr, false); } if (bNotify) @@ -836,7 +835,7 @@ bool CPDF_FormField::IsOptionSelected(int iOptIndex) const { if (!pArray) return false; - for (CPDF_Object* pObj : *pArray) { + for (const auto& pObj : *pArray) { if (pObj->GetInteger() == iOptIndex) return true; } @@ -879,14 +878,14 @@ bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) { if (!NotifyListOrComboBoxBeforeChange(csValue)) return false; } - pArray->InsertAt(i, new CPDF_Number(iOptIndex)); + pArray->InsertNewAt(i, iOptIndex); bReturn = true; break; } } if (!bReturn) { if (bSelected) - pArray->AddInteger(iOptIndex); + pArray->AddNew(iOptIndex); if (pArray->IsEmpty()) m_pDict->RemoveFor("I"); diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index 64d15a0d88..c991598a22 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -1237,8 +1237,8 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( continue; CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); - CPDF_Dictionary* pFieldDict = - new CPDF_Dictionary(pDoc->GetByteStringPool()); + auto pFieldDict = + pdfium::MakeUnique(pDoc->GetByteStringPool()); pFieldDict->SetFor("T", new CPDF_String(fullname)); if (pField->GetType() == CPDF_FormField::CheckBox || pField->GetType() == CPDF_FormField::RadioButton) { @@ -1254,7 +1254,7 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( if (pV) pFieldDict->SetFor("V", pV->CloneDirectObject().release()); } - pFields->Add(pFieldDict); + pFields->Add(std::move(pFieldDict)); } } return pDoc; -- cgit v1.2.3