Here you can find the source of quote(String s, String specials, char quoteChar)
public static String quote(String s, String specials, char quoteChar)
//package com.java2s; /*/*w w w . ja v a 2s .co m*/ Copyright (C) 2003 Morten O. Alver All programs in this directory and subdirectories are published under the GNU General Public License as described below. 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 2 of the License, or (at your option) any later version. 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; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Further information about the GNU GPL is available at: http://www.gnu.org/copyleft/gpl.ja.html */ public class Main { public static String quote(String s, String specials, char quoteChar) { return quote(s, specials, quoteChar, 0); } /** * Quote special characters. * * @param s * The String which may contain special characters. * @param specials * A String containing all special characters except the quoting * character itself, which is automatically quoted. * @param quoteChar * The quoting character. * @param linewrap * The number of characters after which a linebreak is inserted * (this linebreak is undone by unquote()). Set to 0 to disable. * @return A String with every special character (including the quoting * character itself) quoted. */ public static String quote(String s, String specials, char quoteChar, int linewrap) { StringBuffer sb = new StringBuffer(); char c; int linelength = 0; boolean isSpecial; for (int i = 0; i < s.length(); ++i) { c = s.charAt(i); isSpecial = specials.indexOf(c) >= 0 || c == quoteChar; // linebreak? if (linewrap > 0 && (++linelength >= linewrap || (isSpecial && linelength >= linewrap - 1))) { sb.append(quoteChar); sb.append('\n'); linelength = 0; } if (isSpecial) { sb.append(quoteChar); ++linelength; } sb.append(c); } return sb.toString(); } }