1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-09 23:56:43 +02:00

updated CssCompressor.java

This commit is contained in:
Steve Clay
2011-07-05 11:59:48 -04:00
parent 18a22b7937
commit 8c93fdf8a1
2 changed files with 46 additions and 28 deletions

View File

@@ -1,13 +1,13 @@
/*
* YUI Compressor
* http://developer.yahoo.com/yui/compressor/
* Author: Julien Lecomte - http://www.julienlecomte.net/
* Author: Isaac Schlueter - http://foohack.com/
* Author: Stoyan Stefanov - http://phpied.com/
* Copyright (c) 2009 Yahoo! Inc. All rights reserved.
* 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.
*/
package com.yahoo.platform.yui.compressor;
import java.io.IOException;
@@ -47,6 +47,19 @@ public class CssCompressor {
int totallen = css.length();
String placeholder;
// // leave data urls alone to increase parse performance.
// sb = new StringBuffer();
// p = Pattern.compile("url\\(.*data\\:(.*)\\)");
// m = p.matcher(css);
// while (m.find()) {
// token = m.group();
// token = token.substring(1, token.length() - 1);
// preservedTokens.add(token);
// String preserver = "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___";
// m.appendReplacement(sb, preserver);
// }
// m.appendTail(sb);
// css = sb.toString();
// collect all comment blocks...
while ((startIndex = sb.indexOf("/*", startIndex)) >= 0) {
@@ -227,12 +240,17 @@ public class CssCompressor {
m = p.matcher(css);
sb = new StringBuffer();
while (m.find()) {
// Test for AABBCC pattern
if (m.group(3).equalsIgnoreCase(m.group(4)) &&
if (m.group(1).equals("}")) {
// Likely an ID selector. Don't touch.
// #AABBCC is a valid ID. IDs are case-sensitive.
m.appendReplacement(sb, m.group());
} else if (m.group(3).equalsIgnoreCase(m.group(4)) &&
m.group(5).equalsIgnoreCase(m.group(6)) &&
m.group(7).equalsIgnoreCase(m.group(8))) {
// #AABBCC pattern
m.appendReplacement(sb, (m.group(1) + m.group(2) + "#" + m.group(3) + m.group(5) + m.group(7)).toLowerCase());
} else {
// Any other color.
m.appendReplacement(sb, m.group().toLowerCase());
}
}

View File

@@ -13,11 +13,11 @@
* by Yahoo! Inc. under the BSD (revised) open source license.
*/
require_once dirname(__FILE__) . '/Java/String.php';
/**
* Compress CSS (incomplete DO NOT USE)
*
* @see https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/CssCompressor.java
*
* @package Minify
*/
class Minify_YUI_CssCompressor {