Source code: com/tripi/asp/StringNode.java
1 /**
2 * ArrowHead ASP Server
3 * This is a source file for the ArrowHead ASP Server - an 100% Java
4 * VBScript interpreter and ASP server.
5 *
6 * For more information, see http://www.tripi.com/arrowhead
7 *
8 * Copyright (C) 2002 Terence Haddock
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25 package com.tripi.asp;
26
27 /**
28 * This class represents a string in the parsed ASP code.
29 *
30 * @author Terence Haddock
31 */
32 public class StringNode extends DefaultNode
33 {
34 /** String this string node contains */
35 String string;
36
37 /**
38 * Constructor.
39 * @param string String value
40 */
41 public StringNode(Object string)
42 {
43 this.string = (String)string;
44 }
45
46 /**
47 * Dumps this string value.
48 * @see DefaultNode#dump
49 */
50 public void dump()
51 {
52 System.out.print(string);
53 }
54
55 /**
56 * Get the string value.
57 * @return string value
58 */
59 public String getString()
60 {
61 return string;
62 }
63
64 /**
65 * Executes this string, returns the string value stripped of the
66 * surrounding quotes and any escape sequences.
67 * @param context ASP Context
68 * @return Strng value
69 * @see DefaultNode#execute(AspContext)
70 */
71 public Object execute(AspContext context)
72 {
73 return string;
74 /*String substr = string.substring(1, string.length() - 1);
75 int index = substr.indexOf("\"\"");
76 while (index >= 0) {
77 substr = substr.substring(0, index) + substr.substring(index+1);
78 index = substr.indexOf("\"\"", index+1);
79 }
80 return substr;*/
81 }
82
83 /**
84 * Construct a string node from a string token.
85 * @param str String token
86 */
87 public static StringNode fromStringToken(String str)
88 {
89 String substr = str.substring(1, str.length() - 1);
90 int index = substr.indexOf("\"\"");
91 while (index >= 0) {
92 substr = substr.substring(0, index) + substr.substring(index+1);
93 index = substr.indexOf("\"\"", index+1);
94 }
95 return new StringNode(substr);
96 }
97 };
98