OLD | NEW |
---|---|
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 Loading... | |
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); |
Siggi Cherem (dart-lang)
2015/03/31 01:07:49
text.split('\n').first was necessary before when F
| |
69 var lineStart = context.lastIndexOf('\n', textIndex); | 69 if (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 Loading... | |
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 } |
OLD | NEW |