Use std::ranges::find() and find_if()

Mechanically switch from: std::find(c.begin(), c.end(), t)
to: std::ranges::find(c, t).

Change-Id: Ia42e9451bea1478e046838c985d0dd8521bcaf38
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/131150
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
index 410ae30..d1249ce 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
@@ -191,8 +191,7 @@
 std::unique_ptr<CPDF_PageObject> CPDF_PageObjectHolder::RemovePageObject(
     CPDF_PageObject* pPageObj) {
   auto it =
-      std::find(std::begin(page_object_list_), std::end(page_object_list_),
-                fxcrt::MakeFakeUniquePtr(pPageObj));
+      std::ranges::find(page_object_list_, fxcrt::MakeFakeUniquePtr(pPageObj));
   if (it == std::end(page_object_list_)) {
     return nullptr;
   }
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index ca2788d..846fa97 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -233,10 +233,10 @@
 }
 
 bool CPDF_AnnotList::Contains(const CPDF_Annot* pAnnot) const {
-  auto it = std::find_if(annot_list_.begin(), annot_list_.end(),
-                         [pAnnot](const std::unique_ptr<CPDF_Annot>& annot) {
-                           return annot.get() == pAnnot;
-                         });
+  auto it = std::ranges::find_if(
+      annot_list_, [pAnnot](const std::unique_ptr<CPDF_Annot>& annot) {
+        return annot.get() == pAnnot;
+      });
   return it != annot_list_.end();
 }
 
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index a9f6a5f..887234d 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -270,7 +270,7 @@
   }
 
   const auto& controls = GetControls();
-  auto it = std::find(controls.begin(), controls.end(), pControl);
+  auto it = std::ranges::find(controls, pControl);
   if (it == controls.end()) {
     return -1;
   }
diff --git a/core/fxcrt/css/cfx_cssdata.cpp b/core/fxcrt/css/cfx_cssdata.cpp
index 2ac3378..3225615 100644
--- a/core/fxcrt/css/cfx_cssdata.cpp
+++ b/core/fxcrt/css/cfx_cssdata.cpp
@@ -106,11 +106,10 @@
   if (wsName.IsEmpty() || wsName.GetLength() != 2) {
     return nullptr;
   }
-  auto* iter =
-      std::find_if(std::begin(kLengthUnitTable), std::end(kLengthUnitTable),
-                   [wsName](const CFX_CSSData::LengthUnit& unit) {
-                     return wsName.EqualsASCIINoCase(unit.value);
-                   });
+  auto* iter = std::ranges::find_if(
+      kLengthUnitTable, [wsName](const CFX_CSSData::LengthUnit& unit) {
+        return wsName.EqualsASCIINoCase(unit.value);
+      });
   return iter != std::end(kLengthUnitTable) ? iter : nullptr;
 }
 
@@ -118,9 +117,9 @@
   if (wsName.IsEmpty()) {
     return nullptr;
   }
-  auto* iter = std::find_if(std::begin(kColorTable), std::end(kColorTable),
-                            [wsName](const CFX_CSSData::Color& color) {
-                              return wsName.EqualsASCIINoCase(color.name);
-                            });
+  auto* iter = std::ranges::find_if(
+      kColorTable, [wsName](const CFX_CSSData::Color& color) {
+        return wsName.EqualsASCIINoCase(color.name);
+      });
   return iter != std::end(kColorTable) ? iter : nullptr;
 }
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index efb9d0e..c204cce 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -781,10 +781,9 @@
                             subst_font);
   }
 
