OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library pub_semver.src.version; | 5 library pub_semver.src.version; |
6 | 6 |
7 import 'dart:math'; | 7 import 'dart:math'; |
8 | 8 |
9 import 'package:collection/equality.dart'; | 9 import 'package:collection/equality.dart'; |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 try { | 116 try { |
117 int major = int.parse(match[1]); | 117 int major = int.parse(match[1]); |
118 int minor = int.parse(match[2]); | 118 int minor = int.parse(match[2]); |
119 int patch = int.parse(match[3]); | 119 int patch = int.parse(match[3]); |
120 | 120 |
121 String preRelease = match[5]; | 121 String preRelease = match[5]; |
122 String build = match[8]; | 122 String build = match[8]; |
123 | 123 |
124 return new Version._(major, minor, patch, preRelease, build, text); | 124 return new Version._(major, minor, patch, preRelease, build, text); |
125 } on FormatException catch (ex) { | 125 } on FormatException { |
126 throw new FormatException('Could not parse "$text".'); | 126 throw new FormatException('Could not parse "$text".'); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 /// Returns the primary version out of a list of candidates. | 130 /// Returns the primary version out of a list of candidates. |
131 /// | 131 /// |
132 /// This is the highest-numbered stable (non-prerelease) version. If there | 132 /// This is the highest-numbered stable (non-prerelease) version. If there |
133 /// are no stable versions, it's just the highest-numbered version. | 133 /// are no stable versions, it's just the highest-numbered version. |
134 static Version primary(List<Version> versions) { | 134 static Version primary(List<Version> versions) { |
135 var primary; | 135 var primary; |
136 for (var version in versions) { | 136 for (var version in versions) { |
137 if (primary == null || (!version.isPreRelease && primary.isPreRelease) || | 137 if (primary == null || (!version.isPreRelease && primary.isPreRelease) || |
138 (version.isPreRelease == primary.isPreRelease && version > primary)) { | 138 (version.isPreRelease == primary.isPreRelease && version > primary)) { |
139 primary = version; | 139 primary = version; |
140 } | 140 } |
141 } | 141 } |
142 return primary; | 142 return primary; |
143 } | 143 } |
144 | 144 |
145 /// Splits a string of dot-delimited identifiers into their component parts. | 145 /// Splits a string of dot-delimited identifiers into their component parts. |
146 /// | 146 /// |
147 /// Identifiers that are numeric are converted to numbers. | 147 /// Identifiers that are numeric are converted to numbers. |
148 static List _splitParts(String text) { | 148 static List _splitParts(String text) { |
149 return text.split('.').map((part) { | 149 return text.split('.').map((part) { |
150 try { | 150 try { |
151 return int.parse(part); | 151 return int.parse(part); |
152 } on FormatException catch (ex) { | 152 } on FormatException { |
153 // Not a number. | 153 // Not a number. |
154 return part; | 154 return part; |
155 } | 155 } |
156 }).toList(); | 156 }).toList(); |
157 } | 157 } |
158 | 158 |
159 bool operator ==(other) { | 159 bool operator ==(other) { |
160 if (other is! Version) return false; | 160 if (other is! Version) return false; |
161 return major == other.major && minor == other.minor && | 161 return major == other.major && minor == other.minor && |
162 patch == other.patch && | 162 patch == other.patch && |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // Compare two strings. | 303 // Compare two strings. |
304 return aPart.compareTo(bPart); | 304 return aPart.compareTo(bPart); |
305 } | 305 } |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 // The lists are entirely equal. | 309 // The lists are entirely equal. |
310 return 0; | 310 return 0; |
311 } | 311 } |
312 } | 312 } |
OLD | NEW |