Added Constants for the new PartitionScanner
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / StringLiteral.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
13 //import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 //import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream;
15 //import net.sourceforge.phpdt.internal.compiler.impl.Constant;
16 //import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
17 //import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
18
19 public class StringLiteral {
20         char[] source;
21         public int sourceStart, sourceEnd;
22         
23         public StringLiteral(char[] token, int s, int e) {
24                 source = token;
25                 sourceStart = s;
26                 sourceEnd = e;
27         }
28         public StringLiteral(int s, int e) {
29                 sourceStart = s;
30                 sourceEnd = e;
31         }
32
33         /**
34          * source method comment.
35          */
36         public char[] source() {
37                 return source;
38         }
39         public String toStringExpression() {
40
41                 // handle some special char.....
42                 StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
43                 for (int i = 0; i < source.length; i++) {
44                         switch (source[i]) {
45                                 case '\b' :
46                                         result.append("\\b"); //$NON-NLS-1$
47                                         break;
48                                 case '\t' :
49                                         result.append("\\t"); //$NON-NLS-1$
50                                         break;
51                                 case '\n' :
52                                         result.append("\\n"); //$NON-NLS-1$
53                                         break;
54                                 case '\f' :
55                                         result.append("\\f"); //$NON-NLS-1$
56                                         break;
57                                 case '\r' :
58                                         result.append("\\r"); //$NON-NLS-1$
59                                         break;
60                                 case '\"' :
61                                         result.append("\\\""); //$NON-NLS-1$
62                                         break;
63                                 case '\'' :
64                                         result.append("\\'"); //$NON-NLS-1$
65                                         break;
66                                 case '\\' : //take care not to display the escape as a potential real char
67                                         result.append("\\\\"); //$NON-NLS-1$
68                                         break;
69                                 default :
70                                         result.append(source[i]);
71                         }
72                 }
73                 result.append("\""); //$NON-NLS-1$
74                 return result.toString();
75         }
76         
77         /** 
78          * @deprecated - use field instead
79         */
80         public int sourceEnd() {
81                 return sourceEnd;
82         }
83         
84         /** 
85          * @deprecated - use field instead
86         */
87         public int sourceStart() {
88                 return sourceStart;
89         }
90 }