/** Try to find static text. **/ public function scanText() { /* look for next opening tag. */ $text = $this->scanner->scanUntilExclusive(\StringScanner::escape($this->otag)); if ($text === null) { /* Couldn't find any otag, which means the rest is just static text. */ $text = $this->scanner->rest(); $this->scanner->clear(); } if (!empty($text)) { $prev = end($this->result); /* remove previous standalone section if found */ if ($prev[0] === ":standalone") { array_pop($this->result); } /* split text into lines, so that indentation works. */ foreach (preg_split('/(\\n)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $str) { if ($str === "\n") { array_push($this->result, array(":newline")); } else { $this->addStatic($str); } } } }
function testEscape() { $sc = new StringScanner("^^^()\$\$()[]//"); $res = $sc->isMatch(StringScanner::escape("^^")); $this->assertEqual($res, 2); $this->assertEqual($sc[0], "^^"); $res = $sc->scanUntil(StringScanner::escape("\$\$")); $this->assertEqual($res, "^^^()\$\$"); $this->assertEqual($sc[0], "\$\$"); $res = $sc->scanUntil(StringScanner::escape("/")); $this->assertEqual($res, "()[]/"); $this->assertEqual($sc[0], "/"); $sc->unScan(); $res = $sc->scanUntil(StringScanner::escape("//")); $this->assertEqual($res, "()[]//"); $this->assertEqual($sc[0], "//"); }