progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
95
AspClassic.Scripting/SourceCodeReader.cs
Normal file
95
AspClassic.Scripting/SourceCodeReader.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using AspClassic.Scripting.Utils;
|
||||
|
||||
namespace AspClassic.Scripting;
|
||||
|
||||
public class SourceCodeReader : TextReader
|
||||
{
|
||||
public new static readonly SourceCodeReader Null = new SourceCodeReader(TextReader.Null, null);
|
||||
|
||||
private readonly TextReader _textReader;
|
||||
|
||||
private readonly Encoding _encoding;
|
||||
|
||||
public Encoding Encoding => _encoding;
|
||||
|
||||
public TextReader BaseReader => _textReader;
|
||||
|
||||
public SourceCodeReader(TextReader textReader, Encoding encoding)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(textReader, "textReader");
|
||||
_encoding = encoding;
|
||||
_textReader = textReader;
|
||||
}
|
||||
|
||||
public override string ReadLine()
|
||||
{
|
||||
return _textReader.ReadLine();
|
||||
}
|
||||
|
||||
public virtual bool SeekLine(int line)
|
||||
{
|
||||
if (line < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("line");
|
||||
}
|
||||
if (line == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int num = 1;
|
||||
while (true)
|
||||
{
|
||||
switch (_textReader.Read())
|
||||
{
|
||||
case 13:
|
||||
if (_textReader.Peek() == 10)
|
||||
{
|
||||
_textReader.Read();
|
||||
}
|
||||
num++;
|
||||
if (num == line)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
num++;
|
||||
if (num == line)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ReadToEnd()
|
||||
{
|
||||
return _textReader.ReadToEnd();
|
||||
}
|
||||
|
||||
public override int Read(char[] buffer, int index, int count)
|
||||
{
|
||||
return _textReader.Read(buffer, index, count);
|
||||
}
|
||||
|
||||
public override int Peek()
|
||||
{
|
||||
return _textReader.Peek();
|
||||
}
|
||||
|
||||
public override int Read()
|
||||
{
|
||||
return _textReader.Read();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_textReader.Dispose();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue