Java Utililty Methods String Quote

List of utility methods to do String Quote

Description

The list of methods to do String Quote are organized into topic(s).

Method

Stringquote(String string)
From JSONObject.java, from which the copyright notice is the following: Copyright (c) 2002 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
if (string == null || string.length() == 0) {
    return "\"\"";
int len = string.length();
StringBuffer sb = new StringBuffer(len + 4);
sb.append('"');
sb.append(escape(string));
sb.append('"');
...
Stringquote(String string)
quote
if (string.indexOf('"') >= 0) {
    if (string.indexOf('"') >= 0) {
        string = string.replace("\"", "\\\""); 
string = ("\"" + string + "\""); 
return string;
Stringquote(String string)
Like #escape but puts a double quote character ('\"') around the escaped string.
StringBuilder buffer = new StringBuilder();
buffer.append('\"');
escape(string, buffer);
buffer.append('\"');
return buffer.toString();
Stringquote(String string)
Escapes the special characters {}$&#_^~\".
char[] chars = string.toCharArray();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < chars.length; i++) {
    char c = chars[i];
    switch (c) {
    case '{':
        ;
    case '}':
...
Stringquote(String string)
This function puts '"' around
if (string != null && string.length() != 0) {
    return "\"" + string + "\"";
} else {
    return "null";
Stringquote(String string)
Quotes a string if it contains special characters.
return quote(string, "'");
Stringquote(String string)
Add single quotes around the given string.
return string == null ? null : '\'' + string + '\'';
Stringquote(String string)
quote
char b;
char c = 0;
int i;
int len = string.length();
StringBuffer sb = new StringBuffer(len * 2);
String t;
char[] chars = string.toCharArray();
char[] buffer = new char[1030];
...
Stringquote(String string)
quote
boolean quote = false;
if ((string.indexOf('\n') != -1) || (string.indexOf('\r') != -1) || (string.indexOf('\'') != -1)
        || (string.indexOf('"') != -1) || (string.indexOf('\\') != -1) || (string.indexOf('\t') != -1)
        || (string.indexOf('%') != -1) || (string.indexOf('\u001E') != -1)) {
    string = backQuoteChars(string);
    quote = true;
if ((quote == true) || (string.indexOf('{') != -1) || (string.indexOf('}') != -1)
...
Stringquote(String string, boolean escapeHtml)
quote
int length = string.length();
if (string == null || length == 0) {
    return "\"\"";
if (length > 1) {
    if (quoted(string)) {
        return string;
    if (parenthesized(string)) {
        return string;
char c = 0;
int i;
int len = string.length();
StringBuilder sb = new StringBuilder(len + 10);
String t;
sb.append('"');
for (i = 0; i < len; i += 1) {
    c = string.charAt(i);
    switch (c) {
    case '\\':
    case '"':
        sb.append('\\');
        sb.append(c);
        break;
    case '\b':
        sb.append("\\b");
        break;
    case '\t':
        sb.append("\\t");
        break;
    case '\n':
        sb.append("\\\\n");
        break;
    case '\f':
        sb.append("\\f");
        break;
    case '\r':
        sb.append("\\\\r");
        break;
    case ',':
        sb.append(",");
        break;
    case '<':
        if (escapeHtml) {
            sb.append("\\u003c");
        } else {
            sb.append(c);
        break;
    case '>':
        if (escapeHtml) {
            sb.append("\\u003e");
        } else {
            sb.append(c);
        break;
    case '=':
        if (escapeHtml) {
            sb.append("\\u003d");
        } else {
            sb.append(c);
        break;
    case '&':
        if (escapeHtml) {
            sb.append("\\u0026");
        } else {
            sb.append(c);
        break;
    case '\'':
        if (escapeHtml) {
            sb.append("\\u0027");
        } else {
            sb.append(c);
        break;
    default:
        if (c < ' ') {
            t = "000" + Integer.toHexString(c);
            sb.append("\\u" + t.substring(t.length() - 4));
        } else {
            sb.append(c);
sb.append('"');
return sb.toString();