Escape text to ensure valid JSON.

@param value value
@return escaped value
188124
private String escapeString(String value)
   {
      m_buffer.setLength(0);
      m_buffer.append('"');
      for (int index = 0; index < value.length(); index++)
      {
         char c = value.charAt(index);
         switch (c)
         {
            case '"':
            {
               m_buffer.append("\\\"");
               break;
            }

            case '\\':
            {
               m_buffer.append("\\\\");
               break;
            }

            case '/':
            {
               m_buffer.append("\\/");
               break;
            }

            case '\b':
            {
               m_buffer.append("\\b");
               break;
            }

            case '\f':
            {
               m_buffer.append("\\f");
               break;
            }

            case '\n':
            {
               m_buffer.append("\\n");
               break;
            }

            case '\r':
            {
               m_buffer.append("\\r");
               break;
            }

            case '\t':
            {
               m_buffer.append("\\t");
               break;
            }

            default:
            {
               // Append if it's not a control character (0x00 to 0x1f)
               if (c > 0x1f)
               {
                  m_buffer.append(c);
               }
               break;
            }
         }
      }
      m_buffer.append('"');
      return m_buffer.toString();
   }
642552
public static String script(String value) {
        return value != null ? StringEscapeUtils.escapeEcmaScript(value) : value;
    }
40431
private String escape(String value)
    {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < value.length(); ++i)
        {
            char c = value.charAt(i);
            if (c < reservedChars.length && reservedChars[c] == c)
            {
                result.append(ESCAPE_PREFIX);
                int code = c & 0xFF;
                if (code < 16) result.append("0");
                result.append(Integer.toHexString(code));
            }
            else
            {
                result.append(c);
            }
        }
        return result.toString();
    }
1218135
static void escapeJSONString(final String unsafeStr, final StringBuilder buf) {
        if (unsafeStr == null) {
            return;
        }
        // Fast path
        boolean needsEscaping = false;
        for (int i = 0, n = unsafeStr.length(); i < n; i++) {
            final char c = unsafeStr.charAt(i);
            if (c > 0xff || JSON_CHAR_REPLACEMENTS[c] != null) {
                needsEscaping = true;
                break;
            }
        }
        if (!needsEscaping) {
            buf.append(unsafeStr);
            return;
        }
        // Slow path
        for (int i = 0, n = unsafeStr.length(); i < n; i++) {
            final char c = unsafeStr.charAt(i);
            if (c > 0xff) {
                buf.append("\\u");
                final int nibble3 = ((c) & 0xf000) >> 12;
                buf.append(nibble3 <= 9 ? (char) ('0' + nibble3) : (char) ('A' + nibble3 - 10));
                final int nibble2 = ((c) & 0xf00) >> 8;
                buf.append(nibble2 <= 9 ? (char) ('0' + nibble2) : (char) ('A' + nibble2 - 10));
                final int nibble1 = ((c) & 0xf0) >> 4;
                buf.append(nibble1 <= 9 ? (char) ('0' + nibble1) : (char) ('A' + nibble1 - 10));
                final int nibble0 = ((c) & 0xf);
                buf.append(nibble0 <= 9 ? (char) ('0' + nibble0) : (char) ('A' + nibble0 - 10));
            } else {
                final String replacement = JSON_CHAR_REPLACEMENTS[c];
                if (replacement == null) {
                    buf.append(c);
                } else {
                    buf.append(replacement);
                }
            }
        }
    }
846704
public static String encodeString(String value) {
    if (value == null) {
      return null;
    }
    StringBuilder encoded = new StringBuilder();
    int len = value.length();
    for (int i = 0; i < len; i++) {
      char c = value.charAt(i);
      switch (c) {
        case ARRAY_DELIMITER_CHAR:
        case KEY_VALUE_DELIMITER_CHAR:
        case ESCAPE_CHAR:
          encoded.append(ESCAPE_CHAR);
          break;
        default:
          // just append char
      }
      encoded.append(c);
    }
    return encoded.toString();
  }
1217987
def _escape(value):
        
        value = str(value)
        for char, escaped in {' ': '\ ', ',': '\,', '"': '\"'}.items():
            value = value.replace(char, escaped)
        return value
1112703
public JsonWriter writeValue(Boolean value) throws IOException {
        if (!willWriteValue) {
            indent();
        }
        writer.write(value.toString());
        willWriteValue = false;
        return this;
    }
448825
private String unescape(String value)
    {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < value.length(); ++i)
        {
            char c = value.charAt(i);
            if (c == ESCAPE_PREFIX)
            {
                String codeString = value.substring(i + 1, i + 3);
                int code = Integer.parseInt(codeString, 16);
                if (code < reservedChars.length && reservedChars[code] == code)
                {
                    result.append(reservedChars[code]);
                    i += 2;
                }
                else
                {
                    throw new ServiceLocationException("Unknown escaped character " + ESCAPE_PREFIX + codeString + " at position " + (i + 1) + " of " + value, SLPError.PARSE_ERROR);
                }
            }
            else
            {
                result.append(c);
            }
        }
        return result.toString();
    }
1143661
public JsonWriter valueLiteral(CharSequence value) {
        startValue();

        if (value == null) {
            writer.write(kNull);
        } else {
            writer.write(value.toString());
        }
        return this;
    }
607725
def escape(value, quote=True):
    '''
    
    '''
    def escape_one(match):
        return SPECIAL_CHARS[match.group(0)]

    if isinstance(value, string_types):
        value = SPECIAL_CHARS_REGEX.sub(escape_one, value)
        if quote:
            value = "'" + value + "'"
    return text_type(value)
752298
public JsonWriter valueUnescaped(CharSequence value) {
        startValue();

        if (value == null) {
            writer.write(kNull);
        } else {
            writer.write('\"');
            writer.write(value.toString());
            writer.write('\"');
        }
        return this;
    }
882583
protected static String unescape(String value) {

        value = CmsStringUtil.substitute(value, "\\,", ",");
        value = CmsStringUtil.substitute(value, "\\=", "=");
        value = CmsStringUtil.substitute(value, "\\\\", "\\");

        return value;
    }
186847
public static String escapeEscapes(String value)
    {
        assert(value != null);
        InternalStringBuilder sb = new InternalStringBuilder(value.length());
        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);
            if (c == '"') {
                sb.append("&quot;");
                continue;
            }
            if (c == '\\') {
                sb.append("\\\\");
                continue;
            }
            sb.append(c);
        }
        return sb.toString();
    }
621364
public static String escapeJsRegex(SoyValue value) {
    value = normalizeNull(value);
    return escapeJsRegex(value.coerceToString());
  }
197061
public JsonWriter writeValue(String value) throws IOException {
        if (!willWriteValue) {
            indent();
        }
        writer.write(escape(value));
        willWriteValue = false;
        return this;
    }
138553
public String json(String text) {
        if (text == null || text.isEmpty()) {
            return text;
        }
        return StringEscapeUtils.escapeJson(text);
    }
1089457
public static String toJsonString(Object value) {
        if (value == null) {
            return "null";
        }
        else if (value.getClass().equals(String.class)) {
            return "\"" + StringUtils.jsonEncoding(value.toString()) + "\"";
        }
        // else it's a RawJson, Boolean or Number so no escaping or quotes
        else {
            return value.toString();
        }
    }