Here you can find the source of quote(String inp)
Parameter | Description |
---|---|
inp | the string to process |
public static String quote(String inp)
//package com.java2s; /*/*from w w w . j a v a2s. c o m*/ *EXHIBIT A - Sun Industry Standards Source License * *"The contents of this file are subject to the Sun Industry *Standards Source License Version 1.2 (the "License"); *You may not use this file except in compliance with the *License. You may obtain a copy of the *License at http://wbemservices.sourceforge.net/license.html * *Software distributed under the License is distributed on *an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either *express or implied. See the License for the specific *language governing rights and limitations under the License. * *The Original Code is WBEM Services. * *The Initial Developer of the Original Code is: *Sun Microsystems, Inc. * *Portions created by: Sun Microsystems, Inc. *are Copyright 2002 Sun Microsystems, Inc. * *All Rights Reserved. * *Contributor(s): Brian Schlosser */ public class Main { /** * Escapes special characters in a string * * @param inp the string to process * @return The string with all of the special characters escaped. */ public static String quote(String inp) { StringBuffer sb = new StringBuffer(inp.length()); sb.append('\"'); sb.append(escape(inp)); sb.append('\"'); return sb.toString(); } /** * Escapes special characters in a string * * @param str the string to process * @return The string with all of the special characters escaped. */ public static String escape(String str) { int size = str.length(); StringBuffer sb = new StringBuffer(size); for (int i = 0; i < size; i++) { char ch = str.charAt(i); switch (ch) { case 0: continue; case '\n': sb.append("\\n"); break; case '\t': sb.append("\\t"); break; case '\b': sb.append("\\b"); break; case '\r': sb.append("\\r"); break; case '\f': sb.append("\\f"); break; case '\\': sb.append("\\\\"); break; case '\'': sb.append("\\\'"); break; case '\"': sb.append("\\\""); break; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = Integer.toString(ch, 16); sb.append("\\x" + "0000".substring(s.length() - 4) + s); } else { sb.append(ch); } break; } } return sb.toString(); } }