public static function delimit(string $str, string $delimiter, string $encoding = null) : string
    {
        $encoding = $encoding ?: utils\Str::encoding($str);

        // Keep track of the internal encoding as we'll change it temporarily and then revert back to it.
        $internalEncoding = mb_regex_encoding();

        // Swap out the internal encoding for what we want...
        mb_regex_encoding($encoding);

        // ... trim the input string, convert it to lowercase, insert the delimiter.
        $str = mb_ereg_replace('\B([A-Z])', '-\1', mb_ereg_replace("^[[:space:]]+|[[:space:]]+\$", '', $str));
        $str = mb_strtolower($str, $encoding);
        $str = mb_ereg_replace('[-_\s]+', $delimiter, $str);

        // Restore the initial internal encoding.
        mb_regex_encoding($internalEncoding);

        return $str;
    }