1
/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.1 */
2
/* JavaCCOptions:STATIC=false */
3
package org.apache.lucene.benchmark.byTask.feeds.demohtml;
6
* An implementation of interface CharStream, where the stream is assumed to
7
* contain only ASCII characters (without unicode processing).
10
public class SimpleCharStream
12
/** Whether parser is static. */
13
public static final boolean staticFlag = false;
17
/** Position in buffer. */
18
public int bufpos = -1;
19
protected int bufline[];
20
protected int bufcolumn[];
22
protected int column = 0;
23
protected int line = 1;
25
protected boolean prevCharIsCR = false;
26
protected boolean prevCharIsLF = false;
28
protected java.io.Reader inputStream;
30
protected char[] buffer;
31
protected int maxNextCharInd = 0;
32
protected int inBuf = 0;
33
protected int tabSize = 8;
35
protected void setTabSize(int i) { tabSize = i; }
36
protected int getTabSize(int i) { return tabSize; }
39
protected void ExpandBuff(boolean wrapAround)
41
char[] newbuffer = new char[bufsize + 2048];
42
int newbufline[] = new int[bufsize + 2048];
43
int newbufcolumn[] = new int[bufsize + 2048];
49
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
50
System.arraycopy(buffer, 0, newbuffer,
51
bufsize - tokenBegin, bufpos);
54
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
55
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
58
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
59
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
60
bufcolumn = newbufcolumn;
62
maxNextCharInd = (bufpos += (bufsize - tokenBegin));
66
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
69
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
72
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
73
bufcolumn = newbufcolumn;
75
maxNextCharInd = (bufpos -= tokenBegin);
80
throw new Error(t.getMessage());
89
protected void FillBuff() throws java.io.IOException
91
if (maxNextCharInd == available)
93
if (available == bufsize)
95
if (tokenBegin > 2048)
97
bufpos = maxNextCharInd = 0;
98
available = tokenBegin;
100
else if (tokenBegin < 0)
101
bufpos = maxNextCharInd = 0;
105
else if (available > tokenBegin)
107
else if ((tokenBegin - available) < 2048)
110
available = tokenBegin;
115
if ((i = inputStream.read(buffer, maxNextCharInd,
116
available - maxNextCharInd)) == -1)
119
throw new java.io.IOException();
125
catch(java.io.IOException e) {
128
if (tokenBegin == -1)
135
public char BeginToken() throws java.io.IOException
144
protected void UpdateLineColumn(char c)
150
prevCharIsLF = false;
151
line += (column = 1);
153
else if (prevCharIsCR)
155
prevCharIsCR = false;
161
line += (column = 1);
174
column += (tabSize - (column % tabSize));
180
bufline[bufpos] = line;
181
bufcolumn[bufpos] = column;
184
/** Read a character. */
185
public char readChar() throws java.io.IOException
191
if (++bufpos == bufsize)
194
return buffer[bufpos];
197
if (++bufpos >= maxNextCharInd)
200
char c = buffer[bufpos];
211
public int getColumn() {
212
return bufcolumn[bufpos];
220
public int getLine() {
221
return bufline[bufpos];
224
/** Get token end column number. */
225
public int getEndColumn() {
226
return bufcolumn[bufpos];
229
/** Get token end line number. */
230
public int getEndLine() {
231
return bufline[bufpos];
234
/** Get token beginning column number. */
235
public int getBeginColumn() {
236
return bufcolumn[tokenBegin];
239
/** Get token beginning line number. */
240
public int getBeginLine() {
241
return bufline[tokenBegin];
244
/** Backup a number of characters. */
245
public void backup(int amount) {
248
if ((bufpos -= amount) < 0)
253
public SimpleCharStream(java.io.Reader dstream, int startline,
254
int startcolumn, int buffersize)
256
inputStream = dstream;
258
column = startcolumn - 1;
260
available = bufsize = buffersize;
261
buffer = new char[buffersize];
262
bufline = new int[buffersize];
263
bufcolumn = new int[buffersize];
267
public SimpleCharStream(java.io.Reader dstream, int startline,
270
this(dstream, startline, startcolumn, 4096);
274
public SimpleCharStream(java.io.Reader dstream)
276
this(dstream, 1, 1, 4096);
280
public void ReInit(java.io.Reader dstream, int startline,
281
int startcolumn, int buffersize)
283
inputStream = dstream;
285
column = startcolumn - 1;
287
if (buffer == null || buffersize != buffer.length)
289
available = bufsize = buffersize;
290
buffer = new char[buffersize];
291
bufline = new int[buffersize];
292
bufcolumn = new int[buffersize];
294
prevCharIsLF = prevCharIsCR = false;
295
tokenBegin = inBuf = maxNextCharInd = 0;
300
public void ReInit(java.io.Reader dstream, int startline,
303
ReInit(dstream, startline, startcolumn, 4096);
307
public void ReInit(java.io.Reader dstream)
309
ReInit(dstream, 1, 1, 4096);
312
public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
313
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
315
this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
319
public SimpleCharStream(java.io.InputStream dstream, int startline,
320
int startcolumn, int buffersize)
322
this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
326
public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
327
int startcolumn) throws java.io.UnsupportedEncodingException
329
this(dstream, encoding, startline, startcolumn, 4096);
333
public SimpleCharStream(java.io.InputStream dstream, int startline,
336
this(dstream, startline, startcolumn, 4096);
340
public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
342
this(dstream, encoding, 1, 1, 4096);
346
public SimpleCharStream(java.io.InputStream dstream)
348
this(dstream, 1, 1, 4096);
352
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
353
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
355
ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
359
public void ReInit(java.io.InputStream dstream, int startline,
360
int startcolumn, int buffersize)
362
ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
366
public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
368
ReInit(dstream, encoding, 1, 1, 4096);
372
public void ReInit(java.io.InputStream dstream)
374
ReInit(dstream, 1, 1, 4096);
377
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
378
int startcolumn) throws java.io.UnsupportedEncodingException
380
ReInit(dstream, encoding, startline, startcolumn, 4096);
383
public void ReInit(java.io.InputStream dstream, int startline,
386
ReInit(dstream, startline, startcolumn, 4096);
388
/** Get token literal value. */
389
public String GetImage()
391
if (bufpos >= tokenBegin)
392
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
394
return new String(buffer, tokenBegin, bufsize - tokenBegin) +
395
new String(buffer, 0, bufpos + 1);
398
/** Get the suffix. */
399
public char[] GetSuffix(int len)
401
char[] ret = new char[len];
403
if ((bufpos + 1) >= len)
404
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
407
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
409
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
415
/** Reset buffer when finished. */
424
* Method to adjust line and column numbers for the start of a token.
426
public void adjustBeginLineColumn(int newLine, int newCol)
428
int start = tokenBegin;
431
if (bufpos >= tokenBegin)
433
len = bufpos - tokenBegin + inBuf + 1;
437
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
440
int i = 0, j = 0, k = 0;
441
int nextColDiff = 0, columnDiff = 0;
444
bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
446
bufline[j] = newLine;
447
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
448
bufcolumn[j] = newCol + columnDiff;
449
columnDiff = nextColDiff;
455
bufline[j] = newLine++;
456
bufcolumn[j] = newCol + columnDiff;
460
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
461
bufline[j] = newLine++;
463
bufline[j] = newLine;
468
column = bufcolumn[j];
472
/* JavaCC - OriginalChecksum=bbd7b39acd802e39d8ea5411a6821eb2 (do not edit this line) */