ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_Length Class Reference

Represents a measurable length, with a string numeric magnitude and a unit. More...

+ Collaboration diagram for HTMLPurifier_Length:

Public Member Functions

 __construct ($n= '0', $u=false)
 toString ()
 Returns string representation of number.
 getN ()
 Retrieves string numeric magnitude.
 getUnit ()
 Retrieves string unit.
 isValid ()
 Returns true if this length unit is valid.
 compareTo ($l)
 Compares two lengths, and returns 1 if greater, -1 if less and 0 if equal.

Static Public Member Functions

static make ($s)

Protected Member Functions

 validate ()
 Validates the number and unit.

Protected Attributes

 $n
 String numeric magnitude.
 $unit
 String unit.
 $isValid
 Whether or not this length is valid.

Static Protected Attributes

static $allowedUnits
 Lookup array of units recognized by CSS 2.1.

Detailed Description

Represents a measurable length, with a string numeric magnitude and a unit.

This object is immutable.

Definition at line 7 of file Length.php.

Constructor & Destructor Documentation

HTMLPurifier_Length::__construct (   $n = '0',
  $u = false 
)
Parameters
number$nMagnitude
string$uUnit

Definition at line 37 of file Length.php.

References $n, and n.

{
$this->n = (string) $n;
$this->unit = $u !== false ? (string) $u : false;
}

Member Function Documentation

HTMLPurifier_Length::compareTo (   $l)

Compares two lengths, and returns 1 if greater, -1 if less and 0 if equal.

Warning
If both values are too large or small, this calculation will not work properly

Definition at line 103 of file Length.php.

References n.

{
if ($l === false) return false;
if ($l->unit !== $this->unit) {
$converter = new HTMLPurifier_UnitConverter();
$l = $converter->convert($l, $this->unit);
if ($l === false) return false;
}
return $this->n - $l->n;
}
HTMLPurifier_Length::getN ( )

Retrieves string numeric magnitude.

Definition at line 83 of file Length.php.

References $n.

{return $this->n;}
HTMLPurifier_Length::getUnit ( )

Retrieves string unit.

Definition at line 88 of file Length.php.

References $unit.

{return $this->unit;}
HTMLPurifier_Length::isValid ( )

Returns true if this length unit is valid.

Definition at line 93 of file Length.php.

References $isValid, and validate().

Referenced by toString().

{
if ($this->isValid === null) $this->isValid = $this->validate();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static HTMLPurifier_Length::make (   $s)
static
Parameters
string$sUnit string, like '2em' or '3.4in'
Warning
Does not perform validation.

Definition at line 46 of file Length.php.

References $n, and $unit.

{
if ($s instanceof HTMLPurifier_Length) return $s;
$n_length = strspn($s, '1234567890.+-');
$n = substr($s, 0, $n_length);
$unit = substr($s, $n_length);
if ($unit === '') $unit = false;
return new HTMLPurifier_Length($n, $unit);
}
HTMLPurifier_Length::toString ( )

Returns string representation of number.

Definition at line 75 of file Length.php.

References $unit, isValid(), and n.

{
if (!$this->isValid()) return false;
return $this->n . $this->unit;
}

+ Here is the call graph for this function:

HTMLPurifier_Length::validate ( )
protected

Validates the number and unit.

Definition at line 58 of file Length.php.

References $allowedUnits, $result, and n.

Referenced by isValid().

{
// Special case:
if ($this->n === '+0' || $this->n === '-0') $this->n = '0';
if ($this->n === '0' && $this->unit === false) return true;
if (!ctype_lower($this->unit)) $this->unit = strtolower($this->unit);
if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) return false;
// Hack:
$result = $def->validate($this->n, false, false);
if ($result === false) return false;
$this->n = $result;
return true;
}

+ Here is the caller graph for this function:

Field Documentation

HTMLPurifier_Length::$allowedUnits
staticprotected
Initial value:
array(
'em' => true, 'ex' => true, 'px' => true, 'in' => true,
'cm' => true, 'mm' => true, 'pt' => true, 'pc' => true
)

Lookup array of units recognized by CSS 2.1.

Definition at line 28 of file Length.php.

Referenced by validate().

HTMLPurifier_Length::$isValid
protected

Whether or not this length is valid.

Null if not calculated yet.

Definition at line 23 of file Length.php.

Referenced by isValid().

HTMLPurifier_Length::$n
protected

String numeric magnitude.

Definition at line 13 of file Length.php.

Referenced by __construct(), getN(), and make().

HTMLPurifier_Length::$unit
protected

String unit.

False is permitted if $n = 0.

Definition at line 18 of file Length.php.

Referenced by getUnit(), make(), and toString().


The documentation for this class was generated from the following file: