public StringBuffer minifyCSS(final StringBuffer data) {
		// Remove comments and carriage returns
		String compressed = COMMENTS_PATTERN.matcher(data.toString()).replaceAll("");

		// Temporarily replace the strings with a placeholder
		final List<String> licences = new ArrayList<>();
		final Matcher licenceMatcher = LICENCE_PATTERN.matcher(compressed);

		compressed = new MatcherProcessorCallback() {
			@Override
			String matchCallback(final Matcher matcher) {
				final String match = matcher.group();
				String replacement = "";
				if (keepLicence) {
					licences.add(match);
					replacement = LICENCE_PLACEHOLDER;
				}
				return replacement;
			}
		}.processWithMatcher(licenceMatcher);

		// Temporarily replace the strings with a placeholder
		final List<String> strings = new ArrayList<>();
		final Matcher stringMatcher = QUOTED_CONTENT_PATTERN.matcher(compressed);

		compressed = new MatcherProcessorCallback() {
			@Override
			String matchCallback(final Matcher matcher) {
				final String match = matcher.group();
				strings.add(match);
				return STRING_PLACEHOLDER;
			}
		}.processWithMatcher(stringMatcher);

		// Grab all rules and replace whitespace in selectors
		final Matcher rulesmatcher = RULES_PATTERN.matcher(compressed);
		compressed = new MatcherProcessorCallback() {
			@Override
			String matchCallback(final Matcher matcher) {
				final String match = matcher.group(1);
				final String spaced = NEW_LINES_TAB_PATTERN.matcher(match).replaceAll(SPACE).trim();
				return spaced + matcher.group(2);
			}
		}.processWithMatcher(rulesmatcher);

		// Replace all linefeeds and tabs
		compressed = NEW_LINES_TAB_PATTERN.matcher(compressed).replaceAll(" ");

		// Match all empty space we can minify
		final Matcher matcher = SPACES_PATTERN.matcher(compressed);
		compressed = new MatcherProcessorCallback() {
			@Override
			String matchCallback(final Matcher matcher) {
				String replacement = SPACE;
				final String match = matcher.group();

				if (match.contains(PLUS_OPERATOR)) {
					replacement = PLUS_OPERATOR_REPLACEMENT;
				} else if (match.contains(MINUS_OPERATOR)) {
					replacement = MINUS_OPERATOR_REPLACEMENT;
				} else if (match.contains(MULTIPLICATION_OPERATOR)) {
					replacement = MULTIPLICATION_OPERATOR_REPLACEMENT;
				} else if (match.contains(DIVISION_OPERATOR)) {
					replacement = DIVISION_OPERATOR_REPLACEMENT;
				} else if (match.contains(PLUS_OPERATOR)) {
					replacement = PLUS_OPERATOR_REPLACEMENT;
				} else if (match.contains(BRACKET_OPEN)) {
					replacement = BRACKET_OPEN;
				} else if (match.contains(BRACKET_CLOSE)) {
					replacement = BRACKET_CLOSE;
				} else if (match.contains(PAREN_OPEN)) {
					replacement = PAREN_OPEN;
				} else if (match.contains(COLON)) {
					replacement = COLON;
				} else if (match.contains(SEMICOLON)) {
					replacement = SEMICOLON;
				} else if (match.contains(PAREN_CLOSE)) {
					replacement = PAREN_CLOSE;
				}
				return replacement;
			}
		}.processWithMatcher(matcher);

		// Restore all Strings
		final Matcher restoreStringMatcher = STRING_PLACEHOLDER_PATTERN.matcher(compressed);
		final Iterator<String> itStr = strings.iterator();
		compressed = new MatcherProcessorCallback() {
			@Override
			String matchCallback(final Matcher matcher) {

				final String replacement = itStr.next();
				return replacement;
			}
		}.processWithMatcher(restoreStringMatcher);

		// Restore all licences
		final Matcher restoreLicenceMatcher = LICENCE_PLACEHOLDER_PATTERN.matcher(compressed);
		final Iterator<String> itLicence = licences.iterator();
		compressed = new MatcherProcessorCallback() {
			@Override
			String matchCallback(final Matcher matcher) {

				final String replacement = itLicence.next();
				return replacement;
			}
		}.processWithMatcher(restoreLicenceMatcher);

		return new StringBuffer(compressed);
	}
