@@ -2,69 +2,69 @@ |
||
2 | 2 | namespace Ajax\service; |
3 | 3 | class JString { |
4 | 4 | |
5 | - public static function contains($hay,$needle){ |
|
6 | - return strpos($hay, "$needle") !== false; |
|
5 | + public static function contains($hay, $needle) { |
|
6 | + return strpos($hay, "$needle")!==false; |
|
7 | 7 | } |
8 | 8 | public static function startswith($hay, $needle) { |
9 | - return substr($hay, 0, strlen($needle)) === $needle; |
|
9 | + return substr($hay, 0, strlen($needle))===$needle; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | public static function endswith($hay, $needle) { |
13 | - return substr($hay, -strlen($needle)) === $needle; |
|
13 | + return substr($hay, -strlen($needle))===$needle; |
|
14 | 14 | } |
15 | 15 | |
16 | - public static function isNull($s){ |
|
16 | + public static function isNull($s) { |
|
17 | 17 | return (!isset($s) || NULL===$s || ""===$s); |
18 | 18 | } |
19 | - public static function isNotNull($s){ |
|
19 | + public static function isNotNull($s) { |
|
20 | 20 | return (isset($s) && NULL!==$s && ""!==$s); |
21 | 21 | } |
22 | 22 | |
23 | - public static function isBoolean($value){ |
|
23 | + public static function isBoolean($value) { |
|
24 | 24 | return \is_bool($value) || $value==1 || $value==0; |
25 | 25 | } |
26 | 26 | |
27 | - public static function isBooleanTrue($value){ |
|
27 | + public static function isBooleanTrue($value) { |
|
28 | 28 | return $value==1 || $value; |
29 | 29 | } |
30 | 30 | |
31 | - public static function isBooleanFalse($value){ |
|
31 | + public static function isBooleanFalse($value) { |
|
32 | 32 | return $value==0 || !$value; |
33 | 33 | } |
34 | 34 | |
35 | - public static function camelCaseToSeparated($input,$separator=" "){ |
|
35 | + public static function camelCaseToSeparated($input, $separator=" ") { |
|
36 | 36 | return strtolower(preg_replace('/(?<!^)[A-Z]/', $separator.'$0', $input)); |
37 | 37 | } |
38 | 38 | |
39 | - public static function replaceAtFirst($subject,$from, $to){ |
|
40 | - $from = '/\A'.preg_quote($from, '/').'/'; |
|
39 | + public static function replaceAtFirst($subject, $from, $to) { |
|
40 | + $from='/\A'.preg_quote($from, '/').'/'; |
|
41 | 41 | return \preg_replace($from, $to, $subject, 1); |
42 | 42 | } |
43 | 43 | |
44 | - public static function replaceAtLast($subject,$from, $to){ |
|
45 | - $from = '/'.preg_quote($from, '/').'\z/'; |
|
44 | + public static function replaceAtLast($subject, $from, $to) { |
|
45 | + $from='/'.preg_quote($from, '/').'\z/'; |
|
46 | 46 | return \preg_replace($from, $to, $subject, 1); |
47 | 47 | } |
48 | 48 | |
49 | - public static function replaceAtFirstAndLast($subject,$fromFirst,$toFirst,$fromLast,$toLast){ |
|
49 | + public static function replaceAtFirstAndLast($subject, $fromFirst, $toFirst, $fromLast, $toLast) { |
|
50 | 50 | $s=self::replaceAtFirst($subject, $fromFirst, $toFirst); |
51 | 51 | return self::replaceAtLast($s, $fromLast, $toLast); |
52 | 52 | } |
53 | 53 | |
54 | - public static function getValueBetween(&$str,$before="{{",$after="}}"){ |
|
54 | + public static function getValueBetween(&$str, $before="{{", $after="}}") { |
|
55 | 55 | $matches=[]; |
56 | 56 | $result=null; |
57 | 57 | $_before=\preg_quote($before); |
58 | 58 | $_after=\preg_quote($after); |
59 | - if(\preg_match('/'.$_before.'(.*?)'.$_after.'/s', $str, $matches)===1){ |
|
59 | + if (\preg_match('/'.$_before.'(.*?)'.$_after.'/s', $str, $matches)===1) { |
|
60 | 60 | $result=$matches[1]; |
61 | - $str=\str_replace($before.$result.$after,"", $str); |
|
61 | + $str=\str_replace($before.$result.$after, "", $str); |
|
62 | 62 | } |
63 | 63 | return $result; |
64 | 64 | } |
65 | 65 | |
66 | - public static function doubleBackSlashes($value){ |
|
67 | - if(is_string($value)) |
|
66 | + public static function doubleBackSlashes($value) { |
|
67 | + if (is_string($value)) |
|
68 | 68 | return str_replace("\\", "\\\\", $value); |
69 | 69 | return $value; |
70 | 70 | } |