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, word
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:TokenHandler2
A separator (Zs, Zl and Zp unicode categories) was found.- Specified by:
separator
in interfaceContentHandler<RuntimeException>
- Specified by:
separator
in interfaceTokenHandler2
- Overrides:
separator
in 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:TokenHandler2
A control character codepoint was found.- Specified by:
control
in interfaceControlHandler<RuntimeException>
- Specified by:
control
in interfaceTokenHandler2
- Overrides:
control
in classCommentRemovalHandler
- Parameters:
index
- the index at which the control codepoint was found.codePoint
- the control codepoint.
-