1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
//! ref: composer/vendor/composer/semver/src/Comparator.php
use crate::constraint::SimpleConstraint;
pub struct Comparator;
impl Comparator {
pub fn greater_than(version1: String, version2: String) -> bool {
Self::compare(version1, ">".to_string(), version2)
}
pub fn greater_than_or_equal_to(version1: String, version2: String) -> bool {
Self::compare(version1, ">=".to_string(), version2)
}
pub fn less_than(version1: String, version2: String) -> bool {
Self::compare(version1, "<".to_string(), version2)
}
pub fn less_than_or_equal_to(version1: String, version2: String) -> bool {
Self::compare(version1, "<=".to_string(), version2)
}
pub fn equal_to(version1: String, version2: String) -> bool {
Self::compare(version1, "==".to_string(), version2)
}
pub fn not_equal_to(version1: String, version2: String) -> bool {
Self::compare(version1, "!=".to_string(), version2)
}
pub fn compare(version1: String, operator: String, version2: String) -> bool {
let constraint = SimpleConstraint::new(operator, version2, None);
constraint.match_specific(
&SimpleConstraint::new("==".to_string(), version1, None),
true,
)
}
}
|