Skip to content

Commit e32cc82

Browse files
committed
feat: parse boolval
1 parent c7fe77e commit e32cc82

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

parser.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,31 @@ protected function parseObject(): array|null
8989
}
9090

9191
/**
92-
* @return string|array|int|float|null
92+
* @return string|array|int|float|null|bool
9393
* @throws Exception
9494
*/
95-
protected function parseValue(): string|array|null|int|float
95+
protected function parseValue(): string|array|null|int|float|bool
9696
{
9797
$value = $this->parseString()
9898
?: ($this->parseObject()
9999
?: ($this->parseArray()
100100
?: ($this->parseNumber()
101101
?: ($this->parseKeyword('true', true))
102-
?: ($this->parseKeyword('false', false)
103-
?: ($this->parseKeyword('null', null))))));
102+
?: ($this->parseKeyword('null', null)))));
103+
if (!$value) {
104+
$value = $this->parseKeyword('false', false);
105+
}
104106
$this->skipWhiteSpace();
105107
return $value;
106108
}
107109

108-
protected function parseKeyword($name, $value)
110+
protected function parseKeyword($name, $value): bool|null
109111
{
110112
if (substr($this->str, $this->l, strlen($name)) === $name) {
111113
$this->l += strlen($name);
112114
return $value;
113115
}
116+
return null;
114117
}
115118

116119
/**
@@ -216,7 +219,12 @@ public function decode(): array|float|int|string|null
216219
"d": 3
217220
}]
218221
},
219-
"e": 2.3
222+
"e": 2.3,
223+
"de": {
224+
"true": true,
225+
"false": false,
226+
"null": null
227+
}
220228
}
221229
JSON
222230
);

0 commit comments

Comments
 (0)