use std::{string,string_view}::{starts_with,ends_with}
This is generated by
```
comby -i 'base::StartsWith(:[a], :[b], base::CompareCase::SENSITIVE)' ':[a].starts_with(:[b])' $(rg -l '::SENSITIVE')
comby -i 'base::EndsWith(:[a], :[b], base::CompareCase::SENSITIVE)' ':[a].ends_with(:[b])' $(rg -l '::SENSITIVE')
CHROMIUM_BUILDTOOLS_PATH=~/chromium/src/buildtools git cl format --full
```
Change-Id: I38d8266365538010790704e3f9ba9add98069565
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/16480
Reviewed-by: David Turner <digit@google.com>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Takuto Ikuta <tikuta@google.com>
diff --git a/src/gn/analyzer.cc b/src/gn/analyzer.cc
index 1e8ff3e..a4ee31f 100644
--- a/src/gn/analyzer.cc
+++ b/src/gn/analyzer.cc
@@ -444,8 +444,7 @@
for (const auto& cur_file : target->data()) {
if (cur_file == file->value())
return true;
- if (cur_file.back() == '/' &&
- base::StartsWith(file->value(), cur_file, base::CompareCase::SENSITIVE))
+ if (cur_file.back() == '/' && file->value().starts_with(cur_file))
return true;
}
diff --git a/src/gn/bundle_data.cc b/src/gn/bundle_data.cc
index 3615731..62791c3 100644
--- a/src/gn/bundle_data.cc
+++ b/src/gn/bundle_data.cc
@@ -35,19 +35,13 @@
// .*\.xcassets/[^/]*\.symbolset/[^/]*
bool is_file_from_asset_catalog = false;
std::string_view dir = FindDirNoTrailingSeparator(source);
- if (base::EndsWith(source, "/Contents.json", base::CompareCase::SENSITIVE) &&
- base::EndsWith(dir, ".xcassets", base::CompareCase::SENSITIVE)) {
+ if (source.ends_with("/Contents.json") && dir.ends_with(".xcassets")) {
is_file_from_asset_catalog = true;
- } else if (base::EndsWith(dir, ".appiconset", base::CompareCase::SENSITIVE) ||
- base::EndsWith(dir, ".colorset", base::CompareCase::SENSITIVE) ||
- base::EndsWith(dir, ".dataset", base::CompareCase::SENSITIVE) ||
- base::EndsWith(dir, ".imageset", base::CompareCase::SENSITIVE) ||
- base::EndsWith(dir, ".launchimage",
- base::CompareCase::SENSITIVE) ||
- base::EndsWith(dir, ".symbolset", base::CompareCase::SENSITIVE)) {
+ } else if (dir.ends_with(".appiconset") || dir.ends_with(".colorset") ||
+ dir.ends_with(".dataset") || dir.ends_with(".imageset") ||
+ dir.ends_with(".launchimage") || dir.ends_with(".symbolset")) {
dir = FindDirNoTrailingSeparator(dir);
- is_file_from_asset_catalog =
- base::EndsWith(dir, ".xcassets", base::CompareCase::SENSITIVE);
+ is_file_from_asset_catalog = dir.ends_with(".xcassets");
}
if (is_file_from_asset_catalog && asset_catalog) {
std::string asset_catalog_path(dir);
diff --git a/src/gn/c_include_iterator.cc b/src/gn/c_include_iterator.cc
index e4cd7d4..c747034 100644
--- a/src/gn/c_include_iterator.cc
+++ b/src/gn/c_include_iterator.cc
@@ -42,12 +42,11 @@
// We assume the line has leading whitespace trimmed. We also assume that empty
// lines have already been filtered out.
bool ShouldCountTowardNonIncludeLines(std::string_view line) {
- if (base::StartsWith(line, "//", base::CompareCase::SENSITIVE))
+ if (line.starts_with("//"))
return false; // Don't count comments.
- if (base::StartsWith(line, "/*", base::CompareCase::SENSITIVE) ||
- base::StartsWith(line, " *", base::CompareCase::SENSITIVE))
+ if (line.starts_with("/*") || line.starts_with(" *"))
return false; // C-style comment blocks with stars along the left side.
- if (base::StartsWith(line, "#", base::CompareCase::SENSITIVE))
+ if (line.starts_with("#"))
return false; // Don't count preprocessor.
if (base::ContainsOnlyChars(line, base::kWhitespaceASCII))
return false; // Don't count whitespace lines.
@@ -78,11 +77,9 @@
trimmed = TrimLeadingWhitespace(trimmed.substr(1));
std::string_view contents;
- if (base::StartsWith(trimmed, std::string_view(kInclude, kIncludeLen),
- base::CompareCase::SENSITIVE))
+ if (trimmed.starts_with(std::string_view(kInclude, kIncludeLen)))
contents = TrimLeadingWhitespace(trimmed.substr(kIncludeLen));
- else if (base::StartsWith(trimmed, std::string_view(kImport, kImportLen),
- base::CompareCase::SENSITIVE))
+ else if (trimmed.starts_with(std::string_view(kImport, kImportLen)))
contents = TrimLeadingWhitespace(trimmed.substr(kImportLen));
if (contents.empty())
diff --git a/src/gn/command_format.cc b/src/gn/command_format.cc
index 7f22493..1a6f9ec 100644
--- a/src/gn/command_format.cc
+++ b/src/gn/command_format.cc
@@ -411,15 +411,13 @@
binop->op().value() == "-=") &&
ident) {
const std::string_view lhs = ident->value().value();
- if (base::EndsWith(lhs, "sources", base::CompareCase::SENSITIVE) ||
- lhs == "public") {
+ if (lhs.ends_with("sources") || lhs == "public") {
TraverseBinaryOpNode(binop->right(), [](const ParseNode* node) {
const ListNode* list = node->AsList();
if (list)
const_cast<ListNode*>(list)->SortAsStringsList();
});
- } else if (base::EndsWith(lhs, "deps", base::CompareCase::SENSITIVE) ||
- lhs == "visibility") {
+ } else if (lhs.ends_with("deps") || lhs == "visibility") {
TraverseBinaryOpNode(binop->right(), [](const ParseNode* node) {
const ListNode* list = node->AsList();
if (list)
diff --git a/src/gn/commands.cc b/src/gn/commands.cc
index 0f607d9..ba7cff0 100644
--- a/src/gn/commands.cc
+++ b/src/gn/commands.cc
@@ -327,8 +327,7 @@
for (const auto& cur_file : target->data()) {
if (cur_file == file.value())
return HowTargetContainsFile::kData;
- if (cur_file.back() == '/' &&
- base::StartsWith(file.value(), cur_file, base::CompareCase::SENSITIVE))
+ if (cur_file.back() == '/' && file.value().starts_with(cur_file))
return HowTargetContainsFile::kData;
}
diff --git a/src/gn/config_values_generator.cc b/src/gn/config_values_generator.cc
index d8b481f..a2ae225 100644
--- a/src/gn/config_values_generator.cc
+++ b/src/gn/config_values_generator.cc
@@ -148,7 +148,7 @@
// Check for common errors. This is a string and not a file.
const std::string& pch_string = precompiled_header_value->string_value();
- if (base::StartsWith(pch_string, "//", base::CompareCase::SENSITIVE)) {
+ if (pch_string.starts_with("//")) {
*err_ = Err(
*precompiled_header_value, "This precompiled_header value is wrong. ",
"You need to specify a string that the compiler will match against\n"
diff --git a/src/gn/filesystem_utils.cc b/src/gn/filesystem_utils.cc
index d0ad23c..d37750b 100644
--- a/src/gn/filesystem_utils.cc
+++ b/src/gn/filesystem_utils.cc
@@ -179,8 +179,7 @@
OutputFile* result) {
const std::string& build_dir = build_settings->build_dir().value();
- if (base::StartsWith(source_dir.value(), build_dir,
- base::CompareCase::SENSITIVE)) {
+ if (source_dir.value().starts_with(build_dir)) {
size_t build_dir_size = build_dir.size();
result->value().append(&source_dir.value()[build_dir_size],
source_dir.value().size() - build_dir_size);
@@ -709,8 +708,7 @@
const SourceDir& dest_dir,
std::string_view source_root) {
std::string ret;
- DCHECK(source_root.empty() ||
- !base::EndsWith(source_root, "/", base::CompareCase::SENSITIVE));
+ DCHECK(source_root.empty() || !source_root.ends_with("/"));
bool input_is_source_path =
(input.size() >= 2 && input[0] == '/' && input[1] == '/');
diff --git a/src/gn/input_conversion.cc b/src/gn/input_conversion.cc
index 596eba3..9898e9e 100644
--- a/src/gn/input_conversion.cc
+++ b/src/gn/input_conversion.cc
@@ -210,8 +210,7 @@
return Value(); // Empty string means discard the result.
const char kTrimPrefix[] = "trim ";
- if (base::StartsWith(input_conversion, kTrimPrefix,
- base::CompareCase::SENSITIVE)) {
+ if (input_conversion.starts_with(kTrimPrefix)) {
std::string trimmed;
base::TrimWhitespaceASCII(input, base::TRIM_ALL, &trimmed);
diff --git a/src/gn/parse_tree.cc b/src/gn/parse_tree.cc
index 4041781..34602b1 100644
--- a/src/gn/parse_tree.cc
+++ b/src/gn/parse_tree.cc
@@ -61,8 +61,7 @@
std::tuple<std::string_view, std::string_view> SplitAtFirst(
std::string_view str,
char c) {
- if (!base::StartsWith(str, "\"", base::CompareCase::SENSITIVE) ||
- !base::EndsWith(str, "\"", base::CompareCase::SENSITIVE))
+ if (!str.starts_with("\"") || !str.ends_with("\""))
return std::make_tuple(str, std::string_view());
str = str.substr(1, str.length() - 2);
@@ -1090,9 +1089,7 @@
return Value(this, false);
case Token::INTEGER: {
std::string_view s = value_.value();
- if ((base::StartsWith(s, "0", base::CompareCase::SENSITIVE) &&
- s.size() > 1) ||
- base::StartsWith(s, "-0", base::CompareCase::SENSITIVE)) {
+ if ((s.starts_with("0") && s.size() > 1) || s.starts_with("-0")) {
if (s == "-0")
*err = MakeErrorDescribing("Negative zero doesn't make sense");
else
diff --git a/src/gn/target.cc b/src/gn/target.cc
index 500dda5..b6c6ca0 100644
--- a/src/gn/target.cc
+++ b/src/gn/target.cc
@@ -575,9 +575,7 @@
if (tool) {
// Only add the prefix if the name doesn't already have it and it's not
// being overridden.
- if (!output_prefix_override_ &&
- !base::StartsWith(name, tool->output_prefix(),
- base::CompareCase::SENSITIVE))
+ if (!output_prefix_override_ && !name.starts_with(tool->output_prefix()))
result = tool->output_prefix();
}
result.append(name);
diff --git a/src/gn/visual_studio_utils.cc b/src/gn/visual_studio_utils.cc
index 5282d0e..530663e 100644
--- a/src/gn/visual_studio_utils.cc
+++ b/src/gn/visual_studio_utils.cc
@@ -116,7 +116,7 @@
// Parses |ldflags| value and stores it in |options|.
void ParseLinkerOption(const std::string& ldflag, LinkerOptions* options) {
const char kSubsytemPrefix[] = "/SUBSYSTEM:";
- if (base::StartsWith(ldflag, kSubsytemPrefix, base::CompareCase::SENSITIVE)) {
+ if (ldflag.starts_with(kSubsytemPrefix)) {
const std::string subsystem(
ldflag.begin() + std::string(kSubsytemPrefix).length(), ldflag.end());
const std::vector<std::string> tokens = base::SplitString(
diff --git a/src/gn/visual_studio_writer.cc b/src/gn/visual_studio_writer.cc
index 86fb2a1..037450e 100644
--- a/src/gn/visual_studio_writer.cc
+++ b/src/gn/visual_studio_writer.cc
@@ -916,8 +916,7 @@
std::vector<SolutionEntry*> parents;
for (const std::unique_ptr<SolutionEntry>& folder : folders_) {
while (!parents.empty()) {
- if (base::StartsWith(folder->path, parents.back()->path,
- base::CompareCase::SENSITIVE)) {
+ if (folder->path.starts_with(parents.back()->path)) {
folder->parent_folder = parents.back();
break;
} else {
diff --git a/src/gn/xcode_writer.cc b/src/gn/xcode_writer.cc
index 9577295..83c7c16 100644
--- a/src/gn/xcode_writer.cc
+++ b/src/gn/xcode_writer.cc
@@ -134,32 +134,27 @@
bool IsXCUITestRunnerTarget(const Target* target) {
return IsApplicationTarget(target) &&
- base::EndsWith(target->label().name(),
- kXCUITestRunnerTargetNamePostfix,
- base::CompareCase::SENSITIVE);
+ target->label().name().ends_with(kXCUITestRunnerTargetNamePostfix);
}
bool IsXCTestModuleTarget(const Target* target) {
return target->output_type() == Target::CREATE_BUNDLE &&
target->bundle_data().product_type() ==
"com.apple.product-type.bundle.unit-test" &&
- base::EndsWith(target->label().name(), kXCTestModuleTargetNamePostfix,
- base::CompareCase::SENSITIVE);
+ target->label().name().ends_with(kXCTestModuleTargetNamePostfix);
}
bool IsXCUITestModuleTarget(const Target* target) {
return target->output_type() == Target::CREATE_BUNDLE &&
target->bundle_data().product_type() ==
"com.apple.product-type.bundle.ui-testing" &&
- base::EndsWith(target->label().name(), kXCTestModuleTargetNamePostfix,
- base::CompareCase::SENSITIVE);
+ target->label().name().ends_with(kXCTestModuleTargetNamePostfix);
}
bool IsXCTestFile(const SourceFile& file) {
std::string file_name = file.GetName();
for (size_t i = 0; i < std::size(kXCTestFileSuffixes); ++i) {
- if (base::EndsWith(file_name, kXCTestFileSuffixes[i],
- base::CompareCase::SENSITIVE)) {
+ if (file_name.ends_with(kXCTestFileSuffixes[i])) {
return true;
}
}