diff options
Diffstat (limited to 'buildscripts/phing/classes/phing/util/regexp')
-rw-r--r-- | buildscripts/phing/classes/phing/util/regexp/PregEngine.php | 74 | ||||
-rwxr-xr-x[-rw-r--r--] | buildscripts/phing/classes/phing/util/regexp/Regexp.php | 45 | ||||
-rwxr-xr-x[-rw-r--r--] | buildscripts/phing/classes/phing/util/regexp/RegexpEngine.php | 7 |
3 files changed, 111 insertions, 15 deletions
diff --git a/buildscripts/phing/classes/phing/util/regexp/PregEngine.php b/buildscripts/phing/classes/phing/util/regexp/PregEngine.php index 758b40f3..76cf56b3 100644 --- a/buildscripts/phing/classes/phing/util/regexp/PregEngine.php +++ b/buildscripts/phing/classes/phing/util/regexp/PregEngine.php @@ -1,6 +1,6 @@ <?php /* - * $Id: PregEngine.php,v 1.6 2003/12/24 12:38:42 hlellelid Exp $ + * $Id: 94607411e16d4c9091369ff4a65ea8f44bde8781 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -26,14 +26,60 @@ require_once 'phing/util/regexp/RegexpEngine.php'; * Implements a regexp engine using PHP's preg_match(), preg_match_all(), and preg_replace() functions. * * @author hans lellelid, hans@velum.net - * @package phing.util.regex + * @package phing.util.regexp */ class PregEngine implements RegexpEngine { /** + * Set to null by default to distinguish between false and not set * @var boolean */ - private $ignoreCase = false; + private $ignoreCase = null; + + /** + * Set to null by default to distinguish between false and not set + * @var boolean + */ + private $multiline = null; + + /** + * Pattern modifiers + * @link http://php.net/manual/en/reference.pcre.pattern.modifiers.php + * @var string + */ + private $modifiers = null; + + /** + * Sets pattern modifiers for regex engine + * + * @param string $mods Modifiers to be applied to a given regex + * @return void + */ + public function setModifiers($mods) { + $this->modifiers = (string)$mods; + } + + /** + * Gets pattern modifiers. + * @return string + */ + public function getModifiers() { + $mods = $this->modifiers; + if($this->getIgnoreCase()) { + $mods .= 'i'; + } elseif($this->getIgnoreCase() === false) { + $mods = str_replace('i', '', $mods); + } + if($this->getMultiline()) { + $mods .= 's'; + } elseif($this->getMultiline() === false) { + $mods = str_replace('s', '', $mods); + } + // filter out duplicates + $mods = preg_split('//', $mods, -1, PREG_SPLIT_NO_EMPTY); + $mods = implode('', array_unique($mods)); + return $mods; + } /** * Sets whether or not regex operation is case sensitive. @@ -51,6 +97,22 @@ class PregEngine implements RegexpEngine { function getIgnoreCase() { return $this->ignoreCase; } + + /** + * Sets whether regexp should be applied in multiline mode. + * @param boolean $bit + */ + function setMultiline($bit) { + $this->multiline = $bit; + } + + /** + * Gets whether regexp is to be applied in multiline mode. + * @return boolean + */ + function getMultiline() { + return $this->multiline; + } /** * The pattern needs to be converted into PREG style -- which includes adding expression delims & any flags, etc. @@ -59,7 +121,8 @@ class PregEngine implements RegexpEngine { */ private function preparePattern($pattern) { - return '/'.$pattern.'/'.($this->ignoreCase ? 'i' : ''); + // Use backquotes since hardly ever found in a regexp pattern, avoids using preg_quote + return '`'.$pattern.'`' . $this->getModifiers(); } /** @@ -96,10 +159,9 @@ class PregEngine implements RegexpEngine { function replace($pattern, $replace, $source) { // convert \1 -> $1, because we want to use the more generic \1 in the XML // but PREG prefers $1 syntax. - $replace = preg_replace('/[^\\\]\\\(\d+)/', '$1', $replace); + $replace = preg_replace('/\\\(\d+)/', '\$$1', $replace); return preg_replace($this->preparePattern($pattern), $replace, $source); } } -?>
\ No newline at end of file diff --git a/buildscripts/phing/classes/phing/util/regexp/Regexp.php b/buildscripts/phing/classes/phing/util/regexp/Regexp.php index 68c06668..7188997e 100644..100755 --- a/buildscripts/phing/classes/phing/util/regexp/Regexp.php +++ b/buildscripts/phing/classes/phing/util/regexp/Regexp.php @@ -1,6 +1,6 @@ <?php /* - * $Id: Regexp.php,v 1.5 2003/12/24 18:40:33 hlellelid Exp $ + * $Id: b669eb9f2dd8533cba67b2058b7cbc2f558bdeae $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -23,7 +23,7 @@ * A factory class for regex functions. * @author Hans Lellelid <hans@xmpl.org> * @package phing.util.regexp - * @version $Revision: 1.5 $ + * @version $Id$ */ class Regexp { @@ -97,12 +97,11 @@ class Regexp { /** * Gets replacement string. * @return string The pattern to replace matches with. - * @return void */ public function getReplace() { return $this->replace; } - + /** * Performs match of specified pattern against $subject. * @param string $subject The subject, on which to perform matches. @@ -146,6 +145,27 @@ class Regexp { } return $this->groups[$idx]; } + + /** + * Sets pattern modifiers for regex engine + * + * @param string $mods Modifiers to be applied to a given regex + * @return void + */ + public function setModifiers($mods) { + $this->engine->setModifiers($mods); + } + + /** + * Gets pattern modifiers. + * Subsequent call to engines getModifiers() filters out duplicates + * i.e. if i is provided in $mods, and setIgnoreCase(true), "i" + * modifier would be included only once + * @return string + */ + public function getModifiers() { + return $this->engine->getModifiers(); + } /** * Sets whether the regexp matching is case insensitive. @@ -163,6 +183,21 @@ class Regexp { function getIgnoreCase() { return $this->engine->getIgnoreCase(); } + + /** + * Sets whether regexp should be applied in multiline mode. + * @param boolean $bit + */ + function setMultiline($bit) { + $this->engine->setMultiline($bit); + } + + /** + * Gets whether regexp is to be applied in multiline mode. + * @return boolean + */ + function getMultiline() { + return $this->engine->getMultiline(); + } } -?>
\ No newline at end of file diff --git a/buildscripts/phing/classes/phing/util/regexp/RegexpEngine.php b/buildscripts/phing/classes/phing/util/regexp/RegexpEngine.php index 7d323466..3eb8c408 100644..100755 --- a/buildscripts/phing/classes/phing/util/regexp/RegexpEngine.php +++ b/buildscripts/phing/classes/phing/util/regexp/RegexpEngine.php @@ -1,6 +1,6 @@ <?php /* - * $Id: RegexpEngine.php,v 1.4 2003/12/24 12:38:42 hlellelid Exp $ + * $Id: 5e2886f3fae60fff1fd142e79717a3a7a4555772 $ * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -24,8 +24,8 @@ * engine-specific implementations that sub-classes must override. * * @author Hans Lellelid <hans@velum.net> - * @package phing.util.regex - * @version $Revision: 1.4 $ + * @package phing.util.regexp + * @version $Id$ */ interface RegexpEngine { @@ -71,4 +71,3 @@ interface RegexpEngine { } -?>
\ No newline at end of file |