From 3c66ea01f5239a7b1a0da75285e0c8048e5cf784 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 19 Apr 2017 16:07:21 -0400 Subject: Update IFX_CharIter::Clone to return unique_ptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl converts the Clone method of IFX_CharIter to return a unique_ptr. The usages were all converting to a unique_ptr already. Change-Id: I1ca5ddd03eca8f21d616efb2b92fb27899c43c23 Reviewed-on: https://pdfium-review.googlesource.com/4351 Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- core/fxcrt/cfx_chariter.cpp | 6 ++++-- core/fxcrt/cfx_chariter.h | 4 +++- core/fxcrt/cfx_wordbreak.cpp | 8 ++++---- core/fxcrt/ifx_chariter.h | 4 +++- xfa/fde/cfde_txtedtbuf.cpp | 4 ++-- xfa/fde/cfde_txtedtbuf.h | 2 +- xfa/fde/cfde_txtedtpage.cpp | 2 +- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/core/fxcrt/cfx_chariter.cpp b/core/fxcrt/cfx_chariter.cpp index c14db2f322..b726a7e484 100644 --- a/core/fxcrt/cfx_chariter.cpp +++ b/core/fxcrt/cfx_chariter.cpp @@ -6,6 +6,8 @@ #include "core/fxcrt/cfx_chariter.h" +#include "third_party/base/ptr_util.h" + CFX_CharIter::CFX_CharIter(const CFX_WideString& wsText) : m_wsText(wsText), m_nIndex(0) { ASSERT(!wsText.IsEmpty()); @@ -44,8 +46,8 @@ bool CFX_CharIter::IsEOF(bool bTail) const { return bTail ? (m_nIndex + 1 == m_wsText.GetLength()) : (m_nIndex == 0); } -IFX_CharIter* CFX_CharIter::Clone() { - CFX_CharIter* pIter = new CFX_CharIter(m_wsText); +std::unique_ptr CFX_CharIter::Clone() { + auto pIter = pdfium::MakeUnique(m_wsText); pIter->m_nIndex = m_nIndex; return pIter; } diff --git a/core/fxcrt/cfx_chariter.h b/core/fxcrt/cfx_chariter.h index 00a725ef75..50fdde879f 100644 --- a/core/fxcrt/cfx_chariter.h +++ b/core/fxcrt/cfx_chariter.h @@ -7,6 +7,8 @@ #ifndef CORE_FXCRT_CFX_CHARITER_H_ #define CORE_FXCRT_CFX_CHARITER_H_ +#include + #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" #include "core/fxcrt/ifx_chariter.h" @@ -21,7 +23,7 @@ class CFX_CharIter : public IFX_CharIter { void SetAt(int32_t nIndex) override; int32_t GetAt() const override; bool IsEOF(bool bTail = true) const override; - IFX_CharIter* Clone() override; + std::unique_ptr Clone() override; private: const CFX_WideString& m_wsText; diff --git a/core/fxcrt/cfx_wordbreak.cpp b/core/fxcrt/cfx_wordbreak.cpp index c236f599f2..2a31181403 100644 --- a/core/fxcrt/cfx_wordbreak.cpp +++ b/core/fxcrt/cfx_wordbreak.cpp @@ -2793,8 +2793,8 @@ void CFX_WordBreak::Attach(const CFX_WideString& wsText) { } bool CFX_WordBreak::Next(bool bPrev) { - std::unique_ptr pIter( - (bPrev ? m_pPreIter : m_pCurIter)->Clone()); + std::unique_ptr pIter = + (bPrev ? m_pPreIter : m_pCurIter)->Clone(); if (pIter->IsEOF(!bPrev)) return false; @@ -2819,7 +2819,7 @@ void CFX_WordBreak::SetAt(int32_t nIndex) { m_pCurIter->SetAt(nIndex); FindNextBreakPos(m_pCurIter.get(), true, false); m_pPreIter = std::move(m_pCurIter); - m_pCurIter.reset(m_pPreIter->Clone()); + m_pCurIter = m_pPreIter->Clone(); FindNextBreakPos(m_pCurIter.get(), false, false); } @@ -2837,7 +2837,7 @@ void CFX_WordBreak::GetWord(CFX_WideString& wsWord) const { return; } wchar_t* lpBuf = wsWord.GetBuffer(nWordLength); - std::unique_ptr pTempIter(m_pPreIter->Clone()); + std::unique_ptr pTempIter = m_pPreIter->Clone(); int32_t i = 0; while (pTempIter->GetAt() <= m_pCurIter->GetAt()) { lpBuf[i++] = pTempIter->GetChar(); diff --git a/core/fxcrt/ifx_chariter.h b/core/fxcrt/ifx_chariter.h index 4435257cc9..b8e240953a 100644 --- a/core/fxcrt/ifx_chariter.h +++ b/core/fxcrt/ifx_chariter.h @@ -7,6 +7,8 @@ #ifndef CORE_FXCRT_IFX_CHARITER_H_ #define CORE_FXCRT_IFX_CHARITER_H_ +#include + #include "core/fxcrt/fx_system.h" class IFX_CharIter { @@ -18,7 +20,7 @@ class IFX_CharIter { virtual void SetAt(int32_t nIndex) = 0; virtual int32_t GetAt() const = 0; virtual bool IsEOF(bool bTail = true) const = 0; - virtual IFX_CharIter* Clone() = 0; + virtual std::unique_ptr Clone() = 0; }; #endif // CORE_FXCRT_IFX_CHARITER_H_ diff --git a/xfa/fde/cfde_txtedtbuf.cpp b/xfa/fde/cfde_txtedtbuf.cpp index dc88704a6c..1ec3c9721a 100644 --- a/xfa/fde/cfde_txtedtbuf.cpp +++ b/xfa/fde/cfde_txtedtbuf.cpp @@ -343,8 +343,8 @@ bool CFDE_TxtEdtBuf::Iterator::IsEOF(bool bTail) const { return bTail ? m_nIndex == (m_pBuf->GetTextLength() - 2) : m_nIndex == 0; } -IFX_CharIter* CFDE_TxtEdtBuf::Iterator::Clone() { - CFDE_TxtEdtBuf::Iterator* pIter = new CFDE_TxtEdtBuf::Iterator(m_pBuf); +std::unique_ptr CFDE_TxtEdtBuf::Iterator::Clone() { + auto pIter = pdfium::MakeUnique(m_pBuf); pIter->m_nCurChunk = m_nCurChunk; pIter->m_nCurIndex = m_nCurIndex; pIter->m_nIndex = m_nIndex; diff --git a/xfa/fde/cfde_txtedtbuf.h b/xfa/fde/cfde_txtedtbuf.h index 650d375bf8..096ce6bf77 100644 --- a/xfa/fde/cfde_txtedtbuf.h +++ b/xfa/fde/cfde_txtedtbuf.h @@ -31,7 +31,7 @@ class CFDE_TxtEdtBuf { int32_t GetAt() const override; bool IsEOF(bool bTail = true) const override; - IFX_CharIter* Clone() override; + std::unique_ptr Clone() override; private: CFDE_TxtEdtBuf* m_pBuf; diff --git a/xfa/fde/cfde_txtedtpage.cpp b/xfa/fde/cfde_txtedtpage.cpp index faf52316c8..f0b03af7ca 100644 --- a/xfa/fde/cfde_txtedtpage.cpp +++ b/xfa/fde/cfde_txtedtpage.cpp @@ -279,7 +279,7 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, m_nCharCount = nPageEnd - nPageStart + 1; bool bReload = false; float fDefCharWidth = 0; - std::unique_ptr pIter(m_pIter->Clone()); + std::unique_ptr pIter = m_pIter->Clone(); pIter->SetAt(nPageStart); m_pIter->SetAt(nPageStart); bool bFirstPiece = true; -- cgit v1.2.3