private void scan(final char c, final int pos) {
            switch (c) {
                case '<':
                    //is considere normal char inside comments and attribute values
                    if (!tokenOneOf(Token.ATTRIBUTE_VALUE, Token.COMMENT)) {
                        startToken(Token.TAG, pos);
                    }
                    break;
                case '!':
                    if (token == Token.TAG && previousChar == '<') {
                        token = Token.COMMENT;
                    }
                    break;
                case '/':
                    if (tokenOneOf(Token.ATTRIBUTE, Token.ATTRIBUTE_END)) {
                        endToken(pos);
                        startToken(Token.TAG_END, pos);
                    }
                    break;
                case '>':
                    final boolean commentEndCandidate = ("" + previousPreviousChar + previousChar).equals("--");
                    if (token == Token.ATTRIBUTE) {
                        endToken(pos);
                        //add a one-char-TAG_END token
                        startToken(Token.TAG_END, pos);
                        endToken(pos + 1);
                    } else if (tokenOneOf(Token.TAG, Token.TAG_END) || (token == Token.COMMENT) && commentEndCandidate) {
                        endToken(pos + 1);
                    }
                    break;
                case ' ':
                    if (tokenOneOf(Token.TAG)) {
                        endToken(pos);
                        startToken(Token.ATTRIBUTE, pos + 1);
                    }
                    break;
                case '\"':
                    if (tokenOneOf(Token.ATTRIBUTE)) {
                        endToken(pos + 1);
                        startToken(Token.ATTRIBUTE_VALUE, pos + 1);
                    } else if (tokenOneOf(Token.ATTRIBUTE_VALUE)) {
                        endToken(pos);
                        startToken(Token.ATTRIBUTE, pos);
                    }
                    break;
                default:
                    break;
            }
            previousPreviousChar = previousChar;
            previousChar = c;
        }
Appender which scans and tokenizes certain HTML tokens (for later formatting)
main/src/main/java/cgeo/geocaching/utils/html/HtmlUtils.java