From 228ceab39dcd4aeb215a30107914a6d125739631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Mat=C4=9Bj=C4=8Dek?= Date: Wed, 10 Jul 2024 08:58:12 +0200 Subject: [PATCH] feat(TextIterator): add most used setup --- src/Iterators/TextIterator.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Iterators/TextIterator.php b/src/Iterators/TextIterator.php index 8a0e151..e2002f5 100644 --- a/src/Iterators/TextIterator.php +++ b/src/Iterators/TextIterator.php @@ -7,16 +7,16 @@ /** * Iterate via line - * @phpstan-type LINE string|array - * @extends \ArrayIterator + * @template TValue + * @extends \ArrayIterator */ class TextIterator extends \ArrayIterator { - public const SKIP_EMPTY_LINE = 1048576; // 2^20 public const CSV_MODE = 2097152; // 2^21 public const SKIP_FIRST_LINE = 4194304; // 2^22 public const TRIM_LINE = 8388608; // 2^23 + public const SKIP_EMPTY_AND_TRIM_LINE = self::TRIM_LINE | self::SKIP_EMPTY_LINE; private string $_current = ''; @@ -31,7 +31,7 @@ class TextIterator extends \ArrayIterator /** - * @param array|string $text + * @param array|string $text */ public function __construct(array|string $text) { @@ -111,6 +111,7 @@ public function rewind(): void public function valid(): bool { + $flags = $this->getFlags(); do { if (parent::valid() === false) { return false; @@ -118,10 +119,10 @@ public function valid(): bool $current = parent::current(); assert(is_string($current)); $this->_current = $current; - if (BitwiseOperations::check($this->getFlags(), self::TRIM_LINE)) { + if (BitwiseOperations::check($flags, self::TRIM_LINE)) { $this->_current = trim($this->_current); } - } while (BitwiseOperations::check($this->getFlags(), self::SKIP_EMPTY_LINE) && $this->_current === '' && $this->moveInternalPointer()); + } while (BitwiseOperations::check($flags, self::SKIP_EMPTY_LINE) && $this->_current === '' && $this->moveInternalPointer()); return true; }