check() public method

This returns the value that scan would return, without advancing the scan pointer. The match register is affected, though.
public check ( string $pattern )
$pattern string
Esempio n. 1
0
 function testCheck()
 {
     $sc = new StringScanner("foobarbaz");
     $res = $sc->check("123");
     $this->assertEqual($res, null);
     $this->assertEqual($sc->rest(), "foobarbaz");
     $res = $sc->check("foo");
     $this->assertEqual($res, "foo");
     $this->assertEqual($sc->rest(), "foobarbaz");
     $sc = new StringScanner("foobar blorg bla");
     $res = $sc->check("\\w+");
     $this->assertEqual($res, "foobar");
     $this->assertEqual($sc->rest(), "foobar blorg bla");
     $sc->pos += 6;
     $res = $sc->check("\\s+");
     $this->assertEqual($res, " ");
     $this->assertEqual($sc->rest(), " blorg bla");
 }
Esempio n. 2
0
 public function testMatchedSize()
 {
     $s = new StringScanner('test string');
     $this->assertEquals('test', $s->check('/\\w+/'));
     # -> "test"
     $this->assertEquals(4, $s->matchedSize);
     # -> 4
     $this->assertNull($s->check('/\\d+/'));
     # -> null
     $this->assertNull($s->matchedSize);
     # -> null
 }
Esempio n. 3
0
 private function _interpolate($str)
 {
     if (!$this->_containsInterpolation($str)) {
         return $str;
     }
     $nStr = '';
     $s = new StringScanner($str);
     $quote = $s->check(StringScanner::rQUOTE);
     // If it doesn't starts with a quote, it CAN'T be inside php context
     if (empty($quote) || !s($str)->endsWith($quote)) {
         $int = new Interpolation($str);
         return $int->render();
     }
     $int = new Interpolation($str, true);
     return $int->render();
 }