/
AlexeyS_AS
/
Gerber-TEST
Обзор
Документация
Войти
/
AlexeyS_AS
/
Gerber-TEST
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
php/test_2/src/lib/Tokenizer.php
61 строка
1 KB
Alexey Karizhenskiy
Init
13 апр 2025, 01:52
13 апр 2025, 01:52
64d3235
Код
Авторство
О чём код?
<?php namespace Igloo\Gerber\Lib; class Tokenizer { private $file; private $attribute = false; public function __construct($filename) { $this->file = fopen($filename, "r"); } public function __destruct() { fclose($this->file); } public function read() { if(feof($this->file)) { //return false to indicate that there is no characters left to parse return false; } $start = ftell($this->file); while(false !== ($char = fgetc($this->file))) { if($char == '*') { $end = ftell($this->file); fseek($this->file, $start); $command = fread($this->file, $end-$start-1); fseek($this->file, 1, SEEK_CUR); return ['type' => "command", 'command' => trim($command)]; } if($char == '%') { if($this->attribute == false) { $this->attribute = true; return ['type' => "attribute start"]; } else { $this->attribute = false; return ['type' => "attribute end"]; } } } if($char === false){ return false; } return true; } } ?>