Java String Unescape unescape(final String text)

Here you can find the source of unescape(final String text)

Description

unescape

License

Open Source License

Declaration

public static String unescape(final String text) 

Method Source Code

//package com.java2s;
/**/*from   w  w w.j  a va2s  .co  m*/
 * This file is part of Everit - HTML Templating.
 *
 * Everit - HTML Templating is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Everit - HTML Templating is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Everit - HTML Templating.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static String unescape(final String text) {
        StringBuilder result = new StringBuilder(text.length());
        int i = 0;
        int n = text.length();
        while (i < n) {
            char charAt = text.charAt(i);
            if (charAt != '&') {
                result.append(charAt);
                i++;
            } else {
                if (text.startsWith("&amp;", i)) {
                    result.append('&');
                    i += 5;
                } else if (text.startsWith("&apos;", i)) {
                    result.append('\'');
                    i += 6;
                } else if (text.startsWith("&quot;", i)) {
                    result.append('"');
                    i += 6;
                } else if (text.startsWith("&lt;", i)) {
                    result.append('<');
                    i += 4;
                } else if (text.startsWith("&gt;", i)) {
                    result.append('>');
                    i += 4;
                }
            }
        }
        return result.toString();
    }
}

Related

  1. unescape(final String name)
  2. unescape(final String s)
  3. unescape(final String source)
  4. unescape(final String str, final char escapeChar)
  5. unescape(final String string, final char quoteChar)
  6. unescape(final String[] inval, final Character escapeChar)
  7. unescape(String aString)
  8. unescape(String aValue)
  9. unescape(String data)