Here you can find the source of unquote(final CharSequence quotePhrase)
Parameter | Description |
---|---|
quotePhrase | the given quote phrase. |
public static CharSequence unquote(final CharSequence quotePhrase)
//package com.java2s; /***************************************************************** Copyright 2006 by Dung Nguyen (dungnguyen@truthinet.com) Licensed under the iNet Solutions Corp.,; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.truthinet.com/licenses/*from w w w . java 2 s .c o m*/ 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 { /** * Unquote the quote phrase. * * <pre> * This implementation check the given phrase is quote phrase before removing the quote value. * The quote phrase is the phrase has leading and ending with single or double quote character. * </pre> * * @param quotePhrase the given quote phrase. * @return the phare. */ public static CharSequence unquote(final CharSequence quotePhrase) { if (quotePhrase.length() == 0) return quotePhrase; int length = quotePhrase.length(); // check the valid quote phrase. if ((quotePhrase.charAt(0) == '"' && quotePhrase.charAt(length - 1) == '"') || (quotePhrase.charAt(0) == '\'' && quotePhrase .charAt(length - 1) == '\'')) { // unquote the phrase. final StringBuilder builder = new StringBuilder(); char ch = '\0'; for (int index = 1; index < length - 1; index++) { ch = quotePhrase.charAt(index); if (ch == '\\') { builder.append(quotePhrase.charAt(++index)); } else { builder.append(ch); } } return builder.toString(); } else { // the quote phrase is in return quotePhrase; } } }