public static String unquoteHtmlChars ( String item ) { if ( item == null ) { return null ; } int next = item . indexOf ( ' ' ) ; // nothing was quoted if ( next == - 1 ) { return item ; } int len = item . length ( ) ; int posn = 0 ; StringBuilder buffer = new StringBuilder ( ) ; while ( next != - 1 ) { buffer . append ( item . substring ( posn , next ) ) ; if ( item . startsWith ( "&amp;" , next ) ) { buffer . append ( ' ' ) ; next += 5 ; } else if ( item . startsWith ( "&apos;" , next ) ) { buffer . append ( ' ' ) ; next += 6 ; } else if ( item . startsWith ( "&gt;" , next ) ) { buffer . append ( ' ' ) ; next += 4 ; } else if ( item . startsWith ( "&lt;" , next ) ) { buffer . append ( ' ' ) ; next += 4 ; } else if ( item . startsWith ( "&quot;" , next ) ) { buffer . append ( ' ' ) ; next += 6 ; } else { int end = item . indexOf ( ' ' , next ) + 1 ; if ( end == 0 ) { end = len ; } throw new IllegalArgumentException ( "Bad HTML quoting for " + item . substring ( next , end ) ) ; } posn = next ; next = item . indexOf ( ' ' , posn ) ; } buffer . append ( item . substring ( posn , len ) ) ; return buffer . toString ( ) ; }
Remove HTML quoting from a string .