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

Side by Side Diff: utils/pub/version.dart

Issue 10887023: Use new try-catch syntax in runtime/, tools/, and utils/. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | « utils/pub/pub.dart ('k') | utils/template/parser.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 /** 5 /**
6 * Handles version numbers, following the [Semantic Versioning][semver] spec. 6 * Handles version numbers, following the [Semantic Versioning][semver] spec.
7 * 7 *
8 * [semver]: http://semver.org/ 8 * [semver]: http://semver.org/
9 */ 9 */
10 #library('version'); 10 #library('version');
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 try { 63 try {
64 int major = parseInt(match[1]); 64 int major = parseInt(match[1]);
65 int minor = parseInt(match[2]); 65 int minor = parseInt(match[2]);
66 int patch = parseInt(match[3]); 66 int patch = parseInt(match[3]);
67 67
68 String preRelease = match[5]; 68 String preRelease = match[5];
69 String build = match[8]; 69 String build = match[8];
70 70
71 return new Version(major, minor, patch, preRelease, build); 71 return new Version(major, minor, patch, preRelease, build);
72 } catch (FormatException ex) { 72 } on FormatException catch (ex) {
73 throw new FormatException('Could not parse "$text".'); 73 throw new FormatException('Could not parse "$text".');
74 } 74 }
75 } 75 }
76 76
77 bool operator ==(other) { 77 bool operator ==(other) {
78 if (other is! Version) return false; 78 if (other is! Version) return false;
79 return compareTo(other) == 0; 79 return compareTo(other) == 0;
80 } 80 }
81 81
82 bool operator <(Version other) => compareTo(other) < 0; 82 bool operator <(Version other) => compareTo(other) < 0;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 177
178 /** 178 /**
179 * Splits a string of dot-delimited identifiers into their component parts. 179 * Splits a string of dot-delimited identifiers into their component parts.
180 * Identifiers that are numeric are converted to numbers. 180 * Identifiers that are numeric are converted to numbers.
181 */ 181 */
182 List _splitParts(String text) { 182 List _splitParts(String text) {
183 return text.split('.').map((part) { 183 return text.split('.').map((part) {
184 try { 184 try {
185 return parseInt(part); 185 return parseInt(part);
186 } catch (FormatException ex) { 186 } on FormatException catch (ex) {
187 // Not a number. 187 // Not a number.
188 return part; 188 return part;
189 } 189 }
190 }); 190 });
191 } 191 }
192 } 192 }
193 193
194 /** 194 /**
195 * A [VersionConstraint] is a predicate that can determine whether a given 195 * A [VersionConstraint] is a predicate that can determine whether a given
196 * version is valid or not. For example, a ">= 2.0.0" constraint allows any 196 * version is valid or not. For example, a ">= 2.0.0" constraint allows any
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 case '<': return new VersionRange(max: version, includeMax: false); 420 case '<': return new VersionRange(max: version, includeMax: false);
421 case '>=': return new VersionRange(min: version, includeMin: true); 421 case '>=': return new VersionRange(min: version, includeMin: true);
422 case '>': return new VersionRange(min: version, includeMin: false); 422 case '>': return new VersionRange(min: version, includeMin: false);
423 } 423 }
424 } 424 }
425 425
426 // Otherwise, it must be an explicit version. 426 // Otherwise, it must be an explicit version.
427 return new Version.parse(text); 427 return new Version.parse(text);
428 } 428 }
429 } 429 }
OLDNEW
« no previous file with comments | « utils/pub/pub.dart ('k') | utils/template/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698