MediaWiki  REL1_23
CLDRPluralRuleEvaluator_Range.php
Go to the documentation of this file.
00001 <?php
00015 class CLDRPluralRuleEvaluator_Range {
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 
00044     function isNumberIn( $number, $integerConstraint = true ) {
00045         foreach ( $this->parts as $part ) {
00046             if ( is_array( $part ) ) {
00047                 if ( ( !$integerConstraint || floor( $number ) === (float)$number )
00048                     && $number >= $part[0] && $number <= $part[1]
00049                 ) {
00050                     return true;
00051                 }
00052             } else {
00053                 if ( $number == $part ) {
00054                     return true;
00055                 }
00056             }
00057         }
00058         return false;
00059     }
00060 
00068     function isNumberWithin( $number ) {
00069         return $this->isNumberIn( $number, false );
00070     }
00071 
00078     function add( $other ) {
00079         if ( $other instanceof self ) {
00080             $this->parts = array_merge( $this->parts, $other->parts );
00081         } else {
00082             $this->parts[] = $other;
00083         }
00084     }
00085 
00092     function __toString() {
00093         $s = 'Range(';
00094         foreach ( $this->parts as $i => $part ) {
00095             if ( $i ) {
00096                 $s .= ', ';
00097             }
00098             if ( is_array( $part ) ) {
00099                 $s .= $part[0] . '..' . $part[1];
00100             } else {
00101                 $s .= $part;
00102             }
00103         }
00104         $s .= ')';
00105         return $s;
00106     }
00107 
00108 }