public int nextToken ( ) throws IOException { int c ; int nextc = - 1 ; boolean quoted = false ; int result = m_next ; if ( m_next != 0 ) { m_next = 0 ; } m_buffer . setLength ( 0 ) ; while ( result == 0 ) { if ( nextc != - 1 ) { c = nextc ; nextc = - 1 ; } else { c = read ( ) ; } switch ( c ) { case TT_EOF : { if ( m_buffer . length ( ) != 0 ) { result = TT_WORD ; m_next = TT_EOF ; } else { result = TT_EOF ; } break ; } case TT_EOL : { int length = m_buffer . length ( ) ; if ( length != 0 && m_buffer . charAt ( length - 1 ) == ' ' ) { -- length ; m_buffer . setLength ( length ) ; } if ( length == 0 ) { result = TT_EOL ; } else { result = TT_WORD ; m_next = TT_EOL ; } break ; } default : { if ( c == m_quote ) { if ( quoted == false && startQuotedIsValid ( m_buffer ) ) { quoted = true ; } else { if ( quoted == false ) { m_buffer . append ( ( char ) c ) ; } else { nextc = read ( ) ; if ( nextc == m_quote ) { m_buffer . append ( ( char ) c ) ; nextc = - 1 ; } else { quoted = false ; } } } } else { if ( c == m_delimiter && quoted == false ) { result = TT_WORD ; } else { m_buffer . append ( ( char ) c ) ; } } } } } m_type = result ; return ( result ) ; }
This method retrieves the next token and returns a constant representing the type of token found .