| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "tools/gn/err.h" | 5 #include "tools/gn/err.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
| 10 #include "tools/gn/input_file.h" | 10 #include "tools/gn/input_file.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 void OutputHighlighedPosition(const Location& location, | 57 void OutputHighlighedPosition(const Location& location, |
| 58 const Err::RangeList& ranges, | 58 const Err::RangeList& ranges, |
| 59 size_t line_length) { | 59 size_t line_length) { |
| 60 // Make a buffer of the line in spaces. | 60 // Make a buffer of the line in spaces. |
| 61 std::string highlight; | 61 std::string highlight; |
| 62 highlight.resize(line_length); | 62 highlight.resize(line_length); |
| 63 for (size_t i = 0; i < line_length; i++) | 63 for (size_t i = 0; i < line_length; i++) |
| 64 highlight[i] = ' '; | 64 highlight[i] = ' '; |
| 65 | 65 |
| 66 // Highlight all the ranges on the line. | 66 // Highlight all the ranges on the line. |
| 67 for (size_t i = 0; i < ranges.size(); i++) | 67 for (auto& range : ranges) |
| 68 FillRangeOnLine(ranges[i], location.line_number(), &highlight); | 68 FillRangeOnLine(range, location.line_number(), &highlight); |
| 69 | 69 |
| 70 // Allow the marker to be one past the end of the line for marking the end. | 70 // Allow the marker to be one past the end of the line for marking the end. |
| 71 highlight.push_back(' '); | 71 highlight.push_back(' '); |
| 72 CHECK(location.char_offset() - 1 >= 0 && | 72 CHECK(location.char_offset() - 1 >= 0 && |
| 73 location.char_offset() - 1 < static_cast<int>(highlight.size())); | 73 location.char_offset() - 1 < static_cast<int>(highlight.size())); |
| 74 highlight[location.char_offset() - 1] = '^'; | 74 highlight[location.char_offset() - 1] = '^'; |
| 75 | 75 |
| 76 // Trim unused spaces from end of line. | 76 // Trim unused spaces from end of line. |
| 77 while (!highlight.empty() && highlight[highlight.size() - 1] == ' ') | 77 while (!highlight.empty() && highlight[highlight.size() - 1] == ' ') |
| 78 highlight.resize(highlight.size() - 1); | 78 highlight.resize(highlight.size() - 1); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 182 } |
| 183 | 183 |
| 184 // Optional help text. | 184 // Optional help text. |
| 185 if (!help_text_.empty()) | 185 if (!help_text_.empty()) |
| 186 OutputString(help_text_ + "\n"); | 186 OutputString(help_text_ + "\n"); |
| 187 | 187 |
| 188 // Sub errors. | 188 // Sub errors. |
| 189 for (const auto& sub_err : sub_errs_) | 189 for (const auto& sub_err : sub_errs_) |
| 190 sub_err.InternalPrintToStdout(true); | 190 sub_err.InternalPrintToStdout(true); |
| 191 } | 191 } |
| OLD | NEW |