-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcore.cpp
More file actions
126 lines (107 loc) · 2.09 KB
/
Copy pathcore.cpp
File metadata and controls
126 lines (107 loc) · 2.09 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
#include "core.h"
list<string> core::fromListBox(ListBox^ box)
{
list<string> list;
for (int i = 0; i < box->Items->Count; i++)
list.push_back(convertToString(box->Items[i]->ToString()));
return list;
}
std::string core::convertToString(String^ st_ptr)
{
std::string st = msclr::interop::marshal_as<std::string>(st_ptr);
return st;
}
list<string> core::Delete(int line, list<string>l)
{
list<string>::iterator it = l.begin();
advance(it, line);
l.erase(it);
return l;
}
int core::find(string s, list<string>l)
{
bool isfound = false;
int cnt = 0;
for (auto& it : l)
{
if (it.find(s) >= 0 && it.find(s) <= 10000)
{
isfound = true;
break;
}
else cnt++;
}
if (isfound)
return cnt;
else
return -1;
}
list<int> core::FindAll(string s, list<string>& l)
{
list<int> pos;
int cnt = 0;
for (auto& it : l)
{
if (it.find(s) >= 0 && it.find(s) <= 10000)
{
pos.push_back(cnt);
}
cnt++;
}
return pos;
}
list<string> core::ReplaceAll(list<string>lst, string oldst, string newst)
{
for (auto& it : lst)
{
if (it.find(oldst) >= 0 && it.find(oldst) <= 10000)
{
it.replace(it.find(oldst), oldst.length(), newst);
while (it.find(oldst) >= 0 && it.find(oldst) <= 10000)
{
it.replace(it.find(oldst), oldst.length(), newst);
}
}
}
return lst;
}
list<string> core::read(string fileName,list<string> box)
{
fstream infile(fileName, ios::in);
string line = "";
if (infile.is_open()) {
while (getline(infile,line))
{
box.push_back(line);
}
infile.close();
}
return box;
}
void core::write(string fileName, list<string>box)
{
fstream file(fileName, ios::out);
list<string>::iterator it;
while (file.is_open()) {
for (auto it : box) {
file << it;
file << "\n";
}
file.close();
}
}
list<string> core::insert(int index, string line, list<string>box)
{
list<string>::iterator it = box.begin();
advance(it, index);
box.insert(it, line);
return box;
}
list<string> core::update(int index, string line, list<string>box)
{
list<string>::iterator it = box.begin();
advance(it, index);
box.insert(it, line);
box.erase(it);
return box;
}