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

Side by Side Diff: lib/src/span_mixin.dart

Issue 1041163005: Support multiple occurrences of text in context (Closed) Base URL: git@github.com:dart-lang/source_span.git@master
Patch Set: Created 5 years, 8 months 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 | « CHANGELOG.md ('k') | lib/src/span_with_context.dart » ('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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library source_span.span_mixin; 5 library source_span.span_mixin;
6 6
7 import 'dart:math' as math; 7 import 'dart:math' as math;
8 import 'package:path/path.dart' as p; 8 import 'package:path/path.dart' as p;
9 9
10 import 'colors.dart' as colors; 10 import 'colors.dart' as colors;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 buffer.write('line ${line + 1}, column ${column + 1}'); 58 buffer.write('line ${line + 1}, column ${column + 1}');
59 if (sourceUrl != null) buffer.write(' of ${p.prettyUri(sourceUrl)}'); 59 if (sourceUrl != null) buffer.write(' of ${p.prettyUri(sourceUrl)}');
60 buffer.write(': $message'); 60 buffer.write(': $message');
61 61
62 if (length == 0 && this is! SourceSpanWithContext) return buffer.toString(); 62 if (length == 0 && this is! SourceSpanWithContext) return buffer.toString();
63 buffer.write("\n"); 63 buffer.write("\n");
64 64
65 var textLine; 65 var textLine;
66 if (this is SourceSpanWithContext) { 66 if (this is SourceSpanWithContext) {
67 var context = (this as SourceSpanWithContext).context; 67 var context = (this as SourceSpanWithContext).context;
68 var textIndex = context.indexOf(text.split('\n').first); 68 var lineStart = findLineStart(context, text, column);
69 var lineStart = context.lastIndexOf('\n', textIndex); 69 if (lineStart != null && lineStart > 0) {
70 if (lineStart != -1) { 70 buffer.write(context.substring(0, lineStart));
71 buffer.write(context.substring(0, lineStart + 1)); 71 context = context.substring(lineStart);
72 context = context.substring(lineStart + 1);
73 } 72 }
74 var endIndex = context.indexOf('\n'); 73 var endIndex = context.indexOf('\n');
75 textLine = endIndex == -1 ? context : context.substring(0, endIndex + 1); 74 textLine = endIndex == -1 ? context : context.substring(0, endIndex + 1);
76 column = math.min(column, textLine.length - 1); 75 column = math.min(column, textLine.length - 1);
77 } else { 76 } else {
78 textLine = text.split("\n").first; 77 textLine = text.split("\n").first;
79 column = 0; 78 column = 0;
80 } 79 }
81 80
82 var toColumn = 81 var toColumn =
(...skipping 15 matching lines...) Expand all
98 return buffer.toString(); 97 return buffer.toString();
99 } 98 }
100 99
101 bool operator ==(other) => other is SourceSpan && 100 bool operator ==(other) => other is SourceSpan &&
102 start == other.start && end == other.end; 101 start == other.start && end == other.end;
103 102
104 int get hashCode => start.hashCode + (31 * end.hashCode); 103 int get hashCode => start.hashCode + (31 * end.hashCode);
105 104
106 String toString() => '<$runtimeType: from $start to $end "$text">'; 105 String toString() => '<$runtimeType: from $start to $end "$text">';
107 } 106 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/span_with_context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698