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"); }
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 }
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(); }