-
-
Notifications
You must be signed in to change notification settings - Fork 467
/
pregmatch.zep
117 lines (89 loc) · 2.45 KB
/
pregmatch.zep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
namespace Stub;
class Pregmatch
{
public function testWithoutReturnAndMatches()
{
var pattern, subject;
let pattern = "/def$/",
subject = "abcdef";
// without return auto created temp variable
preg_match(pattern, subject);
// compiler optimized, using return_value variable
return preg_match(pattern, subject);
}
public function testWithoutReturns()
{
var pattern, subject, matches = null;
let pattern = "/def$/",
subject = "abcdef";
preg_match(pattern, subject, matches);
return matches;
}
public function testWithoutMatches()
{
var pattern, subject, matched;
let pattern = "/def$/",
subject = "abcdef";
let matched = preg_match(pattern, subject);
return matched;
}
public function testPregMatchAll()
{
var pattern, subject;
let pattern = "/def$/",
subject = "abcdef";
/**
* We cant use preg_match_all with 3 argument because we comment optimizer for it
* @todo remove after php 5.3 support remove or return optimizer for it
*/
var results = [];
return preg_match_all(pattern, subject, results);
}
public function testPregMatchFallback()
{
var pattern, subject, matches = null;
let matches = [];
let pattern = "/def$/",
subject = "abcdef";
return preg_match(pattern, subject, matches, 0, 0);
}
public function testPregMatch2Params(var pattern, var subject)
{
return preg_match(pattern, subject);
}
public function testPregMatch3Params(var pattern, var subject, var matches)
{
return preg_match(pattern, subject, matches);
}
public function testPregMatch4Params(var pattern, var subject, var matches, var flags)
{
return preg_match(pattern, subject, matches, flags);
}
public function testPregMatch5Params(var pattern, var subject, var matches, var flags, var offset)
{
return preg_match(pattern, subject, matches, flags, offset);
}
/**
* @link https://github.com/zephir-lang/zephir/issues/287
*/
public function testPregMatchSaveMatches(string str, string pattern)
{
var matches = null;
preg_match(pattern, str, matches);
return matches;
}
public function testMatchAll(var flags)
{
var text, matches = [];
let text = "test1,test2";
preg_match_all("/(test[0-9]+)/", text, matches, flags);
return matches;
}
public function testMatchAllInZep()
{
var m1, m2;
let m1 = this->testMatchAll(PREG_PATTERN_ORDER);
let m2 = this->testMatchAll(PREG_SET_ORDER);
return [m1, m2];
}
}