public static function collapse(string $str, string $encoding = null) : string
    {
        $encoding = $encoding ?: static::encoding($str);

        return static::trim(static::replace($str, '[[:space:]]+', ' ', 'msr', $encoding), null, $encoding);
    }