diff --git a/src/Neon/Decoder.php b/src/Neon/Decoder.php index 87b6e0ce..95a642f4 100644 --- a/src/Neon/Decoder.php +++ b/src/Neon/Decoder.php @@ -44,6 +44,10 @@ class Decoder const PATTERN_HEX = '#0x[0-9a-fA-F]+\z#A'; + const PATTERN_OCTAL = '#0o[0-7]+\z#A'; + + const PATTERN_BINARY = '#0b[0-1]+\z#A'; + const BRACKETS = [ '[' => ']', '{' => '}', @@ -262,6 +266,10 @@ private function parse($indent, $result = NULL, $key = NULL, $hasKey = FALSE) $converted = $t * 1; } elseif (preg_match(self::PATTERN_HEX, $t)) { $converted = hexdec($t); + } elseif (preg_match(self::PATTERN_OCTAL, $t)) { + $converted = octdec($t); + } elseif (preg_match(self::PATTERN_BINARY, $t)) { + $converted = bindec($t); } elseif (preg_match(self::PATTERN_DATETIME, $t)) { $converted = new \DateTimeImmutable($t); } else { // literal diff --git a/tests/Neon/Decoder.phpt b/tests/Neon/Decoder.phpt index ecc2005b..ba315c11 100644 --- a/tests/Neon/Decoder.phpt +++ b/tests/Neon/Decoder.phpt @@ -56,6 +56,7 @@ $dataSet = [ ['0777', 777], ['00000777', 777], ['0xff', 0xff], + //['0b00010111', '0b00010111'], ['.1', 0.1], ['-.1', -0.1], @@ -76,6 +77,8 @@ $dataSet = [ ['[0777]', [777]], ['[00000777]', [777]], ['[0xff]', [0xff]], + ['0b00010111', 23], + ['0o777', 511], ['[.1]', [0.1]], ['[-.1]', [-0.1]],