scanUntil() public method

Scans the string _until_ the +pattern+ is matched. Returns the substring up to and including the end of the match, advancing the scan pointer to that location. If there is no match, +null+ is returned.
public scanUntil ( string $pattern ) : string
$pattern string
return string The matched string
Esempio n. 1
0
 public function testScanUntil()
 {
     $s = new StringScanner("Fri Dec 12 1975 14:39");
     $this->assertEquals("Fri Dec 1", $s->scanUntil('/1/'), '$s->scanUntil("/1/") should return "Fri Dec 1"');
     $this->assertEquals("1", $s->matched);
     $this->assertEquals("Fri Dec ", $s->preMatch, '$s->preMatch should be "Fri Dec "');
     $this->assertNull($s->scanUntil('/XYZ/'), '$s->scanUntil("/XYZ/") should return null for the string "Fri Dec 12 1975 14:39"');
     $s = new StringScanner('$complex ? \'php\' : "nothing", another="test"');
     $return = $s->scanUntil('/[^,\\}](?=[,\\}])/');
     $this->assertEquals($return, $s->scanned, 'Return value of scanUntil() should be equals $scanner->scanned');
     $this->assertEquals('$complex ? \'php\' : "nothing"', $return, "The scanned value must contain the match");
     $this->assertEquals('$complex ? \'php\' : "nothing', $s->prematch);
     $this->assertEquals(', another="test"', $s->postMatch);
     $s = new StringScanner('$complex ? \'php\' : "nothing"}');
     $return = $s->scanUntil('/(?=[,\\}])/');
     $this->assertEquals($return, $s->scanned, 'Return value of scanUntil() should be equals $scanner->scanned');
     $this->assertEquals('$complex ? \'php\' : "nothing"', $return, "The scanned value must contain the match");
     $this->assertEquals('$complex ? \'php\' : "nothing"', $s->prematch);
     $this->assertEquals('}', $s->postMatch);
     //$s = new StringScanner('$complex ? \'php\' : "nothing"}');
 }
Esempio n. 2
0
 function testGetScanned()
 {
     $sc = new StringScanner("foobar blorg bla");
     $res = $sc->getScanned();
     $this->assertEqual($res, "");
     $sc->scan("foobar");
     $res = $sc->getScanned();
     $this->assertEqual($res, "foobar");
     $sc->scanUntil("rg");
     $res = $sc->getScanned();
     $this->assertEqual($res, "foobar blorg");
 }