concat() public method

This method does not affect scan @mlink{$pointer}.
public concat ( $str )
$str
Beispiel #1
0
 function testConcat()
 {
     $sc = new StringScanner("foo");
     $this->assertEqual($sc->getChar(), "f");
     $this->assertEqual($sc->getChar(), "o");
     $this->assertEqual($sc->getChar(), "o");
     $this->assertTrue($sc->isEos());
     $sc->concat("bar");
     $this->assertFalse($sc->isEos());
     $this->assertEqual($sc->string, "foobar");
     $this->assertEqual($sc->getChar(), "b");
     $this->assertEqual($sc->getChar(), "a");
     $this->assertEqual($sc->getChar(), "r");
     $this->assertTrue($sc->isEos());
 }
Beispiel #2
0
 private function _parseHtmlAttrs(StringScanner $scanner)
 {
     $atts = array('class' => array(), 'id' => array());
     $scanner->scan('/\\(\\s*/');
     while (!$scanner->scan('/\\s*\\)/')) {
         $scanner->scan('/\\s*/');
         if (!($name = $scanner->scan('/[-:\\w]+/'))) {
             throw new SyntaxErrorException("Invalid attribute list: {$scanner->string}");
         }
         $scanner->scan('/\\s*/');
         // If a equal sign doesn't follow, the value is true
         if (!$scanner->scan('/=/')) {
             $atts[$name] = array('t' => 'static', 'v' => true);
         } else {
             $scanner->scan('/\\s*/');
             // if we don't find a quote, it's a php value
             // e.g: name=$avar
             if (!($quote = $scanner->scan('/["\\\']/'))) {
                 if (!($var = $scanner->scan('/\\$\\w+/'))) {
                     // in this mode only variables are accepted
                     throw new SyntaxErrorException("Invalid attribute value for {$name} in list: {$scanner->string}");
                 }
                 if ($name == 'class' || $name == 'id') {
                     $atts[$name][] = array('t' => 'php', 'v' => $var);
                 } else {
                     $atts[$name] = array('t' => 'php', 'v' => $var);
                 }
             } elseif ($scanner->scan('/true|false/i')) {
                 if ($scanner[0] == 'true') {
                     $atts[$name] = array('t' => 'static', 'v' => true);
                 } else {
                     $atts[$name] = array('t' => 'static', 'v' => false);
                 }
             } else {
                 // we've found a quote, let's scan until the ending quote
                 $scanner->scan("/([^\\\\]*?){$quote}/");
                 $content = $scanner[1];
                 if ($name == 'class' || $name == 'id') {
                     $atts[$name][] = array('t' => 'str', 'v' => $content);
                 } else {
                     $atts[$name] = array('t' => 'str', 'v' => $quote . $content . $quote);
                 }
             }
         }
         $scanner->scan('/\\s*/');
         if ($scanner->eos) {
             $next_line = ' ' . trim($this->_compiler->getNextLine());
             $scanner->concat($next_line);
         }
     }
     if (count($atts['id']) == 0) {
         unset($atts['id']);
     }
     if (count($atts['class']) == 0) {
         unset($atts['class']);
     }
     return $atts;
 }