public StringBuffer minifyCSS ( final StringBuffer data ) { String compressed = COMMENTS_PATTERN . matcher ( data . toString ( ) ) . replaceAll ( "" ) ; final List < String > licences = new ArrayList < > ( ) ; final Matcher licenceMatcher = LICENCE_PATTERN . matcher ( compressed ) ; compressed = new MatcherProcessorCallback ( ) { @ Override String matchCallback ( final Matcher matcher ) { final String match = matcher . group ( ) ; String replacement = "" ; if ( keepLicence ) { licences . add ( match ) ; replacement = LICENCE_PLACEHOLDER ; } return replacement ; } } . processWithMatcher ( licenceMatcher ) ; final List < String > strings = new ArrayList < > ( ) ; final Matcher stringMatcher = QUOTED_CONTENT_PATTERN . matcher ( compressed ) ; compressed = new MatcherProcessorCallback ( ) { @ Override String matchCallback ( final Matcher matcher ) { final String match = matcher . group ( ) ; strings . add ( match ) ; return STRING_PLACEHOLDER ; } } . processWithMatcher ( stringMatcher ) ; final Matcher rulesmatcher = RULES_PATTERN . matcher ( compressed ) ; compressed = new MatcherProcessorCallback ( ) { @ Override String matchCallback ( final Matcher matcher ) { final String match = matcher . group ( 1 ) ; final String spaced = NEW_LINES_TAB_PATTERN . matcher ( match ) . replaceAll ( SPACE ) . trim ( ) ; return spaced + matcher . group ( 2 ) ; } } . processWithMatcher ( rulesmatcher ) ; compressed = NEW_LINES_TAB_PATTERN . matcher ( compressed ) . replaceAll ( " " ) ; final Matcher matcher = SPACES_PATTERN . matcher ( compressed ) ; compressed = new MatcherProcessorCallback ( ) { @ Override String matchCallback ( final Matcher matcher ) { String replacement = SPACE ; final String match = matcher . group ( ) ; if ( match . contains ( PLUS_OPERATOR ) ) { replacement = PLUS_OPERATOR_REPLACEMENT ; } else if ( match . contains ( MINUS_OPERATOR ) ) { replacement = MINUS_OPERATOR_REPLACEMENT ; } else if ( match . contains ( MULTIPLICATION_OPERATOR ) ) { replacement = MULTIPLICATION_OPERATOR_REPLACEMENT ; } else if ( match . contains ( DIVISION_OPERATOR ) ) { replacement = DIVISION_OPERATOR_REPLACEMENT ; } else if ( match . contains ( PLUS_OPERATOR ) ) { replacement = PLUS_OPERATOR_REPLACEMENT ; } else if ( match . contains ( BRACKET_OPEN ) ) { replacement = BRACKET_OPEN ; } else if ( match . contains ( BRACKET_CLOSE ) ) { replacement = BRACKET_CLOSE ; } else if ( match . contains ( PAREN_OPEN ) ) { replacement = PAREN_OPEN ; } else if ( match . contains ( COLON ) ) { replacement = COLON ; } else if ( match . contains ( SEMICOLON ) ) { replacement = SEMICOLON ; } else if ( match . contains ( PAREN_CLOSE ) ) { replacement = PAREN_CLOSE ; } return replacement ; } } . processWithMatcher ( matcher ) ; final Matcher restoreStringMatcher = STRING_PLACEHOLDER_PATTERN . matcher ( compressed ) ; final Iterator < String > itStr = strings . iterator ( ) ; compressed = new MatcherProcessorCallback ( ) { @ Override String matchCallback ( final Matcher matcher ) { final String replacement = itStr . next ( ) ; return replacement ; } } . processWithMatcher ( restoreStringMatcher ) ; final Matcher restoreLicenceMatcher = LICENCE_PLACEHOLDER_PATTERN . matcher ( compressed ) ; final Iterator < String > itLicence = licences . iterator ( ) ; compressed = new MatcherProcessorCallback ( ) { @ Override String matchCallback ( final Matcher matcher ) { final String replacement = itLicence . next ( ) ; return replacement ; } } . processWithMatcher ( restoreLicenceMatcher ) ; return new StringBuffer ( compressed ) ; }
@param data
CSS to minify
@return StringBuffer Minified CSS.