Minor changes in pages design.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / StringLiteralSQ.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
13 /**
14  * 
15  * single quoted string literal
16  */
17 public class StringLiteralSQ extends StringLiteral {
18         public StringLiteralSQ(char[] token, int s, int e) {
19                 super(token, s, e);
20         }
21
22         public StringLiteralSQ(int s, int e) {
23
24                 super(s, e);
25         }
26
27         public String toStringExpression() {
28
29                 // handle some special char.....
30                 StringBuffer result = new StringBuffer("\'"); //$NON-NLS-1$
31                 for (int i = 0; i < source.length; i++) {
32                         switch (source[i]) {
33                         case '\b':
34                                 result.append("\\b"); //$NON-NLS-1$
35                                 break;
36                         case '\t':
37                                 result.append("\\t"); //$NON-NLS-1$
38                                 break;
39                         case '\n':
40                                 result.append("\\n"); //$NON-NLS-1$
41                                 break;
42                         case '\f':
43                                 result.append("\\f"); //$NON-NLS-1$
44                                 break;
45                         case '\r':
46                                 result.append("\\r"); //$NON-NLS-1$
47                                 break;
48                         case '\"':
49                                 result.append("\\\""); //$NON-NLS-1$
50                                 break;
51                         case '\'':
52                                 result.append("\\'"); //$NON-NLS-1$
53                                 break;
54                         case '\\': // take care not to display the escape as a potential
55                                                 // real char
56                                 result.append("\\\\"); //$NON-NLS-1$
57                                 break;
58                         default:
59                                 result.append(source[i]);
60                         }
61                 }
62                 result.append("\'"); //$NON-NLS-1$
63                 return result.toString();
64         }
65
66 }