public static String decodeHtml ( String s ) { int firstAmp = s . indexOf ( ' ' ) ; int safeLimit = longestPrefixOfGoodCodeunits ( s ) ; if ( ( firstAmp & safeLimit ) < 0 ) { return s ; } StringBuilder sb ; { int n = s . length ( ) ; sb = new StringBuilder ( n ) ; int pos = 0 ; int amp = firstAmp ; while ( amp >= 0 ) { long endAndCodepoint = HtmlEntities . decodeEntityAt ( s , amp , n ) ; int end = ( int ) ( endAndCodepoint >>> 32 ) ; int codepoint = ( int ) endAndCodepoint ; sb . append ( s , pos , amp ) . appendCodePoint ( codepoint ) ; pos = end ; amp = s . indexOf ( ' ' , end ) ; } sb . append ( s , pos , n ) ; } stripBannedCodeunits ( sb , firstAmp < 0 ? safeLimit : safeLimit < 0 ? firstAmp : Math . min ( firstAmp , safeLimit ) ) ; return sb . toString ( ) ; }
Decodes HTML entities to produce a string containing only valid Unicode scalar values .