summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina <tfarina@chromium.org>2015-12-01 09:41:05 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-01 17:42:51 +0000
commit934d88d64c50f9f4d684194320cf15cd9b29059e (patch)
tree14dd3e1176963a65368c48506225dbcb16bb3379
parent0f0097a318484d99a996d230f3ad4d4ee08ca7ed (diff)
downloadchromium_src-934d88d64c50f9f4d684194320cf15cd9b29059e.zip
chromium_src-934d88d64c50f9f4d684194320cf15cd9b29059e.tar.gz
chromium_src-934d88d64c50f9f4d684194320cf15cd9b29059e.tar.bz2
tools/gn: make use of base's StartsWith() function
Since Brett introduced this funtion to base, we can make use of it and remove our copy from gn. We are also making use of it in other five files already. BUG=None TEST=gn gen + gn_unittests R=scottmg@chromium.org Review URL: https://codereview.chromium.org/1481403006 Cr-Commit-Position: refs/heads/master@{#362446}
-rw-r--r--tools/gn/c_include_iterator.cc19
1 files changed, 8 insertions, 11 deletions
diff --git a/tools/gn/c_include_iterator.cc b/tools/gn/c_include_iterator.cc
index 120295e..bb43803 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())