Esempio n. 1
0
 public function testSeeder()
 {
     $seeder = new Seeder('abc123');
     $this->assertEquals(0, $seeder->getPosition());
     $this->assertEquals(6, $seeder->getLength());
     $this->assertTrue($seeder->sof());
     $this->assertFalse($seeder->eof());
     $this->assertEquals('abc123', $seeder->get(6));
     $this->assertEquals('abc123', $seeder->get(1000));
     $this->assertEquals('abc', $seeder->get(3));
     $this->assertEquals('a', $seeder->get());
     $seeder->forward();
     $this->assertEquals('b', $seeder->get());
     $seeder->forward();
     $this->assertEquals('c', $seeder->get());
     $seeder->forward(2);
     $this->assertEquals('2', $seeder->get());
     $seeder->backward(2);
     $this->assertEquals('c', $seeder->get());
     $seeder->backward();
     $this->assertEquals('b', $seeder->get());
     $seeder->forward(4);
     $this->assertFalse($seeder->eof());
     $seeder->forward(1);
     $this->assertTrue($seeder->eof());
 }
Esempio n. 2
0
 /**
  * @param Seeder $seeder
  * @return bool
  */
 protected static function parseClose(Seeder $seeder)
 {
     if ($seeder->eof()) {
         return true;
     }
     if ("\r\n" == $seeder->get(2)) {
         $seeder->forward(2);
         return true;
     }
     if ("\n" == $seeder->get()) {
         $seeder->forward();
         return true;
     }
     if ("\r" == $seeder->get()) {
         $seeder->forward();
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * @inheritDoc
  */
 public static function parse(Seeder $seeder, array &$result)
 {
     $content = $seeder->get(1, true);
     if (empty($result)) {
         $result[] = new self($content);
         return;
     }
     /** @var Unknown $last */
     $sliced = array_slice($result, -1);
     $last = reset($sliced);
     if (!$last instanceof self) {
         $result[] = new self($content);
         return;
     }
     $last->append($content);
 }
Esempio n. 4
0
 /**
  * @param Seeder $seeder
  * @return bool
  */
 protected static function parseNewLine(Seeder $seeder)
 {
     if ("\r\n" == $seeder->get(2)) {
         $seeder->forward(2);
         self::trackEOF($seeder);
         return true;
     }
     if ("\n" == $seeder->get()) {
         $seeder->forward();
         self::trackEOF($seeder);
         return true;
     }
     if ("\r" == $seeder->get()) {
         $seeder->forward();
         self::trackEOF($seeder);
         return true;
     }
     return false;
 }