Example #1
0
 /**
  * Parses the supports rule.
  *
  * @param $ruleString
  */
 protected function parseRuleString($ruleString)
 {
     // Remove at-rule name and unnecessary white-spaces
     $ruleString = preg_replace('/^[ \\r\\n\\t\\f]*@supports[ \\r\\n\\t\\f]*/i', '', $ruleString);
     $ruleString = trim($ruleString, " \r\n\t\f");
     $charset = $this->getCharset();
     $conditions = [];
     foreach (Condition::splitNestedConditions($ruleString, $this->getCharset()) as $normalizedConditionList) {
         $normalizedConditions = [];
         $currentCondition = "";
         if (preg_match('/[^\\x00-\\x7f]/', $normalizedConditionList)) {
             $isAscii = false;
             $strLen = mb_strlen($normalizedConditionList, $charset);
             $getAnd = function ($i) use($normalizedConditionList) {
                 return strtolower(substr($normalizedConditionList, $i, 5));
             };
         } else {
             $isAscii = true;
             $strLen = strlen($normalizedConditionList);
             $getAnd = function ($i) use($charset, $normalizedConditionList) {
                 return mb_strtolower(mb_substr($normalizedConditionList, $i, 5, $charset), $charset);
             };
         }
         for ($i = 0, $j = $strLen; $i < $j; $i++) {
             if ($isAscii === true) {
                 $char = $normalizedConditionList[$i];
             } else {
                 $char = mb_substr($normalizedConditionList, $i, 1, $charset);
             }
             if ($char === " " && $getAnd($i) === " and ") {
                 $normalizedConditions[] = new SupportsCondition(trim($currentCondition, " \r\n\t\f"));
                 $currentCondition = "";
                 $i += 5 - 1;
             } else {
                 $currentCondition .= $char;
             }
         }
         $currentCondition = trim($currentCondition, " \r\n\t\f");
         if ($currentCondition !== "") {
             $normalizedConditions[] = new SupportsCondition(trim($currentCondition, " \r\n\t\f"));
         }
         foreach ($normalizedConditions as $normalizedCondition) {
             $conditions[] = $normalizedCondition;
         }
     }
     $this->setConditions($conditions);
 }
Example #2
0
 /**
  * Parses the condition part of the media rule.
  *
  * @param string $conditionList
  * @return MediaCondition[]
  */
 protected function parseConditionList($conditionList)
 {
     $charset = $this->getCharset();
     $conditions = [];
     foreach (Condition::splitNestedConditions($conditionList) as $normalizedConditionList) {
         $normalizedConditions = [];
         $currentCondition = "";
         if (preg_match('/[^\\x00-\\x7f]/', $normalizedConditionList)) {
             $isAscii = false;
             $strLen = mb_strlen($normalizedConditionList, $charset);
             $getAnd = function ($i) use($normalizedConditionList) {
                 return strtolower(substr($normalizedConditionList, $i, 5));
             };
         } else {
             $isAscii = true;
             $strLen = strlen($normalizedConditionList);
             $getAnd = function ($i) use($charset, $normalizedConditionList) {
                 return mb_strtolower(mb_substr($normalizedConditionList, $i, 5, $charset), $charset);
             };
         }
         for ($i = 0, $j = $strLen; $i < $j; $i++) {
             if ($isAscii === true) {
                 //$char = substr($normalizedConditionList, $i, 1);
                 $char = $normalizedConditionList[$i];
             } else {
                 $char = mb_substr($normalizedConditionList, $i, 1, $charset);
             }
             if ($char === " " && $getAnd($i) === " and ") {
                 $normalizedConditions[] = new MediaCondition(trim($currentCondition, " \r\n\t\f"));
                 $currentCondition = "";
                 $i += 5 - 1;
             } else {
                 $currentCondition .= $char;
             }
         }
         $currentCondition = trim($currentCondition, " \r\n\t\f");
         if ($currentCondition !== "") {
             $normalizedConditions[] = new MediaCondition(trim($currentCondition, " \r\n\t\f"));
         }
         foreach ($normalizedConditions as $normalizedCondition) {
             $conditions[] = $normalizedCondition;
         }
     }
     return $conditions;
 }