CLDR Plural Rule Parser
Parses CLDR plural rules
Loading...
Searching...
No Matches
CLDRPluralRuleParser\Evaluator Class Reference

Parse and evaluate a plural rule. More...

Static Public Member Functions

static evaluate ( $number, array $rules)
 Evaluate a number against a set of plural rules.
 
static compile (array $rules)
 Convert a set of rules to a compiled form which is optimised for fast evaluation.
 
static evaluateCompiled ( $number, array $rules)
 Evaluate a compiled set of rules returned by compile().
 

Detailed Description

Member Function Documentation

◆ compile()

static CLDRPluralRuleParser\Evaluator::compile ( array  $rules)
static

Convert a set of rules to a compiled form which is optimised for fast evaluation.

The result will be an array of strings, and may be cached.

Parameters
array$rulesThe rules to compile
Returns
array An array of compile rules.

◆ evaluate()

static CLDRPluralRuleParser\Evaluator::evaluate (   $number,
array  $rules 
)
static

Evaluate a number against a set of plural rules.

If a rule passes, return the index of plural rule.

Parameters
int$numberThe number to be evaluated against the rules
array$rulesThe associative array of plural rules in pluralform => rule format.
Returns
int The index of the plural form which passed the evaluation

◆ evaluateCompiled()

static CLDRPluralRuleParser\Evaluator::evaluateCompiled (   $number,
array  $rules 
)
static

Evaluate a compiled set of rules returned by compile().

Do not allow the user to edit the compiled form, or else PHP errors may result.

Parameters
string | int$numberThe number to be evaluated against the rules, in English, or it may be a type convertible to string.
array$rulesThe associative array of plural rules in pluralform => rule format.
Returns
int The index of the plural form which passed the evaluation

The documentation for this class was generated from the following file: