コード例 #1
0
ファイル: Parser.php プロジェクト: sebcode/proust
 /** 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);
             }
         }
     }
 }
コード例 #2
0
ファイル: testStringScanner.php プロジェクト: sebcode/proust
 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], "//");
 }