1 package net.minidev.json.parser;
2
3
18 import static net.minidev.json.parser.ParseException.ERROR_UNEXPECTED_CHAR;
19 import static net.minidev.json.parser.ParseException.ERROR_UNEXPECTED_EOF;
20 import static net.minidev.json.parser.ParseException.ERROR_UNEXPECTED_TOKEN;
21
22 import java.io.IOException;
23
24
31 abstract class JSONParserMemory extends JSONParserBase {
32 protected int len;
33
34 public JSONParserMemory(int permissiveMode) {
35 super(permissiveMode);
36 }
37
38 protected void readNQString(boolean[] stop) throws IOException {
39 int start = pos;
40 skipNQString(stop);
41 extractStringTrim(start, pos);
42 }
43
44 protected Object readNumber(boolean[] stop) throws ParseException, IOException {
45 int start = pos;
46
47 read();
48 skipDigits();
49
50
51 if (c != '.' && c != 'E' && c != 'e') {
52 skipSpace();
53 if (c >= 0 && c < MAX_STOP && !stop[c] && c != EOI) {
54
55 skipNQString(stop);
56 extractStringTrim(start, pos);
57 if (!acceptNonQuote)
58 throw new ParseException(pos, ERROR_UNEXPECTED_TOKEN, xs);
59 return xs;
60 }
61 extractStringTrim(start, pos);
62 return parseNumber(xs);
63 }
64
65 if (c == '.') {
66
67 read();
68 skipDigits();
69 }
70 if (c != 'E' && c != 'e') {
71 skipSpace();
72 if (c >= 0 && c < MAX_STOP && !stop[c] && c != EOI) {
73
74 skipNQString(stop);
75 extractStringTrim(start, pos);
76 if (!acceptNonQuote)
77 throw new ParseException(pos, ERROR_UNEXPECTED_TOKEN, xs);
78 return xs;
79 }
80 extractStringTrim(start, pos);
81 return extractFloat();
82 }
83 sb.append('E');
84 read();
85 if (c == '+' || c == '-' || c >= '0' && c <= '9') {
86 sb.append(c);
87 read();
88 skipDigits();
89 skipSpace();
90 if (c >= 0 && c < MAX_STOP && !stop[c] && c != EOI) {
91
92 skipNQString(stop);
93 extractStringTrim(start, pos);
94 if (!acceptNonQuote)
95 throw new ParseException(pos, ERROR_UNEXPECTED_TOKEN, xs);
96 return xs;
97 }
98 extractStringTrim(start, pos);
99 return extractFloat();
100 } else {
101 skipNQString(stop);
102 extractStringTrim(start, pos);
103 if (!acceptNonQuote)
104 throw new ParseException(pos, ERROR_UNEXPECTED_TOKEN, xs);
105 if (!acceptLeadinZero)
106 checkLeadinZero();
107 return xs;
108 }
109
110 }
111
112 protected void readString() throws ParseException, IOException {
113 if (!acceptSimpleQuote && c == '\'') {
114 if (acceptNonQuote) {
115 readNQString(stopAll);
116 return;
117 }
118 throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c);
119 }
120 int tmpP = indexOf(c, pos + 1);
121 if (tmpP == -1)
122 throw new ParseException(len, ERROR_UNEXPECTED_EOF, null);
123 extractString(pos + 1, tmpP);
124 if (xs.indexOf('\\') == -1) {
125 checkControleChar();
126 pos = tmpP;
127 read();
128
129 return;
130 }
131 sb.clear();
132 readString2();
133 }
134
135 abstract protected void extractString(int start, int stop);
136
137 abstract protected int indexOf(char c, int pos);
138
139 abstract protected void extractStringTrim(int start, int stop);
140 }
141