-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copia di PyClassStruct.cs
259 lines (233 loc) · 5.13 KB
/
Copia di PyClassStruct.cs
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
* Creato da SharpDevelop.
* Utente: michele
* Data: 03/03/2009
* Ora: 13.54
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
namespace textops
{
/*
* 0 : # --- begin [Sec1] section --- B
* 1 : # --- end [Sec1] section --- E
* 2 : # --- begin [Sec2] section --- B
* (3) : data 1
* 3 : # --- begin [Sec2] section --- B
*
* B = 0, S = 0, E = B + S + 1
* Insert PS = B + 1 + Pos, If (Pos = -1) PS = E;
*/
public class PySection
{
private int _begin;
private int _size;
private StringCollection _lines;
private ArrayList _children;
public PySection()
{
_begin = 0;
_size = 0;
_children = new ArrayList();
_lines = new StringCollection();
}
public int Begin
{
get { return _begin; }
set { _begin = value; }
}
public int Size
{
get { return _size; }
set { _size = value; }
}
public int End
{
get { return _begin + _size + 1; }
}
public ArrayList Children
{
get { return _children; }
}
public StringCollection Lines
{
get { return _lines; }
}
public void AddSection(PySection sec)
{
_children.Add(sec);
Size += sec.Size;
}
public void RemSection(PySection sec)
{
_children.Remove(sec);
Size -= sec.Size;
}
public void MoveBeginIndex(int count)
{
_begin += count;
if (_begin < 0) _begin = 0;
}
public void MoveSizeIndex(int count)
{
_size += count;
if (_size < 0) _size = 0;
}
}
/*
public class PyClass
{
private string _classname;
private StringCollection _lines;
// pyfile.py
private const int _sec_count = 4;
public PySection[] _sections;
public PyClassSection _cur_section;
public int _cur_begin;
public int _cur_size;
public PyClass()
{
_lines = new StringCollection();
_sections = new PySection[_sec_count];
for (int i=0; i<_sec_count; i++)
{
_sections[i] = new PySection();
_sections[i].Begin = 1 + i*2;
}
_cur_begin = -1;
_cur_size = -1;
_cur_section = PyClassSection.PYDEF_NONE;
}
public string Name
{
get { return _classname; }
set { _classname = value; }
}
public StringCollection Lines
{
get { return _lines; }
}
public void BeginSection(PyClassSection section)
{
// make this section as current;
_cur_section = section;
_cur_begin = _sections[(int)section].Begin;
_cur_size = _sections[(int)section].Size;
}
public void EndSection()
{
// make this section as current;
_cur_section = PyClassSection.PYDEF_NONE;
_cur_begin = -1;
_cur_size = -1;
}
public void SetBeginLabel(string label)
{
// _lines[_cur_begin].A
}
private int SeekToSection(int pos)
{
int B = _cur_begin;
int E = _cur_begin + _cur_size + 1;
int ps = B + pos + 1;
if (pos == -1) ps = E;
if (ps < 0) ps = B + 1;
if (ps > E) ps = E;
return ps;
}
public void InsertSingleLine(int pos, string str)
{
// pos : relative to section, -1 mean end of section
int row = SeekToSection(pos);
if (row >= _lines.Count)
{
_lines.Add(str);
} else {
_lines.Insert(row, str);
}
MoveSectionSize(1);
}
public void InsertLines(int pos, string str)
{
// pos : relative to section, -1 mean end of section
string[] arr = Regex.Split(str, "\r\n");
int count = arr.Length;
int row = SeekToSection(pos);
for (int i=0; i<count; i++)
{
if (row + i >= _lines.Count)
{
_lines.Add(arr[i]);
} else {
_lines.Insert(row + i, arr[i]);
}
}
MoveSectionSize(count);
}
public void DeleteLine(int pos, int rowcount)
{
int row = SeekToSection(pos);
for (int i=0; i<rowcount; i++)
{
_lines.RemoveAt(row + i);
}
MoveSectionSize(-rowcount);
}
public void ReplaceEntireLine(int pos, string str)
{
// pos : relative to section, -1 mean end of section
int row = SeekToSection(pos);
if (row < _lines.Count)
{
_lines[row] = str;
}
}
public void InsertBeforeSection(string str)
{
// pos : relative to section, -1 mean end of section
int row = SeekToSection(0);
if (row - 1 < 0) row = 0; else row--;
_lines.Insert(row, str);
MoveIndexes(1);
}
public void InsertAfterSection(string str)
{
// pos : relative to section, -1 mean end of section
int row = SeekToSection( -1);
row++;
if (row >= _lines.Count)
{
_lines.Add(str);
} else {
_lines.Insert(row, str);
}
for (int i = (int)(_cur_section) + 1; i<_sec_count; i++)
{
_sections[i].MoveBeginIndex(1);
}
}
public void MoveIndexes(int count)
{
for (int i = (int)_cur_section; i<_sec_count; i++)
{
_sections[i].MoveBeginIndex(count);
}
_cur_begin = _sections[(int)_cur_section].Begin;
}
public void MoveSectionSize(int count)
{
_sections[(int)_cur_section].MoveSizeIndex(count);
for (int i = (int)(_cur_section) + 1; i<_sec_count; i++)
{
_sections[i].MoveBeginIndex(count);
}
_cur_size = _sections[(int)_cur_section].Size;
}
}
*/
}