Update formatting for languages/utils/
Change-Id: I54a19cff97067b71cb6531bc37802adb2d6c52ba
This commit is contained in:
parent
603a35fc4e
commit
54d2e28226
7 changed files with 21 additions and 10 deletions
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author Niklas Laxström, Tim Starling
|
||||
*
|
||||
|
|
@ -97,6 +96,7 @@ class CLDRPluralRuleConverter {
|
|||
*/
|
||||
public static function convert( $rule ) {
|
||||
$parser = new self( $rule );
|
||||
|
||||
return $parser->doConvert();
|
||||
}
|
||||
|
||||
|
|
@ -192,6 +192,7 @@ class CLDRPluralRuleConverter {
|
|||
if ( $length !== 0 ) {
|
||||
$token = $this->newNumber( substr( $this->rule, $this->pos, $length ), $this->pos );
|
||||
$this->pos += $length;
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
|
@ -200,6 +201,7 @@ class CLDRPluralRuleConverter {
|
|||
if ( $op2 === '..' || $op2 === '!=' ) {
|
||||
$token = $this->newOperator( $op2, $this->pos, 2 );
|
||||
$this->pos += 2;
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +209,8 @@ class CLDRPluralRuleConverter {
|
|||
$op1 = $this->rule[$this->pos];
|
||||
if ( $op1 === ',' || $op1 === '=' || $op1 === '%' ) {
|
||||
$token = $this->newOperator( $op1, $this->pos, 1 );
|
||||
$this->pos ++;
|
||||
$this->pos++;
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
|
@ -235,6 +238,7 @@ class CLDRPluralRuleConverter {
|
|||
if ( isset( self::$precedence[$bothWords] ) ) {
|
||||
$token = $this->newOperator( $bothWords, $this->pos, $nextTokenPos - $this->pos );
|
||||
$this->pos = $nextTokenPos;
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
|
|
@ -243,13 +247,15 @@ class CLDRPluralRuleConverter {
|
|||
if ( isset( self::$precedence[$word1] ) ) {
|
||||
$token = $this->newOperator( $word1, $this->pos, strlen( $word1 ) );
|
||||
$this->pos += strlen( $word1 );
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
// The single-character operand symbols
|
||||
if ( strpos( self::OPERAND_SYMBOLS, $word1 ) !== false ) {
|
||||
$token = $this->newNumber( $word1, $this->pos );
|
||||
$this->pos ++;
|
||||
$this->pos++;
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
|
@ -258,6 +264,7 @@ class CLDRPluralRuleConverter {
|
|||
// Samples are like comments, they have no effect on rule evaluation.
|
||||
// They run from the first sample indicator to the end of the string.
|
||||
$this->pos = $this->end;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author Niklas Laxström, Tim Starling
|
||||
*
|
||||
|
|
@ -36,6 +35,7 @@ class CLDRPluralRuleConverterExpression extends CLDRPluralRuleConverterFragment
|
|||
if ( $type === $this->type ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author Niklas Laxström, Tim Starling
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author Niklas Laxström, Tim Starling
|
||||
*
|
||||
|
|
@ -109,6 +108,7 @@ class CLDRPluralRuleConverterOperator extends CLDRPluralRuleConverterFragment {
|
|||
if ( !$right->isType( $rightType ) ) {
|
||||
$newExpr->error( "invalid type for right operand: expected $rightType, got {$right->type}" );
|
||||
}
|
||||
|
||||
return $newExpr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @author Niklas Laxström, Tim Starling
|
||||
*
|
||||
|
|
@ -18,4 +17,4 @@ class CLDRPluralRuleError extends MWException {
|
|||
function __construct( $message ) {
|
||||
parent::__construct( 'CLDR plural rule error: ' . $message );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Parse and evaluate a plural rule.
|
||||
*
|
||||
|
|
@ -30,7 +31,6 @@
|
|||
* @file
|
||||
* @since 1.20
|
||||
*/
|
||||
|
||||
class CLDRPluralRuleEvaluator {
|
||||
/**
|
||||
* Evaluate a number against a set of plural rules. If a rule passes,
|
||||
|
|
@ -42,6 +42,7 @@ class CLDRPluralRuleEvaluator {
|
|||
*/
|
||||
public static function evaluate( $number, array $rules ) {
|
||||
$rules = self::compile( $rules );
|
||||
|
||||
return self::evaluateCompiled( $number, $rules );
|
||||
}
|
||||
|
||||
|
|
@ -58,6 +59,7 @@ class CLDRPluralRuleEvaluator {
|
|||
foreach ( $rules as &$rule ) {
|
||||
$rule = CLDRPluralRuleConverter::convert( $rule );
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +77,7 @@ class CLDRPluralRuleEvaluator {
|
|||
$number = strval( $number );
|
||||
if ( !preg_match( '/^ -? ( ([0-9]+) (?: \. ([0-9]+) )? )$/x', $number, $m ) ) {
|
||||
wfDebug( __METHOD__ . ": invalid number input, returning 'other'\n" );
|
||||
|
||||
return count( $rules );
|
||||
}
|
||||
if ( !isset( $m[3] ) ) {
|
||||
|
|
@ -164,6 +167,7 @@ class CLDRPluralRuleEvaluator {
|
|||
if ( is_int( $left ) ) {
|
||||
return (int)fmod( $left, $right );
|
||||
}
|
||||
|
||||
return fmod( $left, $right );
|
||||
case ',':
|
||||
if ( $left instanceof CLDRPluralRuleEvaluatorRange ) {
|
||||
|
|
@ -172,6 +176,7 @@ class CLDRPluralRuleEvaluator {
|
|||
$range = new CLDRPluralRuleEvaluatorRange( $left );
|
||||
}
|
||||
$range->add( $right );
|
||||
|
||||
return $range;
|
||||
case '..':
|
||||
return new CLDRPluralRuleEvaluatorRange( $left, $right );
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class CLDRPluralRuleEvaluatorRange {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +103,7 @@ class CLDRPluralRuleEvaluatorRange {
|
|||
}
|
||||
}
|
||||
$s .= ')';
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue