From 6e8a3e62e1718c3739f44e94c128123276d85682 Mon Sep 17 00:00:00 2001 From: xlou Date: Fri, 26 Jan 2018 20:06:39 +0000 Subject: Code cleanup - create a new function GetPageNumbers The functionality to get page numbers in FPDF_ImportPages will be used in other functions too. So create a new function which can be reused easily. Change-Id: Iad7726f086168e70c8b7988b07f1c18c758ef303 Reviewed-on: https://pdfium-review.googlesource.com/24250 Commit-Queue: Shirleen Lou Reviewed-by: Henrique Nakashima --- fpdfsdk/fpdfppo.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp index d88f9102b9..836d5723ca 100644 --- a/fpdfsdk/fpdfppo.cpp +++ b/fpdfsdk/fpdfppo.cpp @@ -70,8 +70,8 @@ bool CopyInheritable(CPDF_Dictionary* pCurPageDict, } bool ParserPageRangeString(ByteString rangstring, - std::vector* pageArray, - int nCount) { + int nCount, + std::vector* pageArray) { if (rangstring.IsEmpty()) return true; @@ -124,6 +124,21 @@ bool ParserPageRangeString(ByteString rangstring, return true; } +bool GetPageNumbers(ByteString pageRange, + CPDF_Document* pSrcDoc, + std::vector* pageArray) { + uint16_t nCount = pSrcDoc->GetPageCount(); + if (!pageRange.IsEmpty()) { + if (!ParserPageRangeString(pageRange, nCount, pageArray)) + return false; + } else { + for (uint16_t i = 1; i <= nCount; ++i) { + pageArray->push_back(i); + } + } + return true; +} + } // namespace class CPDF_PageOrganizer { @@ -358,18 +373,15 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_ImportPages(FPDF_DOCUMENT dest_doc, return false; std::vector pageArray; - int nCount = pSrcDoc->GetPageCount(); - if (pagerange) { - if (!ParserPageRangeString(pagerange, &pageArray, nCount)) - return false; - } else { - for (int i = 1; i <= nCount; ++i) { - pageArray.push_back(i); - } - } + if (!GetPageNumbers(pagerange, pSrcDoc, &pageArray)) + return false; CPDF_PageOrganizer pageOrg(pDestDoc, pSrcDoc); - return pageOrg.PDFDocInit() && pageOrg.ExportPage(pageArray, index); + + if (!pageOrg.PDFDocInit()) + return false; + + return pageOrg.ExportPage(pageArray, index); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV -- cgit v1.2.3