<?php
declare(strict_types=1);

namespace mystic\forum\utils;

final class StringUtils {
    use StaticClass;

    public static function camelToSnake(string $camelCase): string {
        $result = '';

        for ($i = 0; $i < strlen($camelCase); $i++) {
            $char = $camelCase[$i];

            if (ctype_upper($char)) {
                $result .= '_' . strtolower($char);
            } else {
                $result .= $char;
            }
        }

        return ltrim($result, '_');
    }

    public static function truncate(string $str, int $maxLength, string $ellipsis = "…"): string {
        return mb_strimwidth($str, 0, $maxLength, $ellipsis);
    }
}