0

Convert base::StringPiece to std::string_view in //components 3/5

The changes of this CL are made using the following script.
Script: https://issues.chromium.org/issues/40506050#comment343

Bug: 40506050
Change-Id: I7b21541a0723d312206c786d3af570f552ceef4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5498922
Auto-Submit: Helmut Januschka <helmut@januschka.com>
Commit-Queue: Helmut Januschka <helmut@januschka.com>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1295637}
This commit is contained in:
Helmut Januschka
2024-05-02 18:42:28 +00:00
committed by Chromium LUCI CQ
parent 68ba09c5a4
commit 3ae90009a0
98 changed files with 441 additions and 387 deletions
components
prefs
printing
safe_browsing
safe_search_api
search_engines
search_provider_logos
segmentation_platform
sessions
shared_highlighting
signin
speech

@ -5,13 +5,13 @@
#include "components/safe_search_api/safe_search_util.h"
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "components/google/core/common/google_util.h"
@ -24,11 +24,11 @@ namespace {
// Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the
// same key as the the |second_parameter| (e.g. foo=baz). Both parameters
// must be in key=value form.
bool HasSameParameterKey(base::StringPiece first_parameter,
base::StringPiece second_parameter) {
bool HasSameParameterKey(std::string_view first_parameter,
std::string_view second_parameter) {
DCHECK(second_parameter.find("=") != std::string::npos);
// Prefix for "foo=bar" is "foo=".
base::StringPiece parameter_prefix =
std::string_view parameter_prefix =
second_parameter.substr(0, second_parameter.find("=") + 1);
return base::StartsWith(first_parameter, parameter_prefix,
base::CompareCase::INSENSITIVE_ASCII);
@ -38,11 +38,11 @@ bool HasSameParameterKey(base::StringPiece first_parameter,
// so that SafeSearch is active. |query| is the string to examine and the
// return value is the |query| string modified such that SafeSearch is active.
std::string AddSafeSearchParameters(const std::string& query) {
std::vector<base::StringPiece> new_parameters;
std::vector<std::string_view> new_parameters;
std::string safe_parameter = safe_search_api::kSafeSearchSafeParameter;
std::string ssui_parameter = safe_search_api::kSafeSearchSsuiParameter;
for (const base::StringPiece& param : base::SplitStringPiece(
for (std::string_view param : base::SplitStringPiece(
query, "&", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
if (!HasSameParameterKey(param, safe_parameter) &&
!HasSameParameterKey(param, ssui_parameter)) {