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

Side by Side Diff: dart/frog/leg/scanner/string_scanner.dart

Issue 9447100: Return null from stringValue and call slowToString() instead of toString(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: changes Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « dart/frog/leg/scanner/scanner_task.dart ('k') | dart/frog/leg/scanner/token.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** 5 /**
6 * Scanner that reads from a String and creates tokens that points to 6 * Scanner that reads from a String and creates tokens that points to
7 * substrings. 7 * substrings.
8 */ 8 */
9 class StringScanner extends ArrayBasedScanner<SourceString> { 9 class StringScanner extends ArrayBasedScanner<SourceString> {
10 final String string; 10 final String string;
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 35
36 class SubstringWrapper implements SourceString { 36 class SubstringWrapper implements SourceString {
37 final String internalString; 37 final String internalString;
38 final int begin; 38 final int begin;
39 final int end; 39 final int end;
40 40
41 const SubstringWrapper(String this.internalString, 41 const SubstringWrapper(String this.internalString,
42 int this.begin, int this.end); 42 int this.begin, int this.end);
43 43
44 int hashCode() => toString().hashCode(); 44 int hashCode() => slowToString().hashCode();
45 45
46 bool operator ==(other) { 46 bool operator ==(other) {
47 return other is SourceString && toString() == other.toString(); 47 return other is SourceString && slowToString() == other.slowToString();
48 } 48 }
49 49
50 void printOn(StringBuffer sb) { 50 void printOn(StringBuffer sb) {
51 sb.add(this); 51 sb.add(internalString.substring(begin, end));
52 } 52 }
53 53
54 String toString() => internalString.substring(begin, end); 54 String slowToString() => internalString.substring(begin, end);
55 55
56 String get stringValue() => toString(); 56 String toString() => "SubstringWrapper(slowToString())";
57
58 String get stringValue() => null;
57 59
58 Iterator<int> iterator() => 60 Iterator<int> iterator() =>
59 new StringCodeIterator.substring(internalString, begin, end); 61 new StringCodeIterator.substring(internalString, begin, end);
60 62
61 SourceString copyWithoutQuotes(int initial, int terminal) { 63 SourceString copyWithoutQuotes(int initial, int terminal) {
62 assert(0 <= initial); 64 assert(0 <= initial);
63 assert(0 <= terminal); 65 assert(0 <= terminal);
64 assert(initial + terminal <= internalString.length); 66 assert(initial + terminal <= internalString.length);
65 return new SubstringWrapper(internalString, 67 return new SubstringWrapper(internalString,
66 begin + initial, end - terminal); 68 begin + initial, end - terminal);
67 } 69 }
68 70
69 bool isEmpty() => begin == end; 71 bool isEmpty() => begin == end;
70 } 72 }
OLDNEW
« no previous file with comments | « dart/frog/leg/scanner/scanner_task.dart ('k') | dart/frog/leg/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698