Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: tools/gn/err.cc

Issue 1525183002: tools/gn: rename char_offset to column_number (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix indentation Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/c_include_iterator_unittest.cc ('k') | tools/gn/header_checker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 if (range.begin().line_number() != line_number && 30 if (range.begin().line_number() != line_number &&
31 range.end().line_number() != line_number) 31 range.end().line_number() != line_number)
32 return; 32 return;
33 33
34 // Watch out, the char offsets in the location are 1-based, so we have to 34 // Watch out, the char offsets in the location are 1-based, so we have to
35 // subtract 1. 35 // subtract 1.
36 int begin_char; 36 int begin_char;
37 if (range.begin().line_number() < line_number) 37 if (range.begin().line_number() < line_number)
38 begin_char = 0; 38 begin_char = 0;
39 else 39 else
40 begin_char = range.begin().char_offset() - 1; 40 begin_char = range.begin().column_number() - 1;
41 41
42 int end_char; 42 int end_char;
43 if (range.end().line_number() > line_number) 43 if (range.end().line_number() > line_number)
44 end_char = static_cast<int>(line->size()); // Ending is non-inclusive. 44 end_char = static_cast<int>(line->size()); // Ending is non-inclusive.
45 else 45 else
46 end_char = range.end().char_offset() - 1; 46 end_char = range.end().column_number() - 1;
47 47
48 CHECK(end_char >= begin_char); 48 CHECK(end_char >= begin_char);
49 CHECK(begin_char >= 0 && begin_char <= static_cast<int>(line->size())); 49 CHECK(begin_char >= 0 && begin_char <= static_cast<int>(line->size()));
50 CHECK(end_char >= 0 && end_char <= static_cast<int>(line->size())); 50 CHECK(end_char >= 0 && end_char <= static_cast<int>(line->size()));
51 for (int i = begin_char; i < end_char; i++) 51 for (int i = begin_char; i < end_char; i++)
52 line->at(i) = '-'; 52 line->at(i) = '-';
53 } 53 }
54 54
55 // The line length is used to clip the maximum length of the markers we'll 55 // The line length is used to clip the maximum length of the markers we'll
56 // make if the error spans more than one line (like unterminated literals). 56 // make if the error spans more than one line (like unterminated literals).
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 (const auto& range : ranges) 67 for (const auto& range : ranges)
68 FillRangeOnLine(range, 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.column_number() - 1 >= 0 &&
73 location.char_offset() - 1 < static_cast<int>(highlight.size())); 73 location.column_number() - 1 < static_cast<int>(highlight.size()));
74 highlight[location.char_offset() - 1] = '^'; 74 highlight[location.column_number() - 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);
79 79
80 highlight += "\n"; 80 highlight += "\n";
81 OutputString(highlight, DECORATION_BLUE); 81 OutputString(highlight, DECORATION_BLUE);
82 } 82 }
83 83
84 } // namespace 84 } // namespace
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « tools/gn/c_include_iterator_unittest.cc ('k') | tools/gn/header_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698