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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 | 106 |
107 std::string after_feature = GetAfterFeature(); | 107 std::string after_feature = GetAfterFeature(); |
108 if (!after_feature.empty()) | 108 if (!after_feature.empty()) |
109 dict->SetString(kAfterHighlightKey, base::UTF8ToUTF16(after_feature)); | 109 dict->SetString(kAfterHighlightKey, base::UTF8ToUTF16(after_feature)); |
110 } | 110 } |
111 | 111 |
112 ManifestHighlighter::ManifestHighlighter(const std::string& manifest, | 112 ManifestHighlighter::ManifestHighlighter(const std::string& manifest, |
113 const std::string& key, | 113 const std::string& key, |
114 const std::string& specific) | 114 const std::string& specific) |
115 : FileHighlighter(manifest) { | 115 : FileHighlighter(manifest) { |
116 start_ = contents_.find('{') + 1; | 116 start_ = contents_.find('{'); |
117 start_ = start_ == std::string::npos ? contents_.size() : start_ + 1; | |
Devlin
2016/08/17 15:14:03
nit: since we reassign start_ in all cases, I thin
Rafał Chłodnicki
2016/08/17 15:54:29
Let me just keep the current version. Proposed sty
| |
117 end_ = contents_.rfind('}'); | 118 end_ = contents_.rfind('}'); |
119 end_ = end_ == std::string::npos ? contents_.size() : end_; | |
118 Parse(key, specific); | 120 Parse(key, specific); |
119 } | 121 } |
120 | 122 |
121 ManifestHighlighter::~ManifestHighlighter() { | 123 ManifestHighlighter::~ManifestHighlighter() { |
122 } | 124 } |
123 | 125 |
124 | 126 |
125 void ManifestHighlighter::Parse(const std::string& key, | 127 void ManifestHighlighter::Parse(const std::string& key, |
126 const std::string& specific) { | 128 const std::string& specific) { |
127 // First, try to find the bounds of the full key. | 129 // First, try to find the bounds of the full key. |
128 if (FindBounds(key, true) /* enforce at top level */ ) { | 130 if (FindBounds(key, true) /* enforce at top level */) { |
129 // If we succeed, and we have a specific location, find the bounds of the | 131 // If we succeed, and we have a specific location, find the bounds of the |
130 // specific. | 132 // specific. |
131 if (!specific.empty()) | 133 if (!specific.empty()) |
132 FindBounds(specific, false /* don't enforce at top level */ ); | 134 FindBounds(specific, false /* don't enforce at top level */); |
133 | 135 |
134 // We may have found trailing whitespace. Don't use base::TrimWhitespace, | 136 // We may have found trailing whitespace. Don't use base::TrimWhitespace, |
135 // because we want to keep any whitespace we find - just not highlight it. | 137 // because we want to keep any whitespace we find - just not highlight it. |
136 size_t trim = contents_.find_last_not_of(" \t\n\r", end_ - 1); | 138 size_t trim = contents_.find_last_not_of(" \t\n\r", end_ - 1); |
137 if (trim < end_ && trim > start_) | 139 if (trim < end_ && trim > start_) |
138 end_ = trim + 1; | 140 end_ = trim + 1; |
139 } else { | 141 } else { |
140 // If we fail, then we set start to end so that the highlighted portion is | 142 // If we fail, then we set start to end so that the highlighted portion is |
141 // empty. | 143 // empty. |
142 start_ = end_; | 144 start_ = end_; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 end_ = contents_.find('\n', start_); | 221 end_ = contents_.find('\n', start_); |
220 | 222 |
221 // 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), |
222 // 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 |
223 // portion is empty. | 225 // portion is empty. |
224 start_ = start_ == std::string::npos ? contents_.size() : start_; | 226 start_ = start_ == std::string::npos ? contents_.size() : start_; |
225 end_ = end_ == std::string::npos ? contents_.size() : end_; | 227 end_ = end_ == std::string::npos ? contents_.size() : end_; |
226 } | 228 } |
227 | 229 |
228 } // namespace extensions | 230 } // namespace extensions |
OLD | NEW |