01: package com.teamkonzept.publishing.markups;
02:
03: /**
04: * @author $Author: mischa $
05: * @version $Revision: 1.6 $
06: */
07: public class TKMarkupFloatParamClass extends TKMarkupParamClass {
08:
09: /**
10: * checks if raw is a string representation of a float
11: * @return the trimmed string (if it is a float) or null
12: */
13: public String checkValue(String raw) {
14: if (raw == null) {
15: return raw;
16: }
17:
18: String value = raw.trim();
19: int pos = 0;
20: // is true as long as there is no '.'
21: boolean isInt = true;
22:
23: while (pos < value.length()) {
24: char chr = value.charAt(pos++);
25:
26: if (chr == '.') {
27: if (!isInt) {
28: return null;
29: } else {
30: isInt = false;
31: }
32: } else if (digitCodes.indexOf(chr) == -1) {
33: return null;
34: }
35: }
36: return value;
37: }
38:
39: public int parseUnquotedValue(String text, int pos,
40: StringBuffer value) throws TKMarkupParserException {
41:
42: if (value != null)
43: value.setLength(0);
44:
45: boolean isInt = true;
46: boolean isFloat = true;
47:
48: while (pos < text.length()) {
49:
50: char chr = text.charAt(pos);
51:
52: if (chr == '.') {
53: if (!isInt) {
54: isFloat = false;
55: } else {
56: isInt = false;
57: }
58: } else if (digitCodes.indexOf(chr) == -1) {
59: isInt = false;
60: isFloat = false;
61: }
62: if (!isInt && !isFloat)
63: break;
64: if (value != null)
65: value.append(chr);
66:
67: pos++;
68: }
69: return pos;
70: }
71:
72: public String wrapValue(String value) {
73:
74: return value;
75: }
76: }
|