updated-packages
This commit is contained in:
@@ -16,7 +16,7 @@ class DNumber extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(float $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,17 @@ class DNumber extends Scalar
|
||||
return ['value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $attributes
|
||||
*/
|
||||
public static function fromString(string $str, array $attributes = []): DNumber
|
||||
{
|
||||
$attributes['rawValue'] = $str;
|
||||
$float = self::parse($str);
|
||||
|
||||
return new DNumber($float, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
@@ -34,13 +45,9 @@ class DNumber extends Scalar
|
||||
* @return float The parsed number
|
||||
*/
|
||||
public static function parse(string $str) : float {
|
||||
// if string contains any of .eE just cast it to float
|
||||
if (false !== strpbrk($str, '.eE')) {
|
||||
return (float) $str;
|
||||
}
|
||||
$str = str_replace('_', '', $str);
|
||||
|
||||
// otherwise it's an integer notation that overflowed into a float
|
||||
// if it starts with 0 it's one of the special integer notations
|
||||
// Check whether this is one of the special integer notations.
|
||||
if ('0' === $str[0]) {
|
||||
// hex
|
||||
if ('x' === $str[1] || 'X' === $str[1]) {
|
||||
@@ -52,16 +59,18 @@ class DNumber extends Scalar
|
||||
return bindec($str);
|
||||
}
|
||||
|
||||
// oct
|
||||
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
|
||||
// so that only the digits before that are used
|
||||
return octdec(substr($str, 0, strcspn($str, '89')));
|
||||
// oct, but only if the string does not contain any of '.eE'.
|
||||
if (false === strpbrk($str, '.eE')) {
|
||||
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit
|
||||
// (8 or 9) so that only the digits before that are used.
|
||||
return octdec(substr($str, 0, strcspn($str, '89')));
|
||||
}
|
||||
}
|
||||
|
||||
// dec
|
||||
return (float) $str;
|
||||
}
|
||||
|
||||
|
||||
public function getType() : string {
|
||||
return 'Scalar_DNumber';
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ class Encapsed extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $parts, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->parts = $parts;
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,7 @@ class EncapsedStringPart extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(string $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
@@ -23,7 +23,7 @@ class LNumber extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(int $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ class LNumber extends Scalar
|
||||
* @return LNumber The constructed LNumber, including kind attribute
|
||||
*/
|
||||
public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber {
|
||||
$attributes['rawValue'] = $str;
|
||||
|
||||
$str = str_replace('_', '', $str);
|
||||
|
||||
if ('0' !== $str[0] || '0' === $str) {
|
||||
$attributes['kind'] = LNumber::KIND_DEC;
|
||||
return new LNumber((int) $str, $attributes);
|
||||
@@ -60,11 +64,16 @@ class LNumber extends Scalar
|
||||
throw new Error('Invalid numeric literal', $attributes);
|
||||
}
|
||||
|
||||
// Strip optional explicit octal prefix.
|
||||
if ('o' === $str[1] || 'O' === $str[1]) {
|
||||
$str = substr($str, 2);
|
||||
}
|
||||
|
||||
// use intval instead of octdec to get proper cutting behavior with malformed numbers
|
||||
$attributes['kind'] = LNumber::KIND_OCT;
|
||||
return new LNumber(intval($str, 8), $attributes);
|
||||
}
|
||||
|
||||
|
||||
public function getType() : string {
|
||||
return 'Scalar_LNumber';
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ abstract class MagicConst extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
|
@@ -34,7 +34,7 @@ class String_ extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(string $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,22 @@ class String_ extends Scalar
|
||||
return ['value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
|
||||
*/
|
||||
public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self
|
||||
{
|
||||
$attributes['kind'] = ($str[0] === "'" || ($str[1] === "'" && ($str[0] === 'b' || $str[0] === 'B')))
|
||||
? Scalar\String_::KIND_SINGLE_QUOTED
|
||||
: Scalar\String_::KIND_DOUBLE_QUOTED;
|
||||
|
||||
$attributes['rawValue'] = $str;
|
||||
|
||||
$string = self::parse($str, $parseUnicodeEscape);
|
||||
|
||||
return new self($string, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
@@ -100,7 +116,7 @@ class String_ extends Scalar
|
||||
if (isset(self::$replacements[$str])) {
|
||||
return self::$replacements[$str];
|
||||
} elseif ('x' === $str[0] || 'X' === $str[0]) {
|
||||
return chr(hexdec($str));
|
||||
return chr(hexdec(substr($str, 1)));
|
||||
} elseif ('u' === $str[0]) {
|
||||
return self::codePointToUtf8(hexdec($matches[2]));
|
||||
} else {
|
||||
@@ -134,7 +150,7 @@ class String_ extends Scalar
|
||||
}
|
||||
throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large');
|
||||
}
|
||||
|
||||
|
||||
public function getType() : string {
|
||||
return 'Scalar_String';
|
||||
}
|
||||
|
Reference in New Issue
Block a user