/**
  * Optimises a sub-value.
  *
  * @since 1.0.0
  */
 public function subvalue()
 {
     $replace_colors =& $this->parser->data['csstidy']['replace_colors'];
     $this->sub_value = trim($this->sub_value);
     if ('' === $this->sub_value) {
         // caution : '0'
         return;
     }
     $important = '';
     if ($this->parser->is_important($this->sub_value)) {
         $important = ' !important';
     }
     $this->sub_value = $this->parser->gvw_important($this->sub_value);
     // Compress font-weight.
     if ('font-weight' === $this->property && $this->parser->get_cfg('compress_font-weight')) {
         if ('bold' === $this->sub_value) {
             $this->sub_value = '700';
             $this->parser->log('Optimised font-weight: Changed "bold" to "700"', 'Information');
         } elseif ('normal' === $this->sub_value) {
             $this->sub_value = '400';
             $this->parser->log('Optimised font-weight: Changed "normal" to "400"', 'Information');
         }
     }
     $temp = $this->compress_numbers($this->sub_value);
     if (0 !== strcasecmp($temp, $this->sub_value)) {
         if (strlen($temp) > strlen($this->sub_value)) {
             $this->parser->log('Fixed invalid number: Changed "' . $this->sub_value . '" to "' . $temp . '"', 'Warning');
         } else {
             $this->parser->log('Optimised number: Changed "' . $this->sub_value . '" to "' . $temp . '"', 'Information');
         }
         $this->sub_value = $temp;
     }
     if ($this->parser->get_cfg('compress_colors')) {
         $temp = $this->cut_color($this->sub_value);
         if ($temp !== $this->sub_value) {
             if (isset($replace_colors[$this->sub_value])) {
                 $this->parser->log('Fixed invalid color name: Changed "' . $this->sub_value . '" to "' . $temp . '"', 'Warning');
             } else {
                 $this->parser->log('Optimised color: Changed "' . $this->sub_value . '" to "' . $temp . '"', 'Information');
             }
             $this->sub_value = $temp;
         }
     }
     $this->sub_value .= $important;
 }
 /**
  * Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain.
  *
  * @since 2.0
  *
  * @param bool   $plain         Optional. Plain text or not.
  * @param string $default_media Optional. Default @media to add to selectors without any @media.
  */
 protected function _print($plain = false, $default_media = '')
 {
     if ($this->output_css && $this->output_css_plain) {
         return;
     }
     $output = '';
     if (!$this->parser->get_cfg('preserve_css')) {
         $this->_convert_raw_css($default_media);
     }
     $template =& $this->template;
     if ($plain) {
         $template = array_map('strip_tags', $template);
     }
     if ($this->parser->get_cfg('timestamp')) {
         array_unshift($this->tokens, array(COMMENT, ' CSSTidy ' . $this->parser->version . ': ' . date('r') . ' '));
     }
     if (!empty($this->charset)) {
         $output .= $template[0] . '@charset ' . $template[5] . $this->charset . $template[6] . $template[13];
     }
     if (!empty($this->import)) {
         for ($i = 0, $size = count($this->import); $i < $size; $i++) {
             $import_components = explode(' ', $this->import[$i]);
             if ('url(' === substr($import_components[0], 0, 4) && ')' === substr($import_components[0], -1, 1)) {
                 $import_components[0] = '\'' . trim(substr($import_components[0], 4, -1), "'\"") . '\'';
                 $this->import[$i] = implode(' ', $import_components);
                 $this->parser->log('Optimised @import : Removed "url("', 'Information');
             }
             $output .= $template[0] . '@import ' . $template[5] . $this->import[$i] . $template[6] . $template[13];
         }
     }
     if (!empty($this->namespace)) {
         if (false !== ($p = strpos($this->namespace, 'url(')) && ')' === substr($this->namespace, -1, 1)) {
             $this->namespace = substr_replace($this->namespace, '"', $p, 4);
             $this->namespace = substr($this->namespace, 0, -1) . '"';
             $this->parser->log('Optimised @namespace : Removed "url("', 'Information');
         }
         $output .= $template[0] . '@namespace ' . $template[5] . $this->namespace . $template[6] . $template[13];
     }
     $in_at_out = '';
     $out =& $output;
     foreach ($this->tokens as $key => $token) {
         switch ($token[0]) {
             case AT_START:
                 if ($this->parser->get_cfg('preserve_css')) {
                     $token[1] = str_replace(',', ",\n", $token[1]);
                 }
                 $out .= $template[0] . $this->_htmlsp($token[1], $plain) . $template[1];
                 $out =& $in_at_out;
                 break;
             case SEL_START:
                 if ($this->parser->get_cfg('lowercase_s')) {
                     $token[1] = strtolower($token[1]);
                 }
                 if ($this->parser->get_cfg('preserve_css')) {
                     $token[1] = str_replace(',', ",\n", $token[1]);
                 }
                 $out .= '@' !== $token[1][0] ? $template[2] . $this->_htmlsp($token[1], $plain) : $template[0] . $this->_htmlsp($token[1], $plain);
                 $out .= $template[3];
                 break;
             case PROPERTY:
                 if (2 === $this->parser->get_cfg('case_properties')) {
                     $token[1] = strtoupper($token[1]);
                 } elseif (1 === $this->parser->get_cfg('case_properties')) {
                     $token[1] = strtolower($token[1]);
                 }
                 $out .= $template[4] . $this->_htmlsp($token[1], $plain) . ':' . $template[5];
                 break;
             case VALUE:
                 $out .= $this->_htmlsp($token[1], $plain);
                 if (SEL_END === $this->_seeknocomment($key, 1) && $this->parser->get_cfg('remove_last_;')) {
                     $out .= str_replace(';', '', $template[6]);
                 } else {
                     $out .= $template[6];
                 }
                 if ($this->parser->get_cfg('preserve_css')) {
                     $out .= COMMENT === $this->tokens[$key + 1][0] ? ' ' : "\n";
                 }
                 break;
             case SEL_END:
                 $out .= $template[7];
                 if (AT_END !== $this->_seeknocomment($key, 1)) {
                     $out .= $template[8];
                 }
                 break;
             case AT_END:
                 $out =& $output;
                 $in_at_out = str_replace("\n\n", "\r\n", $in_at_out);
                 // don't fill empty lines
                 $in_at_out = str_replace("\n", "\n" . $template[10], $in_at_out);
                 $in_at_out = str_replace("\r\n", "\n\n", $in_at_out);
                 $out .= $template[10] . $in_at_out . $template[9];
                 $in_at_out = '';
                 break;
             case COMMENT:
                 $out .= $template[11] . '/*' . $this->_htmlsp($token[1], $plain) . '*/' . $template[12];
                 break;
         }
     }
     if (!$this->parser->get_cfg('preserve_css')) {
         $output = str_replace(' !important', '!important', $output);
     }
     $output = trim($output);
     if (!$plain) {
         $this->output_css = $output;
         $this->_print(true);
     } else {
         // If using spaces in the template, don't want these to appear in the plain output.
         $this->output_css_plain = str_replace('&#160;', '', $output);
     }
 }