1
/* Generated By:JavaCC: Do not edit this line. ASCII_UCodeESC_CharStream.java Version 0.7pre6 */
4
* Cobertura - http://cobertura.sourceforge.net/
6
* This file was taken from JavaNCSS
7
* http://www.kclee.com/clemens/java/javancss/
8
* Copyright (C) 2000 Chr. Clemens Lee <clemens a.t kclee d.o.t com>
10
* Cobertura is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published
12
* by the Free Software Foundation; either version 2 of the License,
13
* or (at your option) any later version.
15
* Cobertura is distributed in the hope that it will be useful, but
16
* WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with Cobertura; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26
package net.sourceforge.cobertura.javancss;
29
* An implementation of interface CharStream, where the stream is assumed to
30
* contain only ASCII characters (with java-like unicode escape processing).
33
public final class ASCII_UCodeESC_CharStream
36
public static final boolean staticFlag = false;
38
private static final int hexval(char c) throws java.io.IOException
83
throw new java.io.IOException(); // Should never come here
86
private int bufpos = -1;
88
private int available;
89
private int tokenBegin;
90
private int bufline[];
91
private int bufcolumn[];
93
private int column = 0;
96
private java.io.Reader inputStream;
98
private boolean prevCharIsCR = false;
99
private boolean prevCharIsLF = false;
101
private char[] nextCharBuf;
102
private char[] buffer;
103
private int maxNextCharInd = 0;
104
private int nextCharInd = -1;
105
private int inBuf = 0;
107
private final void expandBuff(boolean wrapAround)
109
char[] newbuffer = new char[bufsize + 2048];
110
int newbufline[] = new int[bufsize + 2048];
111
int newbufcolumn[] = new int[bufsize + 2048];
117
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
118
System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
121
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
122
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
123
bufline = newbufline;
125
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
126
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
127
bufcolumn = newbufcolumn;
129
bufpos += (bufsize - tokenBegin);
133
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
136
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
137
bufline = newbufline;
139
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
140
bufcolumn = newbufcolumn;
142
bufpos -= tokenBegin;
147
throw new Error(t.getMessage());
150
available = (bufsize += 2048);
154
private final void fillBuff() throws java.io.IOException
157
if (maxNextCharInd == 4096)
158
maxNextCharInd = nextCharInd = 0;
162
if ((i = inputStream.read(nextCharBuf, maxNextCharInd, 4096 - maxNextCharInd)) == -1)
165
throw new java.io.IOException();
170
catch (java.io.IOException e)
179
bufline[bufpos] = line;
180
bufcolumn[bufpos] = column;
186
private final char readByte() throws java.io.IOException
188
if (++nextCharInd >= maxNextCharInd)
191
return nextCharBuf[nextCharInd];
194
public final char beginToken() throws java.io.IOException
199
return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
208
private final void adjustBuffSize()
210
if (available == bufsize)
212
if (tokenBegin > 2048)
215
available = tokenBegin;
220
else if (available > tokenBegin)
222
else if ((tokenBegin - available) < 2048)
225
available = tokenBegin;
228
private final void updateLineColumn(char c)
234
prevCharIsLF = false;
235
line += (column = 1);
237
else if (prevCharIsCR)
239
prevCharIsCR = false;
245
line += (column = 1);
258
column += (8 - (column & 07));
264
bufline[bufpos] = line;
265
bufcolumn[bufpos] = column;
268
public final char readChar() throws java.io.IOException
273
return buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos];
278
if (++bufpos == available)
281
if (((buffer[bufpos] = c = (char)((char)0xff & readByte())) == '\\'))
285
int backSlashCnt = 1;
287
for (;;) // Read all the backslashes
289
if (++bufpos == available)
294
if ((buffer[bufpos] = c = (char)((char)0xff & readByte())) != '\\')
297
// found a non-backslash char.
298
if ((c == 'u') && ((backSlashCnt & 1) == 1))
301
bufpos = bufsize - 1;
306
backup(backSlashCnt);
310
catch (java.io.IOException e)
312
if (backSlashCnt > 1)
313
backup(backSlashCnt);
322
// Here, we have seen an odd number of backslash's followed by a 'u'
325
while ((c = (char)((char)0xff & readByte())) == 'u')
328
buffer[bufpos] = c = (char)(hexval(c) << 12
329
| hexval((char)((char)0xff & readByte())) << 8
330
| hexval((char)((char)0xff & readByte())) << 4 | hexval((char)((char)0xff & readByte())));
334
catch (java.io.IOException e)
336
throw new Error("Invalid escape character at line " + line + " column " + column
340
if (backSlashCnt == 1)
343
backup(backSlashCnt - 1);
351
public final int getEndColumn()
353
return bufcolumn[bufpos];
356
public final int getEndLine()
358
return bufline[bufpos];
361
public final int getBeginColumn()
363
return bufcolumn[tokenBegin];
366
public final int getBeginLine()
368
return bufline[tokenBegin];
371
public final void backup(int amount)
375
if ((bufpos -= amount) < 0)
379
private ASCII_UCodeESC_CharStream(java.io.Reader dstream, int startline, int startcolumn,
382
inputStream = dstream;
384
column = startcolumn - 1;
386
available = bufsize = buffersize;
387
buffer = new char[buffersize];
388
bufline = new int[buffersize];
389
bufcolumn = new int[buffersize];
390
nextCharBuf = new char[4096];
393
public ASCII_UCodeESC_CharStream(java.io.InputStream dstream, int startline, int startcolumn)
395
this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
398
public final String getImage()
400
if (bufpos >= tokenBegin)
401
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
402
return new String(buffer, tokenBegin, bufsize - tokenBegin)
403
+ new String(buffer, 0, bufpos + 1);
406
public final char[] getSuffix(int len)
408
char[] ret = new char[len];
410
if ((bufpos + 1) >= len)
411
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
414
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, len - bufpos - 1);
415
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);