icu::plurals::provider::rules::reference

Function parse

Source
pub fn parse(input: &[u8]) -> Result<Rule, ParseError>
Expand description

Unicode Plural Rule parser converts an input string into a Rule AST.

A single Rule contains a Condition and optionally a set of Samples.

A Condition can be then used by the test_condition to test against PluralOperands, to find the appropriate PluralCategory.

Samples are useful for tooling to help translators understand examples of numbers covered by the given Rule.

At runtime, only the Condition is used and for that, consider using parse_condition.

🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, including in SemVer minor releases. In particular, the `DataProvider` implementations are only guaranteed to match with this version's `*_unstable` providers. Use with caution.

§Examples

use icu::plurals::provider::rules::reference::parse;

let input = b"i = 0 or n = 1 @integer 0, 1 @decimal 0.0~1.0, 0.00~0.04";
assert!(parse(input).is_ok());