Java String Dequote dequote(final String in)

Here you can find the source of dequote(final String in)

Description

dequote

License

Open Source License

Declaration

public static String dequote(final String in) 

Method Source Code

//package com.java2s;
/*//from  w  w w.j  av  a 2  s .  com
 * #%L
 * Tesora Inc.
 * Database Virtualization Engine
 * %%
 * Copyright (C) 2011 - 2014 Tesora Inc.
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */

public class Main {
    private static final String SINGLE_QUOTE = "'";
    private static final String DOUBLE_QUOTE = "\"";
    private static final String BACK_QUOTE = "`";

    public static String dequote(final String in) {
        if ((in != null) && !in.isEmpty() && isQuoted(in)) {
            // strip off the quotes
            return in.substring(1, in.length() - 1);
        }

        return in;
    }

    public static boolean isQuoted(final String value) {
        return (isQuoted(value, SINGLE_QUOTE)
                || isQuoted(value, DOUBLE_QUOTE) || isQuoted(value,
                    BACK_QUOTE));
    }

    private static boolean isQuoted(final String value, final String quote) {
        return value.startsWith(quote) && value.endsWith(quote);
    }
}

Related

  1. deQuote(String in)
  2. dequote(String inputString)
  3. deQuote(String quotedString)
  4. dequote(String s)