From ef1bdb737d73125ab71dd9ff5f0f135ce7aaba07 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 16 May 2026 23:34:08 +0900 Subject: feat(port): port Comparator.php --- crates/shirabe-semver/src/comparator.rs | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'crates/shirabe-semver/src') diff --git a/crates/shirabe-semver/src/comparator.rs b/crates/shirabe-semver/src/comparator.rs index 15df53e..575a656 100644 --- a/crates/shirabe-semver/src/comparator.rs +++ b/crates/shirabe-semver/src/comparator.rs @@ -1 +1,36 @@ //! ref: composer/vendor/composer/semver/src/Comparator.php + +use crate::constraint::constraint::Constraint; + +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 = Constraint::new(operator, version2); + constraint.match_specific(&Constraint::new("==".to_string(), version1), true) + } +} -- cgit v1.3.1