ILIAS  Release_5_0_x_branch Revision 61816
 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
 Array Lookup array of units recognized by CSS 2.1 array.

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
string$nMagnitude
bool | string$uUnit

Definition at line 41 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.

Parameters
HTMLPurifier_Length$l
Returns
int
Warning
If both values are too large or small, this calculation will not work properly

Definition at line 144 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.

Returns
string

Definition at line 111 of file Length.php.

References $n.

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

Retrieves string unit.

Returns
string

Definition at line 120 of file Length.php.

References $unit.

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

Returns true if this length unit is valid.

Returns
bool

Definition at line 129 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'
Returns
HTMLPurifier_Length
Warning
Does not perform validation.

Definition at line 52 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.

Returns
string

Definition at line 99 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.

Returns
bool

Definition at line 70 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
)

Array Lookup array of units recognized by CSS 2.1 array.

Definition at line 32 of file Length.php.

Referenced by validate().

HTMLPurifier_Length::$isValid
protected

Whether or not this length is valid.

Null if not calculated yet. bool

Definition at line 26 of file Length.php.

Referenced by isValid().

HTMLPurifier_Length::$n
protected

String numeric magnitude.

string

Definition at line 14 of file Length.php.

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

HTMLPurifier_Length::$unit
protected

String unit.

False is permitted if $n = 0. string|bool

Definition at line 20 of file Length.php.

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


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