diff --git a/misuzu.php b/misuzu.php index fb86c021..e2c8eeb9 100644 --- a/misuzu.php +++ b/misuzu.php @@ -34,7 +34,6 @@ $errorHandler->pushHandler( ); $errorHandler->register(); -require_once 'src/array.php'; require_once 'src/audit_log.php'; require_once 'src/changelog.php'; require_once 'src/colour.php'; @@ -43,13 +42,11 @@ require_once 'src/csrf.php'; require_once 'src/emotes.php'; require_once 'src/general.php'; require_once 'src/git.php'; -require_once 'src/integer.php'; require_once 'src/manage.php'; require_once 'src/news.php'; require_once 'src/otp.php'; require_once 'src/pagination.php'; require_once 'src/perms.php'; -require_once 'src/string.php'; require_once 'src/twitter.php'; require_once 'src/url.php'; require_once 'src/zalgo.php'; diff --git a/src/array.php b/src/array.php deleted file mode 100644 index 49c52e83..00000000 --- a/src/array.php +++ /dev/null @@ -1,26 +0,0 @@ - $value) { - $array1[$key] |= $array2[$key] ?? 0; - } - - return $array1; -} diff --git a/src/integer.php b/src/integer.php deleted file mode 100644 index 536d5934..00000000 --- a/src/integer.php +++ /dev/null @@ -1,4 +0,0 @@ - $value) { + $array1[$key] |= $array2[$key] ?? 0; + } + + return $array1; +} + +function clamp($num, int $min, int $max): int { + return max($min, min($max, intval($num))); +} + +function starts_with(string $string, string $text, bool $multibyte = true): bool { + $strlen = $multibyte ? 'mb_strlen' : 'strlen'; + $substr = $multibyte ? 'mb_substr' : 'substr'; + return $substr($string, 0, $strlen($text)) === $text; +} + +function ends_with(string $string, string $text, bool $multibyte = true): bool { + $strlen = $multibyte ? 'mb_strlen' : 'strlen'; + $substr = $multibyte ? 'mb_substr' : 'substr'; + return $substr($string, 0 - $strlen($text)) === $text; +} + +function first_paragraph(string $text, string $delimiter = "\n"): string { + $index = mb_strpos($text, $delimiter); + return $index === false ? $text : mb_substr($text, 0, $index); +} + +function camel_to_snake(string $camel): string { + return trim(mb_strtolower(preg_replace('#([A-Z][a-z]+)#', '$1_', $camel)), '_'); +} + +function snake_to_camel(string $snake): string { + return str_replace('_', '', ucwords($snake, '_')); +} + +function unique_chars(string $input, bool $multibyte = true): int { + $chars = []; + $strlen = $multibyte ? 'mb_strlen' : 'strlen'; + $substr = $multibyte ? 'mb_substr' : 'substr'; + $length = $strlen($input); + + for($i = 0; $i < $length; $i++) { + $current = $substr($input, $i, 1); + + if(!in_array($current, $chars, true)) { + $chars[] = $current; + } + } + + return count($chars); +} + +function byte_symbol(int $bytes, bool $decimal = false, array $symbols = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']): string { + if($bytes < 1) { + return '0 B'; + } + + $divider = $decimal ? 1000 : 1024; + $exp = floor(log($bytes) / log($divider)); + $bytes = $bytes / pow($divider, floor($exp)); + $symbol = $symbols[$exp]; + + return sprintf("%.2f %s%sB", $bytes, $symbol, $symbol !== '' && !$decimal ? 'i' : ''); +} + function safe_delete(string $path): void { $path = realpath($path);