Convert a string to a literal, suitable for inclusion in a query (XPath or JCR-SQL2).
See JSR-283 specification v2.0, Section 4.6.6.19.
@param value Any string.
@return A valid JCR query string literal, including enclosing quotes.
165210
@SuppressWarnings({ "unused", "null" })
  public static @NotNull String jcrQueryLiteral(@NotNull String value) {
    if (value == null) {
      throw new IllegalArgumentException("Invalid query string value: " + value);
    }
    return "'" + StringUtils.replace(value, "'", "''") + "'";
  }
645984
public static String urlEncode(String value) {
        if (value == null) {
            return value;
        }
        try {
            value = URLEncoder.encode(value, CommonWebConstants.UTF_8);
        } catch (UnsupportedEncodingException e) {
            // Do nothing - UTF-8 should always be supported
        }
        return value;
    }
366449
static String escape(String value) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);
            String replacement = REPLACEMENTS.get(c);
            if (replacement != null) {
                builder.append(replacement);
            } else {
                builder.append(c);
            }
        }
        return builder.toString();
    }
182559
public static String quote(final String value) {
        if (value == null) {
            return null;
        }
        String result = value;
        if (!result.startsWith("\"")) {
            result = "\"" + result;
        }
        if (!result.endsWith("\"")) {
            result = result + "\"";
        }
        return result;
    }
408903
@Override
    public ValidationResult validate(Object value) {
        if (value == null || value instanceof String) {
            return new ValidationResult.ValidationPassed();
        } else {
            return new ValidationResult.ValidationFailed("Value \"" + value + "\" is not a valid string!");
        }
    }
1274703
public static Object convertSqlXml(Object sqlXml, String value) throws SQLException {
        return convertSqlXml(sqlXml, value.getBytes());
    }
1143661
public JsonWriter valueLiteral(CharSequence value) {
        startValue();

        if (value == null) {
            writer.write(kNull);
        } else {
            writer.write(value.toString());
        }
        return this;
    }
462248
public static String escapeJsString(SoyValue value) {
    value = normalizeNull(value);
    return escapeJsString(value.coerceToString());
  }
158142
public static String fromWellFormed(String value) {
        if (value == null) {
            return LogicalValue.ANY.getAbbreviation();
        }
        //return value.replaceAll("\\\\([^0-9A-Za-z])", "$1");
        StringBuilder buffer = new StringBuilder(value);
        char p = ' ';
        for (int x = 0; x < buffer.length() - 1; x++) {
            char c = buffer.charAt(x);
            if (c == '\\' && p != '\\') {
                buffer.delete(x, x + 1);
                x -= 1;
            }
            p = c;
        }
        return buffer.toString();
    }
103890
public static String getPrefixFromValue(String value) {
    if (value == null) {
      return null;
    } else if (value.contains(DELIMITER)) {
      String[] list = value.split(DELIMITER);
      if (list != null && list.length > 0) {
        return list[0].replaceAll("\u0000", "");
      } else {
        return null;
      }
    } else {
      return value.replaceAll("\u0000", "");
    }
  }
1089119
public static String toAlphanumeric(String value) {
        return Pattern.compile(ALPHANUMERIC_PATTERN).matcher(value).replaceAll("");
    }
1282552
public static String decodeToStr(String value) {
        byte[] decodedValue = delegate.decode(value);
        return new String(decodedValue, UTF_8);
    }
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();
        }
    }
958208
public <T extends Enum<T>> String serializeToQueryParams(T value) {
        return (String) objectMapper.convertValue(value, String.class);
    }
825002
private static String formatValue(String value)
	{
		if(value == null)
			return "";
		
		value = value.trim();
		
		if(value.startsWith("\"")|| value.startsWith("'"))
			value = value.substring(1);
		
		if(value.endsWith("\"")|| value.endsWith("'"))
			value = value.substring(0, value.length() -1);
		
		return value;
	}
821602
@Override
    public String getEscapedValue(String value, boolean toQuote) {
        // Escape special characters
        StringBuilder buf = new StringBuilder(value.length());
        int idx = 0;
        int ch;

        while (idx < value.length()) {
            ch = value.charAt(idx++);
            if (ch == 0) {
                buf.append("\\0");

            } else if (ch == 92) { // backslash
                buf.append("\\\\");

            } else if (ch == 124) { // vertical bar
                // 124 = "|" = AbstractSerializationStream.RPC_SEPARATOR_CHAR
                buf.append("\\!");

            } else if ((ch >= 0xD800) && (ch < 0xFFFF)) {
                buf.append(String.format("\\u%04x", ch));

            } else {
                buf.append((char) ch);
            }
        }

        return buf.toString();
    }
549280
public static List<String> extractAsArrayOfString(String value) {
		Matcher matcher = arrayPattern.matcher(value);

		List<String> result = new ArrayList<String>();

		//	we need to unscape javascript format, otherwise string like " where id like '%' " will become " where id like \'%\' " 
		while (matcher.find()) {
			result.add(StringEscapeUtils.unescapeEcmaScript(matcher.group(1)));
		}

		return result;
	}