public int read ( ) throws IOException { if ( hasNextChar ) { hasNextChar = false ; write ( nextChar ) ; return nextChar ; } if ( previousLine != lexer . getLine ( ) ) { // new line, so reset unicode escapes numUnicodeEscapesFoundOnCurrentLine = 0 ; previousLine = lexer . getLine ( ) ; } int c = reader . read ( ) ; if ( c != ' ' ) { write ( c ) ; return c ; } // Have one backslash, continue if next char is 'u' c = reader . read ( ) ; if ( c != ' ' ) { hasNextChar = true ; nextChar = c ; write ( ' ' ) ; return ' ' ; } // Swallow multiple 'u's int numberOfUChars = 0 ; do { numberOfUChars ++ ; c = reader . read ( ) ; } while ( c == ' ' ) ; // Get first hex digit checkHexDigit ( c ) ; StringBuilder charNum = new StringBuilder ( ) ; charNum . append ( ( char ) c ) ; // Must now be three more hex digits for ( int i = 0 ; i < 3 ; i ++ ) { c = reader . read ( ) ; checkHexDigit ( c ) ; charNum . append ( ( char ) c ) ; } int rv = Integer . parseInt ( charNum . toString ( ) , 16 ) ; write ( rv ) ; numUnicodeEscapesFound += 4 + numberOfUChars ; numUnicodeEscapesFoundOnCurrentLine += 4 + numberOfUChars ; return rv ; }
Gets the next character from the underlying reader translating escapes as required .