MDL-65759 library: Update php-css-parser to 8.3.0
[moodle.git] / lib / php-css-parser / Rule / Rule.php
index 3e48537..3fa031b 100644 (file)
@@ -2,10 +2,11 @@
 
 namespace Sabberworm\CSS\Rule;
 
+use Sabberworm\CSS\Comment\Commentable;
+use Sabberworm\CSS\Parsing\ParserState;
 use Sabberworm\CSS\Renderable;
 use Sabberworm\CSS\Value\RuleValueList;
 use Sabberworm\CSS\Value\Value;
-use Sabberworm\CSS\Comment\Commentable;
 
 /**
  * RuleSets contains Rule objects which always have a key and a value.
@@ -29,6 +30,44 @@ class Rule implements Renderable, Commentable {
                $this->aComments = array();
        }
 
+       public static function parse(ParserState $oParserState) {
+               $aComments = $oParserState->consumeWhiteSpace();
+               $oRule = new Rule($oParserState->parseIdentifier(), $oParserState->currentLine());
+               $oRule->setComments($aComments);
+               $oRule->addComments($oParserState->consumeWhiteSpace());
+               $oParserState->consume(':');
+               $oValue = Value::parseValue($oParserState, self::listDelimiterForRule($oRule->getRule()));
+               $oRule->setValue($oValue);
+               if ($oParserState->getSettings()->bLenientParsing) {
+                       while ($oParserState->comes('\\')) {
+                               $oParserState->consume('\\');
+                               $oRule->addIeHack($oParserState->consume());
+                               $oParserState->consumeWhiteSpace();
+                       }
+               }
+               $oParserState->consumeWhiteSpace();
+               if ($oParserState->comes('!')) {
+                       $oParserState->consume('!');
+                       $oParserState->consumeWhiteSpace();
+                       $oParserState->consume('important');
+                       $oRule->setIsImportant(true);
+               }
+               $oParserState->consumeWhiteSpace();
+               while ($oParserState->comes(';')) {
+                       $oParserState->consume(';');
+               }
+               $oParserState->consumeWhiteSpace();
+
+               return $oRule;
+       }
+
+       private static function listDelimiterForRule($sRule) {
+               if (preg_match('/^font($|-)/', $sRule)) {
+                       return array(',', '/', ' ');
+               }
+               return array(',', ' ', '/');
+       }
+
        /**
         * @return int
         */