Source for file Number.php

Documentation is available at Number.php

  1. <?php
  2.  
  3. /**
  4.  * Validates a number as defined by the CSS spec.
  5.  */
  6. {
  7.     
  8.     /**
  9.      * Bool indicating whether or not only positive values allowed.
  10.      */
  11.     protected $non_negative = false;
  12.     
  13.     /**
  14.      * @param $non_negative Bool indicating whether negatives are forbidden
  15.      */
  16.     public function __construct($non_negative false{
  17.         $this->non_negative = $non_negative;
  18.     }
  19.     
  20.     /**
  21.      * @warning Some contexts do not pass $config, $context. These
  22.      *           variables should not be used without checking HTMLPurifier_Length
  23.      */
  24.     public function validate($number$config$context{
  25.         
  26.         $number $this->parseCDATA($number);
  27.         
  28.         if ($number === ''return false;
  29.         if ($number === '0'return '0';
  30.         
  31.         $sign '';
  32.         switch ($number[0]{
  33.             case '-':
  34.                 if ($this->non_negativereturn false;
  35.                 $sign '-';
  36.             case '+':
  37.                 $number substr($number1);
  38.         }
  39.         
  40.         if (ctype_digit($number)) {
  41.             $number ltrim($number'0');
  42.             return $number $sign $number '0';
  43.         }
  44.         
  45.         // Period is the only non-numeric character allowed
  46.         if (strpos($number'.'=== falsereturn false;
  47.         
  48.         list($left$rightexplode('.'$number2);
  49.         
  50.         if ($left === '' && $right === ''return false;
  51.         if ($left !== '' && !ctype_digit($left)) return false;
  52.         
  53.         $left  ltrim($left,  '0');
  54.         $right rtrim($right'0');
  55.         
  56.         if ($right === ''{
  57.             return $left $sign $left '0';
  58.         elseif (!ctype_digit($right)) {
  59.             return false;
  60.         }
  61.         
  62.         return $sign $left '.' $right;
  63.         
  64.     }
  65.     
  66. }

Documentation generated on Thu, 19 Jun 2008 18:49:50 -0400 by phpDocumentor 1.4.2