01: /*
02: * This file or a portion of this file is licensed under the terms of
03: * the Globus Toolkit Public License, found in file GTPL, or at
04: * http://www.globus.org/toolkit/download/license.html. This notice must
05: * appear in redistributions of this file, with or without modification.
06: *
07: * Redistributions of this Software, with or without modification, must
08: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
09: * some other similar material which is provided with the Software (if
10: * any).
11: *
12: * Copyright 1999-2004 University of Chicago and The University of
13: * Southern California. All rights reserved.
14: */
15: package org.griphyn.vdl.parser;
16:
17: /**
18: * Class to pass the content from a quoted string from scanner to parser.
19: * This class is module-local on purpose.
20: *
21: * @author Jens-S. Vöckler
22: * @version $Revision: 50 $
23: *
24: */
25: class VDLtQuotedString implements VDLtToken {
26: /**
27: * The content of the string to be passed.
28: */
29: private String m_value;
30:
31: /**
32: * Contructs a new string value to pass.
33: * @param value is the content of the string.
34: */
35: public VDLtQuotedString(String value) {
36: this .m_value = value == null ? null : new String(value);
37: }
38:
39: /**
40: * Obtains the current, unmodified content of the string. This
41: * means that quote characters inside the string will remain
42: * as-is.
43: * @return the content of the quoted string.
44: */
45: public String getValue() {
46: return this .m_value;
47: }
48:
49: /**
50: * Turns the content of a string into a quoted version of itself.
51: * The quote and backslash character are quoted by prepending a
52: * backslash in front of them. Single quotes (apostrophe) are not
53: * touched.
54: * @param unquoted is the raw string that may require quoting.
55: * @return null if the input was null, or the quoted string.
56: */
57: public static String getQuotedValue(String unquoted) {
58: if (unquoted == null)
59: return null;
60:
61: StringBuffer result = new StringBuffer(unquoted.length());
62: for (int i = 0; i < unquoted.length(); ++i) {
63: char ch = unquoted.charAt(i);
64: if (ch == '\\' || ch == '\"')
65: result.append('\\');
66: result.append(ch);
67: }
68:
69: return result.toString();
70: }
71: }
|