Changeset View
Changeset View
Standalone View
Standalone View
omnitools/src/Strings/Multibyte/StringUtilities.php
| Show All 23 Lines | public static function pad ( | ||||
| int $padType = STR_PAD_RIGHT, | int $padType = STR_PAD_RIGHT, | ||||
| string $encoding = '' | string $encoding = '' | ||||
| ) : string { | ) : string { | ||||
| return (new StringPad) | return (new StringPad) | ||||
| ->setInput($input) | ->setInput($input) | ||||
| ->setPadLength($padLength) | ->setPadLength($padLength) | ||||
| ->setPadString($padString) | ->setPadString($padString) | ||||
| ->setPadType($padType) | ->setPadType($padType) | ||||
| ->setEncoding($encoding ?: mb_internal_encoding()) | ->setEncoding($encoding ?: "UTF-8") | ||||
| ->pad(); | ->pad(); | ||||
| } | } | ||||
| public static function isSupportedEncoding (string $encoding) : bool { | public static function isSupportedEncoding (string $encoding) : bool { | ||||
| foreach (mb_list_encodings() as $supportedEncoding) { | return match ($encoding) { | ||||
| if ($encoding === $supportedEncoding) { | "UTF-8" => true, | ||||
| return true; | default => in_array($encoding, mb_list_encodings()), | ||||
| } | }; | ||||
| } | |||||
| return false; | |||||
| } | } | ||||
| /** | /** | ||||
| * @deprecated Since PHP 8.0, we can replace by \str_starts_with | * @deprecated Since PHP 8.0, we can replace by \str_starts_with | ||||
| */ | */ | ||||
| public static function startsWith (string $string, string $start) : bool { | public static function startsWith (string $string, string $start) : bool { | ||||
| $length = mb_strlen($start); | $length = mb_strlen($start); | ||||
| return mb_substr($string, 0, $length) === $start; | return mb_substr($string, 0, $length) === $start; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines | |||||
Nasqueron DevCentral · If it had been much bigger the moon would have had a core of ice. · Powered by Phabricator