-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_nodes.cpp
More file actions
32 lines (28 loc) · 933 Bytes
/
Copy pathdelete_nodes.cpp
File metadata and controls
32 lines (28 loc) · 933 Bytes
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
#include <bits/stdc++.h>
#include "graphlib.hpp"
#include <regex>
using namespace std;
void delete_instances(const string& node_to_delete, const string& input_file) {
vector<string> lines;
string line;
regex nodetodeletepattern("^Node " + node_to_delete + "\\b");
regex nodetodeletepattern2("\\bNode " + node_to_delete + "\\b");
regex removetrailingcomma(",\\s*\\r?$");
ifstream in(input_file);
while (getline(in, line)) {
if (regex_search(line, nodetodeletepattern)) {
continue;
}
string cleaned = regex_replace(line, nodetodeletepattern2, "");
cleaned = regex_replace(cleaned, removetrailingcomma, "");
lines.push_back(cleaned);
}
in.close();
ofstream out(input_file);
for (const string& remaining_line : lines) {
if (!remaining_line.empty()) {
out << remaining_line << "\n";
}
}
out.close();
}