boolean addToBuffer ( char c ) throws IOException { int len = sb . length ( ) ; if ( len == 0 && c != CHAR_LT ) return false ; // buffer must starts with '<' sb . append ( c ) ; // if we reached this point then we will return true if ( ++ len >= minTagLen ) { // increment len as it was sampled before we appended c boolean isClosingTag = ( len >= 2 && sb . charAt ( 1 ) == CHAR_SL ) ; String substr ; if ( isClosingTag ) substr = sb . substring ( 2 ) ; // we know that the 1st two chars are "</" else substr = sb . substring ( 1 ) ; // we know that the 1st char is "<" for ( int i = 0 ; i < EXCLUDE_TAGS . length ; i ++ ) { // loop thru list of WS-preserving tags if ( substr . equalsIgnoreCase ( EXCLUDE_TAGS [ i ] ) ) { // we have a match if ( isClosingTag ) { depthDec ( i ) ; // decrement the depth at i and calc depthSum printBuffer ( ) ; lastChar = 0 ; // needed to allow WS after buffer was printed } else { depthInc ( i ) ; // increment the depth at i and calc depthSum } } } } return true ; }
checks if a character is part of an open html tag or close html tag and if so adds it to the buffer otherwise returns false .