1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Mono.Debugger.Frontend
{
internal class MyTextReader : TextReader
{
bool closed = false;
string current_line = null;
int pos = 0;
public string Text {
set {
if (closed)
throw new InvalidOperationException ("Reader is closed.");
pos = 0;
current_line = value;
}
}
bool check_line ()
{
if (closed || (current_line == null))
return false;
if (pos >= current_line.Length) {
current_line = null;
return false;
}
return true;
}
public override int Peek ()
{
if (!check_line ())
return -1;
return current_line [pos];
}
public override int Read ()
{
if (!check_line ())
return -1;
return current_line [pos++];
}
public override string ReadLine ()
{
string retval;
if (!check_line ())
return String.Empty;
retval = current_line;
current_line = null;
return retval;
}
public override string ReadToEnd ()
{
return ReadLine ();
}
public override void Close ()
{
current_line = null;
closed = true;
base.Close ();
}
}
}
|