0

Convert base::StringPiece to std::string_view in //components, //base

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

Bug: 40506050
Change-Id: I469aa87cc8caad4ab6ac2ee6719ca32de6ade26e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5547981
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Auto-Submit: Helmut Januschka <helmut@januschka.com>
Cr-Commit-Position: refs/heads/main@{#1306787}
This commit is contained in:
Helmut Januschka
2024-05-28 15:47:45 +00:00
committed by Chromium LUCI CQ
parent d30dd31a56
commit 6bfb01f54f
9 changed files with 30 additions and 27 deletions

@ -8,6 +8,7 @@
#include <algorithm>
#include <ostream>
#include <string_view>
#include "base/check_op.h"
#include "base/strings/string_number_conversions.h"
@ -23,9 +24,9 @@ namespace {
// when it reaches an invalid item (including the wildcard character). |parsed|
// is the resulting integer vector. Function returns true if all numbers were
// parsed successfully, false otherwise.
bool ParseVersionNumbers(StringPiece version_str,
bool ParseVersionNumbers(std::string_view version_str,
std::vector<uint32_t>* parsed) {
std::vector<StringPiece> numbers =
std::vector<std::string_view> numbers =
SplitStringPiece(version_str, ".", KEEP_WHITESPACE, SPLIT_WANT_ALL);
if (numbers.empty())
return false;
@ -84,7 +85,7 @@ Version::Version(const Version& other) = default;
Version::~Version() = default;
Version::Version(StringPiece version_str) {
Version::Version(std::string_view version_str) {
std::vector<uint32_t> parsed;
if (!ParseVersionNumbers(version_str, &parsed))
return;
@ -100,8 +101,8 @@ bool Version::IsValid() const {
}
// static
bool Version::IsValidWildcardString(StringPiece wildcard_string) {
StringPiece version_string = wildcard_string;
bool Version::IsValidWildcardString(std::string_view wildcard_string) {
std::string_view version_string = wildcard_string;
if (EndsWith(version_string, ".*", CompareCase::SENSITIVE))
version_string = version_string.substr(0, version_string.size() - 2);
@ -109,7 +110,7 @@ bool Version::IsValidWildcardString(StringPiece wildcard_string) {
return version.IsValid();
}
int Version::CompareToWildcardString(StringPiece wildcard_string) const {
int Version::CompareToWildcardString(std::string_view wildcard_string) const {
DCHECK(IsValid());
DCHECK(Version::IsValidWildcardString(wildcard_string));

@ -9,10 +9,10 @@
#include <iosfwd>
#include <string>
#include <string_view>
#include <vector>
#include "base/base_export.h"
#include "base/strings/string_piece.h"
namespace base {
@ -29,7 +29,7 @@ class BASE_EXPORT Version {
// Initializes from a decimal dotted version number, like "0.1.1".
// Each component is limited to a uint32_t. Call IsValid() to learn
// the outcome.
explicit Version(StringPiece version_str);
explicit Version(std::string_view version_str);
// Initializes from a vector of components, like {1, 2, 3, 4}. Call IsValid()
// to learn the outcome.
@ -44,7 +44,7 @@ class BASE_EXPORT Version {
// string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*"
// is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard
// Version behavior (IsValid) if no wildcard is present.
static bool IsValidWildcardString(StringPiece wildcard_string);
static bool IsValidWildcardString(std::string_view wildcard_string);
// Returns -1, 0, 1 for <, ==, >. `this` and `other` must both be valid.
int CompareTo(const Version& other) const;
@ -53,7 +53,7 @@ class BASE_EXPORT Version {
// newer version. This function will default to CompareTo if the string does
// not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be
// true before using this function.
int CompareToWildcardString(StringPiece wildcard_string) const;
int CompareToWildcardString(std::string_view wildcard_string) const;
// Return the string representation of this version.
std::string GetString() const;

@ -4,6 +4,7 @@
#include <optional>
#include <string>
#include <string_view>
#include "base/command_line.h"
#include "base/test/scoped_feature_list.h"
@ -25,7 +26,7 @@ namespace {
// tools/origin_trials/generate_token.py https://example.test
// PermissionElement
// --expire-days 5000
base::StringPiece kOriginTrialToken =
std::string_view kOriginTrialToken =
"AyhOIRw/ha6vGsSq2BU78sDZ49hP+Cv6OC191Ae7YQHf3pYW8UJ5bwCOOuUXjfA/"
"QmXR6y1+4cv+"
"Uy6utB3FJw0AAABceyJvcmlnaW4iOiAiaHR0cHM6Ly9leGFtcGxlLnRlc3Q6NDQzIiwgImZlYX"

@ -22,7 +22,7 @@ WrapWithPrefixPrefStore::~WrapWithPrefixPrefStore() {
target_pref_store_->RemoveObserver(this);
}
bool WrapWithPrefixPrefStore::GetValue(base::StringPiece key,
bool WrapWithPrefixPrefStore::GetValue(std::string_view key,
const base::Value** value) const {
return target_pref_store_->GetValue(AddDottedPrefix(key), value);
}

@ -7,6 +7,7 @@
#include <optional>
#include <string>
#include <string_view>
#include "base/observer_list.h"
#include "components/prefs/persistent_pref_store.h"
@ -41,7 +42,7 @@ class COMPONENTS_PREFS_EXPORT WrapWithPrefixPrefStore
WrapWithPrefixPrefStore& operator=(const WrapWithPrefixPrefStore&) = delete;
// PrefStore implementation.
bool GetValue(base::StringPiece key,
bool GetValue(std::string_view key,
const base::Value** result) const override;
base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;

@ -168,7 +168,7 @@ ResourceRequestsAllowedState ResourceRequestStateToHistogramValue(
// Returns the header value for |name| from |headers| or an empty string if not
// set.
std::string GetHeaderValue(const net::HttpResponseHeaders* headers,
const std::string_view& name) {
std::string_view name) {
std::string value;
headers->EnumerateHeader(nullptr, name, &value);
return value;
@ -178,7 +178,7 @@ std::string GetHeaderValue(const net::HttpResponseHeaders* headers,
// set, return an empty list.
std::vector<std::string> GetHeaderValuesList(
const net::HttpResponseHeaders* headers,
const std::string_view& name) {
std::string_view name) {
std::vector<std::string> values;
size_t iter = 0;
std::string value;

@ -6,8 +6,8 @@
#define COMPONENTS_VERSION_INFO_VERSION_INFO_WITH_USER_AGENT_H_
#include <string>
#include <string_view>
#include "base/strings/string_piece.h"
#include "base/version_info/version_info_values.h"
namespace version_info {
@ -20,7 +20,7 @@ std::string GetProductNameAndVersionForReducedUserAgent(
// Returns the product name and version information for the User-Agent header,
// in the format: Chrome/<major_version>.<minor_version>.<build>.<patch>.
constexpr base::StringPiece GetProductNameAndVersionForUserAgent() {
constexpr std::string_view GetProductNameAndVersionForUserAgent() {
return "Chrome/" PRODUCT_VERSION;
}

@ -4,13 +4,13 @@
#include "components/version_ui/version_handler_helper.h"
#include <string_view>
#include <utility>
#include <vector>
#include "base/base_switches.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_list_including_low_anonymity.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "components/variations/active_field_trials.h"
#include "components/variations/net/variations_command_line.h"
@ -48,7 +48,7 @@ base::Value::List GetVariationsList() {
}
#else
// In release mode, display the hashes only.
variations::GetFieldTrialActiveGroupIdsAsStrings(base::StringPiece(),
variations::GetFieldTrialActiveGroupIdsAsStrings(std::string_view(),
active_groups, &variations);
#endif

@ -117,8 +117,8 @@ VisitedLinkCommon::Fingerprint VisitedLinkCommon::ComputeURLFingerprint(
base::MD5Context ctx;
base::MD5Init(&ctx);
base::MD5Update(&ctx, base::StringPiece(reinterpret_cast<const char*>(salt),
LINK_SALT_LENGTH));
base::MD5Update(&ctx, std::string_view(reinterpret_cast<const char*>(salt),
LINK_SALT_LENGTH));
base::MD5Update(&ctx, canonical_url);
base::MD5Digest digest;
@ -152,22 +152,22 @@ VisitedLinkCommon::Fingerprint VisitedLinkCommon::ComputePartitionedFingerprint(
base::MD5Init(&ctx);
// Salt the hash.
base::MD5Update(&ctx, base::StringPiece(reinterpret_cast<const char*>(&salt),
sizeof(salt)));
base::MD5Update(&ctx, std::string_view(reinterpret_cast<const char*>(&salt),
sizeof(salt)));
// Add the link url.
base::MD5Update(
&ctx, base::StringPiece(link_url.spec().data(), link_url.spec().size()));
&ctx, std::string_view(link_url.spec().data(), link_url.spec().size()));
// Add the serialized schemeful top-level site.
const std::string serialized_site = top_level_site.Serialize();
base::MD5Update(
&ctx, base::StringPiece(serialized_site.data(), serialized_site.size()));
&ctx, std::string_view(serialized_site.data(), serialized_site.size()));
// Add the serialized frame origin.
const std::string serialized_origin = frame_origin.Serialize();
base::MD5Update(&ctx, base::StringPiece(serialized_origin.data(),
serialized_origin.size()));
base::MD5Update(&ctx, std::string_view(serialized_origin.data(),
serialized_origin.size()));
base::MD5Digest digest;
base::MD5Final(&digest, &ctx);