You are here

public static function EasyRdf_Literal_Decimal::canonicalise in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Decimal.php \EasyRdf_Literal_Decimal::canonicalise()

Converts valid xsd:decimal literal to Canonical representation see http://www.w3.org/TR/xmlschema-2/#decimal

Parameters

string $value Valid xsd:decimal literal:

Return value

string

1 call to EasyRdf_Literal_Decimal::canonicalise()
EasyRdf_Literal_Decimal::__construct in vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Decimal.php
Constructor for creating a new decimal literal

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Decimal.php, line 107

Class

EasyRdf_Literal_Decimal
Class that represents an RDF Literal of datatype xsd:decimal

Code

public static function canonicalise($value) {
  $pieces = array();
  mb_ereg(self::DECIMAL_REGEX, $value, $pieces);
  $sign = $pieces[1] === '-' ? '-' : '';

  // '+' is not allowed
  $integer = ltrim($pieces[4] !== false ? $pieces[4] : $pieces[7], '0');
  $fractional = rtrim($pieces[5], '0');
  if (empty($integer)) {
    $integer = '0';
  }
  if (empty($fractional)) {
    $fractional = '0';
  }
  return "{$sign}{$integer}.{$fractional}";
}