@Override public boolean match(int endFlag) { commentSize++; if (commentSize >= endToken.length + startToken.length || (commentSize >= endToken.length && isCommentStartedOnPreviousLine(codeBuilder))) { boolean matches = true; for (int i = 1; i <= endToken.length; i++) { if (code.charAt(-i) != endToken[endToken.length - i]) { matches = false; break; } } if (matches) { setCommentStartedOnPreviousLine(codeBuilder, Boolean.FALSE); return true; } } if (endFlag == '\r' || endFlag == '\n') { setCommentStartedOnPreviousLine(codeBuilder, Boolean.TRUE); return true; } return false; } }
@Override public boolean consume(CodeReader codeReader, List<Node> nodeList) { if (codeReader.charAt(0) != '<') { return false; } int i = 1; while (Character.isWhitespace(codeReader.charAt(i))) { i++; } if (codeReader.charAt(i) == '/' || codeReader.charAt(i) == '!') { i++; } int elementNameIndex = i; while (Character.isLetterOrDigit(codeReader.charAt(i))) { i++; } return i > elementNameIndex && super.consume(codeReader, nodeList); } }
/** * Read without consuming the next characters until a condition is reached (EndMatcher) * * @param matcher * the EndMatcher used to stop the reading * @param appendable * the read characters is appended to appendable */ public final void peekTo(EndMatcher matcher, Appendable appendable) { int index = 0; char nextChar = charAt(index); try { while (!matcher.match(nextChar) && nextChar != -1) { appendable.append(nextChar); nextChar = charAt(++index); } } catch (IOException e) { throw new ChannelException(e.getMessage(), e); } }
/** * Consume attribute value until eol or same quote */ private void consumeAttributeValueUntilQuoteOrEol(CodeReader code, HtmlCodeBuilder codeBuilder, char quote) { // consume attribute value until eol or same quote while (code.peek() != quote && code.peek() != '\r' && code.peek() != '\n') { code.pop(codeBuilder); } if (code.charAt(0) == quote) { // consume the closing quote code.pop(codeBuilder); setAttributeStarted(codeBuilder, false); setAttributeValueStarted(codeBuilder, null); } codeBuilder.appendWithoutTransforming(tagAfterAttributeValue); }
/** * Consume attribute value until eol or same quote */ private void consumeAttributeValueUntilQuoteOrEol(CodeReader code, HtmlCodeBuilder codeBuilder, char quote) { // consume attribute value until eol or same quote while (code.peek() != quote && code.peek() != '\r' && code.peek() != '\n') { code.pop(codeBuilder); } if (code.charAt(0) == quote) { // consume the closing quote code.pop(codeBuilder); setAttributeStarted(codeBuilder, false); setAttributeValueStarted(codeBuilder, null); } codeBuilder.appendWithoutTransforming(tagAfterAttributeValue); }