Here you can find the source of unquote(String str)
Parameter | Description |
---|---|
str | the string to dequotify. |
public static String unquote(String str) throws Exception
//package com.java2s; /*/*from www.j a va 2 s .c o m*/ * Portions of this file Copyright 1999-2005 University of Chicago * Portions of this file Copyright 1999-2005 The University of Southern California. * * This file or a portion of this file is licensed under the * terms of the Globus Toolkit Public License, found at * http://www.globus.org/toolkit/download/license.html. * If you redistribute this file, with or without * modifications, you must include this notice in the file. */ public class Main { /** * Dequotifies a specified string. * The quotes are removed and each \" is replaced with " and * each \\ is replaced with \. * * @param str the string to dequotify. * @return unquotified string. */ public static String unquote(String str) throws Exception { int len = str.length(); StringBuffer buf = new StringBuffer(len); boolean inQuotes = false; char c; int i = 0; if (str.charAt(i) == '"') { inQuotes = true; i++; } while (i < len) { c = str.charAt(i); if (inQuotes) { if (c == '"') { inQuotes = false; } else if (c == '\\') { buf.append(str.charAt(++i)); } else { buf.append(c); } } else { if (c == '\r') { if (str.charAt(i++) != '\n') { throw new Exception("Malformed string."); } } else if (c == '"') { inQuotes = true; i++; } else { buf.append(c); } } i++; } return buf.toString(); } }