reset() public method

Reset the scan pointer (index 0) and clear matching data.
public reset ( )
Esempio n. 1
0
 function testReset()
 {
     $sc = new StringScanner("foo");
     $this->assertEqual($sc->getChar(), "f");
     $this->assertEqual($sc->getChar(), "o");
     $this->assertEqual($sc->getChar(), "o");
     $sc->reset();
     $this->assertEqual($sc->getChar(), "f");
     $this->assertEqual($sc->getChar(), "o");
     $this->assertEqual($sc->getChar(), "o");
 }
Esempio n. 2
0
 public function testUnscan()
 {
     $s = new StringScanner('test string');
     $this->assertEquals('test', $s->scan('/\\w+/'));
     $s->unscan();
     $this->assertEquals('te', $s->scan('/../'));
     $this->assertNull($s->scan('/\\d/'));
     try {
         $s->unscan();
         # ScanError: unscan failed: previous match record not exist
     } catch (Exception $e) {
     }
     $this->assertNotNull($e);
     $s->reset();
     $this->assertEquals('test ', $s->scan('/\\w+\\s/'));
     $this->assertEquals('st', $s->scan('/st/'));
     $this->assertEquals('ri', $s->scan('/ri/'));
     $s->unscan();
     $this->assertEquals(7, $s->pos);
     $this->assertEquals('ri', $s->scan('/ri/'));
 }