KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > generator > core > nodes > StringNode


1 package com.genimen.djeneric.tools.generator.core.nodes;
2
3 import com.genimen.djeneric.tools.generator.core.DjentelParserEngine;
4 import com.genimen.djeneric.tools.generator.core.SimpleNode;
5 import com.genimen.djeneric.tools.generator.core.util.ParseContext;
6
7 public class StringNode extends SimpleNode implements ValueExpression
8 {
9   String JavaDoc _value = null;
10
11   public StringNode(int i)
12   {
13     super(i);
14   }
15
16   public StringNode(DjentelParserEngine p, int i)
17   {
18     super(p, i);
19   }
20
21   public String JavaDoc getName()
22   {
23     return toString();
24   }
25
26   public String JavaDoc toString()
27   {
28     return _value;
29   }
30
31   public void setValue(String JavaDoc v)
32   {
33     // Strip the quotes
34
v = v.substring(1);
35     v = v.substring(0, v.length() - 1);
36
37     _value = translateEscapes(v);
38   }
39
40   public Object JavaDoc getValue(ParseContext context)
41   {
42     return _value;
43   }
44
45   static String JavaDoc _froms = "ntbrf\\'\"";
46   static String JavaDoc _tos = "\n\t\b\r\f\\'\"";
47
48   public static String JavaDoc translateEscapes(String JavaDoc src)
49   {
50     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(src);
51
52     int i = 0;
53     while (i < sb.length() - 1)
54     {
55       if (sb.charAt(i) == '\\')
56       {
57         for (int x = 0; x < _froms.length(); x++)
58         {
59           if (_froms.charAt(x) == sb.charAt(i + 1))
60           {
61             sb.deleteCharAt(i);
62             sb.setCharAt(i, _tos.charAt(x));
63             break;
64           }
65         }
66       }
67       i++;
68     }
69     return sb.toString();
70   }
71 }
Popular Tags