private void addList ( StringBuffer buffer , BufferedReader reader ) throws IOException { char [ ] lastBullet = new char [ 0 ] ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { // no nested list handling, trim lines: line = line . trim ( ) ; if ( line . length ( ) == 0 ) { continue ; } int bulletEnd = line . indexOf ( ' ' ) ; if ( bulletEnd < 1 ) { continue ; } if ( line . charAt ( bulletEnd - 1 ) == ' ' ) { bulletEnd -- ; } char [ ] bullet = line . substring ( 0 , bulletEnd ) . toCharArray ( ) ; // Logger.log("found bullet: ('" + new String(lastBullet) + "') '" + new String(bullet) + "'"); // check whether we find a new list int sharedPrefixEnd ; for ( sharedPrefixEnd = 0 ; ; sharedPrefixEnd ++ ) { if ( bullet . length <= sharedPrefixEnd || lastBullet . length <= sharedPrefixEnd || + bullet [ sharedPrefixEnd ] != lastBullet [ sharedPrefixEnd ] ) { break ; } } for ( int i = sharedPrefixEnd ; i < lastBullet . length ; i ++ ) { //Logger.log("closing " + lastBullet[i]); buffer . append ( closeList . get ( new Character ( lastBullet [ i ] ) ) ) . append ( "\n" ) ; } for ( int i = sharedPrefixEnd ; i < bullet . length ; i ++ ) { //Logger.log("opening " + bullet[i]); buffer . append ( openList . get ( new Character ( bullet [ i ] ) ) ) . append ( "\n" ) ; } buffer . append ( "<li>" ) ; buffer . append ( line . substring ( line . indexOf ( ' ' ) + 1 ) ) ; buffer . append ( "</li>\n" ) ; lastBullet = bullet ; } for ( int i = lastBullet . length - 1 ; i >= 0 ; i -- ) { //Logger.log("closing " + lastBullet[i]); buffer . append ( closeList . get ( new Character ( lastBullet [ i ] ) ) ) ; } }
Adds a list to a buffer