Java String Quote quote(String value)

Here you can find the source of quote(String value)

Description

Surrounds a value with quote characters that are not contained in the value itself.

License

Apache License

Parameter

Parameter Description
value value to be quoted

Exception

Parameter Description
IllegalArgumentException if no unused quote char can be found

Return

quoted value

Declaration

private static String quote(String value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w w w.  j a  v  a2 s.  co  m*/
     * Surrounds a value with quote characters that are not contained in the value itself.
     *
     * @param value value to be quoted
     * @return quoted value
     * @throws IllegalArgumentException if no unused quote char can be found
     */
    private static String quote(String value) {
        String quoteChar = "\"";
        if (value.contains(quoteChar)) {
            quoteChar = "\'";
        }
        if (value.contains(quoteChar)) {
            throw new IllegalArgumentException(String.format(
                    "Could not find quote char for expression: %s", value));
        }
        return String.format("%s%s%s", quoteChar, value, quoteChar);
    }
}

Related

  1. quote(String toQuote, String specials, char quoteChar)
  2. quote(String txt)
  3. quote(String val)
  4. quote(String val)
  5. quote(String val, char quote)
  6. quote(String value)
  7. quote(String value)
  8. quote(String value)
  9. quote(StringBuilder buf, String str)