private static String processUnicodeEscapes ( String value ) { while ( value . contains ( "\\" ) ) { int escapeStart = value . indexOf ( ' ' ) ; try { if ( value . charAt ( escapeStart + 1 ) != ' ' ) { return null ; } String hexDigits ; int escapeEnd ; if ( value . charAt ( escapeStart + 2 ) != ' ' ) { // Simple escape with exactly four hex digits: \\uXXXX escapeEnd = escapeStart + 6 ; hexDigits = value . substring ( escapeStart + 2 , escapeEnd ) ; } else { // Escape with braces can have any number of hex digits: \\u{XXXXXXX} escapeEnd = escapeStart + 3 ; while ( Character . digit ( value . charAt ( escapeEnd ) , 0x10 ) >= 0 ) { escapeEnd ++ ; } if ( value . charAt ( escapeEnd ) != ' ' ) { return null ; } hexDigits = value . substring ( escapeStart + 3 , escapeEnd ) ; escapeEnd ++ ; } // TODO(mattloring): Allow code points greater than the size of a char char ch = ( char ) Integer . parseInt ( hexDigits , 0x10 ) ; if ( ! isIdentifierPart ( ch ) ) { return null ; } value = value . substring ( 0 , escapeStart ) + ch + value . substring ( escapeEnd ) ; } catch ( NumberFormatException | StringIndexOutOfBoundsException e ) { return null ; } } return value ; }
Converts unicode escapes in the given string to the equivalent unicode character . If there are no escapes returns the input unchanged . If there is an invalid escape sequence returns null .