Use %1.15e for double strings, fix base handling.
This commit is contained in:
parent
7941387631
commit
28e8502122
1 changed files with 28 additions and 4 deletions
32
jsonld.php
32
jsonld.php
|
@ -1478,9 +1478,9 @@ class JsonLdProcessor {
|
||||||
}
|
}
|
||||||
// convert double to @value
|
// convert double to @value
|
||||||
else if(is_double($o)) {
|
else if(is_double($o)) {
|
||||||
// do special JSON-LD double format, printf('%1.16e') equivalent
|
// do special JSON-LD double format, printf('%1.15e') equivalent
|
||||||
$o = preg_replace('/(e(?:\+|-))([0-9])$/', '${1}0${2}',
|
$o = preg_replace('/(e(?:\+|-))([0-9])$/', '${1}0${2}',
|
||||||
sprintf('%1.16e', $o));
|
sprintf('%1.15e', $o));
|
||||||
$o = (object)array('@value' => $o, '@type' => self::XSD_DOUBLE);
|
$o = (object)array('@value' => $o, '@type' => self::XSD_DOUBLE);
|
||||||
}
|
}
|
||||||
// convert integer to @value
|
// convert integer to @value
|
||||||
|
@ -2832,7 +2832,7 @@ class JsonLdProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepend base
|
// prepend base
|
||||||
$value = "$base$value";
|
$value = $this->_prependBase($base, $value);
|
||||||
|
|
||||||
// value must now be an absolute IRI
|
// value must now be an absolute IRI
|
||||||
if(!self::_isAbsoluteIri($value)) {
|
if(!self::_isAbsoluteIri($value)) {
|
||||||
|
@ -2897,7 +2897,7 @@ class JsonLdProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepend base to term
|
// prepend base to term
|
||||||
return "$base$term";
|
return $this->_prependBase($base, $term);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3022,6 +3022,30 @@ class JsonLdProcessor {
|
||||||
return $findUrls($input, true);
|
return $findUrls($input, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepends a base IRI to the given relative IRI.
|
||||||
|
*
|
||||||
|
* @param string $base the base IRI.
|
||||||
|
* @param string $iri the relative IRI.
|
||||||
|
*
|
||||||
|
* @return string the absolute IRI.
|
||||||
|
*/
|
||||||
|
protected function _prependBase($base, $iri) {
|
||||||
|
if($iri === '' || strpos($iri, '#') === 0) {
|
||||||
|
return "$base$iri";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// prepend last directory for base
|
||||||
|
$idx = strrpos($base, '/');
|
||||||
|
if($idx === false) {
|
||||||
|
return $iri;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return substr($base, 0, $idx + 1) . $iri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the initial context.
|
* Gets the initial context.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue