Here you can find the source of unescape(String val, char quote)
static public String unescape(String val, char quote)
//package com.java2s; /*/* ww w.j a va 2s .com*/ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of the License "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ public class Main { /** * Unescape escaped chars in a string 'val'. * */ static public String unescape(String val, char quote) { StringBuffer buff = new StringBuffer(); for (int i = 0; i < val.length(); i++) { char ch = val.charAt(i); if (ch == '\\' && i + 1 < val.length()) { ch = val.charAt(++i); if (Character.digit(ch, 8) >= 0 && i + 2 < val.length()) { String code = val.substring(i, i + 3); i += 2; try { int octal = Integer.parseInt(code, 8); buff.append((char) octal); } catch (NumberFormatException x) { // UtilsPlugin.log(x); } } else { switch (ch) { case 't': buff.append('\t'); break; case 'n': buff.append('\n'); break; case 'r': buff.append('\r'); break; case 'f': buff.append('\f'); break; case 'b': buff.append('\b'); break; case 'u': try { String code = val.substring(i + 1, i + 5); buff.append((char) Integer.parseInt(code, 16)); i += 4; } catch (NumberFormatException e) { buff.append('\\'); buff.append('u'); } break; case '\\': buff.append('\\'); break; case '"': buff.append('"'); break; case '\'': buff.append('\''); break; default: buff.append('\\'); buff.append(ch); break; } } } else { buff.append(ch); } } return buff.toString(); } /** * Parse a string into an integer, returning a default * value instead of throwing an exception for invalid strings. */ public static int parseInt(String s, int defaultValue) { int result = defaultValue; // avoid spurious IllegalArgumentException if (s != null) { try { result = Integer.parseInt(s); } catch (NumberFormatException x) { } } return result; } }