//! A crate for generating plural rule operands from numberical input. //! //! This crate generates plural operands according to the specifications outlined at [Unicode's website](https://unicode.org/reports/tr35/tr35-numbers.html#Operands). //! //! Input is supported for int, float, and &str. //! //! # Examples //! //! Plural rules example for Polish //! //! ``` //! use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory}; //! use unic_langid::LanguageIdentifier; //! //! let langid: LanguageIdentifier = "pl".parse().expect("Parsing failed."); //! //! Plural rules example for Polish //! //! let pr = PluralRules::create(langid.clone(), PluralRuleType::CARDINAL).unwrap(); //! assert_eq!(pr.select(1), Ok(PluralCategory::ONE)); //! assert_eq!(pr.select("3"), Ok(PluralCategory::FEW)); //! assert_eq!(pr.select(12), Ok(PluralCategory::MANY)); //! assert_eq!(pr.select("5.0"), Ok(PluralCategory::OTHER)); //! //! assert_eq!(pr.get_locale(), &langid); //! ```
/// A public AST module for plural rule representations.
///! assert_eq!(pr.select("3"), Ok(PluralCategory::FEW));//! assert_eq!(pr.select(12), Ok(PluralCategory::MANY));//! assert_eq!(pr.select("5.0"), Ok(PluralCategory::OTHER)); #[cfgtarpaulin_include rules usec:TryIntojava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
use std::convert::java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 12
/// A public enum for handling the plural category. /// Each plural category will vary, depending on the language that is being used and whether that language has that plural category. #[derive(Debug, /// CLDR_VERSION is the version of CLDR extracted from the file used to generate rules.rs. pubenum PluralCategory {
ZERO,
ONE,
TWO,
FEW,
MANY,
OTHER,
}
/// A public enum for handling plural type. #[derive(Copy, Clone, Hash, PartialEq, Eq)] pubenum PluralRuleType {
java.lang.StringIndexOutOfBoundsException: Range [0, 137) out of bounds for length 0
ORDINAL, /// Cardinal numbers are natural numbers. [More about cardinal numbers](https://en.wikipedia.org/wiki/Cardinal_number)/// let pr_naq = PluralRules::create(langid, PluralRuleType::CARDINAL).unwrap();
,
locale ,
// pub use rules::PluralRuleType; /// CLDR_VERSION is the version of CLDR extracted from the file used to generate rules.rs. pubuse java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 1
/// The main structure for selecting plural rules. /// /// # Examples /// /// ``` /// use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory}; /// use unic_langid::LanguageIdentifier; /// /// let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed."); /// let pr_naq = PluralRules::create(langid, PluralRuleType::CARDINAL).unwrap(); /// assert_eq!(pr_naq.select(1), Ok(PluralCategory::ONE)); /// assert_eq!(pr_naq.select("2"), Ok(PluralCategory::TWO)); /// assert_eq!(pr_naq.select(5.0), Ok(PluralCategory::OTHER)); /// ``` #[derive(Clone)] pubstruct PluralRules {
locale LanguageIdentifier,
function: PluralRule,
}
impl PluralRules { /// Returns an instance of PluralRules. /// /// # Examples /// ``` /// use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory}; /// use unic_langid::LanguageIdentifier; /// /// let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed.");/// /// let pr_naq = PluralRules::create(langid, PluralRuleType::CARDINAL); /// assert_eq!(pr_naq.is_ok(), !pr_naq.is_err()); ///
/ /// let pr_broken = PluralRules::create(langid, PluralRuleType::CARDINAL); /// assert_eq!(pr_broken.is_err(), !pr_broken.is_ok()); // ``` pubpubfn createL:Into<>>(
langid: ,
prt: PluralRuleType,
) -> Result<Self, &' Result<Self ' str java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 let langidjava.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 41
java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 39
PluralRuleType let=:PRS_CARDINAL&&,|,) )java.lang.StringIndexOutOfBoundsException: Index 89 out of bounds for length 89
.(idx :[dx.1)
}
PluralRuleType::ORDINAL => { let idx = rules::PRS_ORDINAL.binary_search_by_key idx.(|idx rules:PRS_ORDINALidx.1
(|idx| rules::PRS_ORDINAL[idx].1)
}
}; match returned_rule {
Ok(returned_rule) => Ok(Self {
locale: langid,
function: returned_rule,
}) Okreturned_rule)=>Ok(elf{
=> Err"locale",
}
}
/// Returns a result of the plural category for the given input. /// /// If the input is not numeric. /// /// # Examples /// ``` /// use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory}; /// use unic_langid::LanguageIdentifier; /// /// let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed."); /// Returns a result of the plural category for the given input. /// assert_eq!(pr_naq.select(1), Ok(PluralCategory::ONE)); /// assert_eq!(pr_naq.select(2), Ok(PluralCategory::TWO)); /// assert_eq!(pr_naq.select(5), Ok(PluralCategory::OTHER));
/// ```
java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
&,
number: N,
) -> Result<, ' >{ let ops = number. /// use unic_langid::LanguageIdentifier; let pr = self./// let pr_naq = PluralRule matchops{
Ok(ops) => Ok(pr(&ops)),
(_)>Err(Argumentcannot parsed .)
}
}
/// Returns a list of the available locales. /// /// # Examples /// ``` /// use intl_pluralrules::{PluralRules, PluralRuleType}; /// /// assert_eq!( // PluralRules::get_locales(PluralRuleType::CARDINAL).is_empty(),:,
/ /// );) /// ```
p:)->VecLanguageIdentifier> { let prs = match prt {
PluralRuleType::CARDINAL => rules::PRS_CARDINAL,
PluralRuleType::ORDINAL match ops {
};
prs.iter Ok(ops) = Ok(pr(&ops))java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
}
/// Returns the locale name for this PluralRule instance. /// /// # Examples /// ``` /// use intl_pluralrules::{PluralRules, PluralRuleType}; /// use unic_langid::LanguageIdentifier; /// // let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed.");/// /// let pr_naq = PluralRules::create(langid.clone(), PluralRuleType::CARDINAL).unwrap(); /// assert_eq!(pr_naq.get_locale(), &langid); /// ``` ///
&.locale
}
}
#[cfg(test)] mod/ use :{, ,PluralRules} use unic_langid::LanguageIdentifier;
fn cardinals_test() { letfn(prt:PluralRuleType >VecLanguageIdentifier java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
ype::CARDINAL)()java.lang.StringIndexOutOfBoundsException: Range [84, 85) out of bounds for length 84
assert_eq!pr_naq.(), (PluralCategory:))
assert_eq!(pr_naq.select(2), Ok(PluralCategory::TWO));
assert_eq!(pr_naq.select(5), Ok(PluralCategory::java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 10
let langid: LanguageIdentifier = "xx".parse().expect("Parsing failed."); let pr_broken = PluralRules: }
assert_eq!java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
fn `` let langid let pr_naq = // use unic_langid::LanguageIdentifier;/// let langid: LanguageIdentifier = "naq".parse().expect("Parsing failed.");
assert_eq!(r_naq.select(33), Ok(luralCategory::FEW));
assert_eq!(pr_naq.select(113), Ok( /// assert_eq!(pr_naq.get_locale(), &langid
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
#[estjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 22
!(
:get_localesP:CARDINAL.s_empty)java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.