2
* Cobertura - http://cobertura.sourceforge.net/
4
* This file was taken from JavaNCSS
5
* http://www.kclee.com/clemens/java/javancss/
6
* Copyright (C) 2000 Chr. Clemens Lee <clemens a.t kclee d.o.t com>
8
* Cobertura is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published
10
* by the Free Software Foundation; either version 2 of the License,
11
* or (at your option) any later version.
13
* Cobertura is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with Cobertura; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
29
* WARNING TO COBERTURA DEVELOPERS
31
* DO NOT MODIFY THIS FILE!
33
* MODIFY THE FILES UNDER THE JAVANCSS DIRECTORY LOCATED AT THE ROOT OF THE COBERTURA PROJECT.
35
* FOLLOW THE PROCEDURE FOR MERGING THE LATEST JAVANCSS INTO COBERTURA LOCATED AT
36
* javancss/coberturaREADME.txt
38
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
40
/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 4.1 */
41
/* JavaCCOptions:STATIC=false */
42
package net.sourceforge.cobertura.javancss.parser;
45
* An implementation of interface CharStream, where the stream is assumed to
46
* contain only ASCII characters (with java-like unicode escape processing).
49
public class JavaCharStream
51
/** Whether parser is static. */
52
public static final boolean staticFlag = false;
53
static final int hexval(char c) throws java.io.IOException {
97
throw new java.io.IOException(); // Should never come here
100
/** Position in buffer. */
101
public int bufpos = -1;
105
protected int bufline[];
106
protected int bufcolumn[];
108
protected int column = 0;
109
protected int line = 1;
111
protected boolean prevCharIsCR = false;
112
protected boolean prevCharIsLF = false;
114
protected java.io.Reader inputStream;
116
protected char[] nextCharBuf;
117
protected char[] buffer;
118
protected int maxNextCharInd = 0;
119
protected int nextCharInd = -1;
120
protected int inBuf = 0;
121
protected int tabSize = 8;
123
protected void setTabSize(int i) { tabSize = i; }
124
protected int getTabSize(int i) { return tabSize; }
126
protected void ExpandBuff(boolean wrapAround)
128
char[] newbuffer = new char[bufsize + 2048];
129
int newbufline[] = new int[bufsize + 2048];
130
int newbufcolumn[] = new int[bufsize + 2048];
136
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
137
System.arraycopy(buffer, 0, newbuffer,
138
bufsize - tokenBegin, bufpos);
141
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
142
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
143
bufline = newbufline;
145
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
146
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
147
bufcolumn = newbufcolumn;
149
bufpos += (bufsize - tokenBegin);
153
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
156
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
157
bufline = newbufline;
159
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
160
bufcolumn = newbufcolumn;
162
bufpos -= tokenBegin;
167
throw new Error(t.getMessage());
170
available = (bufsize += 2048);
174
protected void FillBuff() throws java.io.IOException
177
if (maxNextCharInd == 4096)
178
maxNextCharInd = nextCharInd = 0;
181
if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
182
4096 - maxNextCharInd)) == -1)
185
throw new java.io.IOException();
191
catch(java.io.IOException e) {
199
bufline[bufpos] = line;
200
bufcolumn[bufpos] = column;
206
protected char ReadByte() throws java.io.IOException
208
if (++nextCharInd >= maxNextCharInd)
211
return nextCharBuf[nextCharInd];
214
/** @return starting character for token. */
215
public char BeginToken() throws java.io.IOException
221
if (++bufpos == bufsize)
225
return buffer[bufpos];
234
protected void AdjustBuffSize()
236
if (available == bufsize)
238
if (tokenBegin > 2048)
241
available = tokenBegin;
246
else if (available > tokenBegin)
248
else if ((tokenBegin - available) < 2048)
251
available = tokenBegin;
254
protected void UpdateLineColumn(char c)
260
prevCharIsLF = false;
261
line += (column = 1);
263
else if (prevCharIsCR)
265
prevCharIsCR = false;
271
line += (column = 1);
284
column += (tabSize - (column % tabSize));
290
bufline[bufpos] = line;
291
bufcolumn[bufpos] = column;
294
/** Read a character. */
295
public char readChar() throws java.io.IOException
301
if (++bufpos == bufsize)
304
return buffer[bufpos];
309
if (++bufpos == available)
312
if ((buffer[bufpos] = c = ReadByte()) == '\\')
316
int backSlashCnt = 1;
318
for (;;) // Read all the backslashes
320
if (++bufpos == available)
325
if ((buffer[bufpos] = c = ReadByte()) != '\\')
328
// found a non-backslash char.
329
if ((c == 'u') && ((backSlashCnt & 1) == 1))
332
bufpos = bufsize - 1;
337
backup(backSlashCnt);
341
catch(java.io.IOException e)
343
if (backSlashCnt > 1)
344
backup(backSlashCnt-1);
353
// Here, we have seen an odd number of backslash's followed by a 'u'
356
while ((c = ReadByte()) == 'u')
359
buffer[bufpos] = c = (char)(hexval(c) << 12 |
360
hexval(ReadByte()) << 8 |
361
hexval(ReadByte()) << 4 |
366
catch(java.io.IOException e)
368
throw new Error("Invalid escape character at line " + line +
369
" column " + column + ".");
372
if (backSlashCnt == 1)
376
backup(backSlashCnt - 1);
391
public int getColumn() {
392
return bufcolumn[bufpos];
399
public int getLine() {
400
return bufline[bufpos];
403
/** Get end column. */
404
public int getEndColumn() {
405
return bufcolumn[bufpos];
409
public int getEndLine() {
410
return bufline[bufpos];
413
/** @return column of token start */
414
public int getBeginColumn() {
415
return bufcolumn[tokenBegin];
418
/** @return line number of token start */
419
public int getBeginLine() {
420
return bufline[tokenBegin];
424
public void backup(int amount) {
427
if ((bufpos -= amount) < 0)
432
public JavaCharStream(java.io.Reader dstream,
433
int startline, int startcolumn, int buffersize)
435
inputStream = dstream;
437
column = startcolumn - 1;
439
available = bufsize = buffersize;
440
buffer = new char[buffersize];
441
bufline = new int[buffersize];
442
bufcolumn = new int[buffersize];
443
nextCharBuf = new char[4096];
447
public JavaCharStream(java.io.Reader dstream,
448
int startline, int startcolumn)
450
this(dstream, startline, startcolumn, 4096);
454
public JavaCharStream(java.io.Reader dstream)
456
this(dstream, 1, 1, 4096);
459
public void ReInit(java.io.Reader dstream,
460
int startline, int startcolumn, int buffersize)
462
inputStream = dstream;
464
column = startcolumn - 1;
466
if (buffer == null || buffersize != buffer.length)
468
available = bufsize = buffersize;
469
buffer = new char[buffersize];
470
bufline = new int[buffersize];
471
bufcolumn = new int[buffersize];
472
nextCharBuf = new char[4096];
474
prevCharIsLF = prevCharIsCR = false;
475
tokenBegin = inBuf = maxNextCharInd = 0;
476
nextCharInd = bufpos = -1;
480
public void ReInit(java.io.Reader dstream,
481
int startline, int startcolumn)
483
ReInit(dstream, startline, startcolumn, 4096);
487
public void ReInit(java.io.Reader dstream)
489
ReInit(dstream, 1, 1, 4096);
492
public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
493
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
495
this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
499
public JavaCharStream(java.io.InputStream dstream, int startline,
500
int startcolumn, int buffersize)
502
this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
506
public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
507
int startcolumn) throws java.io.UnsupportedEncodingException
509
this(dstream, encoding, startline, startcolumn, 4096);
513
public JavaCharStream(java.io.InputStream dstream, int startline,
516
this(dstream, startline, startcolumn, 4096);
520
public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
522
this(dstream, encoding, 1, 1, 4096);
526
public JavaCharStream(java.io.InputStream dstream)
528
this(dstream, 1, 1, 4096);
532
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
533
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
535
ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
539
public void ReInit(java.io.InputStream dstream, int startline,
540
int startcolumn, int buffersize)
542
ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
545
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
546
int startcolumn) throws java.io.UnsupportedEncodingException
548
ReInit(dstream, encoding, startline, startcolumn, 4096);
551
public void ReInit(java.io.InputStream dstream, int startline,
554
ReInit(dstream, startline, startcolumn, 4096);
557
public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
559
ReInit(dstream, encoding, 1, 1, 4096);
563
public void ReInit(java.io.InputStream dstream)
565
ReInit(dstream, 1, 1, 4096);
568
/** @return token image as String */
569
public String GetImage()
571
if (bufpos >= tokenBegin)
572
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
574
return new String(buffer, tokenBegin, bufsize - tokenBegin) +
575
new String(buffer, 0, bufpos + 1);
578
/** @return suffix */
579
public char[] GetSuffix(int len)
581
char[] ret = new char[len];
583
if ((bufpos + 1) >= len)
584
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
587
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
589
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
595
/** Set buffers back to null when finished. */
605
* Method to adjust line and column numbers for the start of a token.
607
public void adjustBeginLineColumn(int newLine, int newCol)
609
int start = tokenBegin;
612
if (bufpos >= tokenBegin)
614
len = bufpos - tokenBegin + inBuf + 1;
618
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
621
int i = 0, j = 0, k = 0;
622
int nextColDiff = 0, columnDiff = 0;
625
bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
627
bufline[j] = newLine;
628
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
629
bufcolumn[j] = newCol + columnDiff;
630
columnDiff = nextColDiff;
636
bufline[j] = newLine++;
637
bufcolumn[j] = newCol + columnDiff;
641
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
642
bufline[j] = newLine++;
644
bufline[j] = newLine;
649
column = bufcolumn[j];
653
/* JavaCC - OriginalChecksum=a71d76bc4e3e50f1cadfe216520f8634 (do not edit this line) */