Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: xfa/fee/fx_wordbreak/fx_wordbreak_impl.cpp

Issue 1986373002: Remove Release() from IFX_CharIter, use unique_ptrs. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fee/fx_wordbreak/fx_wordbreak.h ('k') | xfa/fee/ifde_txtedtengine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fee/fx_wordbreak/fx_wordbreak_impl.h" 7 #include "xfa/fee/fx_wordbreak/fx_wordbreak_impl.h"
8 8
9 FX_WordBreakProp FX_GetWordBreakProperty(FX_WCHAR wcCodePoint) { 9 FX_WordBreakProp FX_GetWordBreakProperty(FX_WCHAR wcCodePoint) {
10 uint32_t dwProperty = 10 uint32_t dwProperty =
11 (uint32_t)gs_FX_WordBreak_CodePointProperties[wcCodePoint >> 1]; 11 (uint32_t)gs_FX_WordBreak_CodePointProperties[wcCodePoint >> 1];
12 return (FX_WordBreakProp)(((wcCodePoint)&1) ? (dwProperty & 0x0F) 12 return (FX_WordBreakProp)(((wcCodePoint)&1) ? (dwProperty & 0x0F)
13 : (dwProperty >> 4)); 13 : (dwProperty >> 4));
14 } 14 }
15
15 CFX_CharIter::CFX_CharIter(const CFX_WideString& wsText) 16 CFX_CharIter::CFX_CharIter(const CFX_WideString& wsText)
16 : m_wsText(wsText), m_nIndex(0) { 17 : m_wsText(wsText), m_nIndex(0) {
17 ASSERT(!wsText.IsEmpty()); 18 ASSERT(!wsText.IsEmpty());
18 } 19 }
20
19 CFX_CharIter::~CFX_CharIter() {} 21 CFX_CharIter::~CFX_CharIter() {}
20 void CFX_CharIter::Release() { 22
21 delete this;
22 }
23 FX_BOOL CFX_CharIter::Next(FX_BOOL bPrev) { 23 FX_BOOL CFX_CharIter::Next(FX_BOOL bPrev) {
24 if (bPrev) { 24 if (bPrev) {
25 if (m_nIndex <= 0) { 25 if (m_nIndex <= 0) {
26 return FALSE; 26 return FALSE;
27 } 27 }
28 m_nIndex--; 28 m_nIndex--;
29 } else { 29 } else {
30 if (m_nIndex + 1 >= m_wsText.GetLength()) { 30 if (m_nIndex + 1 >= m_wsText.GetLength()) {
31 return FALSE; 31 return FALSE;
32 } 32 }
(...skipping 14 matching lines...) Expand all
47 return m_nIndex; 47 return m_nIndex;
48 } 48 }
49 FX_BOOL CFX_CharIter::IsEOF(FX_BOOL bTail) const { 49 FX_BOOL CFX_CharIter::IsEOF(FX_BOOL bTail) const {
50 return bTail ? (m_nIndex + 1 == m_wsText.GetLength()) : (m_nIndex == 0); 50 return bTail ? (m_nIndex + 1 == m_wsText.GetLength()) : (m_nIndex == 0);
51 } 51 }
52 IFX_CharIter* CFX_CharIter::Clone() { 52 IFX_CharIter* CFX_CharIter::Clone() {
53 CFX_CharIter* pIter = new CFX_CharIter(m_wsText); 53 CFX_CharIter* pIter = new CFX_CharIter(m_wsText);
54 pIter->m_nIndex = m_nIndex; 54 pIter->m_nIndex = m_nIndex;
55 return pIter; 55 return pIter;
56 } 56 }
57 CFX_WordBreak::CFX_WordBreak() : m_pPreIter(NULL), m_pCurIter(NULL) {} 57
58 CFX_WordBreak::~CFX_WordBreak() { 58 CFX_WordBreak::CFX_WordBreak() {}
59 if (m_pPreIter) { 59 CFX_WordBreak::~CFX_WordBreak() {}
dsinclair 2016/05/17 20:20:47 nit: blank line before
60 m_pPreIter->Release(); 60
61 m_pPreIter = NULL;
62 }
63 if (m_pCurIter) {
64 m_pCurIter->Release();
65 m_pCurIter = NULL;
66 }
67 }
68 void CFX_WordBreak::Release() {
69 delete this;
70 }
71 void CFX_WordBreak::Attach(IFX_CharIter* pIter) { 61 void CFX_WordBreak::Attach(IFX_CharIter* pIter) {
72 ASSERT(pIter); 62 ASSERT(pIter);
73 m_pCurIter = pIter; 63 m_pCurIter.reset(pIter);
74 } 64 }
75 void CFX_WordBreak::Attach(const CFX_WideString& wsText) { 65 void CFX_WordBreak::Attach(const CFX_WideString& wsText) {
76 m_pCurIter = new CFX_CharIter(wsText); 66 m_pCurIter.reset(new CFX_CharIter(wsText));
77 } 67 }
78 FX_BOOL CFX_WordBreak::Next(FX_BOOL bPrev) { 68 FX_BOOL CFX_WordBreak::Next(FX_BOOL bPrev) {
79 IFX_CharIter* pIter = bPrev ? m_pPreIter->Clone() : m_pCurIter->Clone(); 69 std::unique_ptr<IFX_CharIter> pIter(
80 if (pIter->IsEOF(!bPrev)) { 70 (bPrev ? m_pPreIter : m_pCurIter)->Clone());
71 if (pIter->IsEOF(!bPrev))
81 return FALSE; 72 return FALSE;
82 } 73
83 pIter->Next(bPrev); 74 pIter->Next(bPrev);
84 if (!FindNextBreakPos(pIter, bPrev, TRUE)) { 75 if (!FindNextBreakPos(pIter.get(), bPrev, TRUE))
85 pIter->Release();
86 return FALSE; 76 return FALSE;
87 } 77
88 if (bPrev) { 78 if (bPrev) {
89 m_pCurIter->Release(); 79 m_pCurIter = std::move(m_pPreIter);
90 m_pCurIter = m_pPreIter;
91 m_pCurIter->Next(TRUE); 80 m_pCurIter->Next(TRUE);
92 m_pPreIter = pIter; 81 m_pPreIter = std::move(pIter);
93 } else { 82 } else {
94 m_pPreIter->Release(); 83 m_pPreIter = std::move(m_pCurIter);
95 m_pPreIter = m_pCurIter;
96 m_pPreIter->Next(); 84 m_pPreIter->Next();
97 m_pCurIter = pIter; 85 m_pCurIter = std::move(pIter);
98 } 86 }
99 return TRUE; 87 return TRUE;
100 } 88 }
101 void CFX_WordBreak::SetAt(int32_t nIndex) { 89 void CFX_WordBreak::SetAt(int32_t nIndex) {
102 if (m_pPreIter) { 90 m_pPreIter.reset();
103 m_pPreIter->Release();
104 m_pPreIter = NULL;
105 }
106 m_pCurIter->SetAt(nIndex); 91 m_pCurIter->SetAt(nIndex);
107 FindNextBreakPos(m_pCurIter, TRUE, FALSE); 92 FindNextBreakPos(m_pCurIter.get(), TRUE, FALSE);
108 m_pPreIter = m_pCurIter; 93 m_pPreIter = std::move(m_pCurIter);
109 m_pCurIter = m_pPreIter->Clone(); 94 m_pCurIter.reset(m_pPreIter->Clone());
110 FindNextBreakPos(m_pCurIter, FALSE, FALSE); 95 FindNextBreakPos(m_pCurIter.get(), FALSE, FALSE);
111 } 96 }
112 int32_t CFX_WordBreak::GetWordPos() const { 97 int32_t CFX_WordBreak::GetWordPos() const {
113 return m_pPreIter->GetAt(); 98 return m_pPreIter->GetAt();
114 } 99 }
115 int32_t CFX_WordBreak::GetWordLength() const { 100 int32_t CFX_WordBreak::GetWordLength() const {
116 return m_pCurIter->GetAt() - m_pPreIter->GetAt() + 1; 101 return m_pCurIter->GetAt() - m_pPreIter->GetAt() + 1;
117 } 102 }
118 void CFX_WordBreak::GetWord(CFX_WideString& wsWord) const { 103 void CFX_WordBreak::GetWord(CFX_WideString& wsWord) const {
119 int32_t nWordLength = GetWordLength(); 104 int32_t nWordLength = GetWordLength();
120 if (nWordLength <= 0) { 105 if (nWordLength <= 0) {
121 return; 106 return;
122 } 107 }
123 FX_WCHAR* lpBuf = wsWord.GetBuffer(nWordLength); 108 FX_WCHAR* lpBuf = wsWord.GetBuffer(nWordLength);
124 IFX_CharIter* pTempIter = m_pPreIter->Clone(); 109 std::unique_ptr<IFX_CharIter> pTempIter(m_pPreIter->Clone());
125 int32_t i = 0; 110 int32_t i = 0;
126 while (pTempIter->GetAt() <= m_pCurIter->GetAt()) { 111 while (pTempIter->GetAt() <= m_pCurIter->GetAt()) {
127 lpBuf[i++] = pTempIter->GetChar(); 112 lpBuf[i++] = pTempIter->GetChar();
128 FX_BOOL bEnd = pTempIter->Next(); 113 if (!pTempIter->Next())
129 if (!bEnd) {
130 break; 114 break;
131 }
132 } 115 }
133 pTempIter->Release();
134 wsWord.ReleaseBuffer(nWordLength); 116 wsWord.ReleaseBuffer(nWordLength);
135 } 117 }
136 FX_BOOL CFX_WordBreak::IsEOF(FX_BOOL bTail) const { 118 FX_BOOL CFX_WordBreak::IsEOF(FX_BOOL bTail) const {
137 return m_pCurIter->IsEOF(bTail); 119 return m_pCurIter->IsEOF(bTail);
138 } 120 }
139 FX_BOOL CFX_WordBreak::FindNextBreakPos(IFX_CharIter* pIter, 121 FX_BOOL CFX_WordBreak::FindNextBreakPos(IFX_CharIter* pIter,
140 FX_BOOL bPrev, 122 FX_BOOL bPrev,
141 FX_BOOL bFromNext) { 123 FX_BOOL bFromNext) {
142 FX_WordBreakProp ePreType = FX_WordBreakProp_None; 124 FX_WordBreakProp ePreType = FX_WordBreakProp_None;
143 FX_WordBreakProp eCurType = FX_WordBreakProp_None; 125 FX_WordBreakProp eCurType = FX_WordBreakProp_None;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 return TRUE; 208 return TRUE;
227 } 209 }
228 } 210 }
229 } 211 }
230 ePreType = eCurType; 212 ePreType = eCurType;
231 eCurType = eNextType; 213 eCurType = eNextType;
232 bFirst = FALSE; 214 bFirst = FALSE;
233 } while (!pIter->IsEOF(!bPrev)); 215 } while (!pIter->IsEOF(!bPrev));
234 return TRUE; 216 return TRUE;
235 } 217 }
OLDNEW
« no previous file with comments | « xfa/fee/fx_wordbreak/fx_wordbreak.h ('k') | xfa/fee/ifde_txtedtengine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698