| 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. |
| 11 */ | 11 */ |
| 12 class DartString implements Iterable<int> { | 12 abstract class DartString implements Iterable<int> { |
| 13 factory DartString.empty() => const LiteralDartString(""); | 13 factory DartString.empty() => const LiteralDartString(""); |
| 14 // This is a convenience constructor. If you need a const literal DartString, | 14 // This is a convenience constructor. If you need a const literal DartString, |
| 15 // use [const LiteralDartString(string)] directly. | 15 // use [const LiteralDartString(string)] directly. |
| 16 factory DartString.literal(String string) => new LiteralDartString(string); | 16 factory DartString.literal(String string) => new LiteralDartString(string); |
| 17 factory DartString.rawString(SourceString source, int length) => | 17 factory DartString.rawString(SourceString source, int length) => |
| 18 new RawSourceDartString(source, length); | 18 new RawSourceDartString(source, length); |
| 19 factory DartString.escapedString(SourceString source, int length) => | 19 factory DartString.escapedString(SourceString source, int length) => |
| 20 new EscapedSourceDartString(source, length); | 20 new EscapedSourceDartString(source, length); |
| 21 factory DartString.concat(DartString first, DartString second) { | 21 factory DartString.concat(DartString first, DartString second) { |
| 22 if (first.isEmpty()) return second; | 22 if (first.isEmpty()) return second; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 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 abstract 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); |
| 68 abstract Iterator<int> iterator(); | 68 abstract Iterator<int> iterator(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Special case of a [SourceBasedDartString] where we know the source doesn't | 72 * Special case of a [SourceBasedDartString] where we know the source doesn't |
| 73 * contain any escapes. | 73 * contain any escapes. |
| (...skipping 126 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 |