01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.css.lex;
15:
16: import org.itsnat.core.ItsNatException;
17:
18: /**
19: *
20: * @author jmarranz
21: */
22: public abstract class StringLiteral extends Token {
23: protected String value = ""; // Contenido de la cadena sin comillas
24:
25: /**
26: * Creates a new instance of StringLiteral
27: */
28: public StringLiteral(String code, Cursor cursor) {
29: super (cursor.getPos());
30: parse(code, cursor);
31: }
32:
33: public String toString() {
34: char c = getDelimiterChar();
35: return c + value + c;
36: }
37:
38: public abstract char getDelimiterChar();
39:
40: public void parse(String code, Cursor cursor) {
41: // cursor apunta a la primera comilla
42: // Faltarķa procesar los escapes \ incluidos los \" y \'
43: StringBuffer valueTmp = new StringBuffer();
44: int i = cursor.inc();
45: char endChar = getDelimiterChar();
46: while ((i < code.length()) && (endChar != code.charAt(i))) {
47: valueTmp.append(code.charAt(i));
48: i = cursor.inc();
49: }
50:
51: this .value = valueTmp.toString();
52:
53: int end = cursor.getPos();
54: if (end >= code.length())
55: throw new ItsNatException("Missing matching " + endChar
56: + " start pos: " + start + " code: \"" + code
57: + "\"");
58:
59: this .end = end; // apunta a la comilla finalizadora
60: }
61: }
|