ast
13 years ago
cache
13 years ago
XmlImportConfig.php
13 years ago
XmlImportCsvParse.php
13 years ago
XmlImportException.php
13 years ago
XmlImportParser.php
13 years ago
XmlImportReaderInterface.php
13 years ago
XmlImportStringReader.php
13 years ago
XmlImportTemplate.php
13 years ago
XmlImportTemplateCodeGenerator.php
13 years ago
XmlImportTemplateParser.php
13 years ago
XmlImportTemplateScanner.php
13 years ago
XmlImportToken.php
13 years ago
pclzip.lib.php
13 years ago
XmlImportStringReader.php
67 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @author Olexandr Zanichkovsky <olexandr.zanichkovsky@zophiatech.com> |
| 4 | * @package General |
| 5 | */ |
| 6 | |
| 7 | require_once dirname(__FILE__) . '/XmlImportReaderInterface.php'; |
| 8 | |
| 9 | /** |
| 10 | * Allows to either peek or read a character from a string buffer |
| 11 | */ |
| 12 | class XmlImportStringReader implements XmlImportReaderInterface |
| 13 | { |
| 14 | /** |
| 15 | * String buffer |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | private $buffer; |
| 20 | |
| 21 | /** |
| 22 | * Current index |
| 23 | * |
| 24 | * @var int |
| 25 | */ |
| 26 | private $index = -1; |
| 27 | |
| 28 | /** |
| 29 | * Creates new instance |
| 30 | * |
| 31 | * @param string $input |
| 32 | */ |
| 33 | public function __construct($input) |
| 34 | { |
| 35 | if (is_string($input)) |
| 36 | $this->buffer = $input; |
| 37 | else |
| 38 | throw new InvalidArgumentException("String expected as argument."); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the next symbol from the buffer without changes to current index |
| 43 | * or false if buffer ends |
| 44 | * |
| 45 | * @return string |
| 46 | */ |
| 47 | public function peek() |
| 48 | { |
| 49 | if ($this->index + 1 >= strlen($this->buffer)) |
| 50 | return false; |
| 51 | else |
| 52 | return $this->buffer[$this->index + 1]; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the next symbol from the buffer or false if buffer is ended |
| 57 | * |
| 58 | * @return string |
| 59 | */ |
| 60 | public function read() |
| 61 | { |
| 62 | $result = $this->peek(); |
| 63 | if ($this->index < strlen($this->buffer)) |
| 64 | $this->index++; |
| 65 | return $result; |
| 66 | } |
| 67 | } |