Total Complexity | 11 |
Total Lines | 79 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | trait BinaryUtils |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * @param string $string |
||
12 | * @return string |
||
13 | */ |
||
14 | public static function rleEncode(string $string): string |
||
15 | { |
||
16 | $new = ''; |
||
17 | $count = 0; |
||
18 | $null = chr(0); |
||
19 | $chars = str_split($string); |
||
20 | foreach ($chars as $char) { |
||
21 | if ($char === $null) { |
||
22 | $count++; |
||
23 | continue; |
||
24 | } |
||
25 | if ($count > 0) { |
||
26 | $new .= $null . chr($count); |
||
27 | $count = 0; |
||
28 | } |
||
29 | $new .= $char; |
||
30 | } |
||
31 | return $new; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param string $string |
||
36 | * @return string |
||
37 | */ |
||
38 | public static function rleDecode(string $string): string |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param string $string |
||
58 | * @return string |
||
59 | */ |
||
60 | public static function base64UrlDecode(string $string): string |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param string $string |
||
67 | * @return string |
||
68 | */ |
||
69 | public static function base64UrlEncode(string $string): string |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param int $a |
||
76 | * @param int $b |
||
77 | * @return int |
||
78 | */ |
||
79 | public static function positiveModulo(int $a, int $b): int |
||
86 | } |
||
87 | |||
88 | } |