Java String Quote quote(String str, StringBuffer out)

Here you can find the source of quote(String str, StringBuffer out)

Description

quote

License

Open Source License

Declaration

public static StringBuffer quote(String str, StringBuffer out) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*w w w .  jav a2s .c om*/
     */
    public static StringBuffer quote(String str, StringBuffer out) {
        if (out == null) {
            out = new StringBuffer();
        }
        out.append('"');
        int len = str.length();
        for (int i = 0; i < len; i++) {
            char c = str.charAt(i);
            switch (c) {
            case '"':
            case '\\':
                out.append('\\');
                out.append(c);
                break;
            case '\r':
                out.append("\\r");
                break;
            case '\n':
                out.append("\\n");
                break;
            default:
                out.append(c);
                break;
            }
        }
        out.append('"');
        return out;
    }
}

Related

  1. quote(String str)
  2. quote(String str)
  3. quote(String str)
  4. quote(String str, char c)
  5. quote(String str, String quoteChar)
  6. quote(String string)
  7. quote(String string)
  8. quote(String string)
  9. quote(String string)