You are here

private function CSSCompression_Selectors::parse in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg_css_compress/css-compressor-3.x/src/lib/Selectors.inc \CSSCompression_Selectors::parse()

Converts selectors like BODY => body, DIV => div and injects tokens wrappers for attribute values

Parameters

(string) selector: CSS Selector:

1 call to CSSCompression_Selectors::parse()
CSSCompression_Selectors::selectors in advagg_css_compress/css-compressor-3.x/src/lib/Selectors.inc
Selector specific optimizations

File

advagg_css_compress/css-compressor-3.x/src/lib/Selectors.inc, line 101

Class

CSSCompression_Selectors
CSS Compressor [VERSION] [DATE] Corey Hart @ http://www.codenothing.com

Code

private function parse($selector) {
  $clean = '';
  $substr = '';
  $pos = 0;
  while (preg_match($this->rmark, $selector, $match, PREG_OFFSET_CAPTURE, $pos)) {
    $substr = substr($selector, $pos, $match[0][1] + 1 - $pos);
    $clean .= $this->options['lowercase-selectors'] ? strtolower($substr) : $substr;
    $pos = $match[0][1] + strlen($match[1][0]);

    // Class or id match
    if ($match[1][0] == '#' || $match[1][0] == '.') {
      if (preg_match($this->ridclassend, $selector, $m, PREG_OFFSET_CAPTURE, $pos)) {
        $clean .= substr($selector, $pos, $m[0][1] - $pos);
        $pos = $m[0][1];
      }
      else {
        $clean .= substr($selector, $pos);
        $pos = strlen($selector);
        break;
      }
    }
    else {
      if (preg_match($this->rquote, $selector, $m, PREG_OFFSET_CAPTURE, $pos)) {
        if ($selector[$pos] == "\"" || $selector[$pos] == "'") {
          $pos++;
        }
        $clean .= $this->token . substr($selector, $pos, $m[0][1] - $pos) . $this->token . ']';
        $pos = $m[0][1] + strlen($m[0][0]);
      }
      else {
        $clean .= substr($selector, $pos);
        $pos = strlen($selector);
        break;
      }
    }
  }
  return $clean . ($this->options['lowercase-selectors'] ? strtolower(substr($selector, $pos)) : substr($selector, $pos));
}