jodd-core/src/main/java/jodd/net/HtmlDecoder.java
public static String decode(final String html) {

		int ndx = html.indexOf('&');
		if (ndx == -1) {
			return html;
		}

		StringBuilder result = new StringBuilder(html.length());

		int lastIndex = 0;
		int len = html.length();
mainloop:
		while (ndx != -1) {
			result.append(html.substring(lastIndex, ndx));

			lastIndex = ndx;
			while (html.charAt(lastIndex) != ';') {
				lastIndex++;
				if (lastIndex == len) {
					lastIndex = ndx;
					break mainloop;
				}
			}

			if (html.charAt(ndx + 1) == '#') {
				// decimal/hex
				char c = html.charAt(ndx + 2);
				int radix;
				if ((c == 'x') || (c == 'X')) {
					radix = 16;
					ndx += 3;
				} else {
					radix = 10;
					ndx += 2;
				}

				String number = html.substring(ndx, lastIndex);
				int i = Integer.parseInt(number, radix);
				result.append((char) i);
				lastIndex++;
			} else {
				// token
				String encodeToken = html.substring(ndx + 1, lastIndex);

				char[] replacement = ENTITY_MAP.get(encodeToken);
				if (replacement == null) {
					result.append('&');
					lastIndex = ndx + 1;
				} else {
					result.append(replacement);
					lastIndex++;
				}
			}
			ndx = html.indexOf('&', lastIndex);
		}
		result.append(html.substring(lastIndex));
		return result.toString();
	}
public static String decode(final String html) {

		int ndx = html.indexOf('&');
		if (ndx == -1) {
			return html;
		}

		StringBuilder result = new StringBuilder(html.length());

		int lastIndex = 0;
		int len = html.length();
mainloop:
		while (ndx != -1) {
			result.append(html.substring(lastIndex, ndx));

			lastIndex = ndx;
			while (html.charAt(lastIndex) != ';') {
				lastIndex++;
				if (lastIndex == len) {
					lastIndex = ndx;
					break mainloop;
				}
			}

			if (html.charAt(ndx + 1) == '#') {
				// decimal/hex
				char c = html.charAt(ndx + 2);
				int radix;
				if ((c == 'x') || (c == 'X')) {
					radix = 16;
					ndx += 3;
				} else {
					radix = 10;
					ndx += 2;
				}

				String number = html.substring(ndx, lastIndex);
				int i = Integer.parseInt(number, radix);
				result.append((char) i);
				lastIndex++;
			} else {
				// token
				String encodeToken = html.substring(ndx + 1, lastIndex);

				char[] replacement = ENTITY_MAP.get(encodeToken);
				if (replacement == null) {
					result.append('&');
					lastIndex = ndx + 1;
				} else {
					result.append(replacement);
					lastIndex++;
				}
			}
			ndx = html.indexOf('&', lastIndex);
		}
		result.append(html.substring(lastIndex));
		return result.toString();
	}
public static String decode ( final String html ) { int ndx = html . indexOf ( ' ' ) ; if ( ndx == - 1 ) { return html ; } StringBuilder result = new StringBuilder ( html . length ( ) ) ; int lastIndex = 0 ; int len = html . length ( ) ; mainloop : while ( ndx != - 1 ) { result . append ( html . substring ( lastIndex , ndx ) ) ; lastIndex = ndx ; while ( html . charAt ( lastIndex ) != ' ' ) { lastIndex ++ ; if ( lastIndex == len ) { lastIndex = ndx ; break mainloop ; } } if ( html . charAt ( ndx + 1 ) == ' ' ) { // decimal/hex char c = html . charAt ( ndx + 2 ) ; int radix ; if ( ( c == ' ' ) || ( c == ' ' ) ) { radix = 16 ; ndx += 3 ; } else { radix = 10 ; ndx += 2 ; } String number = html . substring ( ndx , lastIndex ) ; int i = Integer . parseInt ( number , radix ) ; result . append ( ( char ) i ) ; lastIndex ++ ; } else { // token String encodeToken = html . substring ( ndx + 1 , lastIndex ) ; char [ ] replacement = ENTITY_MAP . get ( encodeToken ) ; if ( replacement == null ) { result . append ( ' ' ) ; lastIndex = ndx + 1 ; } else { result . append ( replacement ) ; lastIndex ++ ; } } ndx = html . indexOf ( ' ' , lastIndex ) ; } result . append ( html . substring ( lastIndex ) ) ; return result . toString ( ) ; }
Decodes HTML text. Assumes that all character references are properly closed with semi-colon.
Decodes HTML text . Assumes that all character references are properly closed with semi - colon .