Пример #1
0
 /**
  * Lexes one token from the current stream
  *
  * I'll leave the stream's pointer on the first character after the token's last 
  * character. For example, if the stream is "\foo bar", I'll leave the stream on
  * "b" (because the space is part of the control word).
  *
  * @param  Jstewmc\Stream\Stream  $stream  the character stream
  * @return  Jstewmc\Rtf\Token\Token|false
  * @since  0.2.0
  */
 public function lexOne(\Jstewmc\Stream\Stream $stream)
 {
     $token = false;
     // if the stream has characters
     if ($stream->hasCharacters()) {
         // switch on the current character
         switch ($stream->current()) {
             case '{':
                 $token = $this->lexOpenBracket($stream);
                 break;
             case '}':
                 $token = $this->lexCloseBracket($stream);
                 break;
             case '\\':
                 $token = $this->lexBackslash($stream);
                 break;
             case "\t":
                 $token = $this->lexTab($stream);
                 break;
             case "\n":
             case "\r":
             case "\f":
             case "":
                 $token = $this->lexOther($stream);
                 break;
             default:
                 $token = $this->lexText($stream);
         }
         // advance the stream to the next character
         $stream->next();
     }
     return $token;
 }
Пример #2
0
 /**
  * hasCharacters() should return false if stream is after last character
  */
 public function testHasCharacters_returnsFalse_ifAfterLastCharacter()
 {
     $chunker = new Chunker\Text('foo');
     $stream = new Stream($chunker);
     $stream->next();
     $stream->next();
     $stream->next();
     $this->assertFalse($stream->hasCharacters());
     return;
 }