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 /// Handles version numbers, following the [Semantic Versioning][semver] spec. | 5 /// Handles version numbers, following the [Semantic Versioning][semver] spec. |
6 /// | 6 /// |
7 /// [semver]: http://semver.org/ | 7 /// [semver]: http://semver.org/ |
8 library version; | 8 library version; |
9 | 9 |
10 import 'dart:math'; | 10 import 'dart:math'; |
11 | 11 |
12 import 'utils.dart'; | 12 import 'utils.dart'; |
13 | 13 |
14 /// A parsed semantic version number. | 14 /// A parsed semantic version number. |
15 class Version implements Comparable, VersionConstraint { | 15 class Version implements Comparable<Version>, VersionConstraint { |
16 /// No released version: i.e. "0.0.0". | 16 /// No released version: i.e. "0.0.0". |
17 static Version get none => new Version(0, 0, 0); | 17 static Version get none => new Version(0, 0, 0); |
18 | 18 |
19 static final _PARSE_REGEX = new RegExp( | 19 static final _PARSE_REGEX = new RegExp( |
20 r'^' // Start at beginning. | 20 r'^' // Start at beginning. |
21 r'(\d+).(\d+).(\d+)' // Version number. | 21 r'(\d+).(\d+).(\d+)' // Version number. |
22 r'(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Pre-release. | 22 r'(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Pre-release. |
23 r'(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Build. | 23 r'(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?' // Build. |
24 r'$'); // Consume entire string. | 24 r'$'); // Consume entire string. |
25 | 25 |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 419 |
420 class _EmptyVersion implements VersionConstraint { | 420 class _EmptyVersion implements VersionConstraint { |
421 const _EmptyVersion(); | 421 const _EmptyVersion(); |
422 | 422 |
423 bool get isEmpty => true; | 423 bool get isEmpty => true; |
424 bool get isAny => false; | 424 bool get isAny => false; |
425 bool allows(Version other) => false; | 425 bool allows(Version other) => false; |
426 VersionConstraint intersect(VersionConstraint other) => this; | 426 VersionConstraint intersect(VersionConstraint other) => this; |
427 String toString() => '<empty>'; | 427 String toString() => '<empty>'; |
428 } | 428 } |
OLD | NEW |