<s> package org . eclipse . jdt . internal . formatter . comment ; import java . io . IOException ; import java . io . Reader ; import java . util . HashMap ; import java . util . Map ; import org . eclipse . jdt . internal . compiler . parser . ScannerHelper ; public class HTMLEntity2JavaReader extends SubstitutionTextReader { private static final Map fgEntityLookup ; static { fgEntityLookup = new HashMap ( 7 ) ; fgEntityLookup . put ( "lt" , "<" ) ; fgEntityLookup . put ( "gt" , ">" ) ; fgEntityLookup . put ( "nbsp" , " " ) ; fgEntityLookup . put ( "amp" , "&" ) ; fgEntityLookup . put ( "circ" , "^" ) ; fgEntityLookup . put ( "tilde" , "~" ) ; fgEntityLookup . put ( "quot" , "\"" ) ; } public HTMLEntity2JavaReader ( Reader reader ) { super ( reader ) ; setSkipWhitespace ( false ) ; } protected String computeSubstitution ( int c ) throws IOException { if ( c == '&' ) return processEntity ( ) ; return null ; } protected String entity2Text ( String symbol ) { if ( symbol . length ( ) > 1 && symbol . charAt ( 0 ) == '#' ) { int ch ; try { if ( symbol . charAt ( 1 ) == 'x' ) { ch = Integer . parseInt ( symbol . substring ( 2 ) , 16 ) ; } else { ch = Integer . parseInt ( symbol . substring ( 1 ) , 10 ) ; } return String . valueOf ( ( char ) ch ) ; } catch ( NumberFormatException e ) { } } else { String str = ( String ) fgEntityLookup . get ( symbol ) ; if ( str != null ) { return str ; } } return "&" + symbol ; } private String processEntity ( ) throws IOException { StringBuffer buf = new StringBuffer ( ) ; int ch = nextChar ( ) ; while ( ScannerHelper . isLetterOrDigit ( ( char ) ch ) || ch == '#' ) { buf . append ( ( char ) ch ) ; ch = nextChar ( ) ; } if ( ch == ';' ) return entity2Text ( buf . toString ( ) ) ; buf . insert ( 0 , '&' ) ; if ( ch != - 1 ) buf . append ( ( char ) ch ) ; return buf . toString ( ) ; } } </s>