1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-09 15:46:34 +02:00

Now substring and str_slice methods match exactly their Javascript counterparts behavior.

Minor cleaning/formatting.
Tabs to spaces (Clay seems to use spaces instead of tabs)
This commit is contained in:
tubalmartin
2012-03-16 20:48:40 +01:00
parent ff45c76484
commit 73dd77569e

View File

@@ -13,18 +13,18 @@
*/
/*!
* YUI Compressor
* http://developer.yahoo.com/yui/compressor/
* Author: Julien Lecomte - http://www.julienlecomte.net/
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
* The copyrights embodied in the content of this file are licensed
* by Yahoo! Inc. under the BSD (revised) open source license.
*/
* YUI Compressor
* http://developer.yahoo.com/yui/compressor/
* Author: Julien Lecomte - http://www.julienlecomte.net/
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
* The copyrights embodied in the content of this file are licensed
* by Yahoo! Inc. under the BSD (revised) open source license.
*/
class CSSmin
{
private $comments = array();
private $preserved_tokens = array();
private $comments;
private $preserved_tokens;
/**
* @param bool $raisePhpSettingsLimits if true, raisePhpSettingLimits() will
@@ -45,12 +45,6 @@ class CSSmin
*/
public function run($css, $linebreak_pos = FALSE)
{
// Try to increase the memory limit for this script
ini_set('memory_limit', '128M');
// Try to increase the PCRE limits
ini_set('pcre.backtrack_limit', 1000 * 1000);
ini_set('pcre.recursion_limit', 500 * 1000);
$this->comments = array();
$this->preserved_tokens = array();
@@ -478,7 +472,7 @@ class CSSmin
*/
/**
* PHP port of Javascript's "indexOf" function
* PHP port of Javascript's "indexOf" function for strings only
* Author: Tubal Martin http://blog.margenn.com
*
* @param string $haystack
@@ -496,21 +490,17 @@ class CSSmin
/**
* PHP port of Javascript's "substring" function
* Author: Tubal Martin http://blog.margenn.com
* Tests: http://margenn.com/tubal/substring/
*
* @param string $str
* @param int $from index
* @param int|bool $to index (optional)
* @return string
*/
private function substring($str, $from, $to = FALSE)
private function substring($str, $from = 0, $to = FALSE)
{
if ($from < 0) {
$from = 0;
}
if ($to !== FALSE) {
if ($from === $to || $to < 0) {
if ($from == $to || ($from <= 0 && $to < 0)) {
return '';
}
@@ -519,18 +509,19 @@ class CSSmin
$from = $to;
$to = $from_copy;
}
$substring = substr($str, $from, $to - $from);
return ($substring === FALSE) ? '' : $substring;
}
$substring = substr($str, $from);
if ($from < 0) {
$from = 0;
}
$substring = ($to === FALSE) ? substr($str, $from) : substr($str, $from, $to - $from);
return ($substring === FALSE) ? '' : $substring;
}
/**
* PHP port of Javascript's "slice" function
* PHP port of Javascript's "slice" function for strings only
* Author: Tubal Martin http://blog.margenn.com
* Tests: http://margenn.com/tubal/str_slice/
*
@@ -539,15 +530,9 @@ class CSSmin
* @param int|bool $end index (optional)
* @return string
*/
private function str_slice($str, $start, $end = FALSE)
private function str_slice($str, $start = 0, $end = FALSE)
{
if ($start < 0 || $end <= 0) {
if ($end === FALSE) {
$slice = substr($str, $start);
return ($slice === FALSE) ? '' : $slice;
}
if ($end !== FALSE && ($start < 0 || $end <= 0)) {
$max = strlen($str);
if ($start < 0) {
@@ -567,7 +552,7 @@ class CSSmin
}
}
$slice = substr($str, $start, $end - $start);
$slice = ($end === FALSE) ? substr($str, $start) : substr($str, $start, $end - $start);
return ($slice === FALSE) ? '' : $slice;
}