FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BatFix/src/CodePreprocessing.cpp at main · squaresLab/BatFix · GitHub
squaresLab
/
BatFix
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
5
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
BatFix
/
src
/
CodePreprocessing.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
115 lines (97 loc) · 2.97 KB
Breadcrumbs
BatFix
/
src
/
CodePreprocessing.cpp
Copy path
File metadata and controls
115 lines (97 loc) · 2.97 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
CodePreprocessing.h
"
#
include
<
string
>
#
include
<
vector
>
#
include
<
sstream
>
#
include
<
fstream
>
#
include
<
iostream
>
#
include
<
regex
>
std::string
replace_placeholder
(std::string text, std::string placeholder, std::string value) {
auto
index = text.
find
(placeholder);
auto
prev_index = index;
while
(index != std::string::npos) {
prev_index = index;
index = text.
find
(placeholder, prev_index+
1
);
}
text = text.
replace
(prev_index, placeholder.
length
(), value);
return
text;
}
std::string
remove_public
(std::string code) {
std::string p =
"
public :
"
;
auto
idx = code.
find
(p);
if
(idx != std::string::npos) {
code.
erase
(idx, p.
length
());
}
return
std::move
(code);
}
std::string
remove_static
(std::string code) {
//
corner_case
std::string cc =
"
static // f_filled
"
;
std::string p =
"
static //
"
;
auto
idx = code.
find
(cc);
if
(idx != std::string::npos) {
std::regex
rgx
(
"
\n
(.*) f_gold
"
);
std::smatch matches;
std::regex_search
(code, matches, rgx);
code.
replace
(idx, p.
length
(), matches[
1
].
str
());
p =
"
(//)
"
;
idx = code.
find
(p);
code.
erase
(idx, p.
length
());
}
else
{
auto
idx = code.
find
(p);
if
(idx != std::string::npos) {
code.
erase
(idx, p.
length
());
//
remove the comment
p =
"
(//)
"
;
idx = code.
find
(p);
code.
erase
(idx, p.
length
());
}
}
//
std::cerr << code;
return
std::move
(code);
}
std::string
file_to_string
(std::string& file_name) {
std::ifstream
ifs
(file_name);
std::string content;
content.
assign
( (std::istreambuf_iterator<
char
>(ifs) ),
(std::istreambuf_iterator<
char
>() ) );
return
std::move
(content);
}
std::vector<std::string>
file_to_vector
(std::string& file_name) {
std::ifstream
ifs
(file_name);
std::vector<std::string> lines;
for
(std::string line;
std::getline
( ifs, line );
/*
*/
)
lines.
push_back
( line );
return
std::move
(lines);
}
std::string
add_foo
(std::string& code) {
std::string result;
std::istringstream
iss
(code);
std::string line;
std::istringstream
iss_tmp
(code);
bool
found_foo =
false
;
while
(
std::getline
(iss_tmp, line)) {
if
(line.
find
(
"
int foo;
"
) != std::string::npos) {
found_foo =
true
;
}
}
if
(found_foo)
return
code;
while
(
std::getline
(iss, line) ) {
if
(line.
find
(
"
f_filled
"
) != std::string::npos) {
result +=
"
int foo;
\n
"
;
break
;
}
result += line +
"
\n
"
;
}
do
{
result += line +
"
\n
"
;
}
while
(
std::getline
(iss, line));
return
std::move
(result);
}
std::string
preprocess
(std::string& code) {
code =
remove_public
(code);
code =
remove_static
(code);
code =
add_foo
(code);
return
std::move
(code);
}
Back
|
FazBrowse Home
|
New Git URL