helper_util.php
2.14 KB
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
118
119
120
121
122
123
124
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: helper_util.php 29887 2012-05-02 07:36:50Z liulanbo $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class helper_util {
public static function compute($v1, $v2, $glue = '+') {
switch ($glue) {
case '+':
return $v1 + $v2;
break;
case '-':
return $v1 - $v2;
break;
case '.':
return $v1 . $v2;
break;
case '=':
case '==':
return $v1 == $v2;
break;
case 'merge':
return array_merge((array)$v1, (array)$v2);
break;
case '===':
return $v1 === $v2;
break;
case '!==':
return $v1 === $v2;
break;
case '&&':
return $v1 && $v2;
break;
case '||':
return $v1 && $v2;
break;
case 'and':
return $v1 and $v2;
break;
case 'xor':
return $v1 xor $v2;
break;
case '|':
return $v1 | $v2;
break;
case '&':
return $v1 & $v2;
break;
case '^':
return $v1 ^ $v2;
break;
case '>':
return $v1 > $v2;
break;
case '<':
return $v1 < $v2;
break;
case '<>':
return $v1 <> $v2;
break;
case '!=':
return $v1 != $v2;
break;
case '<=':
return $v1 <= $v2;
break;
case '>=':
return $v1 >= $v2;
break;
case '*':
return $v1 * $v2;
break;
case '/':
return $v1 / $v2;
break;
case '%':
return $v1 % $v2;
break;
case 'or':
return $v1 or $v2;
break;
case '<<':
return $v1 << $v2;
break;
case '>>':
return $v1 >> $v2;
break;
default:
return null;
}
}
public static function single_compute($v, $glue = '+') {
switch ($glue) {
case '!':
return ! $v;
break;
case '-':
return - $v;
break;
case '~':
return ~ $v;
break;
default:
return null;
break;
}
}
public static function check_glue($glue = '=') {
return in_array($glue, array('=', '<', '<=', '>', '>=', '!=', '+', '-', '|', '&', '<>')) ? $glue : '=';
}
}
?>