You are here

private function CSSmin::str_slice in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 8.2 advagg_css_minify/yui/CSSMin.inc \CSSmin::str_slice()
  2. 8.3 advagg_css_minify/yui/CSSMin.inc \CSSmin::str_slice()

PHP port of Javascript's "slice" function for strings only Author: Tubal Martin http://blog.margenn.com Tests: http://margenn.com/tubal/str_slice/

Parameters

string $str:

int $start index:

int|bool $end index (optional):

Return value

string

3 calls to CSSmin::str_slice()
CSSmin::minify in advagg_css_compress/yui/CSSMin.inc
Does bulk of the minification
CSSmin::replace_string in advagg_css_compress/yui/CSSMin.inc
CSSmin::run in advagg_css_compress/yui/CSSMin.inc
Minify a string of CSS

File

advagg_css_compress/yui/CSSMin.inc, line 685

Class

CSSmin

Code

private function str_slice($str, $start = 0, $end = FALSE) {
  if ($end !== FALSE && ($start < 0 || $end <= 0)) {
    $max = strlen($str);
    if ($start < 0) {
      if (($start = $max + $start) < 0) {
        return '';
      }
    }
    if ($end < 0) {
      if (($end = $max + $end) < 0) {
        return '';
      }
    }
    if ($end <= $start) {
      return '';
    }
  }
  $slice = $end === FALSE ? substr($str, $start) : substr($str, $start, $end - $start);
  return $slice === FALSE ? '' : $slice;
}