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() => '$tag [${Strings.join(content.map((e) => '$e'), ', ')}]'; | 93 String toString() => |
| 94 '$tag [${Strings.join(content.mappedBy((e) => '$e'), ', ')}]'; |
94 | 95 |
95 int get hashCode => super.hashCode ^ _hashCode(content); | 96 int get hashCode => super.hashCode ^ _hashCode(content); |
96 | 97 |
97 visit(_Visitor v) => v.visitSequence(this); | 98 visit(_Visitor v) => v.visitSequence(this); |
98 } | 99 } |
99 | 100 |
100 /// An alias node is a reference to an anchor. | 101 /// An alias node is a reference to an anchor. |
101 class _AliasNode extends _Node { | 102 class _AliasNode extends _Node { |
102 _AliasNode(String anchor) : super(new _Tag.scalar(_Tag.yaml("str")), anchor); | 103 _AliasNode(String anchor) : super(new _Tag.scalar(_Tag.yaml("str")), anchor); |
103 | 104 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // 20 is the maximum value for this argument, which we use since YAML | 143 // 20 is the maximum value for this argument, which we use since YAML |
143 // doesn't specify a maximum. | 144 // doesn't specify a maximum. |
144 return value.toStringAsExponential(20). | 145 return value.toStringAsExponential(20). |
145 replaceFirst(new RegExp("0+e"), "e"); | 146 replaceFirst(new RegExp("0+e"), "e"); |
146 } | 147 } |
147 | 148 |
148 if (value is String) { | 149 if (value is String) { |
149 // TODO(nweiz): This could be faster if we used a RegExp to check for | 150 // TODO(nweiz): This could be faster if we used a RegExp to check for |
150 // special characters and short-circuited if they didn't exist. | 151 // special characters and short-circuited if they didn't exist. |
151 | 152 |
152 var escapedValue = value.charCodes.map((c) { | 153 var escapedValue = value.charCodes.mappedBy((c) { |
153 switch (c) { | 154 switch (c) { |
154 case _Parser.TAB: return "\\t"; | 155 case _Parser.TAB: return "\\t"; |
155 case _Parser.LF: return "\\n"; | 156 case _Parser.LF: return "\\n"; |
156 case _Parser.CR: return "\\r"; | 157 case _Parser.CR: return "\\r"; |
157 case _Parser.DOUBLE_QUOTE: return '\\"'; | 158 case _Parser.DOUBLE_QUOTE: return '\\"'; |
158 case _Parser.NULL: return "\\0"; | 159 case _Parser.NULL: return "\\0"; |
159 case _Parser.BELL: return "\\a"; | 160 case _Parser.BELL: return "\\a"; |
160 case _Parser.BACKSPACE: return "\\b"; | 161 case _Parser.BACKSPACE: return "\\b"; |
161 case _Parser.VERTICAL_TAB: return "\\v"; | 162 case _Parser.VERTICAL_TAB: return "\\v"; |
162 case _Parser.FORM_FEED: return "\\f"; | 163 case _Parser.FORM_FEED: return "\\f"; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (!(super == other) || other is! _MappingNode) return false; | 215 if (!(super == other) || other is! _MappingNode) return false; |
215 if (content.length != other.content.length) return false; | 216 if (content.length != other.content.length) return false; |
216 for (var key in content.keys) { | 217 for (var key in content.keys) { |
217 if (!other.content.containsKey(key)) return false; | 218 if (!other.content.containsKey(key)) return false; |
218 if (content[key] != other.content[key]) return false; | 219 if (content[key] != other.content[key]) return false; |
219 } | 220 } |
220 return true; | 221 return true; |
221 } | 222 } |
222 | 223 |
223 String toString() { | 224 String toString() { |
224 var strContent = Strings.join(content.keys. | 225 var strContent = content.keys |
225 map((k) => '${k}: ${content[k]}'), ', '); | 226 .mappedBy((k) => '${k}: ${content[k]}') |
| 227 .join(', '); |
226 return '$tag {$strContent}'; | 228 return '$tag {$strContent}'; |
227 } | 229 } |
228 | 230 |
229 int get hashCode => super.hashCode ^ _hashCode(content); | 231 int get hashCode => super.hashCode ^ _hashCode(content); |
230 | 232 |
231 visit(_Visitor v) => v.visitMapping(this); | 233 visit(_Visitor v) => v.visitMapping(this); |
232 } | 234 } |
OLD | NEW |