22 namespace Lucene.Net.Demo.Html
31 public const bool staticFlag =
false;
33 internal int available;
34 internal int tokenBegin;
35 public int bufpos = - 1;
36 protected internal int[] bufline;
37 protected internal int[] bufcolumn;
39 protected internal int column = 0;
40 protected internal int line = 1;
42 protected internal bool prevCharIsCR =
false;
43 protected internal bool prevCharIsLF =
false;
45 protected internal System.IO.StreamReader inputStream;
47 protected internal char[] buffer;
48 protected internal int maxNextCharInd = 0;
49 protected internal int inBuf = 0;
50 protected internal int tabSize = 8;
52 protected internal virtual void SetTabSize(
int i)
56 protected internal virtual int GetTabSize(
int i)
62 protected internal virtual void ExpandBuff(
bool wrapAround)
64 char[] newbuffer =
new char[bufsize + 2048];
65 int[] newbufline =
new int[bufsize + 2048];
66 int[] newbufcolumn =
new int[bufsize + 2048];
72 Array.Copy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
73 Array.Copy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
76 Array.Copy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
77 Array.Copy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
80 Array.Copy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
81 Array.Copy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
82 bufcolumn = newbufcolumn;
84 maxNextCharInd = (bufpos += (bufsize - tokenBegin));
88 Array.Copy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
91 Array.Copy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
94 Array.Copy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
95 bufcolumn = newbufcolumn;
97 maxNextCharInd = (bufpos -= tokenBegin);
100 catch (System.Exception t)
102 throw new System.ApplicationException(t.Message);
111 protected internal virtual void FillBuff()
113 if (maxNextCharInd == available)
115 if (available == bufsize)
117 if (tokenBegin > 2048)
119 bufpos = maxNextCharInd = 0;
120 available = tokenBegin;
122 else if (tokenBegin < 0)
123 bufpos = maxNextCharInd = 0;
127 else if (available > tokenBegin)
129 else if ((tokenBegin - available) < 2048)
132 available = tokenBegin;
140 if ((i = inputStream.Read(buffer, maxNextCharInd, available - maxNextCharInd)) == 0)
143 throw new System.IO.IOException();
149 catch (ObjectDisposedException ode)
151 throw new System.IO.IOException(
"cannot read from a closed Reader", ode);
154 catch (System.IO.IOException e)
158 if (tokenBegin == - 1)
164 public virtual char BeginToken()
173 protected internal virtual void UpdateLineColumn(
char c)
179 prevCharIsLF =
false;
180 line += (column = 1);
182 else if (prevCharIsCR)
184 prevCharIsCR =
false;
190 line += (column = 1);
206 column += (tabSize - (column % tabSize));
214 bufline[bufpos] = line;
215 bufcolumn[bufpos] = column;
218 public virtual char ReadChar()
224 if (++bufpos == bufsize)
227 return buffer[bufpos];
230 if (++bufpos >= maxNextCharInd)
233 char c = buffer[bufpos];
243 public virtual int GetColumn()
245 return bufcolumn[bufpos];
253 public virtual int GetLine()
255 return bufline[bufpos];
258 public virtual int GetEndColumn()
260 return bufcolumn[bufpos];
263 public virtual int GetEndLine()
265 return bufline[bufpos];
268 public virtual int GetBeginColumn()
270 return bufcolumn[tokenBegin];
273 public virtual int GetBeginLine()
275 return bufline[tokenBegin];
278 public virtual void Backup(
int amount)
282 if ((bufpos -= amount) < 0)
286 public SimpleCharStream(System.IO.StreamReader dstream,
int startline,
int startcolumn,
int buffersize)
288 inputStream = dstream;
290 column = startcolumn - 1;
292 available = bufsize = buffersize;
293 buffer =
new char[buffersize];
294 bufline =
new int[buffersize];
295 bufcolumn =
new int[buffersize];
298 public SimpleCharStream(System.IO.StreamReader dstream,
int startline,
int startcolumn):this(dstream, startline, startcolumn, 4096)
306 public virtual void ReInit(System.IO.StreamReader dstream,
int startline,
int startcolumn,
int buffersize)
308 inputStream = dstream;
310 column = startcolumn - 1;
312 if (buffer == null || buffersize != buffer.Length)
314 available = bufsize = buffersize;
315 buffer =
new char[buffersize];
316 bufline =
new int[buffersize];
317 bufcolumn =
new int[buffersize];
319 prevCharIsLF = prevCharIsCR =
false;
320 tokenBegin = inBuf = maxNextCharInd = 0;
324 public virtual void ReInit(System.IO.StreamReader dstream,
int startline,
int startcolumn)
326 ReInit(dstream, startline, startcolumn, 4096);
329 public virtual void ReInit(System.IO.StreamReader dstream)
331 ReInit(dstream, 1, 1, 4096);
334 public SimpleCharStream(System.IO.Stream dstream, System.String encoding,
int startline,
int startcolumn,
int buffersize):this(encoding == null?new System.IO.StreamReader(dstream, System.Text.Encoding.Default):new System.IO.StreamReader(dstream, System.Text.Encoding.GetEncoding(encoding)), startline, startcolumn, buffersize)
338 public SimpleCharStream(System.IO.Stream dstream,
int startline,
int startcolumn,
int buffersize):this(new System.IO.StreamReader(dstream, System.Text.Encoding.Default), startline, startcolumn, buffersize)
342 public SimpleCharStream(System.IO.Stream dstream, System.String encoding,
int startline,
int startcolumn):this(dstream, encoding, startline, startcolumn, 4096)
346 public SimpleCharStream(System.IO.Stream dstream,
int startline,
int startcolumn):this(dstream, startline, startcolumn, 4096)
350 public SimpleCharStream(System.IO.Stream dstream, System.String encoding):this(dstream, encoding, 1, 1, 4096)
358 public virtual void ReInit(System.IO.Stream dstream, System.String encoding,
int startline,
int startcolumn,
int buffersize)
360 ReInit(encoding == null?
new System.IO.StreamReader(dstream, System.Text.Encoding.Default):
new System.IO.StreamReader(dstream, System.Text.Encoding.GetEncoding(encoding)), startline, startcolumn, buffersize);
363 public virtual void ReInit(System.IO.Stream dstream,
int startline,
int startcolumn,
int buffersize)
365 ReInit(
new System.IO.StreamReader(dstream, System.Text.Encoding.Default), startline, startcolumn, buffersize);
368 public virtual void ReInit(System.IO.Stream dstream, System.String encoding)
370 ReInit(dstream, encoding, 1, 1, 4096);
373 public virtual void ReInit(System.IO.Stream dstream)
375 ReInit(dstream, 1, 1, 4096);
377 public virtual void ReInit(System.IO.Stream dstream, System.String encoding,
int startline,
int startcolumn)
379 ReInit(dstream, encoding, startline, startcolumn, 4096);
381 public virtual void ReInit(System.IO.Stream dstream,
int startline,
int startcolumn)
383 ReInit(dstream, startline, startcolumn, 4096);
385 public virtual System.String GetImage()
387 if (bufpos >= tokenBegin)
388 return new System.String(buffer, tokenBegin, bufpos - tokenBegin + 1);
390 return new System.String(buffer, tokenBegin, bufsize - tokenBegin) +
new System.String(buffer, 0, bufpos + 1);
393 public virtual char[] GetSuffix(
int len)
395 char[] ret =
new char[len];
397 if ((bufpos + 1) >= len)
398 Array.Copy(buffer, bufpos - len + 1, ret, 0, len);
401 Array.Copy(buffer, bufsize - (len - bufpos - 1), ret, 0, len - bufpos - 1);
402 Array.Copy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
408 public virtual void Done()
416 public virtual void AdjustBeginLineColumn(
int newLine,
int newCol)
418 int start = tokenBegin;
421 if (bufpos >= tokenBegin)
423 len = bufpos - tokenBegin + inBuf + 1;
427 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
430 int i = 0, j = 0, k = 0;
431 int nextColDiff = 0, columnDiff = 0;
433 while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
435 bufline[j] = newLine;
436 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
437 bufcolumn[j] = newCol + columnDiff;
438 columnDiff = nextColDiff;
444 bufline[j] = newLine++;
445 bufcolumn[j] = newCol + columnDiff;
449 if (bufline[j = start % bufsize] != bufline[++start % bufsize])
450 bufline[j] = newLine++;
452 bufline[j] = newLine;
457 column = bufcolumn[j];