| 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 * 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('pub_version'); | 10 #library('pub_version'); |
| 11 | 11 |
| 12 /** A parsed semantic version number. */ | 12 /** A parsed semantic version number. */ |
| 13 class Version implements Comparable, VersionConstraint { | 13 class Version implements Comparable, Hashable, VersionConstraint { |
| 14 static get none() => new Version(0, 0, 0); |
| 15 |
| 14 static final _PARSE_REGEX = const RegExp( | 16 static final _PARSE_REGEX = const RegExp( |
| 15 @'^' // Start at beginning. | 17 @'^' // Start at beginning. |
| 16 @'(\d+).(\d+).(\d+)' // Version number. | 18 @'(\d+).(\d+).(\d+)' // Version number. |
| 17 @'(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Pre-release. | 19 @'(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Pre-release. |
| 18 @'(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Build. | 20 @'(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Build. |
| 19 @'$'); // Consume entire string. | 21 @'$'); // Consume entire string. |
| 20 | 22 |
| 21 /** The major version number: "1" in "1.2.3". */ | 23 /** The major version number: "1" in "1.2.3". */ |
| 22 final int major; | 24 final int major; |
| 23 | 25 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // Builds always come after no build string. | 99 // Builds always come after no build string. |
| 98 if (build == null) return -1; | 100 if (build == null) return -1; |
| 99 if (other.build == null) return 1; | 101 if (other.build == null) return 1; |
| 100 | 102 |
| 101 return _compareStrings(build, other.build); | 103 return _compareStrings(build, other.build); |
| 102 } | 104 } |
| 103 | 105 |
| 104 return 0; | 106 return 0; |
| 105 } | 107 } |
| 106 | 108 |
| 109 int hashCode() => toString().hashCode(); |
| 110 |
| 107 String toString() { | 111 String toString() { |
| 108 var buffer = new StringBuffer(); | 112 var buffer = new StringBuffer(); |
| 109 buffer.add('$major.$minor.$patch'); | 113 buffer.add('$major.$minor.$patch'); |
| 110 if (preRelease != null) buffer.add('-$preRelease'); | 114 if (preRelease != null) buffer.add('-$preRelease'); |
| 111 if (build != null) buffer.add('+$build'); | 115 if (build != null) buffer.add('+$build'); |
| 112 return buffer.toString(); | 116 return buffer.toString(); |
| 113 } | 117 } |
| 114 | 118 |
| 115 /** | 119 /** |
| 116 * Compares the string part of two versions. This is used for the pre-release | 120 * Compares the string part of two versions. This is used for the pre-release |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 207 } |
| 204 | 208 |
| 205 /** Thrown by [Version.parse()] if the argument isn't a valid version string. */ | 209 /** Thrown by [Version.parse()] if the argument isn't a valid version string. */ |
| 206 class FormatException implements Exception { | 210 class FormatException implements Exception { |
| 207 final String message; | 211 final String message; |
| 208 | 212 |
| 209 FormatException(this.message); | 213 FormatException(this.message); |
| 210 | 214 |
| 211 String toString() => message; | 215 String toString() => message; |
| 212 } | 216 } |
| OLD | NEW |