OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/c_include_iterator.h" | 5 #include "tools/gn/c_include_iterator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "tools/gn/input_file.h" | 9 #include "tools/gn/input_file.h" |
10 #include "tools/gn/location.h" | 10 #include "tools/gn/location.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 // We only handle C-style "//" comments since this is the normal commenting | 41 // We only handle C-style "//" comments since this is the normal commenting |
42 // style used in Chrome, and do so pretty stupidly. We don't want to write a | 42 // style used in Chrome, and do so pretty stupidly. We don't want to write a |
43 // full C++ parser here, we're just trying to get a good heuristic for checking | 43 // full C++ parser here, we're just trying to get a good heuristic for checking |
44 // the file. | 44 // the file. |
45 // | 45 // |
46 // We assume the line has leading whitespace trimmed. We also assume that empty | 46 // We assume the line has leading whitespace trimmed. We also assume that empty |
47 // lines have already been filtered out. | 47 // lines have already been filtered out. |
48 bool ShouldCountTowardNonIncludeLines(const base::StringPiece& line) { | 48 bool ShouldCountTowardNonIncludeLines(const base::StringPiece& line) { |
49 if (StartsWith(line, "//")) | 49 if (StartsWith(line, "//")) |
50 return false; // Don't count comments. | 50 return false; // Don't count comments. |
| 51 if (StartsWith(line, "/*") || StartsWith(line, " *")) |
| 52 return false; // C-style comment blocks with stars along the left side. |
51 if (StartsWith(line, "#")) | 53 if (StartsWith(line, "#")) |
52 return false; // Don't count preprocessor. | 54 return false; // Don't count preprocessor. |
53 if (base::ContainsOnlyChars(line, base::kWhitespaceASCII)) | 55 if (base::ContainsOnlyChars(line, base::kWhitespaceASCII)) |
54 return false; // Don't count whitespace lines. | 56 return false; // Don't count whitespace lines. |
55 return true; // Count everything else. | 57 return true; // Count everything else. |
56 } | 58 } |
57 | 59 |
58 // Given a line, checks to see if it looks like an include or import and | 60 // Given a line, checks to see if it looks like an include or import and |
59 // extract the path. The type of include is returned. Returns INCLUDE_NONE on | 61 // extract the path. The type of include is returned. Returns INCLUDE_NONE on |
60 // error or if this is not an include line. | 62 // error or if this is not an include line. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 line_number_++; | 169 line_number_++; |
168 | 170 |
169 *line = file_.substr(begin, offset_ - begin); | 171 *line = file_.substr(begin, offset_ - begin); |
170 *line_number = line_number_; | 172 *line_number = line_number_; |
171 | 173 |
172 // If we didn't hit EOF, skip past the newline for the next one. | 174 // If we didn't hit EOF, skip past the newline for the next one. |
173 if (offset_ < file_.size()) | 175 if (offset_ < file_.size()) |
174 offset_++; | 176 offset_++; |
175 return true; | 177 return true; |
176 } | 178 } |
OLD | NEW |