-  auto it = std::find_if(
-      face_array_.begin(), face_array_.end(), [Charset](const FaceData& face) {
-        return face.charset == static_cast<uint32_t>(Charset);
-      });
+  auto it = std::ranges::find_if(face_array_, [Charset](const FaceData& face) {
+    return face.charset == static_cast<uint32_t>(Charset);
+  });
   if (it == face_array_.end()) {
     return UseInternalSubst(base_font, old_weight, italic_angle, pitch_family,
                             subst_font);
diff --git a/fpdfsdk/cpdfsdk_annotiteration.cpp b/fpdfsdk/cpdfsdk_annotiteration.cpp
index c3460a8..6440193 100644
--- a/fpdfsdk/cpdfsdk_annotiteration.cpp
+++ b/fpdfsdk/cpdfsdk_annotiteration.cpp
@@ -32,7 +32,7 @@
 
   CPDFSDK_Annot* pTopMostAnnot = page_view->GetFocusAnnot();
   if (pTopMostAnnot) {
-    auto it = std::find(copied_list.begin(), copied_list.end(), pTopMostAnnot);
+    auto it = std::ranges::find(copied_list, pTopMostAnnot);
     if (it != copied_list.end()) {
       copied_list.erase(it);
       auto insert_it =
diff --git a/fpdfsdk/cpdfsdk_annotiterator.cpp b/fpdfsdk/cpdfsdk_annotiterator.cpp
index 6d85a9b..ecde4d1 100644
--- a/fpdfsdk/cpdfsdk_annotiterator.cpp
+++ b/fpdfsdk/cpdfsdk_annotiterator.cpp
@@ -54,7 +54,7 @@
 }
 
 CPDFSDK_Annot* CPDFSDK_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot) {
-  auto iter = std::find(annots_.begin(), annots_.end(), pAnnot);
+  auto iter = std::ranges::find(annots_, pAnnot);
   if (iter == annots_.end()) {
     return nullptr;
   }
@@ -66,7 +66,7 @@
 }
 
 CPDFSDK_Annot* CPDFSDK_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) {
-  auto iter = std::find(annots_.begin(), annots_.end(), pAnnot);
+  auto iter = std::ranges::find(annots_, pAnnot);
   if (iter == annots_.begin() || iter == annots_.end()) {
     return nullptr;
   }
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index 8ba4b75..8ad3862 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -181,8 +181,8 @@
     form_fill_env_->KillFocusAnnot({});
   }
   if (pAnnot) {
-    auto it = std::find(sdkannot_array_.begin(), sdkannot_array_.end(),
-                        fxcrt::MakeFakeUniquePtr(pAnnot.Get()));
+    auto it = std::ranges::find(sdkannot_array_,
+                                fxcrt::MakeFakeUniquePtr(pAnnot.Get()));
     if (it != sdkannot_array_.end()) {
       sdkannot_array_.erase(it);
     }
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 5d31041..f7ffa9c 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -456,10 +456,10 @@
   }
 
   CPDF_ArrayLocker locker(pAnnots);
-  auto it = std::find_if(locker.begin(), locker.end(),
-                         [pAnnotDict](const RetainPtr<CPDF_Object>& candidate) {
-                           return candidate->GetDirect() == pAnnotDict;
-                         });
+  auto it = std::ranges::find_if(
+      locker, [pAnnotDict](const RetainPtr<CPDF_Object>& candidate) {
+        return candidate->GetDirect() == pAnnotDict;
+      });
 
   if (it == locker.end()) {
     return -1;
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp
index 2ec3239..f6d3fc6 100644
--- a/fpdfsdk/pwl/cpwl_wnd.cpp
+++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -102,12 +102,11 @@
     if (pWnd == main_keyboard_wnd_) {
       main_keyboard_wnd_ = nullptr;
     }
-    auto mouse_it = std::find(mouse_paths_.begin(), mouse_paths_.end(), pWnd);
+    auto mouse_it = std::ranges::find(mouse_paths_, pWnd);
     if (mouse_it != mouse_paths_.end()) {
       mouse_paths_.erase(mouse_it);
     }
-    auto keyboard_it =
-        std::find(keyboard_paths_.begin(), keyboard_paths_.end(), pWnd);
+    auto keyboard_it = std::ranges::find(keyboard_paths_, pWnd);
     if (keyboard_it != keyboard_paths_.end()) {
       keyboard_paths_.erase(keyboard_it);
     }
@@ -432,8 +431,7 @@
 
 void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
   DCHECK_EQ(pWnd->parent_, this);
-  auto it =
-      std::find(children_.begin(), children_.end(), MakeFakeUniquePtr(pWnd));
+  auto it = std::ranges::find(children_, MakeFakeUniquePtr(pWnd));
   if (it == children_.end()) {
     return;
   }
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 6e7a9a1..3147dd5 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -1225,7 +1225,7 @@
   }
 
   WideString swIconName = pRuntime->ToWideString(params[0]);
-  auto it = std::find(icon_names_.begin(), icon_names_.end(), swIconName);
+  auto it = std::ranges::find(icon_names_, swIconName);
   if (it == icon_names_.end()) {
     return CJS_Result::Failure(JSMessage::kBadObjectError);
   }
