Java String Unescape unescape(String input)

Here you can find the source of unescape(String input)

Description

Method description

License

Open Source License

Parameter

Parameter Description
input a parameter

Declaration

public static String unescape(String input) 

Method Source Code

//package com.java2s;
/*/*from  w  w w. j  ava2 s .  co  m*/
 * Tigase Jabber/XMPP XML Tools
 * Copyright (C) 2004-2007 "Artur Hefczyc" <artur.hefczyc@tigase.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. Look for COPYING file in the top folder.
 * If not, see http://www.gnu.org/licenses/.
 *
 * $Rev: 480 $
 * Last modified by $Author: cvsdeploy $
 * $Date: 2012/08/20 21:20:17 $
 */

public class Main {
    private static final String[] decoded = { "&", "<", ">", "\"", "\'" };
    private static final String[] encoded = { "&amp;", "&lt;", "&gt;", "&quot;", "&apos;" };

    /**
     * Method description
     *
     *
     * @param input
     *
     * @return
     */
    public static String unescape(String input) {
        return translateAll(input, encoded, decoded);
    }

    /**
     * Method description
     *
     *
     * @param input
     * @param patterns
     * @param replacements
     *
     * @return
     */
    public static String translateAll(String input, String[] patterns, String[] replacements) {
        String result = input;

        for (int i = 0; i < patterns.length; i++) {
            result = result.replaceAll(patterns[i], replacements[i]);
        }

        return result;
    }
}

Related

  1. unescape(String entry)
  2. unescape(String escaped)
  3. unescape(String escaped)
  4. unescape(String escaped, char escape)
  5. unescape(String escapedMessage)
  6. unescape(String input)
  7. unescape(String input, char escapeChar)
  8. unescape(String line)
  9. unescape(String line)