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 part of yaml; | 5 part of yaml; |
6 | 6 |
7 // This file contains the node classes for the internal representations of YAML | 7 // This file contains the node classes for the internal representations of YAML |
8 // documents. These nodes are used for both the serialization tree and the | 8 // documents. These nodes are used for both the serialization tree and the |
9 // representation graph. | 9 // representation graph. |
10 | 10 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 bool operator ==(other) { | 83 bool operator ==(other) { |
84 // Should be super != other; bug 2554 | 84 // Should be super != other; bug 2554 |
85 if (!(super == other) || other is! _SequenceNode) return false; | 85 if (!(super == other) || other is! _SequenceNode) return false; |
86 if (content.length != other.content.length) return false; | 86 if (content.length != other.content.length) return false; |
87 for (var i = 0; i < content.length; i++) { | 87 for (var i = 0; i < content.length; i++) { |
88 if (content[i] != other.content[i]) return false; | 88 if (content[i] != other.content[i]) return false; |
89 } | 89 } |
90 return true; | 90 return true; |
91 } | 91 } |
92 | 92 |
93 String toString() => | 93 String toString() => '$tag [${content.map((e) => '$e').join(', ')}]'; |
94 '$tag [${Strings.join(content.map((e) => '$e'), ', ')}]'; | |
95 | 94 |
96 int get hashCode => super.hashCode ^ _hashCode(content); | 95 int get hashCode => super.hashCode ^ _hashCode(content); |
97 | 96 |
98 visit(_Visitor v) => v.visitSequence(this); | 97 visit(_Visitor v) => v.visitSequence(this); |
99 } | 98 } |
100 | 99 |
101 /// An alias node is a reference to an anchor. | 100 /// An alias node is a reference to an anchor. |
102 class _AliasNode extends _Node { | 101 class _AliasNode extends _Node { |
103 _AliasNode(String anchor) : super(new _Tag.scalar(_Tag.yaml("str")), anchor); | 102 _AliasNode(String anchor) : super(new _Tag.scalar(_Tag.yaml("str")), anchor); |
104 | 103 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 return "\\x${zeroPad(c.toRadixString(16).toUpperCase(), 2)}"; | 171 return "\\x${zeroPad(c.toRadixString(16).toUpperCase(), 2)}"; |
173 } else if (c >= 0x100 && c < 0x10000) { | 172 } else if (c >= 0x100 && c < 0x10000) { |
174 return "\\u${zeroPad(c.toRadixString(16).toUpperCase(), 4)}"; | 173 return "\\u${zeroPad(c.toRadixString(16).toUpperCase(), 4)}"; |
175 } else if (c >= 0x10000) { | 174 } else if (c >= 0x10000) { |
176 return "\\u${zeroPad(c.toRadixString(16).toUpperCase(), 8)}"; | 175 return "\\u${zeroPad(c.toRadixString(16).toUpperCase(), 8)}"; |
177 } else { | 176 } else { |
178 return new String.fromCharCodes([c]); | 177 return new String.fromCharCodes([c]); |
179 } | 178 } |
180 } | 179 } |
181 }); | 180 }); |
182 return '"${Strings.join(escapedValue, '')}"'; | 181 return '"${escapedValue.join()}"'; |
183 } | 182 } |
184 | 183 |
185 throw new YamlException("unknown scalar value: $value"); | 184 throw new YamlException("unknown scalar value: $value"); |
186 } | 185 } |
187 | 186 |
188 String toString() => '$tag "$content"'; | 187 String toString() => '$tag "$content"'; |
189 | 188 |
190 /// Left-pads [str] with zeros so that it's at least [length] characters | 189 /// Left-pads [str] with zeros so that it's at least [length] characters |
191 /// long. | 190 /// long. |
192 String zeroPad(String str, int length) { | 191 String zeroPad(String str, int length) { |
193 assert(length >= str.length); | 192 assert(length >= str.length); |
194 var prefix = []; | 193 var prefix = []; |
195 prefix.insertRange(0, length - str.length, '0'); | 194 prefix.insertRange(0, length - str.length, '0'); |
196 return '${Strings.join(prefix, '')}$str'; | 195 return '${prefix.join()}$str'; |
197 } | 196 } |
198 | 197 |
199 int get hashCode => super.hashCode ^ content.hashCode; | 198 int get hashCode => super.hashCode ^ content.hashCode; |
200 | 199 |
201 visit(_Visitor v) => v.visitScalar(this); | 200 visit(_Visitor v) => v.visitScalar(this); |
202 } | 201 } |
203 | 202 |
204 /// A mapping node represents an unordered map of nodes to nodes. | 203 /// A mapping node represents an unordered map of nodes to nodes. |
205 class _MappingNode extends _Node { | 204 class _MappingNode extends _Node { |
206 /// The node map. | 205 /// The node map. |
(...skipping 18 matching lines...) Expand all Loading... |
225 var strContent = content.keys | 224 var strContent = content.keys |
226 .map((k) => '${k}: ${content[k]}') | 225 .map((k) => '${k}: ${content[k]}') |
227 .join(', '); | 226 .join(', '); |
228 return '$tag {$strContent}'; | 227 return '$tag {$strContent}'; |
229 } | 228 } |
230 | 229 |
231 int get hashCode => super.hashCode ^ _hashCode(content); | 230 int get hashCode => super.hashCode ^ _hashCode(content); |
232 | 231 |
233 visit(_Visitor v) => v.visitMapping(this); | 232 visit(_Visitor v) => v.visitMapping(this); |
234 } | 233 } |
OLD | NEW |