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: /**
17: *
18: * @author jmarranz
19: */
20: public class FloatNumber extends Token {
21: protected String value = "";
22:
23: /**
24: * Creates a new instance of FloatNumber
25: */
26: public FloatNumber(String code, Cursor cursor) {
27: super (cursor.getPos());
28: parse(code, cursor);
29: }
30:
31: public static boolean isFloatNumberStart(char c) {
32: // Yo creo que el + no forma parte del estándar pero por si acaso
33: return (c == '.') || (c == '+') || (c == '-')
34: || Character.isDigit(c);
35: }
36:
37: public static boolean isFloatNumberPart(char c) {
38: // En CSS los números son en coma fija (no mantisa/exponente)
39: return (c == '.') || Character.isDigit(c);
40: }
41:
42: public String toString() {
43: return value;
44: }
45:
46: public float getFloat() {
47: return Float.parseFloat(value);
48: }
49:
50: public void parse(String code, Cursor cursor) {
51: // cursor apunta al comienzo del número
52: StringBuffer valueTmp = new StringBuffer();
53: valueTmp.append(code.charAt(cursor.getPos()));
54: int i = cursor.inc(); // segunda letra (si hay)
55: while ((i < code.length()) && isFloatNumberPart(code.charAt(i))) {
56: valueTmp.append(code.charAt(i));
57: i = cursor.inc();
58: }
59:
60: this .value = valueTmp.toString();
61:
62: cursor.dec();
63: this .end = cursor.getPos(); // apunta al último caracter del número
64: }
65: }
|