@Immutable
    public static String htmlspecialchars_decode(String string, int quoteStyle) {
        int len = string.length();

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < len; i++) {
            char ch = string.charAt(i);

            if (ch != '&') {
                sb.append(ch);

                continue;
            }

            switch (string.charAt(i + 1)) {
                case 'a':
                    sb.append('&');
                    if (i + 4 < len
                        && string.charAt(i + 2) == 'm'
                        && string.charAt(i + 3) == 'p'
                        && string.charAt(i + 4) == ';') {
                        i += 4;
                    }
                    break;

                case 'q':
                    if ((quoteStyle & StringConstants.ENT_HTML_QUOTE_DOUBLE) != 0
                        && i + 5 < len
                        && string.charAt(i + 2) == 'u'
                        && string.charAt(i + 3) == 'o'
                        && string.charAt(i + 4) == 't'
                        && string.charAt(i + 5) == ';') {
                        i += 5;
                        sb.append('"');
                    } else {
                        sb.append('&');
                    }
                    break;

                case '#':
                    if ((quoteStyle & StringConstants.ENT_HTML_QUOTE_SINGLE) != 0
                        && i + 5 < len
                        && string.charAt(i + 2) == '0'
                        && string.charAt(i + 3) == '3'
                        && string.charAt(i + 4) == '9'
                        && string.charAt(i + 5) == ';') {
                        i += 5;
                        sb.append('\'');
                    } else {
                        sb.append('&');
                    }

                    break;

                case 'l':
                    if (i + 3 < len
                        && string.charAt(i + 2) == 't'
                        && string.charAt(i + 3) == ';') {
                        i += 3;

                        sb.append('<');
                    } else {
                        sb.append('&');
                    }
                    break;

                case 'g':
                    if (i + 3 < len
                        && string.charAt(i + 2) == 't'
                        && string.charAt(i + 3) == ';') {
                        i += 3;

                        sb.append('>');
                    } else {
                        sb.append('&');
                    }
                    break;

                default:
                    sb.append('&');
            }
        }

        return sb.toString();
    }
Parses the cslashes bitmap returning an actual bitmap.

@param charset the bitmap string

@return the actual bitmap
exts/jphp-zend-ext/src/main/java/org/develnext/jphp/zend/ext/standard/StringFunctions.java