Banish CFX_WordArray to XFA-land.

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1676913004 .
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 449889e..7179abe 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -435,10 +435,10 @@
     return -1;
   }
 };
-typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray;
 typedef CFX_ArrayTemplate<FX_DWORD> CFX_DWordArray;
 typedef CFX_ArrayTemplate<void*> CFX_PtrArray;
 #ifdef PDF_ENABLE_XFA
+typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray;
 typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray;
 typedef CFX_ArrayTemplate<uint8_t> CFX_ByteArray;
 typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array;
diff --git a/core/src/fpdftext/fpdf_text.cpp b/core/src/fpdftext/fpdf_text.cpp
index 4653fa6..c052676 100644
--- a/core/src/fpdftext/fpdf_text.cpp
+++ b/core/src/fpdftext/fpdf_text.cpp
@@ -7,6 +7,7 @@
 #include <cctype>
 #include <cwctype>
 #include <memory>
+#include <vector>
 
 #include "core/include/fpdfapi/fpdf_page.h"
 #include "core/include/fpdfapi/fpdf_pageobj.h"
@@ -16,6 +17,7 @@
 #include "core/include/fxcrt/fx_ucd.h"
 #include "core/src/fpdftext/text_int.h"
 #include "core/src/fpdftext/txtproc.h"
+#include "third_party/base/stl_util.h"
 
 CFX_ByteString CharFromUnicodeAlt(FX_WCHAR unicode,
                                   int destcp,
@@ -309,22 +311,23 @@
   }
   delete[] pDst;
 }
+
 void NormalizeString(CFX_WideString& str) {
   if (str.GetLength() <= 0) {
     return;
   }
   CFX_WideString sBuffer;
   std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar);
