Here you can find the source of quote(String s)
public static String quote(String s)
//package com.java2s; //License from project: CDDL license public class Main { public static String quote(String s) { if (s.indexOf(' ') >= 0) { char dqc = '"', sqc = '\''; int len = s.length(); if (s.charAt(0) == dqc && s.charAt(len - 1) == dqc) return s; if (s.charAt(0) == sqc && s.charAt(len - 1) == sqc) return s; String qs = (s.indexOf(dqc) >= 0) ? "'" : "\""; return qs + s + qs; } else//w ww. j a v a 2s.c o m return s; } }