summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-16 12:26:06 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-16 12:26:06 -0800
commit8a3aa459fc5284f51bcd7e98e95bf6214f47bb67 (patch)
tree13fb383936d679aded19054f4e7a0387dd52de76 /core/fpdfdoc
parent14a60c50b10de1d9e4edd3629ea210a816940a75 (diff)
downloadpdfium-8a3aa459fc5284f51bcd7e98e95bf6214f47bb67.tar.xz
Make CPDF_Array take unique_ptrs
BUG= Review-Url: https://codereview.chromium.org/2498223005
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_dest_unittest.cpp19
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp17
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp6
3 files changed, 21 insertions, 21 deletions
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<CPDF_Array>();
- array->AddInteger(0); // Page Index.
- array->AddName("XYZ");
- array->AddNumber(4); // X
+ array->AddNew<CPDF_Number>(0); // Page Index.
+ array->AddNew<CPDF_Name>("XYZ");
+ array->AddNew<CPDF_Number>(4); // X
// Not enough entries.
dest = pdfium::MakeUnique<CPDF_Dest>(array.get());
EXPECT_FALSE(dest->GetXYZ(&hasX, &hasY, &hasZoom, &x, &y, &zoom));
- array->AddNumber(5); // Y
- array->AddNumber(6); // Zoom.
+ array->AddNew<CPDF_Number>(5); // Y
+ array->AddNew<CPDF_Number>(6); // Zoom.
dest = pdfium::MakeUnique<CPDF_Dest>(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<CPDF_Number>(4, 0);
dest = pdfium::MakeUnique<CPDF_Dest>(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<CPDF_Null>(2);
+ array->SetNewAt<CPDF_Null>(3);
+ array->SetNewAt<CPDF_Null>(4);
dest = pdfium::MakeUnique<CPDF_Dest>(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<CPDF_String>(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<CPDF_Number>(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<CPDF_String>(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<int>(pOpt->GetCount());
if (index >= iCount) {
- pOpt->AddString(csStr);
+ pOpt->AddNew<CPDF_String>(csStr, false);
index = iCount;
} else {
- CPDF_String* pString = new CPDF_String(csStr, false);
- pOpt->InsertAt(index, pString);
+ pOpt->InsertNewAt<CPDF_String>(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<CPDF_Number>(i, iOptIndex);
bReturn = true;
break;
}
}
if (!bReturn) {
if (bSelected)
- pArray->AddInteger(iOptIndex);
+ pArray->AddNew<CPDF_Number>(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<CPDF_Dictionary>(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;