| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |