| OLD | NEW |
| 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 /** | 5 /** |
| 6 * The [DartString] type represents a Dart string value as a sequence of Unicode | 6 * The [DartString] type represents a Dart string value as a sequence of Unicode |
| 7 * Scalar Values. | 7 * Scalar Values. |
| 8 * After parsing, any valid [LiteralString] will contain a [DartString] | 8 * After parsing, any valid [LiteralString] will contain a [DartString] |
| 9 * representing its content after removing quotes and resolving escapes in | 9 * representing its content after removing quotes and resolving escapes in |
| 10 * its source. | 10 * its source. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 abstract SourceString get source(); | 44 abstract SourceString get source(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * A [DartString] where the content is represented by an actual [String]. | 49 * A [DartString] where the content is represented by an actual [String]. |
| 50 */ | 50 */ |
| 51 class LiteralDartString extends DartString { | 51 class LiteralDartString extends DartString { |
| 52 final String string; | 52 final String string; |
| 53 const LiteralDartString(this.string); | 53 const LiteralDartString(this.string); |
| 54 int get length() => string.length; | 54 int get length => string.length; |
| 55 Iterator<int> iterator() => new StringCodeIterator(string); | 55 Iterator<int> iterator() => new StringCodeIterator(string); |
| 56 String slowToString() => string; | 56 String slowToString() => string; |
| 57 SourceString get source() => new StringWrapper(string); | 57 SourceString get source => new StringWrapper(string); |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * A [DartString] where the content comes from a slice of the program source. | 61 * A [DartString] where the content comes from a slice of the program source. |
| 62 */ | 62 */ |
| 63 class SourceBasedDartString extends DartString { | 63 class SourceBasedDartString extends DartString { |
| 64 String toStringCache = null; | 64 String toStringCache = null; |
| 65 final SourceString source; | 65 final SourceString source; |
| 66 final int length; | 66 final int length; |
| 67 SourceBasedDartString(this.source, this.length); | 67 SourceBasedDartString(this.source, this.length); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 this.right = right, | 117 this.right = right, |
| 118 length = left.length + right.length; | 118 length = left.length + right.length; |
| 119 | 119 |
| 120 Iterator<int> iterator() => new ConsDartStringIterator(this); | 120 Iterator<int> iterator() => new ConsDartStringIterator(this); |
| 121 | 121 |
| 122 String slowToString() { | 122 String slowToString() { |
| 123 if (toStringCache !== null) return toStringCache; | 123 if (toStringCache !== null) return toStringCache; |
| 124 toStringCache = left.slowToString().concat(right.slowToString()); | 124 toStringCache = left.slowToString().concat(right.slowToString()); |
| 125 return toStringCache; | 125 return toStringCache; |
| 126 } | 126 } |
| 127 SourceString get source() => new StringWrapper(slowToString()); | 127 SourceString get source => new StringWrapper(slowToString()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 class ConsDartStringIterator implements Iterator<int> { | 130 class ConsDartStringIterator implements Iterator<int> { |
| 131 Iterator<int> current; | 131 Iterator<int> current; |
| 132 DartString right; | 132 DartString right; |
| 133 bool hasNextLookAhead; | 133 bool hasNextLookAhead; |
| 134 ConsDartStringIterator(ConsDartString cons) | 134 ConsDartStringIterator(ConsDartString cons) |
| 135 : current = cons.left.iterator(), | 135 : current = cons.left.iterator(), |
| 136 right = cons.right { | 136 right = cons.right { |
| 137 hasNextLookAhead = current.hasNext(); | 137 hasNextLookAhead = current.hasNext(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 for (int i = 0; i < 3; i++) { | 200 for (int i = 0; i < 3; i++) { |
| 201 code = source.next(); | 201 code = source.next(); |
| 202 value = value * 16 + hexDigitValue(code); | 202 value = value * 16 + hexDigitValue(code); |
| 203 } | 203 } |
| 204 return value; | 204 return value; |
| 205 } | 205 } |
| 206 return code; | 206 return code; |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| OLD | NEW |