public static String decode(String html){
  if (html.indexOf('&') < 0) {
    return html;
  }
  char[] chars=html.toCharArray();
  int delta=0;
  int n=chars.length;
  for (int i=0; i < n; ) {
    char ch=chars[i];
    if (chars[i] == '&') {
      long packedEndAndCodepoint=HtmlEntities.decodeEntityAt(chars,i,n);
      int end=(int)(packedEndAndCodepoint >>> 32);
      if (end != i + 1) {
        int codepoint=((int)packedEndAndCodepoint) & 0xffffff;
        delta+=end - (i + Character.toChars(codepoint,chars,i - delta));
        i=end;
      }
 else {
        chars[i - delta]=ch;
        ++i;
      }
    }
 else {
      chars[i - delta]=ch;
      ++i;
    }
  }
  if (delta == 0) {
    return html;
  }
  return String.valueOf(chars,0,n - delta);
}

public static String decode ( String html ) { if ( html . indexOf ( '&' ) < 0 ) { return html ; } char [ ] chars = html . toCharArray ( ) ; int delta = 0 ; int n = chars . length ; for ( int i = 0 ; i < n ; ) { char ch = chars [ i ] ; if ( chars [ i ] == '&' ) { long packedEndAndCodepoint = HtmlEntities . decodeEntityAt ( chars , i , n ) ; int end = ( int ) ( packedEndAndCodepoint > > > 32 ) ; if ( end != i + 1 ) { int codepoint = ( ( int ) packedEndAndCodepoint ) & 0xffffff ; delta += end - ( i + Character . toChars ( codepoint , chars , i - delta ) ) ; i = end ; } else { chars [ i - delta ] = ch ; ++ i ; } } else { chars [ i - delta ] = ch ; ++ i ; } } if ( delta == 0 ) { return html ; } return String . valueOf ( chars , 0 , n - delta ) ; }
replace entity references in html cdata with their plain text equivalents .
