Skip to content

Commit

Permalink
Decoder: added support for octal 0o777 and binary 0b11001 numbers [Cl…
Browse files Browse the repository at this point in the history
…oses #31]
  • Loading branch information
dg committed Jun 25, 2016
1 parent 939fc43 commit b98b91e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Neon/Decoder.php
Expand Up @@ -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 = [
'[' => ']',
'{' => '}',
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/Neon/Decoder.phpt
Expand Up @@ -56,6 +56,7 @@ $dataSet = [
['0777', 777],
['00000777', 777],
['0xff', 0xff],
//['0b00010111', '0b00010111'],

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Jun 27, 2016

Contributor

Why is this commented?

['.1', 0.1],
['-.1', -0.1],

Expand All @@ -76,6 +77,8 @@ $dataSet = [
['[0777]', [777]],
['[00000777]', [777]],
['[0xff]', [0xff]],
['0b00010111', 23],
['0o777', 511],

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Jun 27, 2016

Contributor

Why not ['0b00010111', 0b00010111] and ['0o777', 0777]?

This comment has been minimized.

Copy link
@dg

dg Jun 27, 2016

Author Member

These questions…

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Jun 27, 2016

Contributor

Pointless? Ok. Sorry.

This comment has been minimized.

Copy link
@dg

dg Jun 27, 2016

Author Member

There is no "because". So if you feel it should be changed, send PR please.

['[.1]', [0.1]],
['[-.1]', [-0.1]],

Expand Down

0 comments on commit b98b91e

Please sign in to comment.