File: MyTextReader.cs

package info (click to toggle)
mono-debugger 0.60%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,556 kB
  • ctags: 22,787
  • sloc: ansic: 99,407; cs: 42,429; sh: 9,192; makefile: 376
file content (76 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download | duplicates (2)
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 ();
		}
	}
}