Replace CPDF_TextPageFind flags with options.

Instead of having various flags combined into an int, define a struct to
hold the various options.

Change-Id: I7cfcfb57d7c056385ff5e2cf1d670bb5b5faa656
Reviewed-on: https://pdfium-review.googlesource.com/c/50473
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdftext/cpdf_textpage.h b/core/fpdftext/cpdf_textpage.h
index 7ab2702..e10b45d 100644
--- a/core/fpdftext/cpdf_textpage.h
+++ b/core/fpdftext/cpdf_textpage.h
@@ -23,10 +23,6 @@
 class CPDF_Page;
 class CPDF_TextObject;
 
-#define FPDFTEXT_MATCHCASE 0x00000001
-#define FPDFTEXT_MATCHWHOLEWORD 0x00000002
-#define FPDFTEXT_CONSECUTIVE 0x00000004
-
 #define FPDFTEXT_CHAR_NORMAL 0
 #define FPDFTEXT_CHAR_GENERATED 1
 #define FPDFTEXT_CHAR_UNUNICODE 2
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index 829fc56..b431f5d 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -75,16 +75,16 @@
 }
 
 bool CPDF_TextPageFind::FindFirst(const WideString& findwhat,
-                                  int flags,
+                                  const Options& options,
                                   Optional<size_t> startPos) {
   if (!m_pTextPage)
     return false;
-  if (m_strText.IsEmpty() || m_bMatchCase != (flags & FPDFTEXT_MATCHCASE))
+  if (m_strText.IsEmpty() || m_bMatchCase != options.bMatchCase)
     m_strText = m_pTextPage->GetAllPageText();
   WideString findwhatStr = findwhat;
   m_findWhat = findwhatStr;
-  m_flags = flags;
-  m_bMatchCase = flags & FPDFTEXT_MATCHCASE;
+  m_options = options;
+  m_bMatchCase = options.bMatchCase;
   if (m_strText.IsEmpty()) {
     m_IsFind = false;
     return true;
@@ -94,7 +94,7 @@
     findwhatStr.MakeLower();
     m_strText.MakeLower();
   }
-  m_bMatchWholeWord = !!(flags & FPDFTEXT_MATCHWHOLEWORD);
+  m_bMatchWholeWord = options.bMatchWholeWord;
   m_findNextStart = startPos;
   if (!startPos.has_value()) {
     if (!m_strText.IsEmpty())
@@ -212,7 +212,7 @@
   int resStart = GetCharIndex(m_resStart);
   int resEnd = GetCharIndex(m_resEnd);
   m_resArray = m_pTextPage->GetRectArray(resStart, resEnd - resStart + 1);
-  if (m_flags & FPDFTEXT_CONSECUTIVE) {
+  if (m_options.bConsecutive) {
     m_findNextStart = m_resStart + 1;
     m_findPreStart = m_resEnd - 1;
   } else {
@@ -231,7 +231,7 @@
     return m_IsFind;
   }
   CPDF_TextPageFind findEngine(m_pTextPage.Get());
-  bool ret = findEngine.FindFirst(m_findWhat, m_flags, Optional<size_t>(0));
+  bool ret = findEngine.FindFirst(m_findWhat, m_options, 0);
   if (!ret) {
     m_IsFind = false;
     return m_IsFind;
@@ -258,7 +258,7 @@
   m_resEnd = m_pTextPage->TextIndexFromCharIndex(order + MatchedCount - 1);
   m_IsFind = true;
   m_resArray = m_pTextPage->GetRectArray(order, MatchedCount);
-  if (m_flags & FPDFTEXT_CONSECUTIVE) {
+  if (m_options.bConsecutive) {
     m_findNextStart = m_resStart + 1;
     m_findPreStart = m_resEnd - 1;
   } else {
diff --git a/core/fpdftext/cpdf_textpagefind.h b/core/fpdftext/cpdf_textpagefind.h
index 8d59456..e075c41 100644
--- a/core/fpdftext/cpdf_textpagefind.h
+++ b/core/fpdftext/cpdf_textpagefind.h
@@ -19,11 +19,17 @@
 
 class CPDF_TextPageFind {
  public:
+  struct Options {
+    bool bMatchCase = false;
+    bool bMatchWholeWord = false;
+    bool bConsecutive = false;
+  };
+
   explicit CPDF_TextPageFind(const CPDF_TextPage* pTextPage);
   ~CPDF_TextPageFind();
 
   bool FindFirst(const WideString& findwhat,
-                 int flags,
+                 const Options& options,
                  Optional<size_t> startPos);
   bool FindNext();
   bool FindPrev();
@@ -51,7 +57,7 @@
   Optional<size_t> m_findPreStart;
   int m_resStart = 0;
   int m_resEnd = -1;
-  int m_flags = 0;
+  Options m_options;
   bool m_bMatchCase = false;
   bool m_bMatchWholeWord = false;
   bool m_IsFind = false;
diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp
index 044624b..37eba57 100644
--- a/fpdfsdk/fpdf_text.cpp
+++ b/fpdfsdk/fpdf_text.cpp
@@ -279,11 +279,15 @@
   if (!text_page)
     return nullptr;
 
+  CPDF_TextPageFind::Options options;
+  options.bMatchCase = !!(flags & FPDF_MATCHCASE);
+  options.bMatchWholeWord = !!(flags & FPDF_MATCHWHOLEWORD);
+  options.bConsecutive = !!(flags & FPDF_CONSECUTIVE);
   CPDF_TextPageFind* textpageFind =
       new CPDF_TextPageFind(CPDFTextPageFromFPDFTextPage(text_page));
   textpageFind->FindFirst(
-      WideStringFromFPDFWideString(findwhat), flags,
-      start_index >= 0 ? Optional<size_t>(start_index) : Optional<size_t>());
+      WideStringFromFPDFWideString(findwhat), options,
+      start_index >= 0 ? Optional<size_t>(start_index) : pdfium::nullopt);
   return FPDFSchHandleFromCPDFTextPageFind(textpageFind);
 }