diff --git a/composer.json b/composer.json index ace92099..664bb905 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sabberworm/php-css-parser", + "name": "rhagni/php-css-parser", "type": "library", "description": "Parser for CSS Files written in PHP", "keywords": ["parser", "css", "stylesheet"], diff --git a/lib/Sabberworm/CSS/Parser.php b/lib/Sabberworm/CSS/Parser.php index 65ea2f0d..dcd6fde8 100644 --- a/lib/Sabberworm/CSS/Parser.php +++ b/lib/Sabberworm/CSS/Parser.php @@ -113,7 +113,7 @@ private function parseList(CSSList $oList, $bIsRoot = false) { throw new SourceException("Unexpected end of document", $this->iLineNo); } } - + private function parseListItem(CSSList $oList, $bIsRoot = false) { if ($this->comes('@')) { $oAtRule = $this->parseAtRule(); @@ -286,12 +286,14 @@ private function parseCharacter($bIsForIdentifier) { } if ($bIsForIdentifier) { $peek = ord($this->peek()); - // Ranges: a-z A-Z 0-9 - _ - if (($peek >= 97 && $peek <= 122) || - ($peek >= 65 && $peek <= 90) || - ($peek >= 48 && $peek <= 57) || - ($peek === 45) || - ($peek === 95) || + if (($peek >= 97 && $peek <= 122) || // a-z + ($peek >= 65 && $peek <= 90) || // A-Z + ($peek >= 48 && $peek <= 57) || // 0-9 + ($peek === 42) || // * + ($peek === 43) || // + + ($peek === 45) || // - + ($peek === 47) || // / + ($peek === 95) || // _ ($peek > 0xa1)) { return $this->consume(1); } @@ -428,7 +430,7 @@ private static function listDelimiterForRule($sRule) { private function parsePrimitiveValue() { $oValue = null; $this->consumeWhiteSpace(); - if (is_numeric($this->peek()) || ($this->comes('-.') && is_numeric($this->peek(1, 2))) || (($this->comes('-') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) { + if (is_numeric($this->peek()) || ($this->comes('-.') && is_numeric($this->peek(1, 2))) || (($this->comes('-') || $this->comes('+') || $this->comes('*') || $this->comes('/') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) { $oValue = $this->parseNumericValue(); } else if ($this->comes('#') || $this->comes('rgb', true) || $this->comes('hsl', true)) { $oValue = $this->parseColorValue(); @@ -446,10 +448,14 @@ private function parsePrimitiveValue() { } private function parseNumericValue($bForColor = false) { + $sOperator = ''; $sSize = ''; - if ($this->comes('-')) { - $sSize .= $this->consume('-'); - } + $sOperatorPossibilities = ['+', '-', '*', '/']; + foreach ($sOperatorPossibilities as $sOperatorPossibility) { + if ($this->comes($sOperatorPossibility)) { + $sOperator = $this->consume($sOperatorPossibility); + } + } while (is_numeric($this->peek()) || $this->comes('.')) { if ($this->comes('.')) { $sSize .= $this->consume('.'); @@ -468,7 +474,7 @@ private function parseNumericValue($bForColor = false) { } } } - return new Size(floatval($sSize), $sUnit, $bForColor, $this->iLineNo); + return new Size($sOperator . floatval($sSize), $sUnit, $bForColor, $this->iLineNo); } private function parseColorValue() { diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php index 9ad5eb08..8b38a7de 100644 --- a/lib/Sabberworm/CSS/Value/Size.php +++ b/lib/Sabberworm/CSS/Value/Size.php @@ -14,7 +14,7 @@ class Size extends PrimitiveValue { public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0) { parent::__construct($iLineNo); - $this->fSize = floatval($fSize); + $this->fSize = $fSize; $this->sUnit = $sUnit; $this->bIsColorComponent = $bIsColorComponent; } @@ -28,7 +28,7 @@ public function getUnit() { } public function setSize($fSize) { - $this->fSize = floatval($fSize); + $this->fSize = $fSize; } public function getSize() {