public $mRuleTitle = false;
public $mRules = '';// string : the text of the rules
public $mRulesAction = 'none';
- public $mFlags = array();
- public $mVariantFlags = array();
- public $mConvTable = array();
- public $mBidtable = array();// array of the translation in each variant
- public $mUnidtable = array();// array of the translation in each variant
+ public $mFlags = [];
+ public $mVariantFlags = [];
+ public $mConvTable = [];
+ public $mBidtable = [];// array of the translation in each variant
+ public $mUnidtable = [];// array of the translation in each variant
/**
* Constructor
*/
function parseFlags() {
$text = $this->mText;
- $flags = array();
- $variantFlags = array();
+ $flags = [];
+ $variantFlags = [];
$sepPos = strpos( $text, '|' );
if ( $sepPos !== false ) {
if ( !$flags ) {
$flags['S'] = true;
} elseif ( isset( $flags['R'] ) ) {
- $flags = array( 'R' => true );// remove other flags
+ $flags = [ 'R' => true ];// remove other flags
} elseif ( isset( $flags['N'] ) ) {
- $flags = array( 'N' => true );// remove other flags
+ $flags = [ 'N' => true ];// remove other flags
} elseif ( isset( $flags['-'] ) ) {
- $flags = array( '-' => true );// remove other flags
+ $flags = [ '-' => true ];// remove other flags
} elseif ( count( $flags ) == 1 && isset( $flags['T'] ) ) {
$flags['H'] = true;
} elseif ( isset( $flags['H'] ) ) {
// replace A flag, and remove other flags except T
- $temp = array( '+' => true, 'H' => true );
+ $temp = [ '+' => true, 'H' => true ];
if ( isset( $flags['T'] ) ) {
$temp['T'] = true;
}
$variantFlags = array_intersect( array_keys( $flags ), $this->mConverter->mVariants );
if ( $variantFlags ) {
$variantFlags = array_flip( $variantFlags );
- $flags = array();
+ $flags = [];
}
}
$this->mVariantFlags = $variantFlags;
*/
function parseRules() {
$rules = $this->mRules;
- $bidtable = array();
- $unidtable = array();
+ $bidtable = [];
+ $unidtable = [];
$variants = $this->mConverter->mVariants;
$varsep_pattern = $this->mConverter->getVarSeparatorPattern();
$to = trim( $v[1] );
$v = trim( $v[0] );
$u = explode( '=>', $v, 2 );
- // if $to is empty, strtr() could return a wrong result
- if ( count( $u ) == 1 && $to && in_array( $v, $variants ) ) {
+ // if $to is empty (which is also used as $from in bidtable),
+ // strtr() could return a wrong result.
+ if ( count( $u ) == 1 && $to !== '' && in_array( $v, $variants ) ) {
$bidtable[$v] = $to;
} elseif ( count( $u ) == 2 ) {
$from = trim( $u[0] );
$v = trim( $u[1] );
+ // if $from is empty, strtr() could return a wrong result.
if ( array_key_exists( $v, $unidtable )
&& !is_array( $unidtable[$v] )
- && $to
+ && $from !== ''
&& in_array( $v, $variants ) ) {
- $unidtable[$v] = array( $from => $to );
- } elseif ( $to && in_array( $v, $variants ) ) {
+ $unidtable[$v] = [ $from => $to ];
+ } elseif ( $from !== '' && in_array( $v, $variants ) ) {
$unidtable[$v][$from] = $to;
}
}
// syntax error, pass
if ( !isset( $this->mConverter->mVariantNames[$v] ) ) {
- $bidtable = array();
- $unidtable = array();
+ $bidtable = [];
+ $unidtable = [];
break;
}
}
// display current variant in bidirectional array
$disp = $this->getTextInBidtable( $variant );
// or display current variant in fallbacks
- if ( !$disp ) {
+ if ( $disp === false ) {
$disp = $this->getTextInBidtable(
$this->mConverter->getVariantFallbacks( $variant ) );
}
// or display current variant in unidirectional array
- if ( !$disp && array_key_exists( $variant, $unidtable ) ) {
- $disp = array_values( $unidtable[$variant] );
- $disp = $disp[0];
+ if ( $disp === false && array_key_exists( $variant, $unidtable ) ) {
+ $disp = array_values( $unidtable[$variant] )[0];
}
// or display frist text under disable manual convert
- if ( !$disp && $this->mConverter->mManualLevel[$variant] == 'disable' ) {
+ if ( $disp === false && $this->mConverter->mManualLevel[$variant] == 'disable' ) {
if ( count( $bidtable ) > 0 ) {
- $disp = array_values( $bidtable );
- $disp = $disp[0];
+ $disp = array_values( $bidtable )[0];
} else {
- $disp = array_values( $unidtable );
- $disp = array_values( $disp[0] );
- $disp = $disp[0];
+ $disp = array_values( array_values( $unidtable )[0] )[0];
}
}
return $disp;
return $disp;
}
if ( array_key_exists( $variant, $this->mUnidtable ) ) {
- $disp = array_values( $this->mUnidtable[$variant] );
- $disp = $disp[0];
+ $disp = array_values( $this->mUnidtable[$variant] )[0];
}
// Assigned above or still false.
return $disp;
function generateConvTable() {
// Special case optimisation
if ( !$this->mBidtable && !$this->mUnidtable ) {
- $this->mConvTable = array();
+ $this->mConvTable = [];
return;
}
$unidtable = $this->mUnidtable;
$manLevel = $this->mConverter->mManualLevel;
- $vmarked = array();
+ $vmarked = [];
foreach ( $this->mConverter->mVariants as $v ) {
/* for bidirectional array
fill in the missing variants, if any,
&& isset( $unidtable[$v] )
) {
if ( isset( $this->mConvTable[$v] ) ) {
- $this->mConvTable[$v] = array_merge( $this->mConvTable[$v], $unidtable[$v] );
+ $this->mConvTable[$v] = $unidtable[$v] + $this->mConvTable[$v];
} else {
$this->mConvTable[$v] = $unidtable[$v];
}
}
}
}
- $this->mFlags = $flags = array( 'R' => true );
+ $this->mFlags = $flags = [ 'R' => true ];
}
if ( !isset( $flags['R'] ) && !isset( $flags['N'] ) ) {
if ( !$this->mBidtable && !$this->mUnidtable ) {
if ( isset( $flags['+'] ) || isset( $flags['-'] ) ) {
- // fill all variants if text in -{A/H/-|text} without rules
- foreach ( $this->mConverter->mVariants as $v ) {
- $this->mBidtable[$v] = $rules;
+ // fill all variants if text in -{A/H/-|text}- is non-empty but without rules
+ if ( $rules !== '' ) {
+ foreach ( $this->mConverter->mVariants as $v ) {
+ $this->mBidtable[$v] = $rules;
+ }
}
} elseif ( !isset( $flags['N'] ) && !isset( $flags['T'] ) ) {
- $this->mFlags = $flags = array( 'R' => true );
+ $this->mFlags = $flags = [ 'R' => true ];
}
}