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

Side by Side Diff: lib/compiler/implementation/source_file.dart

Issue 11275097: Merge SourceLocation and Source (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: RegExp used for line numbers Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/dartdoc/lib/dartdoc.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_file'); 5 #library('source_file');
6 6
7 #import('dart:math'); 7 #import('dart:math');
8 8
9 #import('colors.dart', prefix: 'colors'); 9 #import('colors.dart', prefix: 'colors');
10 10
11 /** 11 /**
12 * Represents a file of source code. 12 * Represents a file of source code.
13 */ 13 */
14 class SourceFile { 14 class SourceFile {
15 15
16 /** The name of the file. */ 16 /** The name of the file. */
17 final String filename; 17 final String filename;
18 18
19 /** The text content of the file. */ 19 /** The text content of the file. */
20 final String text; 20 final String text;
21 21
22 List<int> _lineStarts; 22 List<int> _lineStarts;
23 23
24 SourceFile(this.filename, this.text); 24 SourceFile(this.filename, this.text);
25 25
26 List<int> get lineStarts { 26 List<int> get lineStarts {
27 if (_lineStarts == null) { 27 if (_lineStarts == null) {
28 var starts = [0]; 28 var starts = [0];
29 var index = 0; 29 for (Match match in const RegExp("\r\n?|\n\r?").allMatches(text)) {
30 while (index < text.length) { 30 starts.add(match.start + 1);
ahe 2012/11/01 13:05:22 What is the performance overhead of this? Perhaps
Johnni Winther 2012/11/01 15:27:13 Enormous. I'll revert.
31 index = text.indexOf('\n', index) + 1;
32 if (index <= 0) break;
33 starts.add(index);
34 } 31 }
35 starts.add(text.length + 1); 32 starts.add(text.length + 1);
36 _lineStarts = starts; 33 _lineStarts = starts;
37 } 34 }
38 return _lineStarts; 35 return _lineStarts;
39 } 36 }
40 37
41 int getLine(int position) { 38 int getLine(int position) {
42 List<int> starts = lineStarts; 39 List<int> starts = lineStarts;
43 if (position < 0 || starts.last <= position) { 40 if (position < 0 || starts.last <= position) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 93 }
97 94
98 for (; i < toColumn; i++) { 95 for (; i < toColumn; i++) {
99 buf.add(color('^')); 96 buf.add(color('^'));
100 } 97 }
101 } 98 }
102 99
103 return buf.toString(); 100 return buf.toString();
104 } 101 }
105 } 102 }
OLDNEW
« no previous file with comments | « no previous file | pkg/dartdoc/lib/dartdoc.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698