Mapleの森を歩く(3): デジャブ

Mapleソースコードを見ていると
「preg_match()の直後にpreg_replace()されているのを前にもどこかで見たような?」
というデジャブに襲われました。


早速、grepを工夫して調べてみました。
grepのAとBオプションは工夫次第では、便利に使えるものなのですね。
フィルターの最後にある"tr"は、結果をblogに貼り付けた際に見やすくするための工夫です。

$ cd ~/public_html/php/maple/maple-3.0.0
$ grep -rn -A3 "preg_match" . | grep -B1 -A3  "preg_replace" | tr "\t" " "
./maple/core/Request.class.php:145:   if (preg_match("/^dispatch_/", $key)) {
./maple/core/Request.class.php-146-    $action = preg_replace("/^dispatch_/", "", $key);
./maple/core/Request.class.php-147-    $this->setParameter(ACTION_KEY, $action);
./maple/core/Request.class.php-148-    break;
--
--
./maple/core/DIContainer.class.php:186:     if (preg_match("/^ref:/", $value)) {
./maple/core/DIContainer.class.php-187-      $value = preg_replace("/^ref:/", "", $value);
./maple/core/DIContainer.class.php-188-      if (!isset($this->_components[$value])) {
./maple/core/DIContainer.class.php-189-       return false;
--
./maple/filter/Filter_Action.class.php:50:    if (preg_match("/^ref:/", $value)) {
./maple/filter/Filter_Action.class.php-51-     $value = preg_replace("/^ref:/", "", $value);
./maple/filter/Filter_Action.class.php-52-     $component =& $container->getComponent($value);
./maple/filter/Filter_Action.class.php-53-     if (is_object($component)) {
--
./maple/filter/Filter_View.class.php:51:   if (preg_match("/location:/", $template)) {
./maple/filter/Filter_View.class.php-52-    $url = preg_replace("/location:/", "", $template);
./maple/filter/Filter_View.class.php-53-    $url = trim($url);
./maple/filter/Filter_View.class.php-54-    $response->setRedirect($url);
[...]

やっぱり、ありました。でも、予想以上に少なかったです。
パターンマッチさせて不要な所を削り取るやり方は、面白い書き方だと思います。