diff --git a/fxjs/xfa/cfxjse_context.cpp b/fxjs/xfa/cfxjse_context.cpp
index fdfeb40..0e29692 100644
--- a/fxjs/xfa/cfxjse_context.cpp
+++ b/fxjs/xfa/cfxjse_context.cpp
@@ -234,11 +234,10 @@
 }
 
 CFXJSE_Class* CFXJSE_Context::GetClassByName(ByteStringView szName) const {
-  auto pClass =
-      std::find_if(classes_.begin(), classes_.end(),
-                   [szName](const std::unique_ptr<CFXJSE_Class>& item) {
-                     return item->IsName(szName);
-                   });
+  auto pClass = std::ranges::find_if(
+      classes_, [szName](const std::unique_ptr<CFXJSE_Class>& item) {
+        return item->IsName(szName);
+      });
   return pClass != classes_.end() ? pClass->get() : nullptr;
 }
 
diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp
index a97b1cd..74ae478 100644
--- a/xfa/fwl/cfwl_listbox.cpp
+++ b/xfa/fwl/cfwl_listbox.cpp
@@ -893,10 +893,10 @@
 }
 
 int32_t CFWL_ListBox::GetItemIndex(CFWL_Widget* pWidget, Item* pItem) {
-  auto it = std::find_if(item_array_.begin(), item_array_.end(),
-                         [pItem](const std::unique_ptr<Item>& candidate) {
-                           return candidate.get() == pItem;
-                         });
+  auto it = std::ranges::find_if(
+      item_array_, [pItem](const std::unique_ptr<Item>& candidate) {
+        return candidate.get() == pItem;
+      });
   return it != item_array_.end()
              ? checked_cast<int32_t>(it - item_array_.begin())
              : -1;
diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp
index 3212aa5..9f2bea9 100644
--- a/xfa/fxfa/cxfa_ffpageview.cpp
+++ b/xfa/fxfa/cxfa_ffpageview.cpp
@@ -412,8 +412,8 @@
 
 bool CXFA_FFTabOrderPageWidgetIterator::SetCurrentWidget(
     CXFA_FFWidget* hWidget) {
-  auto it = std::find(tab_order_widget_array_.begin(),
-                      tab_order_widget_array_.end(), hWidget->GetLayoutItem());
+  auto it =
+      std::ranges::find(tab_order_widget_array_, hWidget->GetLayoutItem());
   if (it == tab_order_widget_array_.end()) {
     return false;
   }
@@ -461,7 +461,7 @@
       tab_order_widget_array_.emplace_back(item);
       CXFA_Node* node = item->GetFFWidget()->GetNode();
       if (node->GetFFWidgetType() == XFA_FFWidgetType::kExclGroup) {
-        auto it = std::find(items.begin(), items.end(), item);
+        auto it = std::ranges::find(items, item);
         size_t index = it != items.end() ? it - items.begin() + 1 : 0;
         while (true) {
           CXFA_FFWidget* radio = items[index % items.size()]->GetFFWidget();
@@ -480,7 +480,7 @@
         continue;
       }
     }
-    auto it = std::find(items.begin(), items.end(), item);
+    auto it = std::ranges::find(items, item);
     size_t index = it != items.end() ? it - items.begin() + 1 : 0;
     item = items[index % items.size()];
   }
diff --git a/xfa/fxfa/formcalc/cxfa_fmlexer.cpp b/xfa/fxfa/formcalc/cxfa_fmlexer.cpp
index e83261d..2ce52a8 100644
--- a/xfa/fxfa/formcalc/cxfa_fmlexer.cpp
+++ b/xfa/fxfa/formcalc/cxfa_fmlexer.cpp
@@ -84,10 +84,9 @@
 
 XFA_FM_TOKEN TokenizeIdentifier(WideStringView str) {
   const XFA_FMKeyword* result =
-      std::find_if(std::begin(kKeyWords), std::end(kKeyWords),
-                   [str](const XFA_FMKeyword& iter) {
-                     return str.EqualsASCII(iter.keyword_);
-                   });
+      std::ranges::find_if(kKeyWords, [str](const XFA_FMKeyword& iter) {
+        return str.EqualsASCII(iter.keyword_);
+      });
   if (result != std::end(kKeyWords) && str.EqualsASCII(result->keyword_)) {
     return result->type_;
   }
diff --git a/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
index 8489ddc..ce1fa87 100644
--- a/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
+++ b/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
@@ -771,7 +771,7 @@
 
 int32_t CXFA_ViewLayoutProcessor::GetPageIndex(
     const CXFA_ViewLayoutItem* pPage) const {
-  auto it = std::find(page_array_.begin(), page_array_.end(), pPage);
+  auto it = std::ranges::find(page_array_, pPage);
   return it != page_array_.end()
              ? pdfium::checked_cast<int32_t>(it - page_array_.begin())
              : -1;
diff --git a/xfa/fxfa/parser/cxfa_arraynodelist.cpp b/xfa/fxfa/parser/cxfa_arraynodelist.cpp
index 342873a..5f148d2 100644
--- a/xfa/fxfa/parser/cxfa_arraynodelist.cpp
+++ b/xfa/fxfa/parser/cxfa_arraynodelist.cpp
@@ -45,7 +45,7 @@
     return true;
   }
 
-  auto it = std::find(array_.begin(), array_.end(), pBeforeNode);
+  auto it = std::ranges::find(array_, pBeforeNode);
   if (it == array_.end()) {
     return false;
   }
@@ -55,7 +55,7 @@
 }
 
 void CXFA_ArrayNodeList::Remove(CXFA_Node* pNode) {
-  auto it = std::find(array_.begin(), array_.end(), pNode);
+  auto it = std::ranges::find(array_, pNode);
   if (it != array_.end()) {
     array_.erase(it);
   }
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index 2070782..3e97e45 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -241,10 +241,10 @@
   std::vector<RecurseRecord> rgResultRecord;
   for (CXFA_Node* pNode = pDataScope->GetFirstChild(); pNode;
        pNode = pNode->GetNextSibling()) {
-    auto it = std::find_if(rgRecords->begin(), rgRecords->end(),
-                           [pNode](const RecurseRecord& record) {
-                             return pNode == record.pDataChild;
-                           });
+    auto it =
+        std::ranges::find_if(*rgRecords, [pNode](const RecurseRecord& record) {
+          return pNode == record.pDataChild;
+        });
     if (it != rgRecords->end()) {
       rgResultRecord.push_back(*it);
       rgRecords->erase(it);
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index c16cb9f..fccfd21 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1402,8 +1402,7 @@
 
 bool CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
   if (BindsFormItems()) {
-    auto it =
-        std::find(binding_nodes_.begin(), binding_nodes_.end(), pFormNode);
+    auto it = std::ranges::find(binding_nodes_, pFormNode);
     if (it != binding_nodes_.end()) {
       binding_nodes_.erase(it);
     }
@@ -4582,8 +4581,7 @@
   }
 
   std::vector<WideString> wsSaveTextArray = GetChoiceListItems(true);
-  auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(),
-                      wsValueArray[nIndex]);
+  auto it = std::ranges::find(wsSaveTextArray, wsValueArray[nIndex]);
   return it != wsSaveTextArray.end()
              ? pdfium::checked_cast<int32_t>(it - wsSaveTextArray.begin())
              : -1;
@@ -4594,7 +4592,7 @@
   std::vector<WideString> wsValueArray = GetSelectedItemsValue();
   std::vector<WideString> wsSaveTextArray = GetChoiceListItems(true);
   for (const auto& value : wsValueArray) {
-    auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(), value);
+    auto it = std::ranges::find(wsSaveTextArray, value);
     if (it != wsSaveTextArray.end()) {
       iSelArray.push_back(
           pdfium::checked_cast<int32_t>(it - wsSaveTextArray.begin()));
@@ -4631,8 +4629,7 @@
 
   int32_t iSel = -1;
   std::vector<WideString> wsValueArray = GetSelectedItemsValue();
-  auto value_iter = std::find(wsValueArray.begin(), wsValueArray.end(),
-                              wsSaveTextArray[nIndex]);
+  auto value_iter = std::ranges::find(wsValueArray, wsSaveTextArray[nIndex]);
   if (value_iter != wsValueArray.end()) {
     iSel = pdfium::checked_cast<int32_t>(value_iter - wsValueArray.begin());
   }
@@ -4648,8 +4645,7 @@
       }
     } else if (iSel >= 0) {
       std::vector<int32_t> iSelArray = GetSelectedItems();
-      auto selected_iter =
-          std::find(iSelArray.begin(), iSelArray.end(), nIndex);
+      auto selected_iter = std::ranges::find(iSelArray, nIndex);
       if (selected_iter != iSelArray.end()) {
         iSelArray.erase(selected_iter);
       }