-  CFX_WordArray order;
+  std::vector<FX_WORD> order;
   FX_BOOL bR2L = FALSE;
   int32_t start = 0, count = 0, i = 0;
   int nR2L = 0, nL2R = 0;
   for (i = 0; i < str.GetLength(); i++) {
     if (pBidiChar->AppendChar(str.GetAt(i))) {
       CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
-      order.Add(start);
-      order.Add(count);
-      order.Add(ret);
+      order.push_back(start);
+      order.push_back(count);
+      order.push_back(ret);
       if (!bR2L) {
         if (ret == CFX_BidiChar::RIGHT) {
           nR2L++;
@@ -336,9 +339,9 @@
   }
   if (pBidiChar->EndChar()) {
     CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
-    order.Add(start);
-    order.Add(count);
-    order.Add(ret);
+    order.push_back(start);
+    order.push_back(count);
+    order.push_back(ret);
     if (!bR2L) {
       if (ret == CFX_BidiChar::RIGHT) {
         nR2L++;
@@ -351,11 +354,11 @@
     bR2L = TRUE;
   }
   if (bR2L) {
-    int count = order.GetSize();
+    int count = pdfium::CollectionSize<int>(order);
     for (int j = count - 1; j > 0; j -= 3) {
-      int ret = order.GetAt(j);
-      int start = order.GetAt(j - 2);
-      int count1 = order.GetAt(j - 1);
+      int ret = order[j];
+      int count1 = order[j - 1];
+      int start = order[j - 2];
       if (ret == 2 || ret == 0) {
         for (int i = start + count1 - 1; i >= start; i--) {
           NormalizeCompositeChar(str[i], sBuffer);
@@ -363,8 +366,8 @@
       } else {
         i = j;
         FX_BOOL bSymbol = FALSE;
-        while (i > 0 && order.GetAt(i) != 2) {
-          bSymbol = !order.GetAt(i);
+        while (i > 0 && order[i] != 2) {
+          bSymbol = !order[i];
           i -= 3;
         }
         int end = start + count1;
@@ -382,8 +385,8 @@
           i = j;
           j = n;
           for (; n <= i; n += 3) {
-            int start = order.GetAt(n - 2);
-            int count1 = order.GetAt(n - 1);
+            int start = order[n - 2];
+            int count1 = order[n - 1];
             int end = start + count1;
             for (int m = start; m < end; m++) {
               sBuffer += str[m];
@@ -393,16 +396,16 @@
       }
     }
   } else {
-    int count = order.GetSize();
+    int count = pdfium::CollectionSize<int>(order);
     FX_BOOL bL2R = FALSE;
     for (int j = 0; j < count; j += 3) {
-      int ret = order.GetAt(j + 2);
-      int start = order.GetAt(j);
-      int count1 = order.GetAt(j + 1);
+      int start = order[j];
+      int count1 = order[j + 1];
+      int ret = order[j + 2];
       if (ret == 2 || (j == 0 && ret == 0 && !bL2R)) {
         int i = j + 3;
         while (bR2L && i < count) {
-          if (order.GetAt(i + 2) == 1) {
+          if (order[i + 2] == 1) {
             break;
           } else {
             i += 3;
@@ -415,7 +418,7 @@
         }
         int end = str.GetLength() - 1;
         if (i < count) {
-          end = order.GetAt(i) - 1;
+          end = order[i] - 1;
         }
         j = i - 3;
         for (int n = end; n >= start; n--) {
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp
index 66d20af..ede5f83 100644
--- a/core/src/fpdftext/fpdf_text_int.cpp
+++ b/core/src/fpdftext/fpdf_text_int.cpp
@@ -144,13 +144,13 @@
   m_pPreTextObj = NULL;
   ProcessObject();
   m_bIsParsed = true;
-  m_CharIndex.RemoveAll();
+  m_CharIndex.clear();
   int nCount = pdfium::CollectionSize<int>(m_CharList);
   if (nCount) {
-    m_CharIndex.Add(0);
+    m_CharIndex.push_back(0);
   }
   for (int i = 0; i < nCount; i++) {
-    int indexSize = m_CharIndex.GetSize();
+    int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
     FX_BOOL bNormal = FALSE;
     const PAGECHAR_INFO& charinfo = m_CharList[i];
     if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) {
@@ -162,27 +162,27 @@
     }
     if (bNormal) {
       if (indexSize % 2) {
-        m_CharIndex.Add(1);
+        m_CharIndex.push_back(1);
       } else {
         if (indexSize <= 0) {
           continue;
         }
-        m_CharIndex.SetAt(indexSize - 1, m_CharIndex.GetAt(indexSize - 1) + 1);
+        m_CharIndex[indexSize - 1] += 1;
       }
     } else {
       if (indexSize % 2) {
         if (indexSize <= 0) {
           continue;
         }
-        m_CharIndex.SetAt(indexSize - 1, i + 1);
+        m_CharIndex[indexSize - 1] = i + 1;
       } else {
-        m_CharIndex.Add(i + 1);
+        m_CharIndex.push_back(i + 1);
       }
     }
   }
-  int indexSize = m_CharIndex.GetSize();
+  int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
   if (indexSize % 2) {
-    m_CharIndex.RemoveAt(indexSize - 1);
+    m_CharIndex.erase(m_CharIndex.begin() + indexSize - 1);
   }
   return TRUE;
 }
@@ -190,28 +190,25 @@
   return pdfium::CollectionSize<int>(m_CharList);
 }
 int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const {
-  int indexSize = m_CharIndex.GetSize();
+  int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
   int count = 0;
   for (int i = 0; i < indexSize; i += 2) {
-    count += m_CharIndex.GetAt(i + 1);
-    if (count > TextIndex) {
-      return TextIndex - count + m_CharIndex.GetAt(i + 1) +
-             m_CharIndex.GetAt(i);
-    }
+    count += m_CharIndex[i + 1];
+    if (count > TextIndex)
+      return TextIndex - count + m_CharIndex[i + 1] + m_CharIndex[i];
   }
   return -1;
 }
 int CPDF_TextPage::TextIndexFromCharIndex(int CharIndex) const {
-  int indexSize = m_CharIndex.GetSize();
+  int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
   int count = 0;
   for (int i = 0; i < indexSize; i += 2) {
-    count += m_CharIndex.GetAt(i + 1);
-    if (m_CharIndex.GetAt(i + 1) + m_CharIndex.GetAt(i) > CharIndex) {
-      if (CharIndex - m_CharIndex.GetAt(i) < 0) {
+    count += m_CharIndex[i + 1];
+    if (m_CharIndex[i + 1] + m_CharIndex[i] > CharIndex) {
+      if (CharIndex - m_CharIndex[i] < 0)
         return -1;
-      }
-      return CharIndex - m_CharIndex.GetAt(i) + count -
-             m_CharIndex.GetAt(i + 1);
+
+      return CharIndex - m_CharIndex[i] + count - m_CharIndex[i + 1];
     }
   }
   return -1;
@@ -993,7 +990,7 @@
   }
   std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar);
   CFX_WideString str = m_TempTextBuf.GetWideString();
-  CFX_WordArray order;
+  std::vector<FX_WORD> order;
   FX_BOOL bR2L = FALSE;
   int32_t start = 0, count = 0;
   int nR2L = 0, nL2R = 0;
@@ -1013,9 +1010,9 @@
     }
     if (pBidiChar->AppendChar(str.GetAt(i))) {
       CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
-      order.Add(start);
-      order.Add(count);
-      order.Add(ret);
+      order.push_back(start);
+      order.push_back(count);
+      order.push_back(ret);
       if (!bR2L) {
         if (ret == CFX_BidiChar::RIGHT) {
           nR2L++;
@@ -1027,9 +1024,9 @@
   }
   if (pBidiChar->EndChar()) {
     CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
-    order.Add(start);
-    order.Add(count);
-    order.Add(ret);
+    order.push_back(start);
+    order.push_back(count);
+    order.push_back(ret);
     if (!bR2L) {
       if (ret == CFX_BidiChar::RIGHT) {
         nR2L++;
@@ -1042,11 +1039,11 @@
     bR2L = TRUE;
   }
   if (m_parserflag == FPDFTEXT_RLTB || bR2L) {
-    int count = order.GetSize();
+    int count = pdfium::CollectionSize<int>(order);
     for (int i = count - 1; i > 0; i -= 3) {
-      int ret = order.GetAt(i);
-      int start = order.GetAt(i - 2);
-      int count1 = order.GetAt(i - 1);
+      int ret = order[i];
+      int count1 = order[i - 1];
+      int start = order[i - 2];
       if (ret == 2 || ret == 0) {
         for (int j = start + count1 - 1; j >= start; j--) {
           AddCharInfoByRLDirection(str, j);
@@ -1054,8 +1051,8 @@
       } else {
         int j = i;
         FX_BOOL bSymbol = FALSE;
-        while (j > 0 && order.GetAt(j) != 2) {
-          bSymbol = !order.GetAt(j);
+        while (j > 0 && order[j] != 2) {
+          bSymbol = !order[j];
           j -= 3;
         }
         int end = start + count1;
@@ -1073,8 +1070,8 @@
           j = i;
           i = n;
           for (; n <= j; n += 3) {
-            int start = order.GetAt(n - 2);
-            int count1 = order.GetAt(n - 1);
+            int start = order[n - 2];
+            int count1 = order[n - 1];
             int end = start + count1;
             for (int m = start; m < end; m++) {
               AddCharInfoByLRDirection(str, m);
@@ -1084,20 +1081,18 @@
       }
     }
   } else {
-    int count = order.GetSize();
+    int count = pdfium::CollectionSize<int>(order);
     FX_BOOL bL2R = FALSE;
     for (int i = 0; i < count; i += 3) {
-      int ret = order.GetAt(i + 2);
-      int start = order.GetAt(i);
-      int count1 = order.GetAt(i + 1);
+      int start = order[i];
+      int count1 = order[i + 1];
+      int ret = order[i + 2];
       if (ret == 2 || (i == 0 && ret == 0 && !bL2R)) {
         int j = i + 3;
         while (bR2L && j < count) {
-          if (order.GetAt(j + 2) == 1) {
+          if (order[j + 2] == 1)
             break;
-          } else {
-            j += 3;
-          }
+          j += 3;
         }
         if (j == 3) {
           i = -3;
@@ -1106,7 +1101,7 @@
         }
         int end = pdfium::CollectionSize<int>(m_TempCharList) - 1;
         if (j < count) {
-          end = order.GetAt(j) - 1;
+          end = order[j] - 1;
         }
         i = j - 3;
         for (int n = end; n >= start; n--) {
@@ -1120,7 +1115,6 @@
       }
     }
   }
-  order.RemoveAll();
   m_TempCharList.clear();
   m_TempTextBuf.Delete(0, m_TempTextBuf.GetLength());
 }
@@ -2035,48 +2029,39 @@
   m_strText = m_pTextPage->GetPageText();
   int nCount = pTextPage->CountChars();
   if (nCount) {
-    m_CharIndex.Add(0);
+    m_CharIndex.push_back(0);
   }
   for (int i = 0; i < nCount; i++) {
     FPDF_CHAR_INFO info;
     pTextPage->GetCharInfo(i, &info);
-    int indexSize = m_CharIndex.GetSize();
+    int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
     if (info.m_Flag == CHAR_NORMAL || info.m_Flag == CHAR_GENERATED) {
       if (indexSize % 2) {
-        m_CharIndex.Add(1);
+        m_CharIndex.push_back(1);
       } else {
         if (indexSize <= 0) {
           continue;
         }
-        m_CharIndex.SetAt(indexSize - 1, m_CharIndex.GetAt(indexSize - 1) + 1);
+        m_CharIndex[indexSize - 1] += 1;
       }
     } else {
       if (indexSize % 2) {
         if (indexSize <= 0) {
           continue;
         }
-        m_CharIndex.SetAt(indexSize - 1, i + 1);
+        m_CharIndex[indexSize - 1] = i + 1;
       } else {
-        m_CharIndex.Add(i + 1);
+        m_CharIndex.push_back(i + 1);
       }
     }
   }
-  int indexSize = m_CharIndex.GetSize();
+  int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
   if (indexSize % 2) {
-    m_CharIndex.RemoveAt(indexSize - 1);
+    m_CharIndex.erase(m_CharIndex.begin() + indexSize - 1);
   }
 }
 int CPDF_TextPageFind::GetCharIndex(int index) const {
   return m_pTextPage->CharIndexFromTextIndex(index);
-  int indexSize = m_CharIndex.GetSize();
-  int count = 0;
-  for (int i = 0; i < indexSize; i += 2) {
-    count += m_CharIndex.GetAt(i + 1);
-    if (count > index) {
-      return index - count + m_CharIndex.GetAt(i + 1) + m_CharIndex.GetAt(i);
-    }
-  }
-  return -1;
 }
 FX_BOOL CPDF_TextPageFind::FindFirst(const CFX_WideString& findwhat,
                                      int flags,
diff --git a/core/src/fpdftext/text_int.h b/core/src/fpdftext/text_int.h
index 8a80326..c420bc7 100644
--- a/core/src/fpdftext/text_int.h
+++ b/core/src/fpdftext/text_int.h
@@ -8,6 +8,7 @@
 #define CORE_SRC_FPDFTEXT_TEXT_INT_H_
 
 #include <deque>
+#include <vector>
 
 #include "core/include/fpdftext/fpdf_text.h"
 #include "core/include/fxcrt/fx_basic.h"
@@ -130,7 +131,7 @@
                         const CPDF_Font* pFont,
                         int nItems) const;
 
-  CFX_WordArray m_CharIndex;
+  std::vector<FX_WORD> m_CharIndex;
   const CPDF_PageObjectList* const m_pPage;
   std::deque<PAGECHAR_INFO> m_CharList;
   std::deque<PAGECHAR_INFO> m_TempCharList;
@@ -180,7 +181,7 @@
   int GetCharIndex(int index) const;
 
  private:
-  CFX_WordArray m_CharIndex;
+  std::vector<FX_WORD> m_CharIndex;
   const IPDF_TextPage* m_pTextPage;
   CFX_WideString m_strText;
   CFX_WideString m_findWhat;
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index 2df44c7..bef3b98 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -9,6 +9,7 @@
 
 #include <map>
 #include <memory>
+#include <vector>
 
 #include "core/include/fpdftext/fpdf_text.h"
 #include "fsdk_actionhandler.h"
@@ -519,14 +520,14 @@
   FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
   FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
 
-  FX_BOOL ExtractPages(const CFX_WordArray& arrExtraPages,
+  FX_BOOL ExtractPages(const std::vector<FX_WORD>& arrExtraPages,
                        CPDF_Document* pDstDoc);
   FX_BOOL InsertPages(int nInsertAt,
                       const CPDF_Document* pSrcDoc,
-                      const CFX_WordArray& arrSrcPages);
+                      const std::vector<FX_WORD>& arrSrcPages);
   FX_BOOL ReplacePages(int nPage,
                        const CPDF_Document* pSrcDoc,
-                       const CFX_WordArray& arrSrcPages);
+                       const std::vector<FX_WORD>& arrSrcPages);
 
   void OnCloseDocument();
 
diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp
index c05c7f3..84ac41d 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -9,6 +9,7 @@
 #include <memory>
 
 #include "fpdfsdk/include/fsdk_define.h"
+#include "third_party/base/stl_util.h"
 
 class CPDF_PageOrganizer {
  public:
@@ -18,7 +19,7 @@
 
   FX_BOOL PDFDocInit(CPDF_Document* pDestPDFDoc, CPDF_Document* pSrcPDFDoc);
   FX_BOOL ExportPage(CPDF_Document* pSrcPDFDoc,
-                     CFX_WordArray* nPageNum,
+                     std::vector<FX_WORD>* pPageNums,
                      CPDF_Document* pDestPDFDoc,
                      int nIndex);
   CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary* pDict,
@@ -87,16 +88,15 @@
 }
 
 FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc,
-                                       CFX_WordArray* nPageNum,
+                                       std::vector<FX_WORD>* pPageNums,
                                        CPDF_Document* pDestPDFDoc,
                                        int nIndex) {
   int curpage = nIndex;
-
   std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap);
-
-  for (int i = 0; i < nPageNum->GetSize(); ++i) {
+  int nSize = pdfium::CollectionSize<int>(*pPageNums);
+  for (int i = 0; i < nSize; ++i) {
     CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage);
-    CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1);
+    CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(pPageNums->at(i) - 1);
     if (!pSrcPageDict || !pCurPageDict)
       return FALSE;
 
@@ -306,7 +306,7 @@
 }
 
 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring,
-                                CFX_WordArray* pageArray,
+                                std::vector<FX_WORD>* pageArray,
                                 int nCount) {
   if (rangstring.GetLength() != 0) {
     rangstring.Remove(' ');
@@ -329,7 +329,7 @@
         long lPageNum = atol(cbMidRange);
         if (lPageNum <= 0 || lPageNum > nCount)
           return FALSE;
-        pageArray->Add((FX_WORD)lPageNum);
+        pageArray->push_back((FX_WORD)lPageNum);
       } else {
         int nStartPageNum = atol(cbMidRange.Mid(0, nMid));
         if (nStartPageNum == 0)
@@ -346,7 +346,7 @@
           return FALSE;
         }
         for (int i = nStartPageNum; i <= nEndPageNum; ++i) {
-          pageArray->Add(i);
+          pageArray->push_back(i);
         }
       }
       nStringFrom = nStringTo + 1;
@@ -367,14 +367,14 @@
   if (!pSrcDoc)
     return FALSE;
 
-  CFX_WordArray pageArray;
+  std::vector<FX_WORD> pageArray;
   int nCount = pSrcDoc->GetPageCount();
   if (pagerange) {
     if (!ParserPageRangeString(pagerange, &pageArray, nCount))
       return FALSE;
   } else {
     for (int i = 1; i <= nCount; ++i) {
-      pageArray.Add(i);
+      pageArray.push_back(i);
     }
   }