/******************************************************************************* * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v0.5 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v05.html * * Contributors: * IBM Corporation - initial API and implementation ******************************************************************************/ package net.sourceforge.phpdt.internal.compiler.ast; //import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor; //import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream; //import net.sourceforge.phpdt.internal.compiler.impl.Constant; //import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope; //import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding; public class StringLiteral { char[] source; public int sourceStart, sourceEnd; public StringLiteral(char[] token, int s, int e) { source = token; sourceStart = s; sourceEnd = e; } public StringLiteral(int s, int e) { sourceStart = s; sourceEnd = e; } /** * source method comment. */ public char[] source() { return source; } public String toStringExpression() { // handle some special char..... StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$ for (int i = 0; i < source.length; i++) { switch (source[i]) { case '\b' : result.append("\\b"); //$NON-NLS-1$ break; case '\t' : result.append("\\t"); //$NON-NLS-1$ break; case '\n' : result.append("\\n"); //$NON-NLS-1$ break; case '\f' : result.append("\\f"); //$NON-NLS-1$ break; case '\r' : result.append("\\r"); //$NON-NLS-1$ break; case '\"' : result.append("\\\""); //$NON-NLS-1$ break; case '\'' : result.append("\\'"); //$NON-NLS-1$ break; case '\\' : //take care not to display the escape as a potential real char result.append("\\\\"); //$NON-NLS-1$ break; default : result.append(source[i]); } } result.append("\""); //$NON-NLS-1$ return result.toString(); } /** * @deprecated - use field instead */ public int sourceEnd() { return sourceEnd; } /** * @deprecated - use field instead */ public int sourceStart() { return sourceStart; } }