Skip to content

Commit

Permalink
Add Regexp#matches().
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Mar 23, 2017
1 parent b5386f7 commit 500ed49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions framework/Refactor/lib/Horde/Refactor/Regexp.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,16 @@ public function __toString()
{
return $this->_regexp;
}

/**
* Returns whether this a string matches this regular expression.
*
* @param string $string A string to match against.
*
* @return boolean True if the string matches.
*/
public function matches($string)
{
return (bool)preg_match($this, $string);
}
}
4 changes: 2 additions & 2 deletions framework/Refactor/lib/Horde/Refactor/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function matches($token, $term = null)
if (is_null($term)) {
return true;
} elseif ($term instanceof Regexp) {
return (bool)preg_match($term, $current[1]);
return $term->matches($current[1]);
} else {
return $current[1] == $term;
}
Expand All @@ -312,7 +312,7 @@ public function matches($token, $term = null)
return false;
}
if ($token instanceof Regexp) {
return (bool)preg_match($token, $current);
return $token->matches($current);
}
return $current == $token;
}
Expand Down

0 comments on commit 500ed49

Please sign in to comment.