-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremcomments.cpp
More file actions
42 lines (34 loc) · 1.16 KB
/
Copy pathremcomments.cpp
File metadata and controls
42 lines (34 loc) · 1.16 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
#include <fstream>
#include <filesystem>
#include <regex>
#include <string>
#include <sstream>
namespace fs = std::filesystem;
int main() {
// Create out directory if it doesn't exist
fs::create_directory("out");
// Regex pattern for user_pref lines
std::regex user_pref_pattern("^user_pref");
for (const auto& entry : fs::directory_iterator(".")) {
if (entry.path().extension() == ".js") {
std::string filename = entry.path().filename().string();
// Read input file
std::ifstream inFile(filename);
std::string content((std::istreambuf_iterator<char>(inFile)),
std::istreambuf_iterator<char>());
inFile.close();
std::stringstream ss(content);
std::string line, result;
while (std::getline(ss, line)) {
if (std::regex_search(line, user_pref_pattern)) {
result += line + "\n";
}
}
// Write to output file
std::ofstream outFile("out/" + filename);
outFile << result;
outFile.close();
}
}
return 0;
}