public static function whitespace($value, array $options = array()) {
        $options = $options + array(
            'space' => true,
            'tab' => true,
            'limit' => 2,
            'strip' => true,
            'trim' => true
        );

        if ($options['limit']) {
            $pattern = '/%s{' . $options['limit'] . ',}/u';

        } else {
            $pattern = '/%s+/u';
            $replace = '';
        }

        if ($options['tab']) {
            $value = preg_replace(sprintf($pattern, '\t'), (isset($replace) ? $replace : "\t"), $value);
        }

        if ($options['space']) {
            $value = preg_replace(sprintf($pattern, ' '), (isset($replace) ? $replace : ' '), $value); // \s replaces other whitespace characters
        }

        if ($options['strip']) {
            $value = str_replace(chr(0xCA), ' ', $value);
        }

        if ($options['trim']) {
            $value = trim($value);
        }

        return $value;
    }