Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function buildContentFiltering(ehough_finder_shell_Command $command, array $contains, $not = false)
 {
     foreach ($contains as $contain) {
         $expr = ehough_finder_expression_Expression::create($contain);
         // todo: avoid forking process for each $pattern by using multiple -e options
         $command->add('| grep -v \'^$\'')->add('| xargs -I{} grep -I')->add($expr->isCaseSensitive() ? null : '-i')->add($not ? '-L' : '-l')->add('-Ee')->arg($expr->renderPattern())->add('{}');
     }
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider getToRegexData
  */
 public function testGlobToRegex($glob, $match, $noMatch)
 {
     foreach ($match as $m) {
         $this->assertRegExp(ehough_finder_expression_Expression::create($glob)->getRegex()->render(), $m, '::toRegex() converts a glob to a regexp');
     }
     foreach ($noMatch as $m) {
         $this->assertNotRegExp(ehough_finder_expression_Expression::create($glob)->getRegex()->render(), $m, '::toRegex() converts a glob to a regexp');
     }
 }
 /**
  * @param ehough_finder_shell_Command  $command
  * @param string   $dir
  * @param string[] $paths
  * @param Boolean  $not
  */
 private function buildPathsFiltering(ehough_finder_shell_Command $command, $dir, array $paths, $not = false)
 {
     if (0 === count($paths)) {
         return;
     }
     $command->add($not ? '-not' : null)->cmd('(');
     foreach ($paths as $i => $path) {
         $expr = ehough_finder_expression_Expression::create($path);
         // Find does not support expandable globs ("*.{a,b}" syntax).
         if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
             $expr = ehough_finder_expression_Expression::create($expr->getGlob()->toRegex(false));
         }
         // Fixes 'not search' regex problems.
         if ($expr->isRegex()) {
             $regex = $expr->getRegex();
             $regex->prepend($regex->hasStartFlag() ? $dir . DIRECTORY_SEPARATOR : '.*')->setEndJoker(!$regex->hasEndFlag());
         } else {
             $expr->prepend('*')->append('*');
         }
         $command->add($i > 0 ? '-or' : null)->add($expr->isRegex() ? $expr->isCaseSensitive() ? '-regex' : '-iregex' : ($expr->isCaseSensitive() ? '-path' : '-ipath'))->arg($expr->renderPattern());
     }
     $command->cmd(')');
 }
 /**
  * Converts glob to regexp.
  *
  * PCRE patterns are left unchanged.
  * ehough_finder_expression_Glob strings are transformed with ehough_finder_expression_Glob::toRegex().
  *
  * @param string $str Pattern: glob or regexp
  *
  * @return string regexp corresponding to a given glob or regexp
  */
 protected function toRegex($str)
 {
     return ehough_finder_expression_Expression::create($str)->getRegex()->render();
 }
 /**
  * Checks whether the string is a regex.
  *
  * @param string $str
  *
  * @return Boolean Whether the given string is a regex
  */
 protected function isRegex($str)
 {
     return ehough_finder_expression_Expression::create($str)->isRegex();
 }
Ejemplo n.º 6
0
 /**
  * @dataProvider getRegexRenderingData
  */
 public function testRegexRendering($expr, $body)
 {
     $this->assertEquals($body, ehough_finder_expression_Expression::create($expr)->renderPattern());
 }