From 4e7fcd376f481bc6fd96114a2cccddf6dc6aa861 Mon Sep 17 00:00:00 2001 From: cdesouza-chromium Date: Thu, 31 Oct 2024 13:44:30 +0000 Subject: [PATCH] [CodeHealth] Use `std::string::[starts|ends]_with` (#26306) For cases where the comparison is case sensitive, we should use the methods provided by the common std string types provided since cxx20. --- app/command_utils.cc.template | 2 +- brave_domains/service_domains_unittest.cc | 9 ++++----- ...eative_search_result_ad_tab_helper_browsertest.cc | 3 +-- .../brave_wallet_sign_message_browsertest.cc | 7 +++---- ...phemeral_storage_forget_by_default_browsertest.cc | 2 +- .../hsts_partitioning_browsertest.cc | 2 +- ...t_redirect_network_delegate_helper_browsertest.cc | 2 +- .../ntp_background/custom_background_file_manager.h | 3 +-- browser/ntp_background/ntp_p3a_helper_impl.cc | 2 +- .../test/playlist_media_discovery_browsertests.cc | 2 +- .../win/module_file_name_patch_browsertest.cc | 3 ++- browser/ui/commander/commander_service.cc | 2 +- browser/ui/commander/fuzzy_finder.cc | 4 ++-- .../ui/views/sidebar/sidebar_items_contents_view.cc | 2 +- browser/ui/webui/skus_internals_ui.cc | 6 +++--- .../signed_exchange_request_browsertest.cc | 6 ++---- .../trace_event/memory_infra_background_allowlist.cc | 5 ++--- chromium_src/chrome/browser/ui/webui/webui_util.cc | 4 +--- .../omnibox/browser/autocomplete_controller.cc | 2 +- .../components/omnibox/browser/omnibox_edit_model.cc | 2 +- .../browser/renderer_host/mixed_content_checker.cc | 2 +- chromium_src/net/base/lookup_string_in_fixed_set.cc | 9 ++++----- .../engine/engine_consumer_claude_unittest.cc | 8 ++++---- .../core/browser/engine/engine_consumer_llama.cc | 2 +- .../browser/engine/engine_consumer_llama_unittest.cc | 8 ++++---- components/ai_chat/core/browser/utils.cc | 3 +-- components/api_request_helper/api_request_helper.cc | 2 +- components/brave_news/browser/publishers_parsing.cc | 2 +- .../brave_news/browser/suggestions_controller.cc | 2 +- .../database_publisher_prefix_list_unittest.cc | 3 +-- .../browser/bitcoin/bitcoin_test_utils.cc | 4 ++-- components/brave_wallet/browser/ens_resolver_task.cc | 2 +- .../browser/keyring_service_migrations.cc | 6 +++--- .../brave_wallet/browser/network_manager_unittest.cc | 2 +- .../brave_wallet/browser/siwe_message_parser.cc | 2 +- components/brave_wallet/common/eth_request_helper.cc | 4 ++-- .../common/eth_sign_typed_data_helper.cc | 8 ++++---- components/brave_wallet/common/hex_utils.cc | 2 +- components/brave_wallet/common/solana_utils.cc | 2 +- .../brave_wayback_machine_utils.cc | 6 ++++-- .../renderer/brave_content_settings_agent_impl.cc | 2 +- components/debounce/core/browser/debounce_rule.cc | 2 +- components/decentralized_dns/core/utils.cc | 6 +++--- .../browser/view_counter_service_unittest.cc | 2 +- components/p3a/constellation_helper_unittest.cc | 6 +++--- components/p3a/message_manager_unittest.cc | 12 ++++++------ components/p3a/metric_log_store.cc | 6 ++---- components/p3a/p3a_message.cc | 2 +- components/p3a/p3a_service.cc | 3 +-- components/p3a/p3a_service_unittest.cc | 2 +- components/p3a/star_randomness_test_util.cc | 2 +- components/request_otr/browser/request_otr_rule.cc | 2 +- components/speedreader/common/url_readable_hints.cc | 3 ++- components/tor/tor_control.cc | 11 +++-------- components/tor/tor_file_watcher.cc | 5 ++--- ios/browser/ui/webui/skus/skus_internals_ui.mm | 6 +++--- renderer/test/subresource_web_bundles_browsertest.cc | 10 +++++----- .../renderer/core/brave_page_graph/page_graph.cc | 4 ++-- tools/redirect_cc/redirect_cc.cc | 6 +++--- utility/importer/brave_profile_import_impl.cc | 6 ++---- utility/importer/chrome_importer.cc | 3 +-- 61 files changed, 115 insertions(+), 135 deletions(-) diff --git a/app/command_utils.cc.template b/app/command_utils.cc.template index cb39335832c..775888756d7 100644 --- a/app/command_utils.cc.template +++ b/app/command_utils.cc.template @@ -82,7 +82,7 @@ std::string GetCommandName(int command_id) { // remove the '&'. For example "Install &PWA". // 2. The & is in brackets, and defines a shortcut key not in the string, in // which case we remove the whole match. For example "Install (&K)PWA". - auto remove = base::StartsWith(match, "(") ? match : "&"; + auto remove = match.starts_with("(") ? match : "&"; base::ReplaceFirstSubstringAfterOffset(&translation, 0, remove, ""); } return translation; diff --git a/brave_domains/service_domains_unittest.cc b/brave_domains/service_domains_unittest.cc index f106041da78..a494a7eb3c7 100644 --- a/brave_domains/service_domains_unittest.cc +++ b/brave_domains/service_domains_unittest.cc @@ -11,7 +11,6 @@ #include "base/debug/debugging_buildflags.h" #include "base/files/file_path.h" #include "base/strings/strcat.h" -#include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "brave/brave_domains/buildflags.h" #include "build/build_config.h" @@ -76,8 +75,8 @@ TEST(BraveServiceDomains, PrefixOverride) { GetServicesDomain(prefix, brave_domains::ServicesEnvironment::PROD, &cl); // Prefixed domain should be production override - EXPECT_TRUE(base::EndsWith(prefixed_domain, kProductionValue)); - EXPECT_TRUE(base::StartsWith(prefixed_domain, prefix)); + EXPECT_TRUE(prefixed_domain.ends_with(kProductionValue)); + EXPECT_TRUE(prefixed_domain.starts_with(prefix)); // All other domain retrievals should be dev EXPECT_EQ( @@ -88,8 +87,8 @@ TEST(BraveServiceDomains, PrefixOverride) { auto other_prefixed_domain = GetServicesDomain( other_prefix, brave_domains::ServicesEnvironment::PROD, &cl); - EXPECT_TRUE(base::EndsWith(other_prefixed_domain, kDevValue)); - EXPECT_TRUE(base::StartsWith(other_prefixed_domain, other_prefix)); + EXPECT_TRUE(other_prefixed_domain.ends_with(kDevValue)); + EXPECT_TRUE(other_prefixed_domain.starts_with(other_prefix)); } TEST(BraveServiceDomains, DefaultEnvValue) { diff --git a/browser/brave_ads/creatives/search_result_ad/creative_search_result_ad_tab_helper_browsertest.cc b/browser/brave_ads/creatives/search_result_ad/creative_search_result_ad_tab_helper_browsertest.cc index 15d78a8c36a..74ab6a0df16 100644 --- a/browser/brave_ads/creatives/search_result_ad/creative_search_result_ad_tab_helper_browsertest.cc +++ b/browser/brave_ads/creatives/search_result_ad/creative_search_result_ad_tab_helper_browsertest.cc @@ -11,7 +11,6 @@ #include "base/path_service.h" #include "base/strings/strcat.h" #include "base/strings/string_number_conversions.h" -#include "base/strings/string_util.h" #include "base/test/scoped_feature_list.h" #include "base/time/time.h" #include "brave/components/brave_ads/browser/ads_service.h" @@ -122,7 +121,7 @@ class BraveAdsCreativeSearchResultAdTabHelperTest const GURL url = request.GetURL(); const std::string_view path = url.path_piece(); - if (!base::StartsWith(path, kClickRedirectPath)) { + if (!path.starts_with(kClickRedirectPath)) { return nullptr; } diff --git a/browser/brave_wallet/brave_wallet_sign_message_browsertest.cc b/browser/brave_wallet/brave_wallet_sign_message_browsertest.cc index eb986665012..e297d4c2ca6 100644 --- a/browser/brave_wallet/brave_wallet_sign_message_browsertest.cc +++ b/browser/brave_wallet/brave_wallet_sign_message_browsertest.cc @@ -9,7 +9,6 @@ #include "base/feature_list.h" #include "base/memory/raw_ptr.h" #include "base/path_service.h" -#include "base/strings/string_util.h" #include "base/test/bind.h" #include "base/test/scoped_feature_list.h" #include "brave/browser/brave_wallet/brave_wallet_service_factory.h" @@ -344,9 +343,9 @@ IN_PROC_BROWSER_TEST_F(BraveWalletSignMessageBrowserTest, SIWE) { brave_wallet_service_->NotifySignMessageRequestProcessed( true, request_index++, nullptr, std::nullopt); // port is dynamic - EXPECT_TRUE(base::StartsWith( - EvalJs(web_contents(), "getSignMessageResult()").ExtractString(), - "0x", base::CompareCase::SENSITIVE)); + EXPECT_TRUE(EvalJs(web_contents(), "getSignMessageResult()") + .ExtractString() + .starts_with("0x")); } } } diff --git a/browser/ephemeral_storage/ephemeral_storage_forget_by_default_browsertest.cc b/browser/ephemeral_storage/ephemeral_storage_forget_by_default_browsertest.cc index f8cc752d4f5..47a3992eed3 100644 --- a/browser/ephemeral_storage/ephemeral_storage_forget_by_default_browsertest.cc +++ b/browser/ephemeral_storage/ephemeral_storage_forget_by_default_browsertest.cc @@ -496,7 +496,7 @@ class EphemeralStorageForgetByDefaultDisabledBrowserTest static bool IsPreTest() { const testing::TestInfo* const test_info = testing::UnitTest::GetInstance()->current_test_info(); - return base::StartsWith(test_info->name(), "PRE_"); + return std::string_view(test_info->name()).starts_with("PRE_"); } private: diff --git a/browser/ephemeral_storage/hsts_partitioning_browsertest.cc b/browser/ephemeral_storage/hsts_partitioning_browsertest.cc index 1358e6a49ad..d14fe87bb8f 100644 --- a/browser/ephemeral_storage/hsts_partitioning_browsertest.cc +++ b/browser/ephemeral_storage/hsts_partitioning_browsertest.cc @@ -538,7 +538,7 @@ class HSTSSameDomainPartitionUsesOldFormatBrowserTest static bool IsPreTest() { const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); - return base::StartsWith(test_info->name(), "PRE_"); + return std::string_view(test_info->name()).starts_with("PRE_"); } private: diff --git a/browser/net/brave_torrent_redirect_network_delegate_helper_browsertest.cc b/browser/net/brave_torrent_redirect_network_delegate_helper_browsertest.cc index 8f01effbc31..06e7cc15c9c 100644 --- a/browser/net/brave_torrent_redirect_network_delegate_helper_browsertest.cc +++ b/browser/net/brave_torrent_redirect_network_delegate_helper_browsertest.cc @@ -50,7 +50,7 @@ class BraveTorrentRedirectNetworkDelegateHelperTest std::unique_ptr HandleRequest( const net::test_server::HttpRequest& request) { auto relative_url = request.relative_url; - if (base::EndsWith(relative_url, ".torrent")) { + if (relative_url.ends_with(".torrent")) { auto response = std::make_unique(); response->set_code(net::HTTP_OK); response->set_content("a torrent file"); diff --git a/browser/ntp_background/custom_background_file_manager.h b/browser/ntp_background/custom_background_file_manager.h index 2d3bef2467e..39684c52406 100644 --- a/browser/ntp_background/custom_background_file_manager.h +++ b/browser/ntp_background/custom_background_file_manager.h @@ -80,8 +80,7 @@ class CustomBackgroundFileManager final { CustomBackgroundFileManager* file_manager = nullptr) : file_manager_(file_manager) { if constexpr (std::is_same_v) { - DCHECK(!base::StartsWith(value, - ntp_background_images::kCustomWallpaperURL)) + DCHECK(!value.starts_with(ntp_background_images::kCustomWallpaperURL)) << "URLs should be passed in as a GURL"; value_ = value; } else if constexpr (std::is_same_v) { diff --git a/browser/ntp_background/ntp_p3a_helper_impl.cc b/browser/ntp_background/ntp_p3a_helper_impl.cc index e66dbb8885f..9990253c743 100644 --- a/browser/ntp_background/ntp_p3a_helper_impl.cc +++ b/browser/ntp_background/ntp_p3a_helper_impl.cc @@ -161,7 +161,7 @@ void NTPP3AHelperImpl::OnP3ARotation(p3a::MetricLogType log_type, void NTPP3AHelperImpl::OnP3AMetricCycled(const std::string& histogram_name, bool is_constellation) { - if (!base::StartsWith(histogram_name, p3a::kCreativeMetricPrefix)) { + if (!histogram_name.starts_with(p3a::kCreativeMetricPrefix)) { return; } diff --git a/browser/playlist/test/playlist_media_discovery_browsertests.cc b/browser/playlist/test/playlist_media_discovery_browsertests.cc index 0bf28eea18f..1df847668bc 100644 --- a/browser/playlist/test/playlist_media_discovery_browsertests.cc +++ b/browser/playlist/test/playlist_media_discovery_browsertests.cc @@ -168,7 +168,7 @@ class PlaylistMediaDiscoveryBrowserTest : public PlatformBrowserTest { std::vector expected_items; base::ranges::for_each(expected_data, [&](ExpectedData& item) { auto fix_host = [&](auto& url_str) { - if (!base::StartsWith(url_str, "/")) { + if (!url_str.starts_with("/")) { return; } diff --git a/browser/sandbox/win/module_file_name_patch_browsertest.cc b/browser/sandbox/win/module_file_name_patch_browsertest.cc index a604a481e9b..9ae3402718c 100644 --- a/browser/sandbox/win/module_file_name_patch_browsertest.cc +++ b/browser/sandbox/win/module_file_name_patch_browsertest.cc @@ -66,7 +66,8 @@ IN_PROC_BROWSER_TEST_P(ModuleFileNameBrowserTest, CheckPath) { WCHAR main_path[MAX_PATH] = {0}; GetModuleFileNameW(nullptr, main_path, MAX_PATH); - EXPECT_TRUE(base::EndsWith(main_path, L"brave_browser_tests.exe")) + EXPECT_TRUE( + std::wstring_view(main_path).ends_with(L"brave_browser_tests.exe")) << main_path; constexpr const size_t kInterceptedFunctions = 4u; diff --git a/browser/ui/commander/commander_service.cc b/browser/ui/commander/commander_service.cc index add6a1d6273..0b6df0b872f 100644 --- a/browser/ui/commander/commander_service.cc +++ b/browser/ui/commander/commander_service.cc @@ -188,7 +188,7 @@ void CommanderService::UpdateText(const std::u16string& text, bool force) { return; } - auto has_prefix = base::StartsWith(text, kCommandPrefix); + auto has_prefix = text.starts_with(kCommandPrefix); if (!has_prefix && !browser->profile()->GetPrefs()->GetBoolean( omnibox::kCommanderSuggestionsEnabled)) { return; diff --git a/browser/ui/commander/fuzzy_finder.cc b/browser/ui/commander/fuzzy_finder.cc index 8617b38775b..9758a9ff653 100644 --- a/browser/ui/commander/fuzzy_finder.cc +++ b/browser/ui/commander/fuzzy_finder.cc @@ -104,7 +104,7 @@ double ConsecutiveMatchWithGaps(const std::u16string& needle, DCHECK(haystack == base::i18n::FoldCase(haystack)); DCHECK(matched_ranges.empty()); // Special case for prefix. - if (base::StartsWith(haystack, needle)) { + if (haystack.starts_with(needle)) { matched_ranges.emplace_back(0, needle.size()); return kPrefixScore; } @@ -265,7 +265,7 @@ double FuzzyFinder::Find(const std::u16string& haystack, } } // Special case 2: needle is a prefix of haystack - if (base::StartsWith(folded, needle_)) { + if (folded.starts_with(needle_)) { matched_ranges.emplace_back(0, needle_.length()); return kPrefixScore; } diff --git a/browser/ui/views/sidebar/sidebar_items_contents_view.cc b/browser/ui/views/sidebar/sidebar_items_contents_view.cc index 23adbf32751..7df76c65fad 100644 --- a/browser/ui/views/sidebar/sidebar_items_contents_view.cc +++ b/browser/ui/views/sidebar/sidebar_items_contents_view.cc @@ -74,7 +74,7 @@ std::string GetFirstCharFromURL(const GURL& url) { if (target.empty()) { target = url.spec(); } - if (base::StartsWith(target, "www.")) { + if (target.starts_with("www.")) { target = target.substr(4, 1); } else { target = target.substr(0, 1); diff --git a/browser/ui/webui/skus_internals_ui.cc b/browser/ui/webui/skus_internals_ui.cc index 4f0fb378664..14809bc17c9 100644 --- a/browser/ui/webui/skus_internals_ui.cc +++ b/browser/ui/webui/skus_internals_ui.cc @@ -125,7 +125,7 @@ base::Value::Dict SkusInternalsUI::GetOrderInfo( base::Value::Dict dict; const auto& skus_state = local_state_->GetDict(skus::prefs::kSkusState); for (const auto kv : skus_state) { - if (!base::StartsWith(kv.first, "skus:")) { + if (!kv.first.starts_with("skus:")) { continue; } @@ -152,7 +152,7 @@ base::Value::Dict SkusInternalsUI::GetOrderInfo( } if (auto* order_location = order_dict->FindString("location")) { - if (!base::StartsWith(*order_location, location)) { + if (!order_location->starts_with(location)) { continue; } order_dict_output.Set("location", *order_location); @@ -258,7 +258,7 @@ std::string SkusInternalsUI::GetSkusStateAsString() const { for (const auto kv : skus_state) { // Only shows "skus:xx" kv in webui. - if (!base::StartsWith(kv.first, "skus:")) { + if (!kv.first.starts_with("skus:")) { continue; } diff --git a/browser/web_package/signed_exchange_request_browsertest.cc b/browser/web_package/signed_exchange_request_browsertest.cc index d5eaa8e1bb1..1e1f22e8043 100644 --- a/browser/web_package/signed_exchange_request_browsertest.cc +++ b/browser/web_package/signed_exchange_request_browsertest.cc @@ -55,8 +55,7 @@ class SignedExchangeRequestBrowserTest : public InProcessBrowserTest { static std::unique_ptr RedirectResponseHandler(const net::test_server::HttpRequest& request) { - if (!base::StartsWith(request.relative_url, "/r?", - base::CompareCase::SENSITIVE)) { + if (!request.relative_url.starts_with("/r?")) { return nullptr; } std::unique_ptr http_response( @@ -72,8 +71,7 @@ class SignedExchangeRequestBrowserTest : public InProcessBrowserTest { std::unique_ptr FallbackSxgResponseHandler( const net::test_server::HttpRequest& request) { const std::string prefix = "/fallback_sxg?"; - if (!base::StartsWith(request.relative_url, prefix, - base::CompareCase::SENSITIVE)) { + if (!request.relative_url.starts_with(prefix)) { return nullptr; } std::string fallback_url(request.relative_url.substr(prefix.length())); diff --git a/chromium_src/base/trace_event/memory_infra_background_allowlist.cc b/chromium_src/base/trace_event/memory_infra_background_allowlist.cc index 7ab7d24571c..876a257b2eb 100644 --- a/chromium_src/base/trace_event/memory_infra_background_allowlist.cc +++ b/chromium_src/base/trace_event/memory_infra_background_allowlist.cc @@ -14,9 +14,8 @@ namespace base { namespace trace_event { bool IsMemoryAllocatorDumpNameInAllowlist(const std::string& name) { - if (base::StartsWith( - name, "extensions/value_store/Extensions.Database.Open.BraveWallet/", - CompareCase::SENSITIVE)) { + if (name.starts_with( + "extensions/value_store/Extensions.Database.Open.BraveWallet/")) { return true; } return IsMemoryAllocatorDumpNameInAllowlist_ChromiumImpl(name); diff --git a/chromium_src/chrome/browser/ui/webui/webui_util.cc b/chromium_src/chrome/browser/ui/webui/webui_util.cc index 52ce3e5a7e4..0952d5855ac 100644 --- a/chromium_src/chrome/browser/ui/webui/webui_util.cc +++ b/chromium_src/chrome/browser/ui/webui/webui_util.cc @@ -22,9 +22,7 @@ bool IsChromeUntrustedDataSource(content::WebUIDataSource* source) { base::StrCat( {content::kChromeUIUntrustedScheme, url::kStandardSchemeSeparator})); - return base::StartsWith(source->GetSource(), - *kChromeUntrustedSourceNamePrefix, - base::CompareCase::SENSITIVE); + return source->GetSource().starts_with(*kChromeUntrustedSourceNamePrefix); } constexpr char kBraveCSP[] = diff --git a/chromium_src/components/omnibox/browser/autocomplete_controller.cc b/chromium_src/components/omnibox/browser/autocomplete_controller.cc index a1576cb61b1..da8da2774b7 100644 --- a/chromium_src/components/omnibox/browser/autocomplete_controller.cc +++ b/chromium_src/components/omnibox/browser/autocomplete_controller.cc @@ -50,7 +50,7 @@ void MaybeShowCommands(AutocompleteResult* result, #if BUILDFLAG(ENABLE_COMMANDER) // If this input isn't a command, return and don't do any work. if (!base::FeatureList::IsEnabled(features::kBraveCommander) || - !base::StartsWith(input.text(), commander::kCommandPrefix)) { + !input.text().starts_with(commander::kCommandPrefix)) { return; } diff --git a/chromium_src/components/omnibox/browser/omnibox_edit_model.cc b/chromium_src/components/omnibox/browser/omnibox_edit_model.cc index eb9c58950dc..f6c24039544 100644 --- a/chromium_src/components/omnibox/browser/omnibox_edit_model.cc +++ b/chromium_src/components/omnibox/browser/omnibox_edit_model.cc @@ -44,7 +44,7 @@ void BraveAdjustTextForCopy(GURL* url) { bool OmniboxEditModel::CanPasteAndGo(const std::u16string& text) const { #if BUILDFLAG(ENABLE_COMMANDER) if (base::FeatureList::IsEnabled(features::kBraveCommander) && - base::StartsWith(text, commander::kCommandPrefix)) { + text.starts_with(commander::kCommandPrefix)) { return false; } #endif diff --git a/chromium_src/content/browser/renderer_host/mixed_content_checker.cc b/chromium_src/content/browser/renderer_host/mixed_content_checker.cc index 86641c89534..c365e509f66 100644 --- a/chromium_src/content/browser/renderer_host/mixed_content_checker.cc +++ b/chromium_src/content/browser/renderer_host/mixed_content_checker.cc @@ -15,7 +15,7 @@ namespace content { bool MixedContentChecker::DoesOriginSchemeRestrictMixedContent( const url::Origin& origin) { constexpr const char kOnion[] = ".onion"; - if (base::EndsWith(origin.host(), kOnion) && + if (origin.host().ends_with(kOnion) && (origin.scheme() == url::kHttpsScheme || origin.scheme() == url::kHttpScheme || origin.scheme() == url::kWsScheme || diff --git a/chromium_src/net/base/lookup_string_in_fixed_set.cc b/chromium_src/net/base/lookup_string_in_fixed_set.cc index e9fd9ecd237..a206e8ee359 100644 --- a/chromium_src/net/base/lookup_string_in_fixed_set.cc +++ b/chromium_src/net/base/lookup_string_in_fixed_set.cc @@ -33,22 +33,21 @@ int LookupSuffixInReversedSet(base::span graph, // OmniboxInputType::UNKNOWN, The first entry in the autocomplete list will be // URL instead of search. for (auto* unstoppable_domain : decentralized_dns::kUnstoppableDomains) { - if (base::EndsWith(host, unstoppable_domain)) { + if (host.ends_with(unstoppable_domain)) { *suffix_length = strlen(unstoppable_domain) - 1; return kDafsaFound; } } - if (base::EndsWith(host, decentralized_dns::kEthDomain)) { + if (host.ends_with(decentralized_dns::kEthDomain)) { *suffix_length = strlen(decentralized_dns::kEthDomain) - 1; return kDafsaFound; } - if (base::EndsWith(host, decentralized_dns::kSolDomain)) { + if (host.ends_with(decentralized_dns::kSolDomain)) { *suffix_length = strlen(decentralized_dns::kSolDomain) - 1; return kDafsaFound; } - if (include_private && - base::EndsWith(host, decentralized_dns::kDNSForEthDomain)) { + if (include_private && host.ends_with(decentralized_dns::kDNSForEthDomain)) { *suffix_length = strlen(decentralized_dns::kDNSForEthDomain) - 1; return kDafsaFound; } diff --git a/components/ai_chat/core/browser/engine/engine_consumer_claude_unittest.cc b/components/ai_chat/core/browser/engine/engine_consumer_claude_unittest.cc index c6306ddddf1..a0bcd9aa34c 100644 --- a/components/ai_chat/core/browser/engine/engine_consumer_claude_unittest.cc +++ b/components/ai_chat/core/browser/engine/engine_consumer_claude_unittest.cc @@ -118,8 +118,8 @@ TEST_F(EngineConsumerClaudeUnitTest, TestGenerateAssistantResponse) { const std::vector& stop_words, EngineConsumer::GenerationCompletedCallback callback, EngineConsumer::GenerationDataCallback data_callback) { - EXPECT_TRUE(base::StartsWith(prompt, prompt_before_time_and_date)); - EXPECT_TRUE(base::EndsWith(prompt, prompt_after_time_and_date)); + EXPECT_TRUE(prompt.starts_with(prompt_before_time_and_date)); + EXPECT_TRUE(prompt.ends_with(prompt_after_time_and_date)); std::move(callback).Run(""); }); { @@ -191,8 +191,8 @@ TEST_F(EngineConsumerClaudeUnitTest, TestGenerateAssistantResponse) { const std::vector& stop_words, EngineConsumer::GenerationCompletedCallback callback, EngineConsumer::GenerationDataCallback data_callback) { - EXPECT_TRUE(base::StartsWith(prompt, prompt_before_time_and_date)); - EXPECT_TRUE(base::EndsWith(prompt, prompt_after_time_and_date)); + EXPECT_TRUE(prompt.starts_with(prompt_before_time_and_date)); + EXPECT_TRUE(prompt.ends_with(prompt_after_time_and_date)); std::move(callback).Run(""); }); diff --git a/components/ai_chat/core/browser/engine/engine_consumer_llama.cc b/components/ai_chat/core/browser/engine/engine_consumer_llama.cc index 1b0cc699f79..5660d1e5703 100644 --- a/components/ai_chat/core/browser/engine/engine_consumer_llama.cc +++ b/components/ai_chat/core/browser/engine/engine_consumer_llama.cc @@ -334,7 +334,7 @@ EngineConsumerLlamaRemote::EngineConsumerLlamaRemote( max_associated_content_length_ = model_options.max_associated_content_length; - is_mixtral_ = base::StartsWith(model_options.name, "mixtral"); + is_mixtral_ = model_options.name.starts_with("mixtral"); } EngineConsumerLlamaRemote::~EngineConsumerLlamaRemote() = default; diff --git a/components/ai_chat/core/browser/engine/engine_consumer_llama_unittest.cc b/components/ai_chat/core/browser/engine/engine_consumer_llama_unittest.cc index 21c9f19df21..0c8df3db5db 100644 --- a/components/ai_chat/core/browser/engine/engine_consumer_llama_unittest.cc +++ b/components/ai_chat/core/browser/engine/engine_consumer_llama_unittest.cc @@ -112,8 +112,8 @@ TEST_F(EngineConsumerLlamaUnitTest, TestGenerateAssistantResponse) { const std::vector& history, EngineConsumer::GenerationCompletedCallback callback, EngineConsumer::GenerationDataCallback data_callback) { - EXPECT_TRUE(base::StartsWith(prompt, prompt_before_time_and_date)); - EXPECT_TRUE(base::EndsWith(prompt, prompt_after_time_and_date)); + EXPECT_TRUE(prompt.starts_with(prompt_before_time_and_date)); + EXPECT_TRUE(prompt.ends_with(prompt_after_time_and_date)); std::move(callback).Run(""); }); { @@ -161,8 +161,8 @@ TEST_F(EngineConsumerLlamaUnitTest, TestGenerateAssistantResponse) { const std::vector& history, EngineConsumer::GenerationCompletedCallback callback, EngineConsumer::GenerationDataCallback data_callback) { - EXPECT_TRUE(base::StartsWith(prompt, prompt_before_time_and_date)); - EXPECT_TRUE(base::EndsWith(prompt, prompt_after_time_and_date)); + EXPECT_TRUE(prompt.starts_with(prompt_before_time_and_date)); + EXPECT_TRUE(prompt.ends_with(prompt_after_time_and_date)); std::move(callback).Run(""); }); std::vector history2; diff --git a/components/ai_chat/core/browser/utils.cc b/components/ai_chat/core/browser/utils.cc index ea31beb668d..9df25cf759b 100644 --- a/components/ai_chat/core/browser/utils.cc +++ b/components/ai_chat/core/browser/utils.cc @@ -139,8 +139,7 @@ bool IsBraveSearchSERP(const GURL& url) { return url.SchemeIs(url::kHttpsScheme) && url.host_piece() == brave_domains::GetServicesDomain(kBraveSearchURLPrefix) && - url.path_piece() == "/search" && - base::StartsWith(url.query_piece(), "q="); + url.path_piece() == "/search" && url.query_piece().starts_with("q="); } bool IsPremiumStatus(mojom::PremiumStatus status) { diff --git a/components/api_request_helper/api_request_helper.cc b/components/api_request_helper/api_request_helper.cc index e687a89641e..54e8fdb955a 100644 --- a/components/api_request_helper/api_request_helper.cc +++ b/components/api_request_helper/api_request_helper.cc @@ -546,7 +546,7 @@ void APIRequestHelper::URLLoaderHandler::ParseSSE( static constexpr char kDataPrefix[] = "data: {"; std::erase_if(stream_data, [](std::string_view item) { DVLOG(3) << "Received chunk: " << item; - if (!base::StartsWith(item, kDataPrefix)) { + if (!item.starts_with(kDataPrefix)) { // This is useful to log in case an API starts // coming back with unknown data type in some // scenarios. diff --git a/components/brave_news/browser/publishers_parsing.cc b/components/brave_news/browser/publishers_parsing.cc index c908d92085b..b24052228e9 100644 --- a/components/brave_news/browser/publishers_parsing.cc +++ b/components/brave_news/browser/publishers_parsing.cc @@ -39,7 +39,7 @@ std::optional ParseCombinedPublisherList(const base::Value& value) { auto& entry = *parsed_publisher; GURL site_url = [&entry] { - if (base::StartsWith(entry.site_url, "https://")) { + if (entry.site_url.starts_with("https://")) { return GURL(entry.site_url); } else { return GURL("https://" + entry.site_url); diff --git a/components/brave_news/browser/suggestions_controller.cc b/components/brave_news/browser/suggestions_controller.cc index fa8b2c190e0..2cf57ca1b34 100644 --- a/components/brave_news/browser/suggestions_controller.cc +++ b/components/brave_news/browser/suggestions_controller.cc @@ -84,7 +84,7 @@ double GetVisitWeighting( // while we wait for them to be fixed. // Relevant issues: https://github.com/brave/news-aggregator/issues/58 and // https://github.com/brave/brave-browser/issues/26092 - if (!base::StartsWith(host_name, "www.")) { + if (!host_name.starts_with("www.")) { it = visit_weightings.find("www." + host_name); } diff --git a/components/brave_rewards/core/database/database_publisher_prefix_list_unittest.cc b/components/brave_rewards/core/database/database_publisher_prefix_list_unittest.cc index 08ce19dbaf1..f6ad407e269 100644 --- a/components/brave_rewards/core/database/database_publisher_prefix_list_unittest.cc +++ b/components/brave_rewards/core/database/database_publisher_prefix_list_unittest.cc @@ -86,8 +86,7 @@ TEST_F(RewardsDatabasePublisherPrefixListTest, Reset) { EXPECT_EQ(transaction->commands.size(), 2u); EXPECT_EQ(transaction->commands[0]->command, "DELETE FROM publisher_prefix_list"); - EXPECT_TRUE(base::StartsWith( - transaction->commands[1]->command, + EXPECT_TRUE(transaction->commands[1]->command.starts_with( "INSERT OR REPLACE INTO publisher_prefix_list (hash_prefix) " "VALUES (x'00000000'),(x'00000001'),(x'00000002'),")); } diff --git a/components/brave_wallet/browser/bitcoin/bitcoin_test_utils.cc b/components/brave_wallet/browser/bitcoin/bitcoin_test_utils.cc index 764cf404837..cc0d666379d 100644 --- a/components/brave_wallet/browser/bitcoin/bitcoin_test_utils.cc +++ b/components/brave_wallet/browser/bitcoin/bitcoin_test_utils.cc @@ -41,10 +41,10 @@ std::string ExtractApiRequestPath(const GURL& request_url) { ->rpc_endpoints[0] .spec(); - if (base::StartsWith(spec, mainnet_url_spec)) { + if (spec.starts_with(mainnet_url_spec)) { return spec.substr(mainnet_url_spec.size()); } - if (base::StartsWith(spec, testnet_url_spec)) { + if (spec.starts_with(testnet_url_spec)) { return spec.substr(testnet_url_spec.size()); } diff --git a/components/brave_wallet/browser/ens_resolver_task.cc b/components/brave_wallet/browser/ens_resolver_task.cc index 90db35f0592..82aa5e597da 100644 --- a/components/brave_wallet/browser/ens_resolver_task.cc +++ b/components/brave_wallet/browser/ens_resolver_task.cc @@ -73,7 +73,7 @@ EnsResolverTaskError MakeInvalidParamsError() { } std::string GetParent(const std::string& domain) { - DCHECK(domain == "eth" || base::EndsWith(domain, ".eth")); + DCHECK(domain == "eth" || domain.ends_with(".eth")); if (domain == "eth") { return ""; } diff --git a/components/brave_wallet/browser/keyring_service_migrations.cc b/components/brave_wallet/browser/keyring_service_migrations.cc index ab4438a0a0c..a55f8b22527 100644 --- a/components/brave_wallet/browser/keyring_service_migrations.cc +++ b/components/brave_wallet/browser/keyring_service_migrations.cc @@ -61,18 +61,18 @@ std::optional ExtractAccountIndex(mojom::KeyringId keyring_id, auto account_index = std::string_view(path); auto root_path = HDKeyring::GetRootPath(keyring_id); - if (!base::StartsWith(account_index, root_path)) { + if (!account_index.starts_with(root_path)) { return std::nullopt; } account_index.remove_prefix(root_path.size()); - if (!base::StartsWith(account_index, "/")) { + if (!account_index.starts_with("/")) { return std::nullopt; } account_index.remove_prefix(1); if (keyring_id == mojom::KeyringId::kSolana) { - if (!base::EndsWith(account_index, "'/0'")) { + if (!account_index.ends_with("'/0'")) { return std::nullopt; } account_index.remove_suffix(4); diff --git a/components/brave_wallet/browser/network_manager_unittest.cc b/components/brave_wallet/browser/network_manager_unittest.cc index bcb7dc2a683..d969d23d860 100644 --- a/components/brave_wallet/browser/network_manager_unittest.cc +++ b/components/brave_wallet/browser/network_manager_unittest.cc @@ -428,7 +428,7 @@ TEST_F(NetworkManagerUnitTest, GetNetworkURLForKnownChains) { NetworkManager::GetAllKnownChains(mojom::CoinType::ETH)) { auto network_url = network_manager()->GetNetworkURL(chain->chain_id, mojom::CoinType::ETH); - EXPECT_EQ(base::EndsWith(network_url.host(), ".brave.com"), + EXPECT_EQ(network_url.host().ends_with(".brave.com"), known_chains.contains(chain->chain_id)); } } diff --git a/components/brave_wallet/browser/siwe_message_parser.cc b/components/brave_wallet/browser/siwe_message_parser.cc index 2d9c2e05953..e062b3c1896 100644 --- a/components/brave_wallet/browser/siwe_message_parser.cc +++ b/components/brave_wallet/browser/siwe_message_parser.cc @@ -413,7 +413,7 @@ bool SIWEMessageParser::ParseOptionalResources( StringTokenizer tokenizer(urls_str, "\n"); std::vector urls; while (tokenizer.GetNext()) { - if (!base::StartsWith(tokenizer.token(), kResourcesSeperator)) { + if (!tokenizer.token().starts_with(kResourcesSeperator)) { return false; } auto url_str = tokenizer.token().substr(strlen(kResourcesSeperator)); diff --git a/components/brave_wallet/common/eth_request_helper.cc b/components/brave_wallet/common/eth_request_helper.cc index d192655e782..1fdf50744f8 100644 --- a/components/brave_wallet/common/eth_request_helper.cc +++ b/components/brave_wallet/common/eth_request_helper.cc @@ -732,8 +732,8 @@ mojom::BlockchainTokenPtr ParseWalletWatchAssetParams( const std::string* image = options_dict->FindString("image"); if (image) { GURL url = GURL(*image); - if (url.is_valid() && (url.SchemeIsHTTPOrHTTPS() || - base::StartsWith(*image, "data:image/"))) { + if (url.is_valid() && + (url.SchemeIsHTTPOrHTTPS() || image->starts_with("data:image/"))) { logo = url.spec(); } } diff --git a/components/brave_wallet/common/eth_sign_typed_data_helper.cc b/components/brave_wallet/common/eth_sign_typed_data_helper.cc index aee765cb75f..c2a40825bc5 100644 --- a/components/brave_wallet/common/eth_sign_typed_data_helper.cc +++ b/components/brave_wallet/common/eth_sign_typed_data_helper.cc @@ -201,7 +201,7 @@ std::optional> EthSignTypedDataHelper::EncodeField( constexpr double kMaxSafeInteger = static_cast(kMaxSafeIntegerUint64); std::vector result; - if (base::EndsWith(type, "]")) { + if (type.ends_with(']')) { if (version_ != Version::kV4) { VLOG(0) << "version has to be v4 to support array"; return std::nullopt; @@ -271,7 +271,7 @@ std::optional> EthSignTypedDataHelper::EncodeField( result.push_back(0); } result.insert(result.end(), address.begin(), address.end()); - } else if (base::StartsWith(type, "bytes", base::CompareCase::SENSITIVE)) { + } else if (type.starts_with("bytes")) { unsigned num_bits; if (!base::StringToUint(type.data() + 5, &num_bits) || num_bits > 32) { return std::nullopt; @@ -289,7 +289,7 @@ std::optional> EthSignTypedDataHelper::EncodeField( for (size_t i = 0; i < 32u - bytes.size(); ++i) { result.push_back(0); } - } else if (base::StartsWith(type, "uint", base::CompareCase::SENSITIVE)) { + } else if (type.starts_with("uint")) { // uint8 to uint256 in steps of 8 unsigned num_bits; if (!base::StringToUint(type.data() + 4, &num_bits) || @@ -328,7 +328,7 @@ std::optional> EthSignTypedDataHelper::EncodeField( for (int i = 256 - 8; i >= 0; i -= 8) { result.push_back(static_cast((encoded_value >> i) & 0xFF)); } - } else if (base::StartsWith(type, "int", base::CompareCase::SENSITIVE)) { + } else if (type.starts_with("int")) { // int8 to int256 in steps of 8 unsigned num_bits; if (!base::StringToUint(type.data() + 3, &num_bits) || diff --git a/components/brave_wallet/common/hex_utils.cc b/components/brave_wallet/common/hex_utils.cc index 4d74d2ae0fe..9cf037c0c64 100644 --- a/components/brave_wallet/common/hex_utils.cc +++ b/components/brave_wallet/common/hex_utils.cc @@ -44,7 +44,7 @@ bool IsValidHexString(const std::string& hex_input) { if (hex_input.length() < 2) { return false; } - if (!base::StartsWith(hex_input, "0x")) { + if (!hex_input.starts_with("0x")) { return false; } for (const auto& c : hex_input.substr(2)) { diff --git a/components/brave_wallet/common/solana_utils.cc b/components/brave_wallet/common/solana_utils.cc index 1433d8de686..e27aa56724d 100644 --- a/components/brave_wallet/common/solana_utils.cc +++ b/components/brave_wallet/common/solana_utils.cc @@ -78,7 +78,7 @@ bool IsBase58EncodedSolanaPubkey(const std::string& key) { bool Uint8ArrayDecode(const std::string& str, std::vector* ret, size_t len) { - if (!base::StartsWith(str, "[") || !base::EndsWith(str, "]")) { + if (!str.starts_with('[') || !str.ends_with(']')) { return false; } DCHECK(ret); diff --git a/components/brave_wayback_machine/brave_wayback_machine_utils.cc b/components/brave_wayback_machine/brave_wayback_machine_utils.cc index 6253de3abcb..26483b1eb86 100644 --- a/components/brave_wayback_machine/brave_wayback_machine_utils.cc +++ b/components/brave_wayback_machine/brave_wayback_machine_utils.cc @@ -22,11 +22,13 @@ bool IsWaybackMachineDisabledFor(const GURL& url) { if (net::IsLocalhost(url)) return true; - if (base::EndsWith(url.host(), ".local", base::CompareCase::SENSITIVE)) + if (url.host().ends_with(".local")) { return true; + } - if (base::EndsWith(url.host(), ".onion", base::CompareCase::SENSITIVE)) + if (url.host().ends_with(".onion")) { return true; + } // Disable on web.archive.org if (url.host() == kWaybackHost) diff --git a/components/content_settings/renderer/brave_content_settings_agent_impl.cc b/components/content_settings/renderer/brave_content_settings_agent_impl.cc index 602f784af98..e91c20f0569 100644 --- a/components/content_settings/renderer/brave_content_settings_agent_impl.cc +++ b/components/content_settings/renderer/brave_content_settings_agent_impl.cc @@ -78,7 +78,7 @@ bool IsBraveShieldsDown(const blink::WebFrame* frame, bool ShouldSkipResource(const GURL& resource_url) { return (resource_url.path_piece().empty() || ((resource_url.path_piece().size() > 1) && - !base::EndsWith(resource_url.path_piece(), kJavascriptExtension))); + !resource_url.path_piece().ends_with(kJavascriptExtension))); } } // namespace diff --git a/components/debounce/core/browser/debounce_rule.cc b/components/debounce/core/browser/debounce_rule.cc index 0180dbc06fb..82a41ccae30 100644 --- a/components/debounce/core/browser/debounce_rule.cc +++ b/components/debounce/core/browser/debounce_rule.cc @@ -48,7 +48,7 @@ const int64_t kMaxLengthRegexPattern = 200; // Removes trailing dot from |host_piece| if any. // Copied from extensions/common/url_pattern.cc std::string_view CanonicalizeHostForMatching(std::string_view host_piece) { - if (base::EndsWith(host_piece, ".")) { + if (host_piece.ends_with('.')) { host_piece.remove_suffix(1); } return host_piece; diff --git a/components/decentralized_dns/core/utils.cc b/components/decentralized_dns/core/utils.cc index e71522d3386..82c9873d39d 100644 --- a/components/decentralized_dns/core/utils.cc +++ b/components/decentralized_dns/core/utils.cc @@ -56,7 +56,7 @@ void MigrateObsoleteLocalStatePrefs(PrefService* local_state) { bool IsUnstoppableDomainsTLD(std::string_view host) { for (auto* domain : kUnstoppableDomains) { - if (base::EndsWith(host, domain)) { + if (host.ends_with(domain)) { return true; } } @@ -94,7 +94,7 @@ bool IsUnstoppableDomainsResolveMethodEnabled(PrefService* local_state) { } bool IsENSTLD(std::string_view host) { - return base::EndsWith(host, kEthDomain); + return host.ends_with(kEthDomain); } void SetENSResolveMethod(PrefService* local_state, ResolveMethodTypes method) { @@ -133,7 +133,7 @@ EnsOffchainResolveMethod GetEnsOffchainResolveMethod(PrefService* local_state) { } bool IsSnsTLD(std::string_view host) { - return base::EndsWith(host, kSolDomain); + return host.ends_with(kSolDomain); } void SetSnsResolveMethod(PrefService* local_state, ResolveMethodTypes method) { diff --git a/components/ntp_background_images/browser/view_counter_service_unittest.cc b/components/ntp_background_images/browser/view_counter_service_unittest.cc index a080c45f05e..0f767157c16 100644 --- a/components/ntp_background_images/browser/view_counter_service_unittest.cc +++ b/components/ntp_background_images/browser/view_counter_service_unittest.cc @@ -424,7 +424,7 @@ TEST_F(NTPBackgroundImagesViewCounterTest, GetCurrentWallpaperTest) { delegate_->image_enabled_ = true; background = view_counter_->GetCurrentWallpaper(); bg_url = background->FindString(kWallpaperImageURLKey); - EXPECT_TRUE(base::StartsWith(*bg_url, kCustomWallpaperURL)) + EXPECT_TRUE(bg_url->starts_with(kCustomWallpaperURL)) << "actual url " << *bg_url; // Disable custom image background. diff --git a/components/p3a/constellation_helper_unittest.cc b/components/p3a/constellation_helper_unittest.cc index 4635c228b32..dcb1ff67bdd 100644 --- a/components/p3a/constellation_helper_unittest.cc +++ b/components/p3a/constellation_helper_unittest.cc @@ -76,12 +76,12 @@ class P3AConstellationHelperTest : public testing::Test { ValidateURLAndGetMetricLogType(request.url, kTestHost); std::string response; - if (base::EndsWith(request.url.spec(), "/info")) { + if (request.url.spec().ends_with("/info")) { response = HandleInfoRequest(request, log_type, GetTestEpoch(log_type), GetTestNextEpochTime(log_type)); info_request_made_[log_type] = true; - } else if (base::EndsWith(request.url.spec(), "/randomness")) { + } else if (request.url.spec().ends_with("/randomness")) { response = HandleRandomnessRequest(request, GetTestEpoch(log_type)); points_request_made_[log_type] = true; } @@ -283,7 +283,7 @@ TEST_F(P3AConstellationHelperTest, IncludeRefcode) { base::SplitResult::SPLIT_WANT_NONEMPTY); EXPECT_EQ(no_refcode_layers.size(), 8U); - EXPECT_FALSE(base::StartsWith(no_refcode_layers.at(7), "ref")); + EXPECT_FALSE(no_refcode_layers.at(7).starts_with("ref")); std::string message_with_refcode = GenerateP3AConstellationMessage( kTestHistogramName, 0, meta_info, kP3AUploadType, true, false); diff --git a/components/p3a/message_manager_unittest.cc b/components/p3a/message_manager_unittest.cc index 6b7066237f8..44a947e4942 100644 --- a/components/p3a/message_manager_unittest.cc +++ b/components/p3a/message_manager_unittest.cc @@ -105,7 +105,7 @@ class P3AMessageManagerTest : public testing::Test, std::string response = "{}"; - if (base::StartsWith(request.url.spec(), kTestStarRandomnessHost)) { + if (request.url.spec().starts_with(kTestStarRandomnessHost)) { MetricLogType log_type = ValidateURLAndGetMetricLogType( request.url, kTestStarRandomnessHost); @@ -116,14 +116,14 @@ class P3AMessageManagerTest : public testing::Test, "}"}); } else if (interceptor_invalid_response_from_randomness_non_json_) { response = "invalid response that is not json"; - } else if (base::EndsWith(request.url.spec(), "/info")) { + } else if (request.url.spec().ends_with("/info")) { EXPECT_EQ(request.method, net::HttpRequestHeaders::kGetMethod); std::string next_epoch_time_str = TimeFormatAsIso8601(next_epoch_time_); response = HandleInfoRequest(request, log_type, current_epoch_, next_epoch_time_str.c_str()); info_request_made_[log_type] = true; - } else if (base::EndsWith(request.url.spec(), "/randomness")) { + } else if (request.url.spec().ends_with("/randomness")) { response = HandleRandomnessRequest(request, current_epoch_); url_loader_factory_.AddResponse( request.url.spec(), response, @@ -141,8 +141,8 @@ class P3AMessageManagerTest : public testing::Test, } else if (request.url == p3a_config_.p2a_json_upload_url) { EXPECT_EQ(request.method, net::HttpRequestHeaders::kPostMethod); StoreJsonMetricInMap(request, true); - } else if (base::StartsWith(request.url.spec(), - std::string(kTestStarUploadHost))) { + } else if (request.url.spec().starts_with( + std::string(kTestStarUploadHost))) { std::string log_type_str = request.url.path(); EXPECT_TRUE(base::TrimString(log_type_str, "/", &log_type_str)); std::optional log_type = @@ -217,7 +217,7 @@ class P3AMessageManagerTest : public testing::Test, p2a_i++; } } else if (p3a_i < p3a_count && - (base::StartsWith(*histogram_name_i, "Brave.Core") || + (histogram_name_i->starts_with("Brave.Core") || log_type == MetricLogType::kExpress)) { result.push_back(std::string(*histogram_name_i)); p3a_i++; diff --git a/components/p3a/metric_log_store.cc b/components/p3a/metric_log_store.cc index 3251111a42e..a2efcf3af34 100644 --- a/components/p3a/metric_log_store.cc +++ b/components/p3a/metric_log_store.cc @@ -49,13 +49,11 @@ void RecordSentAnswersCount(uint64_t answers_count) { } bool IsMetricP2A(const std::string& histogram_name) { - return base::StartsWith(histogram_name, "Brave.P2A", - base::CompareCase::SENSITIVE); + return histogram_name.starts_with("Brave.P2A"); } bool IsMetricCreative(const std::string& histogram_name) { - return base::StartsWith(histogram_name, kCreativeMetricPrefix, - base::CompareCase::SENSITIVE); + return histogram_name.starts_with(kCreativeMetricPrefix); } } // namespace diff --git a/components/p3a/p3a_message.cc b/components/p3a/p3a_message.cc index 39b8eef2cdf..0a11de4b5db 100644 --- a/components/p3a/p3a_message.cc +++ b/components/p3a/p3a_message.cc @@ -248,7 +248,7 @@ void MessageMetainfo::InitRef() { #endif // !BUILDFLAG(IS_IOS) if (referral_code.empty()) { ref = kRefNone; - } else if (base::StartsWith(referral_code, kOrganicRefPrefix)) { + } else if (referral_code.starts_with(kOrganicRefPrefix)) { ref = referral_code; } else { ref = kRefOther; diff --git a/components/p3a/p3a_service.cc b/components/p3a/p3a_service.cc index 4b2dcecd1f0..85e51cf043e 100644 --- a/components/p3a/p3a_service.cc +++ b/components/p3a/p3a_service.cc @@ -275,8 +275,7 @@ void P3AService::OnHistogramChanged(const char* histogram_name, } // Special handling of P2A histograms. - if (base::StartsWith(histogram_name, "Brave.P2A", - base::CompareCase::SENSITIVE)) { + if (std::string_view(histogram_name).starts_with("Brave.P2A")) { // We need the bucket count to make proper perturbation. // All P2A metrics should be implemented as linear histograms. base::SampleVector* vector = diff --git a/components/p3a/p3a_service_unittest.cc b/components/p3a/p3a_service_unittest.cc index 446fa11c11e..5d3ec2a2ca5 100644 --- a/components/p3a/p3a_service_unittest.cc +++ b/components/p3a/p3a_service_unittest.cc @@ -112,7 +112,7 @@ class P3AServiceTest : public testing::Test { p2a_i++; } } else if (p3a_i < p3a_count && - base::StartsWith(histogram_name, "Brave.Core")) { + histogram_name.starts_with("Brave.Core")) { result.push_back(std::string(histogram_name)); p3a_i++; } diff --git a/components/p3a/star_randomness_test_util.cc b/components/p3a/star_randomness_test_util.cc index 6f31fcbc21c..2dd517c1868 100644 --- a/components/p3a/star_randomness_test_util.cc +++ b/components/p3a/star_randomness_test_util.cc @@ -29,7 +29,7 @@ MetricLogType ValidateURLAndGetMetricLogType(const GURL& url, const char* expected_host) { std::string url_prefix = base::StrCat({expected_host, "/instances/"}); - EXPECT_TRUE(base::StartsWith(url.spec(), url_prefix)); + EXPECT_TRUE(url.spec().starts_with(url_prefix)); std::vector path_segments = base::SplitString( url.path(), "/", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); diff --git a/components/request_otr/browser/request_otr_rule.cc b/components/request_otr/browser/request_otr_rule.cc index c5a8ababcb2..1cda5f25047 100644 --- a/components/request_otr/browser/request_otr_rule.cc +++ b/components/request_otr/browser/request_otr_rule.cc @@ -29,7 +29,7 @@ constexpr char kExclude[] = "exclude"; // Removes trailing dot from |host_piece| if any. // Copied from extensions/common/url_pattern.cc std::string_view CanonicalizeHostForMatching(std::string_view host_piece) { - if (base::EndsWith(host_piece, ".")) { + if (host_piece.ends_with('.')) { host_piece.remove_suffix(1); } return host_piece; diff --git a/components/speedreader/common/url_readable_hints.cc b/components/speedreader/common/url_readable_hints.cc index b4b29037ec3..473fe44ab69 100644 --- a/components/speedreader/common/url_readable_hints.cc +++ b/components/speedreader/common/url_readable_hints.cc @@ -45,8 +45,9 @@ bool IsURLLooksReadable(const GURL& url) { if (!url.has_path() || url.path() == "/") return false; - if (base::StartsWith(url.host_piece(), kReadableBlogSubdomain)) + if (url.host_piece().starts_with(kReadableBlogSubdomain)) { return true; + } // Look for single components such as /blog/, /news/, /article/ and for // multi-path components like /YYYY/MM/DD diff --git a/components/tor/tor_control.cc b/components/tor/tor_control.cc index 1cdb2892c73..dc714d9f9c0 100644 --- a/components/tor/tor_control.cc +++ b/components/tor/tor_control.cc @@ -400,9 +400,7 @@ void TorControl::GetVersionLine(std::string* version, const std::string& status, const std::string& reply) { DCHECK_CALLED_ON_VALID_SEQUENCE(io_sequence_checker_); - if (status != "250" || - !base::StartsWith(reply, kGetVersionReply, - base::CompareCase::SENSITIVE) || + if (status != "250" || !reply.starts_with(kGetVersionReply) || !version->empty()) { VLOG(0) << "tor: unexpected " << kGetVersionCmd << " reply"; return; @@ -447,8 +445,7 @@ void TorControl::GetSOCKSListenersLine(std::vector* listeners, const std::string& status, const std::string& reply) { DCHECK_CALLED_ON_VALID_SEQUENCE(io_sequence_checker_); - if (status != "250" || !base::StartsWith(reply, kGetSOCKSListenersReply, - base::CompareCase::SENSITIVE)) { + if (status != "250" || !reply.starts_with(kGetSOCKSListenersReply)) { VLOG(0) << "tor: unexpected " << kGetSOCKSListenersCmd << " reply"; return; } @@ -491,9 +488,7 @@ void TorControl::GetCircuitEstablishedLine(std::string* established, const std::string& status, const std::string& reply) { DCHECK_CALLED_ON_VALID_SEQUENCE(io_sequence_checker_); - if (status != "250" || - !base::StartsWith(reply, kGetCircuitEstablishedReply, - base::CompareCase::SENSITIVE) || + if (status != "250" || !reply.starts_with(kGetCircuitEstablishedReply) || !established->empty()) { VLOG(0) << "tor: unexpected " << kGetCircuitEstablishedCmd << " reply"; return; diff --git a/components/tor/tor_file_watcher.cc b/components/tor/tor_file_watcher.cc index 42196a5a85c..6dac1822bbb 100644 --- a/components/tor/tor_file_watcher.cc +++ b/components/tor/tor_file_watcher.cc @@ -264,8 +264,7 @@ bool TorFileWatcher::EatControlPort(int& port, base::Time& mtime) { std::string text(buf); // Sanity-check the content. - if (!base::StartsWith(text, "PORT=", base::CompareCase::SENSITIVE) || - !base::EndsWith(text, kLineBreak, base::CompareCase::SENSITIVE)) { + if (!text.starts_with("PORT=") || !text.ends_with(kLineBreak)) { VLOG(0) << "tor: invalid control port: " << "`" << text << ";"; // XXX escape return false; @@ -273,7 +272,7 @@ bool TorFileWatcher::EatControlPort(int& port, base::Time& mtime) { // Verify that it's localhost. const char expected[] = "PORT=127.0.0.1:"; - if (!base::StartsWith(text, expected, base::CompareCase::SENSITIVE)) { + if (!text.starts_with(expected)) { VLOG(0) << "tor: control port has non-local control address"; return false; } diff --git a/ios/browser/ui/webui/skus/skus_internals_ui.mm b/ios/browser/ui/webui/skus/skus_internals_ui.mm index 2a8a4c30fd3..c2f30b20876 100644 --- a/ios/browser/ui/webui/skus/skus_internals_ui.mm +++ b/ios/browser/ui/webui/skus/skus_internals_ui.mm @@ -140,7 +140,7 @@ base::Value::Dict SkusInternalsUI::GetOrderInfo( const auto& skus_state = local_state_->GetDict(skus::prefs::kSkusState); for (const auto kv : skus_state) { - if (!base::StartsWith(kv.first, "skus:")) { + if (!kv.first.starts_with("skus:")) { continue; } @@ -168,7 +168,7 @@ base::Value::Dict SkusInternalsUI::GetOrderInfo( } if (auto* order_location = order_dict->FindString("location")) { - if (!base::StartsWith(*order_location, location)) { + if (!order_location->starts_with(location)) { continue; } order_dict_output.Set("location", *order_location); @@ -218,7 +218,7 @@ std::string SkusInternalsUI::GetSkusStateAsString() const { for (const auto kv : skus_state) { // Only shows "skus:xx" kv in webui. - if (!base::StartsWith(kv.first, "skus:")) { + if (!kv.first.starts_with("skus:")) { continue; } diff --git a/renderer/test/subresource_web_bundles_browsertest.cc b/renderer/test/subresource_web_bundles_browsertest.cc index 4222fafd601..e326fe4600c 100644 --- a/renderer/test/subresource_web_bundles_browsertest.cc +++ b/renderer/test/subresource_web_bundles_browsertest.cc @@ -57,12 +57,12 @@ constexpr char kLoadPassJs[] = R"( )"; std::string GetHeadersForURL(const std::string& url) { - if (base::EndsWith(url, kPage, base::CompareCase::SENSITIVE)) { + if (url.ends_with(kPage)) { return kPageHeaders; - } else if (base::EndsWith(url, kPassJs, base::CompareCase::SENSITIVE)) { + } else if (url.ends_with(kPassJs)) { return kPassJsHeaders; } else { - EXPECT_FALSE(base::EndsWith(url, kWebBundle, base::CompareCase::SENSITIVE)) + EXPECT_FALSE(url.ends_with(kWebBundle)) << "Received request for web bundle headers, which should not have " "happened. URL:" << url; @@ -71,10 +71,10 @@ std::string GetHeadersForURL(const std::string& url) { } std::string GetContentForURL(const std::string& url) { - if (base::EndsWith(url, kPage, base::CompareCase::SENSITIVE)) { + if (url.ends_with(kPage)) { return kPageHtml; } else { - EXPECT_FALSE(base::EndsWith(url, kWebBundle, base::CompareCase::SENSITIVE)) + EXPECT_FALSE(url.ends_with(kWebBundle)) << "Received request for web bundle content, which should not have " "happened. URL:" << url; diff --git a/third_party/blink/renderer/core/brave_page_graph/page_graph.cc b/third_party/blink/renderer/core/brave_page_graph/page_graph.cc index 4ed6cb767a1..5d7d2d0e26f 100644 --- a/third_party/blink/renderer/core/brave_page_graph/page_graph.cc +++ b/third_party/blink/renderer/core/brave_page_graph/page_graph.cc @@ -849,7 +849,7 @@ void PageGraph::RegisterPageGraphWebAPICallWithResult( const blink::ExceptionState* exception_state, const std::optional& result) { const std::string_view name_piece(name); - if (base::StartsWith(name_piece, "Document.")) { + if (name_piece.starts_with("Document.")) { if (name_piece == "Document.cookie.get") { RegisterStorageRead(execution_context, String(*receiver_data.FindString("cookie_url")), @@ -867,7 +867,7 @@ void PageGraph::RegisterPageGraphWebAPICallWithResult( brave_page_graph::StorageLocation::kCookie); return; } - } else if (base::StartsWith(name_piece, "Storage.")) { + } else if (name_piece.starts_with("Storage.")) { String storage_type(*receiver_data.FindString("storage_type")); DCHECK(storage_type == "localStorage" || storage_type == "sessionStorage"); const auto storage = storage_type == "localStorage" diff --git a/tools/redirect_cc/redirect_cc.cc b/tools/redirect_cc/redirect_cc.cc index 4d0d403862e..7b9b3be77e5 100644 --- a/tools/redirect_cc/redirect_cc.cc +++ b/tools/redirect_cc/redirect_cc.cc @@ -96,8 +96,8 @@ class RedirectCC { // Find directories to work with first. for (const auto* arg : args_.subspan(first_compiler_arg_idx)) { base::FilePath::StringPieceType arg_piece(arg); - if (base::StartsWith(arg_piece, kIncludeFlag) && - base::EndsWith(arg_piece, kBraveChromiumSrc)) { + if (arg_piece.starts_with(kIncludeFlag) && + arg_piece.ends_with(kBraveChromiumSrc)) { arg_piece.remove_prefix(kIncludeFlag.size()); brave_chromium_src_dir = base::FilePath::StringType(arg_piece); arg_piece.remove_suffix(kBraveChromiumSrc.size()); @@ -141,7 +141,7 @@ class RedirectCC { // is used by asm compiler. We can safely ignore this, becaused we // don't redirect asm files. path_cc = base::FilePath::StringPieceType(); - } else if (base::StartsWith(path_cc, chromium_src_dir_with_slash)) { + } else if (path_cc.starts_with(chromium_src_dir_with_slash)) { // Most common case - a file is located directly in src/... path_cc.remove_prefix(chromium_src_dir_with_slash.size()); } else { diff --git a/utility/importer/brave_profile_import_impl.cc b/utility/importer/brave_profile_import_impl.cc index 372c68450a3..007260ff0ee 100644 --- a/utility/importer/brave_profile_import_impl.cc +++ b/utility/importer/brave_profile_import_impl.cc @@ -64,13 +64,11 @@ void BraveProfileImportImpl::StartImport( mojo::PendingRemote brave_observer) { // Signal change to OSCrypt password for importing from Chrome/Chromium base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - if (base::StartsWith(base::UTF16ToUTF8(source_profile.importer_name), - "Chrome", base::CompareCase::SENSITIVE)) { + if (source_profile.importer_name.starts_with(u"Chrome")) { command_line->AppendSwitch("import-chrome"); } else if (source_profile.importer_type == importer::TYPE_EDGE_CHROMIUM) { command_line->AppendSwitch("import-edge"); - } else if (base::StartsWith(base::UTF16ToUTF8(source_profile.importer_name), - "Chromium", base::CompareCase::SENSITIVE)) { + } else if (source_profile.importer_name.starts_with(u"Chromium")) { command_line->AppendSwitch("import-chromium"); } else if (source_profile.importer_type == importer::TYPE_OPERA) { command_line->AppendSwitch("import-opera"); diff --git a/utility/importer/chrome_importer.cc b/utility/importer/chrome_importer.cc index d9658f4d656..83ea8b04d5e 100644 --- a/utility/importer/chrome_importer.cc +++ b/utility/importer/chrome_importer.cc @@ -98,8 +98,7 @@ bool SetEncryptionKeyForPasswordImporting( base::Base64Decode(*base64_encrypted_key, &encrypted_key_with_header); - if (!base::StartsWith(encrypted_key_with_header, kDPAPIKeyPrefix, - base::CompareCase::SENSITIVE)) { + if (!encrypted_key_with_header.starts_with(kDPAPIKeyPrefix)) { return false; } std::string encrypted_key =