Ejemplo n.º 1
0
 protected function removingRegisteredPattern($strict = false)
 {
     $name = sha1(time());
     $this->pattern->register($name, '.*', $strict);
     $this->assertEquals('.*', $this->pattern->get($name, $strict));
     $this->pattern->remove($name, $strict);
     $this->assertFalse($this->pattern->exist($name, $strict));
 }
Ejemplo n.º 2
0
 /**
  * Generate combined patterns
  *
  * @param string $string
  * @param string $quantifier
  * @return string
  */
 protected function generateCombinedPatterns($string, $quantifier)
 {
     $chars = str_split(trim($string));
     $pattern = '';
     $combinedPattern = '';
     $part = '';
     $connected = true;
     foreach ($chars as $char) {
         if ($char == '-') {
             $pattern .= $this->pattern->get($part);
             $part = '';
             $connected = true;
         } elseif ($char == '|') {
             $pattern .= $this->pattern->get($part);
             $combinedPattern .= '[' . $pattern . ']' . $quantifier . '|';
             $pattern = '';
             $part = '';
             $connected = false;
         } else {
             $part .= $char;
         }
     }
     if ($connected) {
         $pattern .= $this->pattern->get($part);
         $combinedPattern .= '[' . $pattern . ']' . $quantifier;
         $combinedPattern = '(' . $combinedPattern . ')';
     } else {
         $pattern .= $this->pattern->get($part);
         $combinedPattern .= '[' . $pattern . ']' . $quantifier;
         $combinedPattern = '(' . $combinedPattern . ')';
     }
     return $combinedPattern;
 }