public function testRewind()
 {
     $iterator = new WordsIterator(new Words('text text'));
     $iterator->next();
     $iterator->next();
     $iterator->next();
     $iterator->next();
     $iterator->next();
     $iterator->next();
     $this->assertTrue($iterator->valid());
     $iterator->rewind();
     $this->assertEquals(0, $iterator->current());
 }
Exemple #2
0
 /**
  * @param WordsIterator $iterator
  * @param int $length
  * @throws InvalidArgumentException
  * @return string
  */
 public function getLongestDistanceMatchingWord(WordsIterator $iterator, $length)
 {
     if (!is_int($length)) {
         throw new InvalidArgumentException('Parameter $length must be an integer');
     }
     $textLength = $this->textLength;
     $word = '';
     while (--$textLength && $iterator->valid()) {
         if (!preg_match("/^{$this->getBasePattern()}\$/", $this->text[$textLength])) {
             if ($this->matchWord($word) && strlen($word) == $length) {
                 $word = strrev($word);
                 break;
             }
             $word = '';
             continue;
         }
         $word .= $this->text[$textLength];
     }
     return $word;
 }