MediaWiki
REL1_24
|
00001 <?php 00015 class CLDRPluralRuleEvaluatorRange { 00021 public $parts = array(); 00022 00029 function __construct( $start, $end = false ) { 00030 if ( $end === false ) { 00031 $this->parts[] = $start; 00032 } else { 00033 $this->parts[] = array( $start, $end ); 00034 } 00035 } 00036 00045 function isNumberIn( $number, $integerConstraint = true ) { 00046 foreach ( $this->parts as $part ) { 00047 if ( is_array( $part ) ) { 00048 if ( ( !$integerConstraint || floor( $number ) === (float)$number ) 00049 && $number >= $part[0] && $number <= $part[1] 00050 ) { 00051 return true; 00052 } 00053 } else { 00054 if ( $number == $part ) { 00055 return true; 00056 } 00057 } 00058 } 00059 00060 return false; 00061 } 00062 00070 function isNumberWithin( $number ) { 00071 return $this->isNumberIn( $number, false ); 00072 } 00073 00080 function add( $other ) { 00081 if ( $other instanceof self ) { 00082 $this->parts = array_merge( $this->parts, $other->parts ); 00083 } else { 00084 $this->parts[] = $other; 00085 } 00086 } 00087 00094 function __toString() { 00095 $s = 'Range('; 00096 foreach ( $this->parts as $i => $part ) { 00097 if ( $i ) { 00098 $s .= ', '; 00099 } 00100 if ( is_array( $part ) ) { 00101 $s .= $part[0] . '..' . $part[1]; 00102 } else { 00103 $s .= $part; 00104 } 00105 } 00106 $s .= ')'; 00107 00108 return $s; 00109 } 00110 }