Java String Quote quoted(String s)

Here you can find the source of quoted(String s)

Description

Returns a String which equals the argument except that occurrences of '"' are expanded into its quoted-printable escaped equivalent sequence, '\"'.

License

Apache License

Declaration

protected static String quoted(String s) 

Method Source Code

//package com.java2s;
/*/*from   w  w w . ja v  a  2 s  .co m*/
 * Copyright 2010 the original author or authors.
 * Copyright 2010 SorcerSoft.org.
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Returns a String which equals the argument except that occurrences of '"'
     * are expanded into its quoted-printable escaped equivalent sequence, '\"'.
     * If the argument contains no double-quotes the original String is
     * returned.
     */
    protected static String quoted(String s) {
        if (s == null || s.indexOf('"') < 0)
            return s;

        StringBuffer sb = new StringBuffer(s.length() + 5);
        int i, start = 0;
        while ((i = s.indexOf('"', start)) > -1) {
            sb.append(s.substring(start, i));
            sb.append("\\\"");
            start = i + 1;
        }
        sb.append(s.substring(start));
        return sb.toString();
    }
}

Related

  1. quoted(CharSequence s)
  2. quoted(CharSequence s)
  3. quoted(final String str)
  4. quoted(String i, char q)
  5. quoted(String path)
  6. quoteD(String s)
  7. quoted(String str)
  8. quoted(String text)
  9. quoted(String val, boolean wrap)