class StringUtilities {

    public static String unEscapeString(String str)
    {
        final StringBuilder result = new StringBuilder(str.length());
        int index = str.indexOf('&');
        int lastIndex = 0;
        while (index++ >= 0)
        {
            if (str.regionMatches(true, index, "lt;", 0, 3))
            {
                result.append('<');
                lastIndex = index + 3;
            }
            else if (str.regionMatches(true, index, "gt;", 0, 3))
            {
                result.append('>');
                lastIndex = index + 3;
            }
            else if (str.regionMatches(true, index, "quot;", 0, 5))
            {
                result.append('"');
                lastIndex = index + 5;
            }
            else if (str.regionMatches(true, index, "amp;", 0, 4))
            {
                result.append('&');
                lastIndex = index + 4;
            }
            else if (str.regionMatches(true, index, "apos;", 0, 5))
            {
                result.append('\'');
                lastIndex = index + 5;
            }
            else
            {
                result.append('&');
                lastIndex = index;
            }
            index = str.indexOf('&', lastIndex);

            if (index > lastIndex)
            {
                result.append(str, lastIndex, index);
            }
        }
        if (lastIndex < str.length())
        {
            result.append(str, lastIndex, str.length());
        }

        return result.toString();
    }

    private  StringUtilities();

}