You appear to be a bot. Output may be restricted
Description
Parenthesize plural expression.
Legacy workaround for PHP's flipped precedence order for ternary.
Usage
$string = PluralFormsTest::parenthesize_plural_expression( $expression );
Parameters
- $expression
- ( string ) required – the expression without parentheses
Returns
string the expression with parentheses added
Source
File name: wordpress-develop-tests/phpunit/tests/pomo/pluralForms.php
Lines:
1 to 24 of 24
protected static function parenthesize_plural_expression( $expression ) { $expression .= ';'; $res = ''; $depth = 0; for ( $i = 0; $i < strlen( $expression ); ++$i ) { $char = $expression[ $i ]; switch ( $char ) { case '?': $res .= ' ? ('; $depth++; break; case ':': $res .= ') : ('; break; case ';': $res .= str_repeat( ')', $depth ) . ';'; $depth = 0; break; default: $res .= $char; } } return rtrim( $res, ';' ); }