Java Reference
In-Depth Information
1 /**
2 * Return an identifier read from input stream
3 * First character is already read into ch
4 */
5 private String getRemainingString( )
6 {
7 StringBuilder result = new StringBuilder( ch );
8
9 for( ; nextChar( ); result.append( ch ) )
10 if( !isIdChar( ch ) )
11 {
12 putBackChar( );
13 break;
14 }
15
16 return new String( result );
17 }
figure 12.28
A routine for returning
a String from input
1 /**
2 * Return next identifier, skipping comments
3 * string constants, and character constants.
4 * Place identifier in currentIdNode.word and return false
5 * only if end of stream is reached.
6 */
7 public String getNextID( )
8 {
9 while( nextChar( ) )
10 {
11 if( ch == '/' )
12 processSlash( );
13 else if( ch == '\\' )
14 nextChar( );
15 else if( ch == '\'' || ch == '"' )
16 skipQuote( ch );
17 else if( !Character.isDigit( ch ) && isIdChar( ch ) )
18 return getRemainingString( );
19 }
20 return null; // End of file
21 }
figure 12.29
A routine for returning
the next identifier
token. The fact that getNextID and getNextOpenClose are so similar suggests
that it would have been worthwhile to write a private member function that
performs their common tasks.
Search WWH ::




Custom Search