You are here

function csstidy_optimise::explode_ws in Advanced CSS/JS Aggregation 7

Same name and namespace in other branches
  1. 6 advagg_css_compress/csstidy/class.csstidy_optimise.inc \csstidy_optimise::explode_ws()

Explodes a string as explode() does, however, not if $sep is escaped or within a string.

@version 1.0

Parameters

string $sep seperator:

string $string:

Return value

array

3 calls to csstidy_optimise::explode_ws()
csstidy_optimise::dissolve_short_bg in advagg_css_compress/csstidy/class.csstidy_optimise.inc
Dissolve background property
csstidy_optimise::dissolve_short_font in advagg_css_compress/csstidy/class.csstidy_optimise.inc
Dissolve font property
csstidy_optimise::merge_bg in advagg_css_compress/csstidy/class.csstidy_optimise.inc
Merges all background properties

File

advagg_css_compress/csstidy/class.csstidy_optimise.inc, line 580

Class

csstidy_optimise
CSS Optimising Class

Code

function explode_ws($sep, $string) {
  $status = 'st';
  $to = '';
  $output = array();
  $num = 0;
  for ($i = 0, $len = strlen($string); $i < $len; $i++) {
    switch ($status) {
      case 'st':
        if ($string[$i] == $sep && !csstidy::escaped($string, $i)) {
          ++$num;
        }
        elseif ($string[$i] === '"' || $string[$i] === '\'' || $string[$i] === '(' && !csstidy::escaped($string, $i)) {
          $status = 'str';
          $to = $string[$i] === '(' ? ')' : $string[$i];
          isset($output[$num]) ? $output[$num] .= $string[$i] : ($output[$num] = $string[$i]);
        }
        else {
          isset($output[$num]) ? $output[$num] .= $string[$i] : ($output[$num] = $string[$i]);
        }
        break;
      case 'str':
        if ($string[$i] == $to && !csstidy::escaped($string, $i)) {
          $status = 'st';
        }
        isset($output[$num]) ? $output[$num] .= $string[$i] : ($output[$num] = $string[$i]);
        break;
    }
  }
  if (isset($output[0])) {
    return $output;
  }
  else {
    return array(
      $output,
    );
  }
}