001 /** 002 * ========================================= 003 * LibFormula : a free Java formula library 004 * ========================================= 005 * 006 * Project Info: http://reporting.pentaho.org/libformula/ 007 * 008 * (C) Copyright 2006-2007, by Pentaho Corporation and Contributors. 009 * 010 * This library is free software; you can redistribute it and/or modify it under the terms 011 * of the GNU Lesser General Public License as published by the Free Software Foundation; 012 * either version 2.1 of the License, or (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 015 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 016 * See the GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public License along with this 019 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 020 * Boston, MA 02111-1307, USA. 021 * 022 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 023 * in the United States and other countries.] 024 * 025 * 026 * ------------ 027 * $Id: ParserTools.java 4483 2008-02-20 12:07:43Z tmorgner $ 028 * ------------ 029 * (C) Copyright 2006-2007, by Pentaho Corporation. 030 */ 031 package org.jfree.formula.parser; 032 033 /** 034 * Creation-Date: 03.11.2006, 18:57:23 035 * 036 * @author Thomas Morgner 037 */ 038 public class ParserTools 039 { 040 private ParserTools() 041 { 042 } 043 044 /** 045 * Unconditionally removes the first and last character of the given string and also unquotes the quoted double-quotes. 046 * 047 * @param s the string to be stripped. 048 * @return the stripped string. 049 */ 050 public static String stripQuote(final String s) 051 { 052 boolean encounteredQuote = false; 053 054 final StringBuffer b = new StringBuffer(s.length() - 2); 055 final int size = s.length() - 1; 056 for (int i = 1; i < size; i++) 057 { 058 final char c = s.charAt(i); 059 if (encounteredQuote) 060 { 061 if (c == '"') 062 { 063 encounteredQuote = false; 064 continue; 065 } 066 } 067 if (c == '"') 068 { 069 encounteredQuote = true; 070 } 071 else 072 { 073 encounteredQuote = false; 074 } 075 b.append(c); 076 } 077 return b.toString(); 078 } 079 080 }