value); } /** * @param string $value * * @throws UnexpectedValueException */ public static function validate($value) { if (!mb_ereg_match(self::DECIMAL_REGEX, $value)) { throw new UnexpectedValueException("'{$value}' doesn't look like a valid decimal"); } } /** * Converts valid xsd:decimal literal to Canonical representation * see http://www.w3.org/TR/xmlschema-2/#decimal * * @param string $value Valid xsd:decimal literal * * @return string */ 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}"; } }