init: quirks: implement regex replacement

This commit is contained in:
Peter Cai 2021-10-15 20:57:26 -04:00
parent 80f1d3004a
commit 464f41137a
2 changed files with 6 additions and 3 deletions

View file

@ -3,6 +3,8 @@
#include "quirks.h"
#include <regex>
#include <sstream>
#include <vector>
#include <sys/mount.h>
@ -105,7 +107,8 @@ void Quirks::OverrideFileWith(filesystem::path p, function<void(istream&, ostrea
}
void Quirks::OverrideFileReplaceSubstr(filesystem::path p, string pattern, string replacement) {
Quirks::OverrideFileWith(p, [](istream& is, ostream& os) {
os << is.rdbuf();
Quirks::OverrideFileWith(p, [pattern, replacement](istream& is, ostream& os) {
string str = string((istreambuf_iterator<char>(is)), istreambuf_iterator<char>());
os << regex_replace(str, regex(pattern), replacement);;
});
}

View file

@ -29,7 +29,7 @@ public:
void Run() {
for (auto& p : PATHS) {
if (filesystem::exists(p)) {
Quirks::OverrideFileReplaceSubstr(p, "AT+EAIC=2", "AT+EAIC=3");
Quirks::OverrideFileReplaceSubstr(p, "AT\\+EAIC=2", "AT+EAIC=3");
}
}
}