mirror of
https://github.com/halaxa/json-machine.git
synced 2025-01-17 13:08:16 +01:00
Extract json insignificant bytes map to separate method for readability.
This commit is contained in:
parent
4157d6d990
commit
f5492d7223
@ -23,14 +23,9 @@ class Lexer implements \IteratorAggregate, PositionAware
|
|||||||
#[\ReturnTypeWillChange]
|
#[\ReturnTypeWillChange]
|
||||||
public function getIterator()
|
public function getIterator()
|
||||||
{
|
{
|
||||||
// init the map of JSON-structure (in)significant bytes as local variable variables for the fastest lookup
|
// init the map as local variable variables for the fastest lookup
|
||||||
foreach (range(0, 255) as $ord) {
|
foreach ($this->jsonInsignificantBytes() as $jsonInsignificantByte) {
|
||||||
if (! in_array(
|
${$jsonInsignificantByte} = true;
|
||||||
chr($ord),
|
|
||||||
["\\", '"', "\xEF", "\xBB", "\xBF", ' ', "\n", "\r", "\t", '{', '}', '[', ']', ':', ',']
|
|
||||||
)) {
|
|
||||||
${chr($ord)} = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokenBoundaries = $this->tokenBoundaries();
|
$tokenBoundaries = $this->tokenBoundaries();
|
||||||
@ -131,4 +126,16 @@ class Lexer implements \IteratorAggregate, PositionAware
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function jsonInsignificantBytes()
|
||||||
|
{
|
||||||
|
$jsonSignificantBytes = ["\\", '"', "\xEF", "\xBB", "\xBF", ' ', "\n", "\r", "\t", '{', '}', '[', ']', ':', ','];
|
||||||
|
|
||||||
|
foreach (range(0, 255) as $ord) {
|
||||||
|
$asciiChar = chr($ord);
|
||||||
|
if (! in_array($asciiChar, $jsonSignificantBytes)) {
|
||||||
|
yield chr($ord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user