123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?php
- class Regexp {
-
- private $groups = array();
-
-
- private $pattern;
-
-
- private $replace;
-
-
- private $engine;
-
-
- function __construct($engineType='preg') {
- if ($engineType == 'preg') {
- include_once 'phing/util/regexp/PregEngine.php';
- $this->engine = new PregEngine();
- } elseif ($engineType == 'ereg') {
- include_once 'phing/util/regexp/EregEngine.php';
- $this->engine = new EregEngine();
- } else {
- throw new BuildException("Invalid engine type for Regexp: " . $engineType);
- }
- }
-
- public function setPattern($pat) {
- $this->pattern = (string) $pat;
- }
-
-
-
- public function getPattern() {
- return $this->pattern;
- }
-
-
- public function setReplace($rep) {
- $this->replace = (string) $rep;
- }
-
-
- public function getReplace() {
- return $this->replace;
- }
-
- public function matches($subject) {
- if($this->pattern === null) {
- throw new Exception("No pattern specified for regexp match().");
- }
- return $this->engine->match($this->pattern, $subject, $this->groups);
- }
-
-
- public function replace($subject) {
- if ($this->pattern === null || $this->replace === null) {
- throw new Exception("Missing pattern or replacement string regexp replace().");
- }
- return $this->engine->replace($this->pattern, $this->replace, $subject);
- }
-
-
-
- function getGroups() {
- return $this->groups;
- }
-
-
- function getGroup($idx) {
- if (!isset($this->groups[$idx])) {
- return null;
- }
- return $this->groups[$idx];
- }
-
- public function setModifiers($mods) {
- $this->engine->setModifiers($mods);
- }
-
- public function getModifiers() {
- return $this->engine->getModifiers();
- }
-
-
-
- function setIgnoreCase($bit) {
- $this->engine->setIgnoreCase($bit);
- }
-
-
- function getIgnoreCase() {
- return $this->engine->getIgnoreCase();
- }
-
- function setMultiline($bit) {
- $this->engine->setMultiline($bit);
- }
-
- function getMultiline() {
- return $this->engine->getMultiline();
- }
- }
|