-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer1.h
174 lines (171 loc) · 5.16 KB
/
layer1.h
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
#include "layer0.h"
std::map<std::vector<std::vector<unsigned int>>, std::vector<std::vector<std::string>>> regex_findr_bgn_low(std::string &searched, std::string &x) {
std::vector<unsigned int> conditions_idxv = {};
const unsigned int n = searched.length();
const unsigned int n2 = x.length();
unsigned int cnt = 0;
unsigned int cnt2 = 0;
unsigned int rtn_lst_cnt;
unsigned int ref_rep_val;
bool is_ref = 0;
bool is_greedy1 = 0;
std::string cur_searched = "";
std::string cur_str;
std::string cur_x = x;
std::vector<std::vector<unsigned int>> idx_hmn;
std::vector<std::vector<std::string>> str_hmn;
std::map<std::vector<unsigned int>, std::map<bool, std::string>> cur_mp;
std::map<std::vector<unsigned int>, std::map<bool, std::string>>::iterator cur_it;
std::map<bool, std::string>::iterator rslt_mp;
std::vector<unsigned int> idx_v;
std::vector<unsigned int> cur_idx_hmn;
std::vector<std::string> cur_str_hmn;
if (searched[0] == '[') {
cnt = 1;
while (1) {
conditions_idxv.push_back(cnt);
if (searched[cnt] == ']' & searched[cnt - 1] != '\\') {
break;
};
if (searched[cnt + 1] == '-' & searched[cnt] != '\\') {
cnt += 2;
};
if (searched[cnt + 1] == '{') {
cnt += 1;
while (searched[cnt] != '}') {
cnt += 1;
};
};
cnt += 1;
};
if (cnt + 1 < n) {
cnt += 1;
if (searched[cnt] == '{') {
is_ref = 1;
cnt += 1;
if (searched[cnt] == '+') {
cnt += 1;
is_greedy1 = 1;
};
ref_rep_val = int(searched[cnt]) - 48;
cnt += 1;
while (searched[cnt] != '}') {
ref_rep_val *= 10;
ref_rep_val += (int(searched[cnt]) - 48);
cnt += 1;
};
};
};
for (cnt = 0; cnt < conditions_idxv.size() - 1; ++cnt) {
cur_searched = "";
cur_x = x;
for (cnt2 = conditions_idxv[cnt]; cnt2 < conditions_idxv[cnt + 1]; ++cnt2) {
cur_searched.push_back(searched[cnt2]);
};
if (is_ref) {
cur_searched.insert(0, 1, '[');
cur_searched.push_back(']');
cur_searched.push_back('{');
if (is_greedy1) {
cur_searched.push_back('+');
};
cur_searched += std::to_string(ref_rep_val);
cur_searched.push_back('}');
};
cur_mp = regex_findr1sub(cur_searched, cur_x);
cur_it = cur_mp.begin();
rslt_mp = cur_it->second.begin();
cur_idx_hmn = {};
cur_str_hmn = {};
if (rslt_mp->first) {
idx_v = cur_it->first;
rtn_lst_cnt = idx_v[1];
cur_str = rslt_mp->second;
cur_str_hmn.push_back(cur_str);
cur_idx_hmn.push_back(rtn_lst_cnt);
cur_x = "";
for (cnt2 = rtn_lst_cnt + 1; cnt2 < n2; ++cnt2) {
cur_x.push_back(x[cnt2]);
};
while (1) {
cur_mp = regex_findr1sub(cur_searched, cur_x);
cur_it = cur_mp.begin();
rslt_mp = cur_it->second.begin();
if (rslt_mp->first) {
idx_v = cur_it->first;
rtn_lst_cnt += idx_v[1];
cur_str = rslt_mp->second;
cur_str_hmn.push_back(cur_str);
rtn_lst_cnt += 1;
cur_idx_hmn.push_back(rtn_lst_cnt);
cur_x = "";
for (cnt2 = rtn_lst_cnt + 1; cnt2 < n2; ++cnt2) {
cur_x.push_back(x[cnt2]);
};
} else {
break;
};
};
idx_hmn.push_back(cur_idx_hmn);
str_hmn.push_back(cur_str_hmn);
};
};
} else {
cur_searched.push_back(searched[0]);
if (n > 2) {
cnt += 1;
if (searched[cnt] == '-') {
cur_searched.push_back(searched[1]);
cur_searched.push_back(searched[2]);
cnt += 2;
};
if (searched[cnt] == '{') {
cur_searched.push_back('{');
cnt += 1;
while (searched[cnt] != '}') {
cur_searched.push_back(searched[cnt]);
cnt += 1;
};
cur_searched.push_back('}');
};
};
cur_mp = regex_findr1sub(cur_searched, cur_x);
cur_it = cur_mp.begin();
rslt_mp = cur_it->second.begin();
cur_idx_hmn = {};
cur_str_hmn = {};
if (rslt_mp->first) {
idx_v = cur_it->first;
rtn_lst_cnt = idx_v[1];
cur_str = rslt_mp->second;
cur_str_hmn.push_back(cur_str);
cur_idx_hmn.push_back(rtn_lst_cnt);
cur_x = "";
for (cnt2 = rtn_lst_cnt + 1; cnt2 < n2; ++cnt2) {
cur_x.push_back(x[cnt2]);
};
while (1) {
cur_mp = regex_findr1sub(cur_searched, cur_x);
cur_it = cur_mp.begin();
rslt_mp = cur_it->second.begin();
if (rslt_mp->first) {
idx_v = cur_it->first;
rtn_lst_cnt += idx_v[1];
rtn_lst_cnt += 1;
cur_str = rslt_mp->second;
cur_str_hmn.push_back(cur_str);
cur_idx_hmn.push_back(rtn_lst_cnt);
cur_x = "";
for (cnt2 = rtn_lst_cnt + 1; cnt2 < n2; ++cnt2) {
cur_x.push_back(x[cnt2]);
};
} else {
break;
};
};
idx_hmn.push_back(cur_idx_hmn);
str_hmn.push_back(cur_str_hmn);
};
};
return {{idx_hmn, str_hmn}};
};