private static int doUnescape ( String s , int i , StringBuilder sb , ErrorReporter errorReporter , SourceLocation loc ) { checkArgument ( i < s . length ( ) , "Found escape sequence at the end of a string." ) ; char c = s . charAt ( i ++ ) ; switch ( c ) { case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : case ' ' : case ' ' : case ' ' : sb . append ( c ) ; break ; case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : -- i ; // backup to first octal digit int nOctalDigits = 1 ; int digitLimit = c < ' ' ? 3 : 2 ; while ( nOctalDigits < digitLimit && i + nOctalDigits < s . length ( ) && isOctal ( s . charAt ( i + nOctalDigits ) ) ) { ++ nOctalDigits ; } sb . append ( ( char ) Integer . parseInt ( s . substring ( i , i + nOctalDigits ) , 8 ) ) ; i += nOctalDigits ; break ; case ' ' : case ' ' : String hexCode ; int nHexDigits = ( c == ' ' ? 4 : 2 ) ; try { hexCode = s . substring ( i , i + nHexDigits ) ; } catch ( IndexOutOfBoundsException ioobe ) { errorReporter . report ( loc . offsetStartCol ( i + 1 ) , INVALID_UNICODE_SEQUENCE , s . substring ( i ) ) ; return i + nHexDigits ; } int unicodeValue ; try { unicodeValue = Integer . parseInt ( hexCode , 16 ) ; } catch ( NumberFormatException nfe ) { errorReporter . report ( loc . offsetStartCol ( i + 1 ) , INVALID_UNICODE_SEQUENCE , hexCode ) ; return i + nHexDigits ; } sb . append ( ( char ) unicodeValue ) ; i += nHexDigits ; break ; default : errorReporter . report ( loc . offsetStartCol ( i ) , UNKNOWN_ESCAPE_CODE , c ) ; return i ; } return i ; }
Looks for an escape code starting at index i of s and appends it to sb .