Convert base::StringPiece to std::string_view //base
The changes of this CL are made using the following script. Script: https://issues.chromium.org/issues/40506050#comment343 Bug: 40506050 Change-Id: Ibf57a257801447cb22cbcb22e04f85f24ce19345 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5661276 Auto-Submit: Helmut Januschka <helmut@januschka.com> Owners-Override: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Helmut Januschka <helmut@januschka.com> Cr-Commit-Position: refs/heads/main@{#1327948}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
08662ef1b0
commit
8800b664e7
ash/ambient/util
base
allocator
debug
fuchsia
strings
escape.ccstring_number_conversions.hstring_util.ccstring_util.hstring_util_internal.hstring_util_win.cc
test
time
values.cccontent/browser/renderer_host/input
ui/ozone/platform/drm/common
@ -95,9 +95,9 @@ struct ASH_EXPORT ParsedDynamicAssetId {
|
||||
ASH_EXPORT bool ParseDynamicLottieAssetId(std::string_view asset_id,
|
||||
ParsedDynamicAssetId& parsed_output);
|
||||
|
||||
// AmbientTheme converted to a string for readability. The returned StringPiece
|
||||
// is guaranteed to be null-terminated and point to memory valid for the
|
||||
// lifetime of the program.
|
||||
// AmbientTheme converted to a string for readability. The returned
|
||||
// std::string_view is guaranteed to be null-terminated and point to memory
|
||||
// valid for the lifetime of the program.
|
||||
ASH_EXPORT std::string_view AmbientThemeToString(
|
||||
personalization_app::mojom::AmbientTheme theme);
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/feature_list.h"
|
||||
#include "base/metrics/field_trial_params.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/time/time.h"
|
||||
#include "build/build_config.h"
|
||||
#include "partition_alloc/buildflags.h"
|
||||
|
@ -424,7 +424,7 @@ std::string ExtractDanglingPtrSignature(std::string stacktrace) {
|
||||
for (size_t i = 0; i < lines.size(); ++i) {
|
||||
for (const auto& patterns : callee_patterns) {
|
||||
if (ranges::all_of(patterns, [&](std::string_view pattern) {
|
||||
return lines[i].find(pattern) != StringPiece::npos;
|
||||
return lines[i].find(pattern) != std::string_view::npos;
|
||||
})) {
|
||||
caller_index = i + 1;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "base/debug/asan_invalid_access.h"
|
||||
#include "base/memory/raw_ref.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/test/bind.h"
|
||||
#include "base/test/task_environment.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
|
@ -178,13 +178,15 @@ Process GetDebuggerProcess() {
|
||||
std::string_view status(buf, static_cast<size_t>(num_read));
|
||||
std::string_view tracer("TracerPid:\t");
|
||||
|
||||
StringPiece::size_type pid_index = status.find(tracer);
|
||||
if (pid_index == StringPiece::npos)
|
||||
std::string_view::size_type pid_index = status.find(tracer);
|
||||
if (pid_index == std::string_view::npos) {
|
||||
return Process();
|
||||
}
|
||||
pid_index += tracer.size();
|
||||
StringPiece::size_type pid_end_index = status.find('\n', pid_index);
|
||||
if (pid_end_index == StringPiece::npos)
|
||||
std::string_view::size_type pid_end_index = status.find('\n', pid_index);
|
||||
if (pid_end_index == std::string_view::npos) {
|
||||
return Process();
|
||||
}
|
||||
|
||||
std::string_view pid_str(buf + pid_index, pid_end_index - pid_index);
|
||||
int pid = 0;
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include "base/fuchsia/fuchsia_logging.h"
|
||||
#include "base/fuchsia/process_context.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
|
||||
using ::fuchsia::intl::Profile;
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
#include "base/base_export.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
|
@ -540,7 +540,7 @@ std::string UnescapeBinaryURLComponent(std::string_view escaped_text,
|
||||
|
||||
// If there are no '%' characters in the string, there will be nothing to
|
||||
// unescape, so we can take the fast path.
|
||||
if (escaped_text.find('%') == StringPiece::npos) {
|
||||
if (escaped_text.find('%') == std::string_view::npos) {
|
||||
std::string unescaped_text(escaped_text);
|
||||
if (rules & UnescapeRule::REPLACE_PLUS_WITH_SPACE)
|
||||
std::replace(unescaped_text.begin(), unescaped_text.end(), '+', ' ');
|
||||
|
@ -14,11 +14,11 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "base/base_export.h"
|
||||
#include "base/containers/span.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "build/build_config.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -75,20 +75,20 @@ BASE_EXPORT std::u16string NumberToString16(double value);
|
||||
// - Empty string. |*output| will be set to 0.
|
||||
// WARNING: Will write to |output| even when returning false.
|
||||
// Read the comments above carefully.
|
||||
BASE_EXPORT bool StringToInt(StringPiece input, int* output);
|
||||
BASE_EXPORT bool StringToInt(StringPiece16 input, int* output);
|
||||
BASE_EXPORT bool StringToInt(std::string_view input, int* output);
|
||||
BASE_EXPORT bool StringToInt(std::u16string_view input, int* output);
|
||||
|
||||
BASE_EXPORT bool StringToUint(StringPiece input, unsigned* output);
|
||||
BASE_EXPORT bool StringToUint(StringPiece16 input, unsigned* output);
|
||||
BASE_EXPORT bool StringToUint(std::string_view input, unsigned* output);
|
||||
BASE_EXPORT bool StringToUint(std::u16string_view input, unsigned* output);
|
||||
|
||||
BASE_EXPORT bool StringToInt64(StringPiece input, int64_t* output);
|
||||
BASE_EXPORT bool StringToInt64(StringPiece16 input, int64_t* output);
|
||||
BASE_EXPORT bool StringToInt64(std::string_view input, int64_t* output);
|
||||
BASE_EXPORT bool StringToInt64(std::u16string_view input, int64_t* output);
|
||||
|
||||
BASE_EXPORT bool StringToUint64(StringPiece input, uint64_t* output);
|
||||
BASE_EXPORT bool StringToUint64(StringPiece16 input, uint64_t* output);
|
||||
BASE_EXPORT bool StringToUint64(std::string_view input, uint64_t* output);
|
||||
BASE_EXPORT bool StringToUint64(std::u16string_view input, uint64_t* output);
|
||||
|
||||
BASE_EXPORT bool StringToSizeT(StringPiece input, size_t* output);
|
||||
BASE_EXPORT bool StringToSizeT(StringPiece16 input, size_t* output);
|
||||
BASE_EXPORT bool StringToSizeT(std::string_view input, size_t* output);
|
||||
BASE_EXPORT bool StringToSizeT(std::u16string_view input, size_t* output);
|
||||
|
||||
// For floating-point conversions, only conversions of input strings in decimal
|
||||
// form are defined to work. Behavior with strings representing floating-point
|
||||
@ -98,8 +98,8 @@ BASE_EXPORT bool StringToSizeT(StringPiece16 input, size_t* output);
|
||||
// If your input is locale specific, use ICU to read the number.
|
||||
// WARNING: Will write to |output| even when returning false.
|
||||
// Read the comments here and above StringToInt() carefully.
|
||||
BASE_EXPORT bool StringToDouble(StringPiece input, double* output);
|
||||
BASE_EXPORT bool StringToDouble(StringPiece16 input, double* output);
|
||||
BASE_EXPORT bool StringToDouble(std::string_view input, double* output);
|
||||
BASE_EXPORT bool StringToDouble(std::u16string_view input, double* output);
|
||||
|
||||
// Hex encoding ----------------------------------------------------------------
|
||||
|
||||
@ -110,7 +110,7 @@ BASE_EXPORT bool StringToDouble(StringPiece16 input, double* output);
|
||||
// max size for |size| should be is
|
||||
// std::numeric_limits<size_t>::max() / 2
|
||||
BASE_EXPORT std::string HexEncode(base::span<const uint8_t> bytes);
|
||||
BASE_EXPORT std::string HexEncode(StringPiece chars);
|
||||
BASE_EXPORT std::string HexEncode(std::string_view chars);
|
||||
// TODO(crbug.com/40284755): The pointer-based overload should be removed.
|
||||
BASE_EXPORT std::string HexEncode(const void* bytes, size_t size);
|
||||
|
||||
@ -133,34 +133,34 @@ inline void AppendHexEncodedByte(uint8_t byte,
|
||||
// Best effort conversion, see StringToInt above for restrictions.
|
||||
// Will only successful parse hex values that will fit into |output|, i.e.
|
||||
// -0x80000000 < |input| < 0x7FFFFFFF.
|
||||
BASE_EXPORT bool HexStringToInt(StringPiece input, int* output);
|
||||
BASE_EXPORT bool HexStringToInt(std::string_view input, int* output);
|
||||
|
||||
// Best effort conversion, see StringToInt above for restrictions.
|
||||
// Will only successful parse hex values that will fit into |output|, i.e.
|
||||
// 0x00000000 < |input| < 0xFFFFFFFF.
|
||||
// The string is not required to start with 0x.
|
||||
BASE_EXPORT bool HexStringToUInt(StringPiece input, uint32_t* output);
|
||||
BASE_EXPORT bool HexStringToUInt(std::string_view input, uint32_t* output);
|
||||
|
||||
// Best effort conversion, see StringToInt above for restrictions.
|
||||
// Will only successful parse hex values that will fit into |output|, i.e.
|
||||
// -0x8000000000000000 < |input| < 0x7FFFFFFFFFFFFFFF.
|
||||
BASE_EXPORT bool HexStringToInt64(StringPiece input, int64_t* output);
|
||||
BASE_EXPORT bool HexStringToInt64(std::string_view input, int64_t* output);
|
||||
|
||||
// Best effort conversion, see StringToInt above for restrictions.
|
||||
// Will only successful parse hex values that will fit into |output|, i.e.
|
||||
// 0x0000000000000000 < |input| < 0xFFFFFFFFFFFFFFFF.
|
||||
// The string is not required to start with 0x.
|
||||
BASE_EXPORT bool HexStringToUInt64(StringPiece input, uint64_t* output);
|
||||
BASE_EXPORT bool HexStringToUInt64(std::string_view input, uint64_t* output);
|
||||
|
||||
// Similar to the previous functions, except that output is a vector of bytes.
|
||||
// |*output| will contain as many bytes as were successfully parsed prior to the
|
||||
// error. There is no overflow, but input.size() must be evenly divisible by 2.
|
||||
// Leading 0x or +/- are not allowed.
|
||||
BASE_EXPORT bool HexStringToBytes(StringPiece input,
|
||||
BASE_EXPORT bool HexStringToBytes(std::string_view input,
|
||||
std::vector<uint8_t>* output);
|
||||
|
||||
// Same as HexStringToBytes, but for an std::string.
|
||||
BASE_EXPORT bool HexStringToString(StringPiece input, std::string* output);
|
||||
BASE_EXPORT bool HexStringToString(std::string_view input, std::string* output);
|
||||
|
||||
// Decodes the hex string |input| into a presized |output|. The output buffer
|
||||
// must be sized exactly to |input.size() / 2| or decoding will fail and no
|
||||
@ -168,7 +168,8 @@ BASE_EXPORT bool HexStringToString(StringPiece input, std::string* output);
|
||||
// considered a failure. When decoding fails due to encountering invalid input
|
||||
// characters, |output| will have been filled with the decoded bytes up until
|
||||
// the failure.
|
||||
BASE_EXPORT bool HexStringToSpan(StringPiece input, base::span<uint8_t> output);
|
||||
BASE_EXPORT bool HexStringToSpan(std::string_view input,
|
||||
base::span<uint8_t> output);
|
||||
|
||||
} // namespace base
|
||||
|
||||
|
@ -226,12 +226,12 @@ std::string CollapseWhitespaceASCII(std::string_view text,
|
||||
}
|
||||
|
||||
bool ContainsOnlyChars(std::string_view input, std::string_view characters) {
|
||||
return input.find_first_not_of(characters) == StringPiece::npos;
|
||||
return input.find_first_not_of(characters) == std::string_view::npos;
|
||||
}
|
||||
|
||||
bool ContainsOnlyChars(std::u16string_view input,
|
||||
std::u16string_view characters) {
|
||||
return input.find_first_not_of(characters) == StringPiece16::npos;
|
||||
return input.find_first_not_of(characters) == std::u16string_view::npos;
|
||||
}
|
||||
|
||||
bool IsStringASCII(std::string_view str) {
|
||||
|
@ -103,8 +103,7 @@ constexpr std::basic_string_view<CharT> MakeBasicStringPiece(Iter begin,
|
||||
return {base::to_address(begin), static_cast<size_t>(end - begin)};
|
||||
}
|
||||
|
||||
// Explicit instantiations of MakeBasicStringPiece for the BasicStringPiece
|
||||
// aliases defined in base/strings/string_piece.h
|
||||
// Explicit instantiations of MakeBasicStringPiece.
|
||||
template <typename Iter>
|
||||
constexpr std::string_view MakeStringPiece(Iter begin, Iter end) {
|
||||
return MakeBasicStringPiece<char>(begin, end);
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "base/ranges/algorithm.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
|
||||
namespace base::internal {
|
||||
|
||||
|
@ -74,7 +74,7 @@ std::wstring CollapseWhitespace(std::wstring_view text,
|
||||
}
|
||||
|
||||
bool ContainsOnlyChars(std::wstring_view input, std::wstring_view characters) {
|
||||
return input.find_first_not_of(characters) == StringPiece::npos;
|
||||
return input.find_first_not_of(characters) == std::string_view::npos;
|
||||
}
|
||||
|
||||
bool EqualsASCII(std::wstring_view str, std::string_view ascii) {
|
||||
|
@ -185,7 +185,7 @@ void HistogramTester::GetBucketCountForSamples(
|
||||
|
||||
HistogramTester::CountsMap HistogramTester::GetTotalCountsForPrefix(
|
||||
std::string_view prefix) const {
|
||||
EXPECT_TRUE(prefix.find('.') != StringPiece::npos)
|
||||
EXPECT_TRUE(prefix.find('.') != std::string_view::npos)
|
||||
<< "|prefix| ought to contain at least one period, to avoid matching too"
|
||||
<< " many histograms.";
|
||||
|
||||
|
@ -1625,7 +1625,7 @@ bool FailOnTaskEnvironmentLog(int severity,
|
||||
size_t message_start,
|
||||
const std::string& str) {
|
||||
std::string_view file_str(file);
|
||||
if (file_str.find("task_environment.cc") != StringPiece::npos) {
|
||||
if (file_str.find("task_environment.cc") != std::string_view::npos) {
|
||||
ADD_FAILURE() << str;
|
||||
return true;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ struct ParsedDecimal {
|
||||
constexpr std::optional<ParsedDecimal> ConsumeDurationNumber(
|
||||
std::string_view& number_string) {
|
||||
ParsedDecimal res;
|
||||
StringPiece::const_iterator orig_start = number_string.begin();
|
||||
std::string_view::const_iterator orig_start = number_string.begin();
|
||||
// Parse contiguous digits.
|
||||
for (; !number_string.empty(); number_string.remove_prefix(1)) {
|
||||
const int d = number_string.front() - '0';
|
||||
|
@ -869,7 +869,7 @@ std::optional<Value> Value::Dict::ExtractByDottedPath(std::string_view path) {
|
||||
// removing dictionaries that become empty if a value matching `path` is
|
||||
// extracted.
|
||||
size_t dot_index = path.find('.');
|
||||
if (dot_index == StringPiece::npos) {
|
||||
if (dot_index == std::string_view::npos) {
|
||||
return Extract(path);
|
||||
}
|
||||
// This could be clever to avoid a double-lookup by using storage_ directly,
|
||||
|
@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/test/bind.h"
|
||||
#include "base/test/scoped_feature_list.h"
|
||||
@ -74,8 +75,8 @@ class ScrollTracingBrowserTest : public ContentBrowserTest {
|
||||
}
|
||||
|
||||
void ValidateUkm(GURL url,
|
||||
base::StringPiece entry_name,
|
||||
std::map<base::StringPiece, int64_t> expected_values) {
|
||||
std::string_view entry_name,
|
||||
std::map<std::string_view, int64_t> expected_values) {
|
||||
const auto& entries =
|
||||
test_ukm_recorder_->GetMergedEntriesByName(entry_name);
|
||||
EXPECT_EQ(1u, entries.size());
|
||||
|
@ -1094,11 +1094,11 @@ std::optional<TileProperty> ParseTileBlob(
|
||||
const std::string tile_str(
|
||||
static_cast<char*>(tile_blob.data),
|
||||
base::strict_cast<std::string::size_type>(tile_blob.length));
|
||||
base::StringPiece tile_string_piece(tile_str);
|
||||
std::string_view tile_string_piece(tile_str);
|
||||
tile_string_piece = base::TrimString(tile_string_piece, std::string("\0", 1u),
|
||||
base::TRIM_TRAILING);
|
||||
|
||||
std::vector<base::StringPiece> tile_properties = base::SplitStringPiece(
|
||||
std::vector<std::string_view> tile_properties = base::SplitStringPiece(
|
||||
tile_string_piece, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
|
||||
|
||||
if (tile_properties.size() != 8) {
|
||||
|
Reference in New Issue
Block a user