MediaWiki  1.23.2
CLDRPluralRuleEvaluator Class Reference

Static Public Member Functions

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

Static Private Member Functions

static doOperation ( $token, $left, $right)
 Do a single operation. More...
 

Detailed Description

Definition at line 34 of file CLDRPluralRuleEvaluator.php.

Member Function Documentation

◆ compile()

static CLDRPluralRuleEvaluator::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.

Definition at line 55 of file CLDRPluralRuleEvaluator.php.

References as, and CLDRPluralRuleConverter\convert().

Referenced by evaluate(), and LocalisationCache\getCompiledPluralRules().

◆ doOperation()

static CLDRPluralRuleEvaluator::doOperation (   $token,
  $left,
  $right 
)
staticprivate

Do a single operation.

Parameters
string$tokenThe token string
mixed$leftThe left operand. If it is an object, its state may be destroyed.
mixed$rightThe right operand
Exceptions
CLDRPluralRuleError
Returns
mixed The operation result

Definition at line 140 of file CLDRPluralRuleEvaluator.php.

References $right, and array().

Referenced by evaluateCompiled().

◆ evaluate()

static CLDRPluralRuleEvaluator::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

Definition at line 43 of file CLDRPluralRuleEvaluator.php.

References compile(), and evaluateCompiled().

Referenced by CLDRPluralRuleEvaluatorTest\testInvalidRules(), and CLDRPluralRuleEvaluatorTest\testValidRules().

◆ evaluateCompiled()

static CLDRPluralRuleEvaluator::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$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

Definition at line 73 of file CLDRPluralRuleEvaluator.php.

References $right, array(), as, doOperation(), StringUtils\explode(), and wfDebug().

Referenced by evaluate(), and Language\getPluralRuleIndexNumber().


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