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 <xlou@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index d88f910..836d572 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -70,8 +70,8 @@
 }
 
 bool ParserPageRangeString(ByteString rangstring,
-                           std::vector<uint16_t>* pageArray,
-                           int nCount) {
+                           int nCount,
+                           std::vector<uint16_t>* pageArray) {
   if (rangstring.IsEmpty())
     return true;
 
@@ -124,6 +124,21 @@
   return true;
 }
 
+bool GetPageNumbers(ByteString pageRange,
+                    CPDF_Document* pSrcDoc,
+                    std::vector<uint16_t>* 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 @@
     return false;
 
   std::vector<uint16_t> 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