We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 35 | abstract class Strings { |
||
| 36 | /** |
||
| 37 | * Utility patterns for splitting string parameter lists into arrays. |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | const _RE_PARAMETER_SPLITTING = '/[\s,]+/S'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * An array of encodings in detection order. |
||
| 45 | * |
||
| 46 | * ASCII has to be first to have a chance of detection. |
||
| 47 | * |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | const _ENCODINGS = [ 'ASCII', 'UTF-8' ]; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * A hash map for string functions according to encoding. |
||
| 54 | * |
||
| 55 | * @var array $encoding => [ 'strlen' => $function_name, ... ]. |
||
| 56 | */ |
||
| 57 | const _STRING_FUNCTIONS = [ |
||
| 58 | 'UTF-8' => [ |
||
| 59 | 'strlen' => 'mb_strlen', |
||
| 60 | 'str_split' => [ __CLASS__, 'mb_str_split' ], |
||
| 61 | 'strtolower' => 'mb_strtolower', |
||
| 62 | 'strtoupper' => 'mb_strtoupper', |
||
| 63 | 'substr' => 'mb_substr', |
||
| 64 | 'u' => 'u', |
||
| 65 | ], |
||
| 66 | 'ASCII' => [ |
||
| 67 | 'strlen' => 'strlen', |
||
| 68 | 'str_split' => 'str_split', |
||
| 69 | 'strtolower' => 'strtolower', |
||
| 70 | 'strtoupper' => 'strtoupper', |
||
| 71 | 'substr' => 'substr', |
||
| 72 | 'u' => '', |
||
| 73 | ], |
||
| 74 | false => [], |
||
| 75 | ]; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Retrieves str* functions. |
||
| 79 | * |
||
| 80 | * @param string $str A string to detect the encoding from. |
||
| 81 | * @return array { |
||
| 82 | * An array of string functions. |
||
| 83 | * |
||
| 84 | * 'strlen' => callable, |
||
| 85 | * 'str_split' => callable, |
||
| 86 | * 'strtolower' => callable, |
||
| 87 | * 'strtoupper' => callable, |
||
| 88 | * 'substr' => callable, |
||
| 89 | * 'u' => modifier string |
||
| 90 | * } |
||
| 91 | */ |
||
| 92 | public static function functions( $str ) { |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Multibyte-safe str_split function. |
||
| 98 | * |
||
| 99 | * Unlike str_split, a $split_length less than 1 is ignored (and thus |
||
| 100 | * equivalent to the default). |
||
| 101 | * |
||
| 102 | * @param string $str Required. |
||
| 103 | * @param int $split_length Optional. Default 1. |
||
| 104 | * |
||
| 105 | * @return array An array of $split_length character chunks. |
||
| 106 | */ |
||
| 107 | public static function mb_str_split( $str, $split_length = 1 ) { |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Converts decimal value to unicode character. |
||
| 124 | * |
||
| 125 | * @param int|string|array $codes Decimal value(s) coresponding to unicode character(s). |
||
| 126 | * |
||
| 127 | * @return string Unicode character(s). |
||
| 128 | */ |
||
| 129 | public static function uchr( $codes ) { |
||
| 144 | |||
| 145 | /** |
||
| 146 | * If necessary, split the passed parameters string into an array. |
||
| 147 | * |
||
| 148 | * @param array|string $params Parameters. |
||
| 149 | * |
||
| 150 | * @return array |
||
| 151 | */ |
||
| 152 | public static function maybe_split_parameters( $params ) { |
||
| 159 | } |
||
| 160 |