Пример #1
0
 /**
  * Creates a control symbol token from stream
  *
  * @param  Jstewmc\Stream  $stream  a stream of characters (the current character
  *     must be the backslash character, and the next character should be non-
  *     alphanumeric)
  * @return  Jstewmc\Rtf\Token\Control\Symbol|false
  * @throws  InvalidArgumentException  if the current character in $stream is
  *     not a backslash
  * @throws  InvalidArgumentException  if the next character in $stream is not
  *     a non-alphanumeric character
  * @since  0.1.0
  * @since  0.2.0  renamed from createFromSource() to createFromStream; replaced
  *     argument $characters, an array of characters, with $stream, an instance 
  *     of Jstewmc\STream
  */
 public static function createFromStream(\Jstewmc\Stream\Stream $stream)
 {
     $symbol = false;
     // if a current character exists
     if ($stream->current()) {
         // if the current character is a backslash
         if ($stream->current() === '\\') {
             // if the next character exists
             if ($stream->next() !== false) {
                 // if the now current character is not alphanumeric
                 if (!ctype_alnum($stream->current())) {
                     // create a new control symbol
                     $symbol = new Symbol($stream->current());
                     // if the current character is an apostrophe, get the symbol's parameter
                     if ($stream->current() === '\'') {
                         $parameter = $stream->next() . $stream->next();
                         $symbol->setParameter($parameter);
                     }
                     // if the next character is a space, the control symbol is space-delimited,
                     //     and we should set the flag; otherwise, it's not, and we should rollback
                     //     to leave the pointer on the last character in the token (i.e., the
                     //     symbol)
                     //
                     if ($stream->next() === ' ') {
                         $symbol->setIsSpaceDelimited(true);
                     } else {
                         $symbol->setIsSpaceDelimited(false);
                         $stream->previous();
                     }
                 } else {
                     throw new \InvalidArgumentException(__METHOD__ . "() expects the next element in parameter one, characters, to " . "be a non-alphanumeric character");
                 }
             } else {
                 // hmm, do nothing?
             }
         } else {
             throw new \InvalidArgumentException(__METHOD__ . "() expects the current element in parameter one, characters, to " . "be the backslash character");
         }
     }
     return $symbol;
 }
Пример #2
0
 /**
  * __toString() should return string if the control symbol is not space delimited
  */
 public function testToString_returnsString_ifNotSpaceDelimited()
 {
     $symbol = new Symbol();
     $symbol->setSymbol('+');
     $symbol->setIsSpaceDelimited(false);
     $expected = '\\+';
     $actual = (string) $symbol;
     $this->assertEquals($expected, $actual);
     return;
 }