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 17 matching lines...) Expand all Loading... |
28 bool isEmpty() => length == 0; | 28 bool isEmpty() => length == 0; |
29 abstract Iterator<int> iterator(); | 29 abstract Iterator<int> iterator(); |
30 abstract String slowToString(); | 30 abstract String slowToString(); |
31 | 31 |
32 bool operator ==(var other) { | 32 bool operator ==(var other) { |
33 if (other is !DartString) return false; | 33 if (other is !DartString) return false; |
34 DartString otherString = other; | 34 DartString otherString = other; |
35 if (length != otherString.length) return false; | 35 if (length != otherString.length) return false; |
36 Iterator it1 = iterator(); | 36 Iterator it1 = iterator(); |
37 Iterator it2 = otherString.iterator(); | 37 Iterator it2 = otherString.iterator(); |
38 while (it1.hasNext()) { | 38 while (it1.hasNext) { |
39 if (it1.next() != it2.next()) return false; | 39 if (it1.next() != it2.next()) return false; |
40 } | 40 } |
41 return true; | 41 return true; |
42 } | 42 } |
43 String toString() => "DartString#${length}:${slowToString()}"; | 43 String toString() => "DartString#${length}:${slowToString()}"; |
44 abstract SourceString get source; | 44 abstract SourceString get source; |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 /** | 48 /** |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 class EscapedSourceDartString extends SourceBasedDartString { | 89 class EscapedSourceDartString extends SourceBasedDartString { |
90 EscapedSourceDartString(source, length) : super(source, length); | 90 EscapedSourceDartString(source, length) : super(source, length); |
91 Iterator<int> iterator() { | 91 Iterator<int> iterator() { |
92 if (toStringCache != null) return new StringCodeIterator(toStringCache); | 92 if (toStringCache != null) return new StringCodeIterator(toStringCache); |
93 return new StringEscapeIterator(source); | 93 return new StringEscapeIterator(source); |
94 } | 94 } |
95 String slowToString() { | 95 String slowToString() { |
96 if (toStringCache != null) return toStringCache; | 96 if (toStringCache != null) return toStringCache; |
97 StringBuffer buffer = new StringBuffer(); | 97 StringBuffer buffer = new StringBuffer(); |
98 StringEscapeIterator it = new StringEscapeIterator(source); | 98 StringEscapeIterator it = new StringEscapeIterator(source); |
99 while (it.hasNext()) { | 99 while (it.hasNext) { |
100 buffer.addCharCode(it.next()); | 100 buffer.addCharCode(it.next()); |
101 } | 101 } |
102 toStringCache = buffer.toString(); | 102 toStringCache = buffer.toString(); |
103 return toStringCache; | 103 return toStringCache; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 /** | 107 /** |
108 * The concatenation of two [DartString]s. | 108 * The concatenation of two [DartString]s. |
109 */ | 109 */ |
(...skipping 17 matching lines...) Expand all Loading... |
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; |
138 if (!hasNextLookAhead) { | 138 if (!hasNextLookAhead) { |
139 nextPart(); | 139 nextPart(); |
140 } | 140 } |
141 } | 141 } |
142 bool hasNext() { | 142 bool get hasNext { |
143 return hasNextLookAhead; | 143 return hasNextLookAhead; |
144 } | 144 } |
145 int next() { | 145 int next() { |
146 assert(hasNextLookAhead); | 146 assert(hasNextLookAhead); |
147 int result = current.next(); | 147 int result = current.next(); |
148 hasNextLookAhead = current.hasNext(); | 148 hasNextLookAhead = current.hasNext; |
149 if (!hasNextLookAhead) { | 149 if (!hasNextLookAhead) { |
150 nextPart(); | 150 nextPart(); |
151 } | 151 } |
152 return result; | 152 return result; |
153 } | 153 } |
154 void nextPart() { | 154 void nextPart() { |
155 if (right != null) { | 155 if (right != null) { |
156 current = right.iterator(); | 156 current = right.iterator(); |
157 right = null; | 157 right = null; |
158 hasNextLookAhead = current.hasNext(); | 158 hasNextLookAhead = current.hasNext; |
159 } | 159 } |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 /** | 163 /** |
164 *Iterator that returns the actual string contents of a string with escapes. | 164 *Iterator that returns the actual string contents of a string with escapes. |
165 */ | 165 */ |
166 class StringEscapeIterator implements Iterator<int>{ | 166 class StringEscapeIterator implements Iterator<int>{ |
167 final Iterator<int> source; | 167 final Iterator<int> source; |
168 StringEscapeIterator(SourceString source) : this.source = source.iterator(); | 168 StringEscapeIterator(SourceString source) : this.source = source.iterator(); |
169 bool hasNext() => source.hasNext(); | 169 bool get hasNext => source.hasNext; |
170 int next() { | 170 int next() { |
171 int code = source.next(); | 171 int code = source.next(); |
172 if (!identical(code, $BACKSLASH)) { | 172 if (!identical(code, $BACKSLASH)) { |
173 return code; | 173 return code; |
174 } | 174 } |
175 code = source.next(); | 175 code = source.next(); |
176 if (identical(code, $n)) return $LF; | 176 if (identical(code, $n)) return $LF; |
177 if (identical(code, $r)) return $CR; | 177 if (identical(code, $r)) return $CR; |
178 if (identical(code, $t)) return $TAB; | 178 if (identical(code, $t)) return $TAB; |
179 if (identical(code, $b)) return $BS; | 179 if (identical(code, $b)) return $BS; |
(...skipping 20 matching lines...) Expand all 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 |