initial commit; version 22.5.12042
This commit is contained in:
56
libs/Doctrine/SqlFormatter/Cursor.php
Normal file
56
libs/Doctrine/SqlFormatter/Cursor.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\SqlFormatter;
|
||||
|
||||
final class Cursor
|
||||
{
|
||||
/** @var int */
|
||||
private $position = -1;
|
||||
|
||||
/** @var Token[] */
|
||||
private $tokens;
|
||||
|
||||
/**
|
||||
* @param Token[] $tokens
|
||||
*/
|
||||
public function __construct(array $tokens)
|
||||
{
|
||||
$this->tokens = $tokens;
|
||||
}
|
||||
|
||||
public function next(int $exceptTokenType = null)
|
||||
{
|
||||
while ($token = $this->tokens[++$this->position] ?? null) {
|
||||
if ($exceptTokenType !== null && $token->isOfType($exceptTokenType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function previous(int $exceptTokenType = null)
|
||||
{
|
||||
while ($token = $this->tokens[--$this->position] ?? null) {
|
||||
if ($exceptTokenType !== null && $token->isOfType($exceptTokenType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function subCursor() : self
|
||||
{
|
||||
$cursor = new self($this->tokens);
|
||||
$cursor->position = $this->position;
|
||||
|
||||
return $cursor;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user