X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fnikic%2Fphp-parser%2Flib%2FPhpParser%2FNode%2FScalar%2FDNumber.php;fp=vendor%2Fnikic%2Fphp-parser%2Flib%2FPhpParser%2FNode%2FScalar%2FDNumber.php;h=84ef75d34bec48707dfa697eabb3919f38f242c5;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php new file mode 100644 index 000000000..84ef75d34 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php @@ -0,0 +1,64 @@ +value = $value; + } + + public function getSubNodeNames() { + return array('value'); + } + + /** + * @internal + * + * Parses a DNUMBER token like PHP would. + * + * @param string $str A string number + * + * @return float The parsed number + */ + public static function parse($str) { + // if string contains any of .eE just cast it to float + if (false !== strpbrk($str, '.eE')) { + return (float) $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 + if ('0' === $str[0]) { + // hex + if ('x' === $str[1] || 'X' === $str[1]) { + return hexdec($str); + } + + // bin + if ('b' === $str[1] || 'B' === $str[1]) { + 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'))); + } + + // dec + return (float) $str; + } +}