protected function parseRule($rule)
    {
        $parsedRule = [];

        if (preg_match_all(self::PATTERN_MATCH_SUBRULE, strtolower(str_replace(' ', '', $rule)), $matches, \PREG_SET_ORDER)) {
            foreach ($matches as $matchedSubrule) {
                $subrule = [];

                if ($matchedSubrule[1] === 'nmod') {
                    $subrule['modulo'] = (int)$matchedSubrule[2];
                } else {
                    $subrule['modulo'] = false;
                }

                $condition = [$matchedSubrule[3], (int)$matchedSubrule[4]];
                if (!in_array($matchedSubrule[3], ['is', 'isnot'], true)) {
                    $condition[2] = (int)$matchedSubrule[5];
                }

                $subrule['condition'] = $condition;

                if (isset($matchedSubrule[6]) && ($matchedSubrule[6] === 'and' || $matchedSubrule[6] === 'or')) {
                    $subrule['logicalOperator'] = $matchedSubrule[6];
                } else {
                    $subrule['logicalOperator'] = false;
                }

                $parsedRule[] = $subrule;
            }
        } else {
            throw new Exception\InvalidPluralRuleException('A plural rule string is invalid. CLDR files might be corrupted.', 1275493982);
        }

        return $parsedRule;
    }
protected function parseRule($rule)
    {
        $parsedRule = [];

        if (preg_match_all(self::PATTERN_MATCH_SUBRULE, strtolower(str_replace(' ', '', $rule)), $matches, \PREG_SET_ORDER)) {
            foreach ($matches as $matchedSubrule) {
                $subrule = [];

                if ($matchedSubrule[1] === 'nmod') {
                    $subrule['modulo'] = (int)$matchedSubrule[2];
                } else {
                    $subrule['modulo'] = false;
                }

                $condition = [$matchedSubrule[3], (int)$matchedSubrule[4]];
                if (!in_array($matchedSubrule[3], ['is', 'isnot'], true)) {
                    $condition[2] = (int)$matchedSubrule[5];
                }

                $subrule['condition'] = $condition;

                if (isset($matchedSubrule[6]) && ($matchedSubrule[6] === 'and' || $matchedSubrule[6] === 'or')) {
                    $subrule['logicalOperator'] = $matchedSubrule[6];
                } else {
                    $subrule['logicalOperator'] = false;
                }

                $parsedRule[] = $subrule;
            }
        } else {
            throw new Exception\InvalidPluralRuleException('A plural rule string is invalid. CLDR files might be corrupted.', 1275493982);
        }

        return $parsedRule;
    }
protected function parseRule ( $ rule ) { $ parsedRule = [ ] ; if ( preg_match_all ( self :: PATTERN_MATCH_SUBRULE , strtolower ( str_replace ( ' ' , '' , $ rule ) ) , $ matches , \ PREG_SET_ORDER ) ) { foreach ( $ matches as $ matchedSubrule ) { $ subrule = [ ] ; if ( $ matchedSubrule [ 1 ] === 'nmod' ) { $ subrule [ 'modulo' ] = ( int ) $ matchedSubrule [ 2 ] ; } else { $ subrule [ 'modulo' ] = false ; } $ condition = [ $ matchedSubrule [ 3 ] , ( int ) $ matchedSubrule [ 4 ] ] ; if ( ! in_array ( $ matchedSubrule [ 3 ] , [ 'is' , 'isnot' ] , true ) ) { $ condition [ 2 ] = ( int ) $ matchedSubrule [ 5 ] ; } $ subrule [ 'condition' ] = $ condition ; if ( isset ( $ matchedSubrule [ 6 ] ) && ( $ matchedSubrule [ 6 ] === 'and' || $ matchedSubrule [ 6 ] === 'or' ) ) { $ subrule [ 'logicalOperator' ] = $ matchedSubrule [ 6 ] ; } else { $ subrule [ 'logicalOperator' ] = false ; } $ parsedRule [ ] = $ subrule ; } } else { throw new Exception \ InvalidPluralRuleException ( 'A plural rule string is invalid. CLDR files might be corrupted.' , 1275493982 ) ; } return $ parsedRule ; }
Parses a plural rule from CLDR.

A plural rule in CLDR is a string with one or more test conditions, with
'and' or 'or' logical operators between them. Whole expression can look
like this:

n is 0 OR n is not 1 AND n mod 100 in 1..19

As CLDR documentation says, following test conditions can be used:
- is x, is not x: $n is (not) equal $x
- in x..y, not in x..y: $n is (not) one of integers from range <$x, $y>
- within x..y, not within x..y: $n is (not) any number from range <$x, $y>

Where $n can be a number (also float) as is, or a result of $n mod $x.

Array returned follows simple internal format (see documentation for
$rulesets property for details).

@param string $rule
@return array Parsed rule
@throws Exception\InvalidPluralRuleException When plural rule does not match regexp pattern
Parses a plural rule from CLDR .