MatthiasMullie\Minify\CSS::shortenZeroes PHP Метод

shortenZeroes() защищенный Метод

Shorthand 0 values to plain 0, instead of e.g. -0em.
protected shortenZeroes ( string $content ) : string
$content string The CSS content to shorten the zero values for
Результат string
    protected function shortenZeroes($content)
    {
        // reusable bits of code throughout these regexes:
        // before & after are used to make sure we don't match lose unintended
        // 0-like values (e.g. in #000, or in http://url/1.0)
        // units can be stripped from 0 values, or used to recognize non 0
        // values (where wa may be able to strip a .0 suffix)
        $before = '(?<=[:(, ])';
        $after = '(?=[ ,);}])';
        $units = '(em|ex|%|px|cm|mm|in|pt|pc|ch|rem|vh|vw|vmin|vmax|vm)';
        // strip units after zeroes (0px -> 0)
        // NOTE: it should be safe to remove all units for a 0 value, but in
        // practice, Webkit (especially Safari) seems to stumble over at least
        // 0%, potentially other units as well. Only stripping 'px' for now.
        // @see https://github.com/matthiasmullie/minify/issues/60
        $content = preg_replace('/' . $before . '(-?0*(\\.0+)?)(?<=0)px' . $after . '/', '\\1', $content);
        // strip 0-digits (.0 -> 0)
        $content = preg_replace('/' . $before . '\\.0+' . $units . '?' . $after . '/', '0\\1', $content);
        // strip trailing 0: 50.10 -> 50.1, 50.10px -> 50.1px
        $content = preg_replace('/' . $before . '(-?[0-9]+\\.[0-9]+)0+' . $units . '?' . $after . '/', '\\1\\2', $content);
        // strip trailing 0: 50.00 -> 50, 50.00px -> 50px
        $content = preg_replace('/' . $before . '(-?[0-9]+)\\.0+' . $units . '?' . $after . '/', '\\1\\2', $content);
        // strip leading 0: 0.1 -> .1, 01.1 -> 1.1
        $content = preg_replace('/' . $before . '(-?)0+([0-9]*\\.[0-9]+)' . $units . '?' . $after . '/', '\\1\\2\\3', $content);
        // strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0)
        $content = preg_replace('/' . $before . '-?0+' . $units . '?' . $after . '/', '0\\1', $content);
        // remove zeroes where they make no sense in calc: e.g. calc(100px - 0)
        // the 0 doesn't have any effect, and this isn't even valid without unit
        // strip all `+ 0` or `- 0` occurrences: calc(10% + 0) -> calc(10%)
        // looped because there may be multiple 0s inside 1 group of parentheses
        do {
            $previous = $content;
            $content = preg_replace('/\\(([^\\(\\)]+)\\s+[\\+\\-]\\s+0(\\s+[^\\(\\)]+)?\\)/', '(\\1\\2)', $content);
        } while ($content !== $previous);
        // strip all `0 +` occurrences: calc(0 + 10%) -> calc(10%)
        $content = preg_replace('/\\(\\s*0\\s+\\+\\s+([^\\(\\)]+)\\)/', '(\\1)', $content);
        // strip all `0 -` occurrences: calc(0 - 10%) -> calc(-10%)
        $content = preg_replace('/\\(\\s*0\\s+\\-\\s+([^\\(\\)]+)\\)/', '(-\\1)', $content);
        // I'm not going to attempt to optimize away `x * 0` instances:
        // it's dumb enough code already that it likely won't occur, and it's
        // too complex to do right (order of operations would have to be
        // respected etc)
        // what I cared about most here was fixing incorrectly truncated units
        return $content;
    }