-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText.cs
More file actions
128 lines (118 loc) · 3.51 KB
/
Copy pathText.cs
File metadata and controls
128 lines (118 loc) · 3.51 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
//-------+----------------------------------------
//author : 배준현
//email : outersky@gmail.com
//date : 2017.11.16
//modify : 2017.11.16
//at : kumoh national institude of technology
//-------+----------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace editor
{
public struct LC
{
public int L;
public int C;
public LC(int L, int C) : this()
{
this.L = L;
this.C = C;
}
}
enum WordType
{
comment = 0,
normal = 1,
instruction = 2,
label = 3,
space = 4
}
class Text
{
private List<string> Sentences;
public List<int> fail;
public void GetFail(string searchText)
{
for (int i = 0; i < searchText.Length; i++) {
fail.Add(0);
}
for (int i = 1, j = 0; i < searchText.Length; i++)
{
while (j > 0 && searchText[i] != searchText[j]) j = fail[j - 1];
if (searchText[i] == searchText[j]) fail[i] = ++j;
}
}
public List<LC> Search(string searchText)
{
fail = new List<int>();
List<LC> StartingPoint = new List<LC>();
GetFail(searchText);
for (int k = 0; k < Sentences.Count; k++)
{
string S = Sentences[k];
for (int i = 0, j = 0; i < S.Length; i++)
{
while (j > 0 && S[i] != searchText[j]) j = fail[j - 1];
if (S[i] == searchText[j])
{
if (j == searchText.Length - 1)
{
LC temp = new LC( k, i - searchText.Length + 1 );
StartingPoint.Add(temp);
j = fail[j];
}
else j++;
}
}
}
return StartingPoint;
}
public Text()
{
Sentences = new List<string>();
Sentences.Add("");
}
public List<string> GetText() => Sentences;
public void SetText(List<string> Sentences) => this.Sentences = Sentences;
public void Insert(int L, int C, string SubStr)
{
string Temp = Sentences[L];
Temp = Temp.Substring(0, C) + SubStr + Temp.Substring(C);
Sentences[L] = Temp;
}
public void LineFeed(int L, int C)
{
string Temp = Sentences[L];
string Temp2 = Temp.Substring(C);
Temp = Temp.Substring(0, C);
Sentences[L] = Temp;
Sentences.Insert(L + 1, Temp2);
}
public int Erase(int L, int C)
{
if (C == 0)
{
Sentences[L - 1] = Sentences[L - 1] + Sentences[L];
Sentences.RemoveAt(L);
return 1;
}
Sentences[L] = Sentences[L].Remove(C - 1, 1);
return 0;
}
public void DErase(int L, int C)
{
if (L != Sentences.Count - 1 && Sentences[L].Length == C)
{
Sentences[L] += Sentences[L + 1];
Sentences.RemoveAt(L + 1);
}
else if(Sentences[L].Length != C)
{
Sentences[L]= Sentences[L].Remove(C, 1);
}
}
}
}