java.lang.Object
io.sf.carte.uparser.CommentRemovalHandler
io.sf.carte.uparser.MinificationHandler
- All Implemented Interfaces:
ContentHandler<RuntimeException>,ControlHandler<RuntimeException>,TokenErrorHandler<RuntimeException>,TokenHandler2,TokenHandler3<RuntimeException>
A handler that minifies by removing comments and consecutive whitespace.
Example:
String minify(String text) {
String[] opening = { "/*", "<!--" };
String[] closing = { "*/", "-->" };
MinificationHandler handler = new MinificationHandler(text.length());
TokenProducer tp = new TokenProducer(handler);
tp.setHandleAllSeparators(false);
try {
tp.parseMultiComment(new StringReader(text), opening, closing);
} catch (IOException e) {
}
return handler.getBuffer().toString();
}
-
Constructor Summary
ConstructorsConstructorDescriptionMinificationHandler(int bufSize) Construct the handler with the given initial buffer size.MinificationHandler(StringBuilder buffer) Construct the handler with the given buffer. -
Method Summary
Methods inherited from class io.sf.carte.uparser.CommentRemovalHandler
character, commented, endOfStream, error, escaped, getBuffer, getPreviousCodepoint, leftCurlyBracket, leftParenthesis, leftSquareBracket, quoted, quotedNewlineChar, quotedWithControl, rightCurlyBracket, rightParenthesis, rightSquareBracket, setPreviousCodepoint, tokenStart, wordMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.sf.carte.uparser.TokenHandler2
endPunctuation, startPunctuation
-
Constructor Details
-
MinificationHandler
public MinificationHandler(int bufSize) Construct the handler with the given initial buffer size.- Parameters:
bufSize- the initial buffer size.
-
MinificationHandler
Construct the handler with the given buffer.- Parameters:
buffer- the buffer.
-
-
Method Details
-
separator
public void separator(int index, int codePoint) Description copied from interface:TokenHandler2A separator (Zs, Zl and Zp unicode categories) was found.- Specified by:
separatorin interfaceContentHandler<RuntimeException>- Specified by:
separatorin interfaceTokenHandler2- Overrides:
separatorin classCommentRemovalHandler- Parameters:
index- the index at which the separator was found.codePoint- the codepoint of the found separator.
-
control
public void control(int index, int codePoint) Description copied from interface:TokenHandler2A control character codepoint was found.- Specified by:
controlin interfaceControlHandler<RuntimeException>- Specified by:
controlin interfaceTokenHandler2- Overrides:
controlin classCommentRemovalHandler- Parameters:
index- the index at which the control codepoint was found.codePoint- the control codepoint.
-