Java String Quote quote(String literal)

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

Description

Puts a quote before and after given string.

License

LGPL

Parameter

Parameter Description
text the content to quote.

Return

the quoted version of such content.

Declaration

public static String quote(String literal) 

Method Source Code

//package com.java2s;
/**/*from www. j  a v a 2 s .  com*/
 * Converts a line of text into an array of lower case words using a
 * BreakIterator.wordInstance(). <p>
 *
 * This method is under the Jive Open Source Software License and was
 * written by Mark Imbriaco.
 *
 * @param text a String of text to convert into an array of words
 * @return text broken up into an array of words.
 */

public class Main {
    /**
     * Puts a quote before and after given string.
     * @param text the content to quote.
     * @return the quoted version of such content.
     */
    public static String quote(String literal) {
        String result = "";

        boolean t_bProcessed = true;

        if ((literal != null) && (literal.length() > 0)) {
            if (literal.charAt(0) != '\"') {
                if (literal.charAt(0) != '\'') {
                    result = "\"" + literal + "\"";
                } else {
                    if (literal.trim().length() > 0) {
                        result = "\"" + literal.substring(1, literal.length() - 1) + "\"";
                    } else {
                        t_bProcessed = false;
                    }
                }
            } else {
                result = literal;
            }
        }

        if (!t_bProcessed) {
            result = "\"\"";
        }

        return result;
    }
}

Related

  1. quote(String entityName)
  2. quote(String filepath)
  3. quote(String inp)
  4. quote(String input)
  5. quote(String input)
  6. quote(String message, String quotationMark)
  7. quote(String name)
  8. quote(String name)
  9. quote(String name)