Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/file_highlighter.h" | 5 #include "extensions/browser/file_highlighter.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 SourceHighlighter::SourceHighlighter(const std::string& contents, | 196 SourceHighlighter::SourceHighlighter(const std::string& contents, |
| 197 size_t line_number) | 197 size_t line_number) |
| 198 : FileHighlighter(contents) { | 198 : FileHighlighter(contents) { |
| 199 Parse(line_number); | 199 Parse(line_number); |
| 200 } | 200 } |
| 201 | 201 |
| 202 SourceHighlighter::~SourceHighlighter() { | 202 SourceHighlighter::~SourceHighlighter() { |
| 203 } | 203 } |
| 204 | 204 |
| 205 void SourceHighlighter::Parse(size_t line_number) { | 205 void SourceHighlighter::Parse(size_t line_number) { |
| 206 for (size_t i = 1; i < line_number; ++i) | 206 // If line 0 is requested, highlight nothing. |
| 207 start_ = contents_.find('\n', start_) + 1; | 207 if (line_number == 0) { |
| 208 start_ = contents_.size(); | |
| 209 return; | |
| 210 } | |
| 211 | |
| 212 for (size_t i = 1; i < line_number; ++i) { | |
| 213 start_ = contents_.find('\n', start_); | |
| 214 // If we find the end of the string, then break. Otherwise, increment start | |
| 215 // to be at the first character of the new line. | |
|
Finnur
2013/09/09 18:19:30
One doesn't gain much information from this commen
Devlin
2013/09/09 18:26:16
Removed.
| |
| 216 if (start_ == std::string::npos) | |
| 217 break; | |
| 218 start_ += 1; | |
| 219 } | |
| 220 | |
| 208 end_ = contents_.find('\n', start_); | 221 end_ = contents_.find('\n', start_); |
| 209 | 222 |
| 210 // If we went off the end of the string (i.e., the line number was invalid), | 223 // If we went off the end of the string (i.e., the line number was invalid), |
| 211 // then move start and end to the end of the string, so that the highlighted | 224 // then move start and end to the end of the string, so that the highlighted |
| 212 // portion is empty. | 225 // portion is empty. |
| 213 start_ = start_ == std::string::npos ? contents_.size() : start_; | 226 start_ = start_ == std::string::npos ? contents_.size() : start_; |
| 214 end_ = end_ == std::string::npos ? contents_.size() : end_; | 227 end_ = end_ == std::string::npos ? contents_.size() : end_; |
| 215 } | 228 } |
| 216 | 229 |
| 217 } // namespace extensions | 230 } // namespace extensions |
| OLD | NEW |