-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelpers.cs
More file actions
154 lines (125 loc) · 3.25 KB
/
Helpers.cs
File metadata and controls
154 lines (125 loc) · 3.25 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Compiler
{
class Pair<T1, T2>
{
public T1 first;
public T2 last;
public Pair(T1 _first, T2 _last)
{
first = _first;
last = _last;
}
public Pair()
{
first = default(T1);
last = default(T2);
}
}
class StreamWriter : System.IO.StreamWriter
{
private long charPos = 0;
private long charLine = 0;
public StreamWriter(System.IO.Stream stream) : base(stream) { }
public StreamWriter(string path) : base(path) { }
public StreamWriter(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
public StreamWriter(string path, bool append) : base(path, append) { }
public StreamWriter(System.IO.Stream stream, Encoding encoding, int bufferSize)
: base(stream, encoding, bufferSize) { }
public StreamWriter(string path, bool append, Encoding encoding)
: base(path, append, encoding) { }
public StreamWriter(string path, bool append, Encoding encoding, int bufferSize)
: base(path, append, encoding, bufferSize) { }
public override void Write(string value)
{
base.Write(value);
if (value.IndexOf(this.NewLine) != -1)
{
this.charPos = 0;
this.charLine += (value.Length - value.Replace(this.NewLine, "").Length) / this.NewLine.Length;
}
else
{
this.charPos += value.Length;
}
}
public int GetCharPos()
{
return (int)this.charPos;
}
public int GetCharLine()
{
return (int)this.charLine;
}
}
class Three<T1, T2, T3> : Pair<T1, T3>
{
public T2 middle;
public Three(T1 _first, T2 _middle, T3 _last)
{
first = _first;
middle = _middle;
last = _last;
}
public Three()
{
first = default(T1);
middle = default(T2);
last = default(T3);
}
}
class Exception : System.Exception
{
public override string Message
{
get
{
return this.title + string.Format(" в строке {0}, позиции {1}: {2}", this.line, this.index, base.Message);
}
}
protected string title = "";
public int index, line;
public Exception(string title, string message, int index, int line) : base(message)
{
this.title = title;
this.index = index;
this.line = line;
}
public Exception(string message, int index, int line)
: base(message)
{
this.line = line;
this.index = index;
}
}
abstract class PrintObject
{
public void Print(StreamWriter stream, int indent = 0)
{
this.Print(stream, new String(' ', indent), true);
}
protected string GenIndent(string indent, bool last = false)
{
return indent + (last ? "└──" : "├──");
}
virtual protected void Print(StreamWriter stream, string indent = "", bool last = false)
{
stream.Write(GenIndent(indent, last) + "{" + this.ToString() + "}");
stream.AutoFlush = true;
this.PrintChildrens(stream, indent, last);
}
virtual protected void PrintChildrens(StreamWriter stream, string indent = "", bool last = false)
{
List<PrintObject> childrens = this.GetChildrens();
for (int i = childrens.Count - 1; i >= 0; --i)
{
stream.Write(stream.NewLine);
childrens.ElementAt(i).Print(stream, indent + (last ? " " : "│ "), i == childrens.Count - 1);
}
}
public abstract List<PrintObject> GetChildrens();
}
}