Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: pkg/yaml/lib/composer.dart

Issue 12282038: Remove deprecated string features. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/webdriver/lib/webdriver.dart ('k') | pkg/yaml/lib/model.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// Takes a parsed YAML document (what the spec calls the "serialization tree") 7 /// Takes a parsed YAML document (what the spec calls the "serialization tree")
8 /// and resolves aliases, resolves tags, and parses scalars to produce the 8 /// and resolves aliases, resolves tags, and parses scalars to produce the
9 /// "representation graph". 9 /// "representation graph".
10 class _Composer extends _Visitor { 10 class _Composer extends _Visitor {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 /// Parses an integer scalar. 113 /// Parses an integer scalar.
114 _ScalarNode parseInt(String content) { 114 _ScalarNode parseInt(String content) {
115 var match = new RegExp("^[-+]?[0-9]+\$").firstMatch(content); 115 var match = new RegExp("^[-+]?[0-9]+\$").firstMatch(content);
116 if (match != null) { 116 if (match != null) {
117 return new _ScalarNode(_Tag.yaml("int"), 117 return new _ScalarNode(_Tag.yaml("int"),
118 value: int.parse(match.group(0))); 118 value: int.parse(match.group(0)));
119 } 119 }
120 120
121 match = new RegExp("^0o([0-7]+)\$").firstMatch(content); 121 match = new RegExp("^0o([0-7]+)\$").firstMatch(content);
122 if (match != null) { 122 if (match != null) {
123 // TODO(nweiz): clean this up when Dart can parse an octal string 123 int n = int.parse(match.group(1), radix: 8);
124 var n = 0;
125 for (var c in match.group(1).charCodes) {
126 n *= 8;
127 n += c - 48;
128 }
129 return new _ScalarNode(_Tag.yaml("int"), value: n); 124 return new _ScalarNode(_Tag.yaml("int"), value: n);
130 } 125 }
131 126
132 match = new RegExp("^0x[0-9a-fA-F]+\$").firstMatch(content); 127 match = new RegExp("^0x[0-9a-fA-F]+\$").firstMatch(content);
133 if (match != null) { 128 if (match != null) {
134 return new _ScalarNode(_Tag.yaml("int"), 129 return new _ScalarNode(_Tag.yaml("int"),
135 value: int.parse(match.group(0))); 130 value: int.parse(match.group(0)));
136 } 131 }
137 132
138 return null; 133 return null;
139 } 134 }
140 135
141 /// Parses a floating-point scalar. 136 /// Parses a floating-point scalar.
142 _ScalarNode parseFloat(String content) { 137 _ScalarNode parseFloat(String content) {
143 var match = new RegExp( 138 var match = new RegExp(
144 "^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?\$"). 139 "^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?\$").
145 firstMatch(content); 140 firstMatch(content);
146 if (match != null) { 141 if (match != null) {
147 // YAML allows floats of the form "0.", but Dart does not. Fix up those 142 // YAML allows floats of the form "0.", but Dart does not. Fix up those
148 // floats by removing the trailing dot. 143 // floats by removing the trailing dot.
149 var matchStr = match.group(0).replaceAll(new RegExp(r"\.$"), ""); 144 var matchStr = match.group(0).replaceAll(new RegExp(r"\.$"), "");
150 return new _ScalarNode(_Tag.yaml("float"), 145 return new _ScalarNode(_Tag.yaml("float"),
151 value: double.parse(matchStr)); 146 value: double.parse(matchStr));
152 } 147 }
153 148
154 match = new RegExp("^([+-]?)\.(inf|Inf|INF)\$").firstMatch(content); 149 match = new RegExp("^([+-]?)\.(inf|Inf|INF)\$").firstMatch(content);
155 if (match != null) { 150 if (match != null) {
156 var infinityStr = match.group(1) == "-" ? "-Infinity" : "Infinity"; 151 var value = match.group(1) == "-" ? -double.INFINITY : double.INFINITY;
157 return new _ScalarNode(_Tag.yaml("float"), 152 return new _ScalarNode(_Tag.yaml("float"), value: value);
158 value: double.parse(infinityStr));
159 } 153 }
160 154
161 match = new RegExp("^\.(nan|NaN|NAN)\$").firstMatch(content); 155 match = new RegExp("^\.(nan|NaN|NAN)\$").firstMatch(content);
162 if (match != null) { 156 if (match != null) {
163 return new _ScalarNode(_Tag.yaml("float"), 157 return new _ScalarNode(_Tag.yaml("float"), value: double.NAN);
164 value: double.parse("NaN"));
165 } 158 }
166 159
167 return null; 160 return null;
168 } 161 }
169 162
170 /// Parses a string scalar. 163 /// Parses a string scalar.
171 _ScalarNode parseString(String content) => 164 _ScalarNode parseString(String content) =>
172 new _ScalarNode(_Tag.yaml("str"), value: content); 165 new _ScalarNode(_Tag.yaml("str"), value: content);
173 } 166 }
OLDNEW
« no previous file with comments | « pkg/webdriver/lib/webdriver.dart ('k') | pkg/yaml/lib/model.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698