Index: core/fpdftext/fpdf_text_int.cpp |
diff --git a/core/fpdftext/fpdf_text_int.cpp b/core/fpdftext/fpdf_text_int.cpp |
index 741331fb7711984b851d25053cefc5def0d50828..4da251c78e6653a5a7138fe29ab35b9269f13125 100644 |
--- a/core/fpdftext/fpdf_text_int.cpp |
+++ b/core/fpdftext/fpdf_text_int.cpp |
@@ -2330,43 +2330,28 @@ int CPDF_TextPageFind::GetMatchedCount() const { |
return resEnd - resStart + 1; |
} |
-CPDF_LinkExtract::CPDF_LinkExtract() |
- : m_pTextPage(nullptr), m_bIsParsed(false) {} |
+CPDF_LinkExtract::CPDF_LinkExtract(const CPDF_TextPage* pTextPage) |
+ : m_pTextPage(pTextPage), m_bIsParsed(false) {} |
CPDF_LinkExtract::~CPDF_LinkExtract() { |
- DeleteLinkList(); |
} |
-FX_BOOL CPDF_LinkExtract::ExtractLinks(const CPDF_TextPage* pTextPage) { |
- if (!pTextPage || !pTextPage->IsParsed()) |
+FX_BOOL CPDF_LinkExtract::ExtractLinks() { |
+ if (!m_pTextPage->IsParsed()) |
return FALSE; |
- m_pTextPage = (const CPDF_TextPage*)pTextPage; |
+ m_LinkList.clear(); |
m_strPageText = m_pTextPage->GetPageText(0, -1); |
- DeleteLinkList(); |
- if (m_strPageText.IsEmpty()) { |
+ if (m_strPageText.IsEmpty()) |
return FALSE; |
- } |
+ |
ParseLink(); |
m_bIsParsed = true; |
return TRUE; |
} |
-void CPDF_LinkExtract::DeleteLinkList() { |
- while (m_LinkList.GetSize()) { |
- CPDF_LinkExt* linkinfo = NULL; |
- linkinfo = m_LinkList.GetAt(0); |
- m_LinkList.RemoveAt(0); |
- delete linkinfo; |
- } |
- m_LinkList.RemoveAll(); |
-} |
- |
int CPDF_LinkExtract::CountLinks() const { |
- if (!m_bIsParsed) { |
- return -1; |
- } |
- return m_LinkList.GetSize(); |
+ return m_bIsParsed ? pdfium::CollectionSize<int>(m_LinkList) : -1; |
} |
void CPDF_LinkExtract::ParseLink() { |
@@ -2395,7 +2380,8 @@ void CPDF_LinkExtract::ParseLink() { |
} |
if (nCount > 5 && |
(CheckWebLink(strBeCheck) || CheckMailLink(strBeCheck))) { |
- AppendToLinkList(start, nCount, strBeCheck); |
+ m_LinkList.push_back( |
+ std::unique_ptr<Item>(new Item(start, nCount, strBeCheck))); |
} |
} |
start = ++pos; |
@@ -2501,50 +2487,30 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) { |
return TRUE; |
} |
-void CPDF_LinkExtract::AppendToLinkList(int start, |
- int count, |
- const CFX_WideString& strUrl) { |
- CPDF_LinkExt* linkInfo = new CPDF_LinkExt; |
- linkInfo->m_strUrl = strUrl; |
- linkInfo->m_Start = start; |
- linkInfo->m_Count = count; |
- m_LinkList.Add(linkInfo); |
-} |
- |
CFX_WideString CPDF_LinkExtract::GetURL(int index) const { |
dsinclair
2016/04/20 13:05:19
Can index be changed from an int to a size_t so we
Tom Sepez
2016/04/20 19:07:39
Done. Pushed negative value checking up to API ca
|
- if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { |
- return L""; |
- } |
- CPDF_LinkExt* link = NULL; |
- link = m_LinkList.GetAt(index); |
- if (!link) { |
+ if (!m_bIsParsed || index < 0 || |
Lei Zhang
2016/04/19 23:52:06
Helper function instead of repeating this thrice?
Tom Sepez
2016/04/20 19:07:39
Nah, short enough to prefer transparency over cons
|
+ index >= pdfium::CollectionSize<int>(m_LinkList)) { |
return L""; |
} |
- return link->m_strUrl; |
+ return m_LinkList[index]->m_strUrl; |
} |
+ |
void CPDF_LinkExtract::GetBoundedSegment(int index, |
dsinclair
2016/04/20 13:05:19
size_t?
Tom Sepez
2016/04/20 19:07:39
Done.
|
int& start, |
int& count) const { |
- if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { |
+ if (!m_bIsParsed || index < 0 || |
+ index >= pdfium::CollectionSize<int>(m_LinkList)) { |
return; |
} |
- CPDF_LinkExt* link = NULL; |
- link = m_LinkList.GetAt(index); |
- if (!link) { |
- return; |
- } |
- start = link->m_Start; |
- count = link->m_Count; |
+ start = m_LinkList[index]->m_Start; |
+ count = m_LinkList[index]->m_Count; |
} |
void CPDF_LinkExtract::GetRects(int index, CFX_RectArray& rects) const { |
dsinclair
2016/04/20 13:05:19
size_t?
Tom Sepez
2016/04/20 19:07:39
Done.
|
- if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { |
- return; |
- } |
- CPDF_LinkExt* link = NULL; |
- link = m_LinkList.GetAt(index); |
- if (!link) { |
+ if (!m_bIsParsed || index < 0 || |
+ index >= pdfium::CollectionSize<int>(m_LinkList)) { |
return; |
} |
- m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); |
+ m_pTextPage->GetRectArray(m_LinkList[index]->m_Start, |
+ m_LinkList[index]->m_Count, rects); |
} |