Adds parentheses to the inner parts of ternary operators in plural expressions, because PHP evaluates ternary operators from left to right
Description
See also
Parameters
$expression
stringrequired- the expression without parentheses
Source
public function parenthesize_plural_exression( $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, ';' );
}
Changelog
Version | Description |
---|---|
6.5.0 | Use the Plural_Forms class instead. |
2.8.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.