| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 int cur_line_number = 0; | 126 int cur_line_number = 0; |
| 127 while (lines_since_last_include_ <= kMaxNonIncludeLines && | 127 while (lines_since_last_include_ <= kMaxNonIncludeLines && |
| 128 GetNextLine(&line, &cur_line_number)) { | 128 GetNextLine(&line, &cur_line_number)) { |
| 129 base::StringPiece include_contents; | 129 base::StringPiece include_contents; |
| 130 int begin_char; | 130 int begin_char; |
| 131 IncludeType type = ExtractInclude(line, &include_contents, &begin_char); | 131 IncludeType type = ExtractInclude(line, &include_contents, &begin_char); |
| 132 if (type == INCLUDE_USER) { | 132 if (type == INCLUDE_USER) { |
| 133 // Only count user includes for now. | 133 // Only count user includes for now. |
| 134 *out = include_contents; | 134 *out = include_contents; |
| 135 *location = LocationRange( | 135 *location = LocationRange( |
| 136 Location(input_file_, cur_line_number, begin_char), | 136 Location(input_file_, |
| 137 Location(input_file_, cur_line_number, | 137 cur_line_number, |
| 138 begin_char + static_cast<int>(include_contents.size()))); | 138 begin_char, |
| 139 -1 /* TODO(scottmg): Is this important? */), |
| 140 Location(input_file_, |
| 141 cur_line_number, |
| 142 begin_char + static_cast<int>(include_contents.size()), |
| 143 -1 /* TODO(scottmg): Is this important? */)); |
| 139 | 144 |
| 140 lines_since_last_include_ = 0; | 145 lines_since_last_include_ = 0; |
| 141 return true; | 146 return true; |
| 142 } | 147 } |
| 143 | 148 |
| 144 if (ShouldCountTowardNonIncludeLines(line)) | 149 if (ShouldCountTowardNonIncludeLines(line)) |
| 145 lines_since_last_include_++; | 150 lines_since_last_include_++; |
| 146 } | 151 } |
| 147 return false; | 152 return false; |
| 148 } | 153 } |
| 149 | 154 |
| 150 bool CIncludeIterator::GetNextLine(base::StringPiece* line, int* line_number) { | 155 bool CIncludeIterator::GetNextLine(base::StringPiece* line, int* line_number) { |
| 151 if (offset_ == file_.size()) | 156 if (offset_ == file_.size()) |
| 152 return false; | 157 return false; |
| 153 | 158 |
| 154 size_t begin = offset_; | 159 size_t begin = offset_; |
| 155 while (offset_ < file_.size() && file_[offset_] != '\n') | 160 while (offset_ < file_.size() && file_[offset_] != '\n') |
| 156 offset_++; | 161 offset_++; |
| 157 line_number_++; | 162 line_number_++; |
| 158 | 163 |
| 159 *line = file_.substr(begin, offset_ - begin); | 164 *line = file_.substr(begin, offset_ - begin); |
| 160 *line_number = line_number_; | 165 *line_number = line_number_; |
| 161 | 166 |
| 162 // If we didn't hit EOF, skip past the newline for the next one. | 167 // If we didn't hit EOF, skip past the newline for the next one. |
| 163 if (offset_ < file_.size()) | 168 if (offset_ < file_.size()) |
| 164 offset_++; | 169 offset_++; |
| 165 return true; | 170 return true; |
| 166 } | 171 } |
| OLD | NEW |