Use hold_until_date in item_scheduler.
[order_line_extra.git] / hincludes / lib / EReg.class.php
1 <?php
2
3 class EReg {
4         public function __construct($r, $opt) {
5                 if( !php_Boot::$skip_constructor ) {
6                 $this->pattern = $r;
7                 $a = _hx_explode("g", $opt);
8                 $this->hglobal = $a->length > 1;
9                 if($this->hglobal) {
10                         $opt = $a->join("");
11                 }
12                 $this->options = $opt;
13                 $this->re = "/" . ((str_replace("/", "\\/", $r) . "/") . $opt);
14         }}
15         public $r;
16         public $last;
17         public $hglobal;
18         public $pattern;
19         public $options;
20         public $re;
21         public $matches;
22         public function match($s) {
23                 $p = preg_match($this->re, $s, $this->matches, PREG_OFFSET_CAPTURE);
24                 if($p > 0) {
25                         $this->last = $s;
26                 }
27                 else {
28                         $this->last = null;
29                 }
30                 return $p > 0;
31         }
32         public function matched($n) {
33                 if($n < 0) {
34                         throw new HException("EReg::matched");
35                 }
36                 if($n >= count($this->matches)) {
37                         return null;
38                 }
39                 if($this->matches[$n][1] < 0) {
40                         return null;
41                 }
42                 return $this->matches[$n][0];
43         }
44         public function matchedLeft() {
45                 if(count($this->matches) === 0) {
46                         throw new HException("No string matched");
47                 }
48                 return _hx_substr($this->last, 0, $this->matches[0][1]);
49         }
50         public function matchedRight() {
51                 if(count($this->matches) === 0) {
52                         throw new HException("No string matched");
53                 }
54                 $x = $this->matches[0][1] + strlen($this->matches[0][0]);
55                 return _hx_substr($this->last, $x, null);
56         }
57         public function matchedPos() {
58                 return _hx_anonymous(array("pos" => $this->matches[0][1], "len" => strlen($this->matches[0][0])));
59         }
60         public function split($s) {
61                 return new _hx_array(preg_split($this->re, $s, $this->hglobal ? -1 : 2));
62         }
63         public function replace($s, $by) {
64                 $by = str_replace("\$\$", "\\\$", $by);
65                 if(!preg_match('/\\([^?].+?\\)/', $this->re)) $by = preg_replace('/\$(\d+)/', '\\\$\1', $by);
66                 return preg_replace($this->re, $by, $s, ($this->hglobal ? -1 : 1));
67         }
68         public function customReplace($s, $f) {
69                 $buf = new StringBuf();
70                 while(true) {
71                         if(!$this->match($s)) {
72                                 break;
73                         }
74                         $buf->b .= $this->matchedLeft();
75                         $buf->b .= call_user_func_array($f, array($this));
76                         $s = $this->matchedRight();
77                         ;
78                 }
79                 $buf->b .= $s;
80                 return $buf->b;
81         }
82         public function __call($m, $a) {
83                 if(isset($this->$m) && is_callable($this->$m))
84                         return call_user_func_array($this->$m, $a);
85                 else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))
86                         return call_user_func_array($this->»dynamics[$m], $a);
87                 else if('toString' == $m)
88                         return $this->__toString();
89                 else
90                         throw new HException('Unable to call «'.$m.'»');
91         }
92         function __toString() { return 'EReg'; }
93 }