Here you can find the source of unescape(String str)
Parameter | Description |
---|---|
str | the string to unescape |
public static String unescape(String str)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005,2007 Cognium Systems SA and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Apache License, Version 2.0 * which accompanies this distribution, and is available at * http://www.apache.org/licenses/LICENSE-2.0 * /*from w w w .jav a 2s.c o m*/ * Contributors: * Cognium Systems SA - initial API and implementation *******************************************************************************/ public class Main { /** * The default character to use has escaping char. */ private static final char DEFAULT_ESCAPECHAR = '\u005c\u005c'; /** * Unescapes the given string and returns the result. This method uses the * default escape symbol (see {@link #DEFAULT_ESCAPECHAR}). * * @param str the string to unescape * @return an unescaped string */ public static String unescape(String str) { return unescape(str, DEFAULT_ESCAPECHAR); } /** * Unescapes the given string and returns the result. * * @param str the string to unescape * @param escape the symbol used to escape characters * @return an unescaped string */ public static String unescape(String str, char escape) { if (str == null) return ""; StringBuffer buf = new StringBuffer(); char[] array = str.toCharArray(); boolean escaped = false; for (int i = 0; i < array.length; i++) { char ch = array[i]; if (escaped) { buf.append(ch); escaped = false; } else { escaped = (ch == escape); if (!escaped) buf.append(ch); } } return buf.toString(); } }