Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1310)

Unified Diff: tools/gn/c_include_iterator.cc

Issue 1481403006: tools/gn: make use of base's StartsWith() function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/c_include_iterator.cc
diff --git a/tools/gn/c_include_iterator.cc b/tools/gn/c_include_iterator.cc
index 120295ea41650c04fe7edef6363bebc4f74b771a..bb4380357d76d91af954ca30bb205d66e61125d7 100644
--- a/tools/gn/c_include_iterator.cc
+++ b/tools/gn/c_include_iterator.cc
@@ -17,12 +17,6 @@ enum IncludeType {
INCLUDE_USER // #include "..."
};
-// Returns true if str starts with the prefix.
-bool StartsWith(const base::StringPiece& str, const base::StringPiece& prefix) {
- base::StringPiece extracted = str.substr(0, prefix.size());
- return extracted == prefix;
-}
-
// Returns a new string piece referencing the same buffer as the argument, but
// with leading space trimmed. This only checks for space and tab characters
// since we're dealing with lines in C source files.
@@ -46,11 +40,12 @@ base::StringPiece TrimLeadingWhitespace(const base::StringPiece& str) {
// We assume the line has leading whitespace trimmed. We also assume that empty
// lines have already been filtered out.
bool ShouldCountTowardNonIncludeLines(const base::StringPiece& line) {
- if (StartsWith(line, "//"))
+ if (base::StartsWith(line, "//", base::CompareCase::SENSITIVE))
return false; // Don't count comments.
- if (StartsWith(line, "/*") || StartsWith(line, " *"))
+ if (base::StartsWith(line, "/*", base::CompareCase::SENSITIVE) ||
+ base::StartsWith(line, " *", base::CompareCase::SENSITIVE))
return false; // C-style comment blocks with stars along the left side.
- if (StartsWith(line, "#"))
+ if (base::StartsWith(line, "#", base::CompareCase::SENSITIVE))
return false; // Don't count preprocessor.
if (base::ContainsOnlyChars(line, base::kWhitespaceASCII))
return false; // Don't count whitespace lines.
@@ -76,9 +71,11 @@ IncludeType ExtractInclude(const base::StringPiece& line,
return INCLUDE_NONE;
base::StringPiece contents;
- if (StartsWith(trimmed, base::StringPiece(kInclude, kIncludeLen)))
+ if (base::StartsWith(trimmed, base::StringPiece(kInclude, kIncludeLen),
+ base::CompareCase::SENSITIVE))
contents = TrimLeadingWhitespace(trimmed.substr(kIncludeLen));
- else if (StartsWith(trimmed, base::StringPiece(kImport, kImportLen)))
+ else if (base::StartsWith(trimmed, base::StringPiece(kImport, kImportLen),
+ base::CompareCase::SENSITIVE))
contents = TrimLeadingWhitespace(trimmed.substr(kImportLen));
if (contents.empty())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698