src/share/jaxws_classes/com/sun/xml/internal/rngom/parse/compact/UCode_UCodeESC_CharStream.java

changeset 408
b0610cd08440
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
405:cc682329886b 408:b0610cd08440
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any 22 * or visit www.oracle.com if you need additional information or have any
23 * questions. 23 * questions.
24 */ 24 */
25 /* 25 /*
26 * Copyright (C) 2004-2011 26 * Copyright (C) 2004-2012
27 * 27 *
28 * Permission is hereby granted, free of charge, to any person obtaining a copy 28 * Permission is hereby granted, free of charge, to any person obtaining a copy
29 * of this software and associated documentation files (the "Software"), to deal 29 * of this software and associated documentation files (the "Software"), to deal
30 * in the Software without restriction, including without limitation the rights 30 * in the Software without restriction, including without limitation the rights
31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44 * THE SOFTWARE. 44 * THE SOFTWARE.
45 */ 45 */
46 /* Generated By:JavaCC: Do not edit this line. UCode_UCodeESC_CharStream.java Version 0.7pre6 */ 46 /* Generated By:JavaCC: Do not edit this line. UCode_UCodeESC_CharStream.java Version 0.7pre6 */
47 /* The previous line keeps JavaCC quiet. In fact, the JavaCC generated file 47 /* The previous line keeps JavaCC quiet. In fact, the JavaCC generated file
48 has been edited to fix some bugs. */ 48 has been edited to fix some bugs. */
49 package com.sun.xml.internal.rngom.parse.compact; 49 package com.sun.xml.internal.rngom.parse.compact;
50 50
51 import com.sun.xml.internal.rngom.util.Utf16; 51 import com.sun.xml.internal.rngom.util.Utf16;
52 import com.sun.xml.internal.rngom.ast.builder.BuildException; 52 import com.sun.xml.internal.rngom.ast.builder.BuildException;
53 53
56 /** 56 /**
57 * An implementation of interface CharStream, where the stream is assumed to 57 * An implementation of interface CharStream, where the stream is assumed to
58 * contain 16-bit unicode characters. 58 * contain 16-bit unicode characters.
59 */ 59 */
60 public final class UCode_UCodeESC_CharStream { 60 public final class UCode_UCodeESC_CharStream {
61 public static final boolean staticFlag = false; 61
62 62 public static final boolean staticFlag = false;
63 static final int hexval(char c) { 63
64 switch (c) { 64 static final int hexval(char c) {
65 case '0': 65 switch (c) {
66 return 0; 66 case '0':
67 case '1': 67 return 0;
68 return 1; 68 case '1':
69 case '2': 69 return 1;
70 return 2; 70 case '2':
71 case '3': 71 return 2;
72 return 3; 72 case '3':
73 case '4': 73 return 3;
74 return 4; 74 case '4':
75 case '5': 75 return 4;
76 return 5; 76 case '5':
77 case '6': 77 return 5;
78 return 6; 78 case '6':
79 case '7': 79 return 6;
80 return 7; 80 case '7':
81 case '8': 81 return 7;
82 return 8; 82 case '8':
83 case '9': 83 return 8;
84 return 9; 84 case '9':
85 85 return 9;
86 case 'a': 86
87 case 'A': 87 case 'a':
88 return 10; 88 case 'A':
89 case 'b': 89 return 10;
90 case 'B': 90 case 'b':
91 return 11; 91 case 'B':
92 case 'c': 92 return 11;
93 case 'C': 93 case 'c':
94 return 12; 94 case 'C':
95 case 'd': 95 return 12;
96 case 'D': 96 case 'd':
97 return 13; 97 case 'D':
98 case 'e': 98 return 13;
99 case 'E': 99 case 'e':
100 return 14; 100 case 'E':
101 case 'f': 101 return 14;
102 case 'F': 102 case 'f':
103 return 15; 103 case 'F':
104 } 104 return 15;
105 return -1; 105 }
106 } 106 return -1;
107 107 }
108 public int bufpos = -1; 108 public int bufpos = -1;
109 int bufsize; 109 int bufsize;
110 int available; 110 int available;
111 int tokenBegin; 111 int tokenBegin;
112 private int bufline[]; 112 private int bufline[];
113 private int bufcolumn[]; 113 private int bufcolumn[];
114 114 private int column = 0;
115 private int column = 0; 115 private int line = 1;
116 private int line = 1; 116 private java.io.Reader inputStream;
117 117 private boolean closed = false;
118 private java.io.Reader inputStream; 118 private boolean prevCharIsLF = false;
119 private boolean closed = false; 119 private char[] nextCharBuf;
120 120 private char[] buffer;
121 private boolean prevCharIsLF = false; 121 private int maxNextCharInd = 0;
122 122 private int nextCharInd = -1;
123 private char[] nextCharBuf; 123 private int inBuf = 0;
124 private char[] buffer; 124
125 private int maxNextCharInd = 0; 125 private final void ExpandBuff(boolean wrapAround) {
126 private int nextCharInd = -1; 126 char[] newbuffer = new char[bufsize + 2048];
127 private int inBuf = 0; 127 int newbufline[] = new int[bufsize + 2048];
128 128 int newbufcolumn[] = new int[bufsize + 2048];
129 private final void ExpandBuff(boolean wrapAround) { 129
130 char[] newbuffer = new char[bufsize + 2048]; 130 if (wrapAround) {
131 int newbufline[] = new int[bufsize + 2048]; 131 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
132 int newbufcolumn[] = new int[bufsize + 2048]; 132 System.arraycopy(buffer, 0, newbuffer,
133 133 bufsize - tokenBegin, bufpos);
134 if (wrapAround) { 134 buffer = newbuffer;
135 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); 135
136 System.arraycopy(buffer, 0, newbuffer, 136 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
137 bufsize - tokenBegin, bufpos); 137 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
138 buffer = newbuffer; 138 bufline = newbufline;
139 139
140 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); 140 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
141 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); 141 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
142 bufline = newbufline; 142 bufcolumn = newbufcolumn;
143 143
144 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); 144 bufpos += (bufsize - tokenBegin);
145 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); 145 } else {
146 bufcolumn = newbufcolumn; 146 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
147 147 buffer = newbuffer;
148 bufpos += (bufsize - tokenBegin); 148
149 } 149 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
150 else { 150 bufline = newbufline;
151 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); 151
152 buffer = newbuffer; 152 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
153 153 bufcolumn = newbufcolumn;
154 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); 154
155 bufline = newbufline; 155 bufpos -= tokenBegin;
156 156 }
157 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); 157
158 bufcolumn = newbufcolumn; 158 available = (bufsize += 2048);
159 159 tokenBegin = 0;
160 bufpos -= tokenBegin; 160 }
161 } 161
162 162 private final void FillBuff() throws EOFException {
163 available = (bufsize += 2048); 163 int i;
164 tokenBegin = 0; 164 if (maxNextCharInd == 4096) {
165 } 165 maxNextCharInd = nextCharInd = 0;
166 166 }
167 private final void FillBuff() throws EOFException { 167
168 int i; 168 if (closed) {
169 if (maxNextCharInd == 4096) 169 throw new EOFException();
170 maxNextCharInd = nextCharInd = 0; 170 }
171
172 if (closed)
173 throw new EOFException();
174 try {
175 if ((i = inputStream.read(nextCharBuf, maxNextCharInd, 4096 - maxNextCharInd)) == -1) {
176 closed = true;
177 inputStream.close();
178 throw new EOFException();
179 }
180 else
181 maxNextCharInd += i;
182 }
183 catch (IOException e) {
184 throw new BuildException(e);
185 }
186 }
187
188 private final char ReadChar() throws EOFException {
189 if (++nextCharInd >= maxNextCharInd)
190 FillBuff();
191
192 return nextCharBuf[nextCharInd];
193 }
194
195 private final char PeekChar() throws EOFException {
196 char c = ReadChar();
197 --nextCharInd;
198 return c;
199 }
200
201 public final char BeginToken() throws EOFException {
202 if (inBuf > 0) {
203 --inBuf;
204 return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0)
205 : ++bufpos];
206 }
207
208 tokenBegin = 0;
209 bufpos = -1;
210
211 return readChar();
212 }
213
214 private final void AdjustBuffSize() {
215 if (available == bufsize) {
216 if (tokenBegin > 2048) {
217 bufpos = 0;
218 available = tokenBegin;
219 }
220 else
221 ExpandBuff(false);
222 }
223 else if (available > tokenBegin)
224 available = bufsize;
225 else if ((tokenBegin - available) < 2048)
226 ExpandBuff(true);
227 else
228 available = tokenBegin;
229 }
230
231 private final void UpdateLineColumn(char c) {
232 column++;
233
234 if (prevCharIsLF) {
235 prevCharIsLF = false;
236 line += (column = 1);
237 }
238
239 switch (c) {
240 case NEWLINE_MARKER:
241 prevCharIsLF = true;
242 break;
243 case '\t':
244 column--;
245 column += (8 - (column & 07));
246 break;
247 default :
248 break;
249 }
250
251 bufline[bufpos] = line;
252 bufcolumn[bufpos] = column;
253 }
254
255 private final char NEWLINE_MARKER = '\u0000';
256
257 public final char readChar() throws EOFException {
258 if (inBuf > 0) {
259 --inBuf;
260 return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
261 }
262
263 char c;
264 try {
265 c = ReadChar();
266 switch (c) {
267 case '\r':
268 c = NEWLINE_MARKER;
269 try { 171 try {
270 if (PeekChar() == '\n') 172 if ((i = inputStream.read(nextCharBuf, maxNextCharInd, 4096 - maxNextCharInd)) == -1) {
271 ReadChar(); 173 closed = true;
272 } 174 inputStream.close();
273 catch (EOFException e) { 175 throw new EOFException();
274 } 176 } else {
275 break; 177 maxNextCharInd += i;
276 case '\n': 178 }
277 c = NEWLINE_MARKER; 179 } catch (IOException e) {
278 break; 180 throw new BuildException(e);
279 case '\t': 181 }
280 break; 182 }
281 default: 183
282 if (c >= 0x20) { 184 private final char ReadChar() throws EOFException {
283 if (Utf16.isSurrogate(c)) { 185 if (++nextCharInd >= maxNextCharInd) {
284 if (Utf16.isSurrogate2(c)) 186 FillBuff();
285 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 1); 187 }
286 if (++bufpos == available) 188
287 AdjustBuffSize(); 189 return nextCharBuf[nextCharInd];
288 buffer[bufpos] = c; 190 }
289 // UpdateLineColumn(c); 191
290 try { 192 private final char PeekChar() throws EOFException {
291 c = ReadChar(); 193 char c = ReadChar();
292 } 194 --nextCharInd;
293 catch (EOFException e) { 195 return c;
294 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 1); 196 }
295 } 197
296 if (!Utf16.isSurrogate2(c)) 198 public final char BeginToken() throws EOFException {
297 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 2); 199 if (inBuf > 0) {
298 } 200 --inBuf;
299 break; 201 return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0)
300 } 202 : ++bufpos];
301 // fall through 203 }
302 case '\uFFFE': 204
303 case '\uFFFF': 205 tokenBegin = 0;
304 throw new EscapeSyntaxException("illegal_char_code", line, column + 1); 206 bufpos = -1;
305 } 207
306 } 208 return readChar();
307 catch (EOFException e) { 209 }
308 if (bufpos == -1) { 210
309 if (++bufpos == available) 211 private final void AdjustBuffSize() {
310 AdjustBuffSize(); 212 if (available == bufsize) {
213 if (tokenBegin > 2048) {
214 bufpos = 0;
215 available = tokenBegin;
216 } else {
217 ExpandBuff(false);
218 }
219 } else if (available > tokenBegin) {
220 available = bufsize;
221 } else if ((tokenBegin - available) < 2048) {
222 ExpandBuff(true);
223 } else {
224 available = tokenBegin;
225 }
226 }
227
228 private final void UpdateLineColumn(char c) {
229 column++;
230
231 if (prevCharIsLF) {
232 prevCharIsLF = false;
233 line += (column = 1);
234 }
235
236 switch (c) {
237 case NEWLINE_MARKER:
238 prevCharIsLF = true;
239 break;
240 case '\t':
241 column--;
242 column += (8 - (column & 07));
243 break;
244 default:
245 break;
246 }
247
311 bufline[bufpos] = line; 248 bufline[bufpos] = line;
312 bufcolumn[bufpos] = column; 249 bufcolumn[bufpos] = column;
313 } 250 }
314 throw e; 251 private static final char NEWLINE_MARKER = '\u0000';
315 } 252
316 if (++bufpos == available) 253 public final char readChar() throws EOFException {
317 AdjustBuffSize(); 254 if (inBuf > 0) {
318 buffer[bufpos] = c; 255 --inBuf;
319 UpdateLineColumn(c); 256 return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
320 try { 257 }
321 if (c != '\\' || PeekChar() != 'x') 258
322 return c; 259 char c;
323 } 260 try {
324 catch (EOFException e) { 261 c = ReadChar();
325 return c; 262 switch (c) {
326 } 263 case '\r':
327 264 c = NEWLINE_MARKER;
328 int xCnt = 1; 265 try {
329 for (;;) { 266 if (PeekChar() == '\n') {
330 ReadChar(); 267 ReadChar();
331 if (++bufpos == available) 268 }
332 AdjustBuffSize(); 269 } catch (EOFException e) {
333 buffer[bufpos] = 'x'; 270 }
334 UpdateLineColumn('x'); 271 break;
335 try { 272 case '\n':
336 c = PeekChar(); 273 c = NEWLINE_MARKER;
337 } 274 break;
338 catch (EOFException e) { 275 case '\t':
339 backup(xCnt); 276 break;
340 return '\\'; 277 default:
341 } 278 if (c >= 0x20) {
342 if (c == '{') { 279 if (Utf16.isSurrogate(c)) {
343 ReadChar(); 280 if (Utf16.isSurrogate2(c)) {
344 column++; 281 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 1);
345 // backup past the 'x's 282 }
346 bufpos -= xCnt; 283 if (++bufpos == available) {
347 if (bufpos < 0) 284 AdjustBuffSize();
348 bufpos += bufsize; 285 }
349 break; 286 buffer[bufpos] = c;
350 } 287 // UpdateLineColumn(c);
351 if (c != 'x') { 288 try {
352 backup(xCnt); 289 c = ReadChar();
353 return '\\'; 290 } catch (EOFException e) {
354 } 291 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 1);
355 xCnt++; 292 }
356 } 293 if (!Utf16.isSurrogate2(c)) {
357 try { 294 throw new EscapeSyntaxException("illegal_surrogate_pair", line, column + 2);
358 int scalarValue = hexval(ReadChar()); 295 }
359 column++; 296 }
360 if (scalarValue < 0) 297 break;
361 throw new EscapeSyntaxException("illegal_hex_digit", line, column); 298 }
362 while ((c = ReadChar()) != '}') { 299 // fall through
363 column++; 300 case '\uFFFE':
364 int n = hexval(c); 301 case '\uFFFF':
365 if (n < 0) 302 throw new EscapeSyntaxException("illegal_char_code", line, column + 1);
366 throw new EscapeSyntaxException("illegal_hex_digit", line, column); 303 }
367 scalarValue <<= 4; 304 } catch (EOFException e) {
368 scalarValue |= n; 305 if (bufpos == -1) {
369 if (scalarValue >= 0x110000) 306 if (++bufpos == available) {
370 throw new EscapeSyntaxException("char_code_too_big", line, column); 307 AdjustBuffSize();
371 } 308 }
372 column++; // for the '}' 309 bufline[bufpos] = line;
373 if (scalarValue <= 0xFFFF) { 310 bufcolumn[bufpos] = column;
374 c = (char)scalarValue; 311 }
375 switch (c) { 312 throw e;
376 case '\n': 313 }
377 case '\r': 314 if (++bufpos == available) {
378 case '\t': 315 AdjustBuffSize();
379 break;
380 default:
381 if (c >= 0x20 && !Utf16.isSurrogate(c))
382 break;
383 // fall through
384 case '\uFFFE':
385 case '\uFFFF':
386 throw new EscapeSyntaxException("illegal_char_code_ref", line, column);
387 } 316 }
388 buffer[bufpos] = c; 317 buffer[bufpos] = c;
389 return c; 318 UpdateLineColumn(c);
390 } 319 try {
391 c = Utf16.surrogate1(scalarValue); 320 if (c != '\\' || PeekChar() != 'x') {
392 buffer[bufpos] = c; 321 return c;
393 int bufpos1 = bufpos; 322 }
394 if (++bufpos == bufsize) 323 } catch (EOFException e) {
395 bufpos = 0; 324 return c;
396 buffer[bufpos] = Utf16.surrogate2(scalarValue); 325 }
397 bufline[bufpos] = bufline[bufpos1]; 326
398 bufcolumn[bufpos] = bufcolumn[bufpos1]; 327 int xCnt = 1;
399 backup(1); 328 for (;;) {
400 return c; 329 ReadChar();
401 } 330 if (++bufpos == available) {
402 catch (EOFException e) { 331 AdjustBuffSize();
403 throw new EscapeSyntaxException("incomplete_escape", line, column); 332 }
404 } 333 buffer[bufpos] = 'x';
405 } 334 UpdateLineColumn('x');
406 335 try {
407 /** 336 c = PeekChar();
408 * @deprecated 337 } catch (EOFException e) {
409 * @see #getEndColumn 338 backup(xCnt);
410 */ 339 return '\\';
411 340 }
412 public final int getColumn() { 341 if (c == '{') {
413 return bufcolumn[bufpos]; 342 ReadChar();
414 } 343 column++;
415 344 // backup past the 'x's
416 /** 345 bufpos -= xCnt;
417 * @deprecated 346 if (bufpos < 0) {
418 * @see #getEndLine 347 bufpos += bufsize;
419 */ 348 }
420 349 break;
421 public final int getLine() { 350 }
422 return bufline[bufpos]; 351 if (c != 'x') {
423 } 352 backup(xCnt);
424 353 return '\\';
425 public final int getEndColumn() { 354 }
426 return bufcolumn[bufpos]; 355 xCnt++;
427 } 356 }
428 357 try {
429 public final int getEndLine() { 358 int scalarValue = hexval(ReadChar());
430 return bufline[bufpos]; 359 column++;
431 } 360 if (scalarValue < 0) {
432 361 throw new EscapeSyntaxException("illegal_hex_digit", line, column);
433 public final int getBeginColumn() { 362 }
434 return bufcolumn[tokenBegin]; 363 while ((c = ReadChar()) != '}') {
435 } 364 column++;
436 365 int n = hexval(c);
437 public final int getBeginLine() { 366 if (n < 0) {
438 return bufline[tokenBegin]; 367 throw new EscapeSyntaxException("illegal_hex_digit", line, column);
439 } 368 }
440 369 scalarValue <<= 4;
441 public final void backup(int amount) { 370 scalarValue |= n;
442 371 if (scalarValue >= 0x110000) {
443 inBuf += amount; 372 throw new EscapeSyntaxException("char_code_too_big", line, column);
444 if ((bufpos -= amount) < 0) 373 }
445 bufpos += bufsize; 374 }
446 } 375 column++; // for the '}'
447 376 if (scalarValue <= 0xFFFF) {
448 public UCode_UCodeESC_CharStream(java.io.Reader dstream, 377 c = (char) scalarValue;
449 int startline, int startcolumn, int buffersize) { 378 switch (c) {
450 inputStream = dstream; 379 case '\n':
451 line = startline; 380 case '\r':
452 column = startcolumn - 1; 381 case '\t':
453 382 break;
454 available = bufsize = buffersize; 383 default:
455 buffer = new char[buffersize]; 384 if (c >= 0x20 && !Utf16.isSurrogate(c)) {
456 bufline = new int[buffersize]; 385 break;
457 bufcolumn = new int[buffersize]; 386 }
458 nextCharBuf = new char[4096]; 387 // fall through
459 skipBOM(); 388 case '\uFFFE':
460 } 389 case '\uFFFF':
461 390 throw new EscapeSyntaxException("illegal_char_code_ref", line, column);
462 public UCode_UCodeESC_CharStream(java.io.Reader dstream, 391 }
463 int startline, int startcolumn) { 392 buffer[bufpos] = c;
464 this(dstream, startline, startcolumn, 4096); 393 return c;
465 } 394 }
466 395 c = Utf16.surrogate1(scalarValue);
467 public void ReInit(java.io.Reader dstream, 396 buffer[bufpos] = c;
468 int startline, int startcolumn, int buffersize) { 397 int bufpos1 = bufpos;
469 inputStream = dstream; 398 if (++bufpos == bufsize) {
470 closed = false; 399 bufpos = 0;
471 line = startline; 400 }
472 column = startcolumn - 1; 401 buffer[bufpos] = Utf16.surrogate2(scalarValue);
473 402 bufline[bufpos] = bufline[bufpos1];
474 if (buffer == null || buffersize != buffer.length) { 403 bufcolumn[bufpos] = bufcolumn[bufpos1];
475 available = bufsize = buffersize; 404 backup(1);
476 buffer = new char[buffersize]; 405 return c;
477 bufline = new int[buffersize]; 406 } catch (EOFException e) {
478 bufcolumn = new int[buffersize]; 407 throw new EscapeSyntaxException("incomplete_escape", line, column);
479 nextCharBuf = new char[4096]; 408 }
480 } 409 }
481 prevCharIsLF = false; 410
482 tokenBegin = inBuf = maxNextCharInd = 0; 411 /**
483 nextCharInd = bufpos = -1; 412 * @deprecated @see #getEndColumn
484 skipBOM(); 413 */
485 } 414 public final int getColumn() {
486 415 return bufcolumn[bufpos];
487 public void ReInit(java.io.Reader dstream, 416 }
488 int startline, int startcolumn) { 417
489 ReInit(dstream, startline, startcolumn, 4096); 418 /**
490 } 419 * @deprecated @see #getEndLine
491 420 */
492 public UCode_UCodeESC_CharStream(java.io.InputStream dstream, int startline, 421 public final int getLine() {
493 int startcolumn, int buffersize) { 422 return bufline[bufpos];
494 this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); 423 }
495 } 424
496 425 public final int getEndColumn() {
497 public UCode_UCodeESC_CharStream(java.io.InputStream dstream, int startline, 426 return bufcolumn[bufpos];
498 int startcolumn) { 427 }
499 this(dstream, startline, startcolumn, 4096); 428
500 } 429 public final int getEndLine() {
501 430 return bufline[bufpos];
502 public void ReInit(java.io.InputStream dstream, int startline, 431 }
503 int startcolumn, int buffersize) { 432
504 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); 433 public final int getBeginColumn() {
505 } 434 return bufcolumn[tokenBegin];
506 435 }
507 public void ReInit(java.io.InputStream dstream, int startline, 436
508 int startcolumn) { 437 public final int getBeginLine() {
509 ReInit(dstream, startline, startcolumn, 4096); 438 return bufline[tokenBegin];
510 } 439 }
511 440
512 static private final char BOM = '\ufeff'; 441 public final void backup(int amount) {
513 442
514 private void skipBOM() { 443 inBuf += amount;
515 try { 444 if ((bufpos -= amount) < 0) {
516 if (PeekChar() == BOM) 445 bufpos += bufsize;
517 ReadChar(); 446 }
518 } 447 }
519 catch (EOFException e) { 448
520 } 449 public UCode_UCodeESC_CharStream(java.io.Reader dstream,
521 } 450 int startline, int startcolumn, int buffersize) {
522 451 inputStream = dstream;
523 public final String GetImage() { 452 line = startline;
524 if (bufpos >= tokenBegin) 453 column = startcolumn - 1;
525 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); 454
526 else 455 available = bufsize = buffersize;
527 return new String(buffer, tokenBegin, bufsize - tokenBegin) + 456 buffer = new char[buffersize];
528 new String(buffer, 0, bufpos + 1); 457 bufline = new int[buffersize];
529 } 458 bufcolumn = new int[buffersize];
530 459 nextCharBuf = new char[4096];
531 public final char[] GetSuffix(int len) { 460 skipBOM();
532 char[] ret = new char[len]; 461 }
533 462
534 if ((bufpos + 1) >= len) 463 public UCode_UCodeESC_CharStream(java.io.Reader dstream,
535 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); 464 int startline, int startcolumn) {
536 else { 465 this(dstream, startline, startcolumn, 4096);
537 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, 466 }
538 len - bufpos - 1); 467
539 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); 468 public void ReInit(java.io.Reader dstream,
540 } 469 int startline, int startcolumn, int buffersize) {
541 470 inputStream = dstream;
542 return ret; 471 closed = false;
543 } 472 line = startline;
544 473 column = startcolumn - 1;
545 public void Done() { 474
546 nextCharBuf = null; 475 if (buffer == null || buffersize != buffer.length) {
547 buffer = null; 476 available = bufsize = buffersize;
548 bufline = null; 477 buffer = new char[buffersize];
549 bufcolumn = null; 478 bufline = new int[buffersize];
550 } 479 bufcolumn = new int[buffersize];
551 480 nextCharBuf = new char[4096];
552 /** 481 }
553 * Method to adjust line and column numbers for the start of a token.<BR> 482 prevCharIsLF = false;
554 */ 483 tokenBegin = inBuf = maxNextCharInd = 0;
555 public void adjustBeginLineColumn(int newLine, int newCol) { 484 nextCharInd = bufpos = -1;
556 int start = tokenBegin; 485 skipBOM();
557 int len; 486 }
558 487
559 if (bufpos >= tokenBegin) { 488 public void ReInit(java.io.Reader dstream,
560 len = bufpos - tokenBegin + inBuf + 1; 489 int startline, int startcolumn) {
561 } 490 ReInit(dstream, startline, startcolumn, 4096);
562 else { 491 }
563 len = bufsize - tokenBegin + bufpos + 1 + inBuf; 492
564 } 493 public UCode_UCodeESC_CharStream(java.io.InputStream dstream, int startline,
565 494 int startcolumn, int buffersize) {
566 int i = 0, j = 0, k = 0; 495 this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
567 int nextColDiff = 0, columnDiff = 0; 496 }
568 497
569 while (i < len && 498 public UCode_UCodeESC_CharStream(java.io.InputStream dstream, int startline,
570 bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) { 499 int startcolumn) {
571 bufline[j] = newLine; 500 this(dstream, startline, startcolumn, 4096);
572 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; 501 }
573 bufcolumn[j] = newCol + columnDiff; 502
574 columnDiff = nextColDiff; 503 public void ReInit(java.io.InputStream dstream, int startline,
575 i++; 504 int startcolumn, int buffersize) {
576 } 505 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
577 506 }
578 if (i < len) { 507
579 bufline[j] = newLine++; 508 public void ReInit(java.io.InputStream dstream, int startline,
580 bufcolumn[j] = newCol + columnDiff; 509 int startcolumn) {
581 510 ReInit(dstream, startline, startcolumn, 4096);
582 while (i++ < len) { 511 }
583 if (bufline[j = start % bufsize] != bufline[++start % bufsize]) 512 static private final char BOM = '\ufeff';
584 bufline[j] = newLine++; 513
585 else 514 private void skipBOM() {
586 bufline[j] = newLine; 515 try {
587 } 516 if (PeekChar() == BOM) {
588 } 517 ReadChar();
589 518 }
590 line = bufline[j]; 519 } catch (EOFException e) {
591 column = bufcolumn[j]; 520 }
592 } 521 }
593 522
523 public final String GetImage() {
524 if (bufpos >= tokenBegin) {
525 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
526 } else {
527 return new String(buffer, tokenBegin, bufsize - tokenBegin)
528 + new String(buffer, 0, bufpos + 1);
529 }
530 }
531
532 public final char[] GetSuffix(int len) {
533 char[] ret = new char[len];
534
535 if ((bufpos + 1) >= len) {
536 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
537 } else {
538 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
539 len - bufpos - 1);
540 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
541 }
542
543 return ret;
544 }
545
546 public void Done() {
547 nextCharBuf = null;
548 buffer = null;
549 bufline = null;
550 bufcolumn = null;
551 }
552
553 /**
554 * Method to adjust line and column numbers for the start of a token.<BR>
555 */
556 public void adjustBeginLineColumn(int newLine, int newCol) {
557 int start = tokenBegin;
558 int len;
559
560 if (bufpos >= tokenBegin) {
561 len = bufpos - tokenBegin + inBuf + 1;
562 } else {
563 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
564 }
565
566 int i = 0, j = 0, k = 0;
567 int nextColDiff, columnDiff = 0;
568
569 while (i < len
570 && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) {
571 bufline[j] = newLine;
572 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
573 bufcolumn[j] = newCol + columnDiff;
574 columnDiff = nextColDiff;
575 i++;
576 }
577
578 if (i < len) {
579 bufline[j] = newLine++;
580 bufcolumn[j] = newCol + columnDiff;
581
582 while (i++ < len) {
583 if (bufline[j = start % bufsize] != bufline[++start % bufsize]) {
584 bufline[j] = newLine++;
585 } else {
586 bufline[j] = newLine;
587 }
588 }
589 }
590
591 line = bufline[j];
592 column = bufcolumn[j];
593 }
594 } 594 }

mercurial