public static String unhtmlentities(final String str){
  if (str == null) {
    return null;
  }
  if (htmlentities_map.isEmpty()) {
    initializeEntitiesTables();
  }
  final StringBuilder buf=new StringBuilder();
  for (int i=0; i < str.length(); ++i) {
    final char ch=str.charAt(i);
    if (ch == '&') {
      final int semi=str.indexOf(';',i + 1);
      if (semi == -1 || semi - i > 7) {
        buf.append(ch);
        continue;
      }
      final String entity=str.substring(i,semi + 1);
      Integer iso;
      if (entity.charAt(1) == ' ') {
        buf.append(ch);
        continue;
      }
      if (entity.charAt(1) == '#') {
        if (entity.charAt(2) == 'x') {
          iso=new Integer(Integer.parseInt(entity.substring(3,entity.length() - 1),16));
        }
 else {
          iso=new Integer(entity.substring(2,entity.length() - 1));
        }
      }
 else {
        iso=unhtmlentities_map.get(entity);
      }
      if (iso == null) {
        buf.append(entity);
      }
 else {
        buf.append((char)iso.intValue());
      }
      i=semi;
    }
 else {
      buf.append(ch);
    }
  }
  return buf.toString();
}

public static String unhtmlentities ( final String str ) { if ( str == null ) { return null ; } if ( htmlentities_map . isEmpty ( ) ) { initializeEntitiesTables ( ) ; } final StringBuilder buf = new StringBuilder ( ) ; for ( int i = 0 ; i < str . length ( ) ; ++ i ) { final char ch = str . charAt ( i ) ; if ( ch == '&' ) { final int semi = str . indexOf ( ';' , i + 1 ) ; if ( semi == - 1 || semi - i > 7 ) { buf . append ( ch ) ; continue ; } final String entity = str . substring ( i , semi + 1 ) ; Integer iso ; if ( entity . charAt ( 1 ) == ' ' ) { buf . append ( ch ) ; continue ; } if ( entity . charAt ( 1 ) == '#' ) { if ( entity . charAt ( 2 ) == 'x' ) { iso = new Integer ( Integer . parseInt ( entity . substring ( 3 , entity . length ( ) - 1 ) , 16 ) ) ; } else { iso = new Integer ( entity . substring ( 2 , entity . length ( ) - 1 ) ) ; } } else { iso = unhtmlentities_map . get ( entity ) ; } if ( iso == null ) { buf . append ( entity ) ; } else { buf . append ( ( char ) iso . intValue ( ) ) ; } i = semi ; } else { buf . append ( ch ) ; } } return buf . toString ( ) ; }
convert html entities to special and extended unicode characters equivalents .
