From 3f679f2d545d5f3f8066aed7cf267d828e6408de Mon Sep 17 00:00:00 2001 From: Lewis Wynne Date: Mon, 10 Mar 2025 19:36:00 +0000 Subject: [PATCH] get_count --- src/inflect_rs.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/inflect_rs.rs b/src/inflect_rs.rs index 6ced7fd..7256f3f 100644 --- a/src/inflect_rs.rs +++ b/src/inflect_rs.rs @@ -2572,4 +2572,44 @@ impl Engine { } pub fn check_gender(&self) -> &String { &self.the_gender } + + fn get_count>(&self, count: Option) -> i32 { + if count.is_none() { + if self.persistent_count.is_some() { + return self.persistent_count.unwrap(); + } else { + return 0; + } + } + + let c = count.unwrap().into(); + match c { + IntOrString::Int(n) => return n, + IntOrString::Str(s) => { + if pl_count_one().contains(&s) || + (*self.classical_dict.get("zero").unwrap_or(&false) && pl_count_zero().contains(&s.to_lowercase())) { + return 1; + } else { + return 2; + } + } + } + } +} + +enum IntOrString { + Int(i32), + Str(String), +} + +impl From for IntOrString { + fn from(n: i32) -> Self { IntOrString::Int(n) } +} + +impl From for IntOrString { + fn from(s: String) -> Self { IntOrString::Str(s) } +} + +impl From<&str> for IntOrString { + fn from(s: &str) -> Self { IntOrString::Str(s.to_string()) } }