mirror of
https://github.com/halaxa/json-machine.git
synced 2025-01-17 04:58: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]
|
||||
public function getIterator()
|
||||
{
|
||||
// init the map of JSON-structure (in)significant bytes as local variable variables for the fastest lookup
|
||||
foreach (range(0, 255) as $ord) {
|
||||
if (! in_array(
|
||||
chr($ord),
|
||||
["\\", '"', "\xEF", "\xBB", "\xBF", ' ', "\n", "\r", "\t", '{', '}', '[', ']', ':', ',']
|
||||
)) {
|
||||
${chr($ord)} = true;
|
||||
}
|
||||
// init the map as local variable variables for the fastest lookup
|
||||
foreach ($this->jsonInsignificantBytes() as $jsonInsignificantByte) {
|
||||
${$jsonInsignificantByte} = true;
|
||||
}
|
||||
|
||||
$tokenBoundaries = $this->tokenBoundaries();
|
||||
@ -131,4 +126,16 @@ class Lexer implements \IteratorAggregate, PositionAware
|
||||
{
|
||||
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