Java String Quote quote(String name)

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

Description

Return a representation of the given name ensuring quoting (wrapped with '`' characters).

License

Apache License

Parameter

Parameter Description
name The name to quote.

Return

The quoted version.

Declaration

public static String quote(String name) 

Method Source Code

//package com.java2s;
/*/*from w  w  w  .j a v a  2 s  .  c om*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Return a representation of the given name ensuring quoting (wrapped with
     * '`' characters). If already wrapped return name.
     * 
     * @param name
     *            The name to quote.
     * @return The quoted version.
     */
    public static String quote(String name) {
        if (name == null || name.length() == 0 || isQuoted(name)) {
            return name;
        } else {
            return new StringBuffer(name.length() + 2).append('`').append(name).append('`').toString();
        }
    }

    /**
     * Determine if the given string is quoted (wrapped by '`' characters at
     * beginning and end).
     * 
     * @param name
     *            The name to check.
     * @return True if the given string starts and ends with '`'; false
     *         otherwise.
     */
    public static boolean isQuoted(String name) {
        return name != null && name.length() != 0 && name.charAt(0) == '`' && name.charAt(name.length() - 1) == '`';
    }

    public static String toString(Object[] array) {
        int len = array.length;
        if (len == 0)
            return "";
        StringBuffer buf = new StringBuffer(len * 12);
        for (int i = 0; i < len - 1; i++) {
            buf.append(array[i]).append(", ");
        }
        return buf.append(array[len - 1]).toString();
    }
}

Related

  1. quote(String input)
  2. quote(String literal)
  3. quote(String message, String quotationMark)
  4. quote(String name)
  5. quote(String name)
  6. quote(String name)
  7. quote(String p_sql)
  8. quote(String p_string)
  9. quote(String path)