removes <em> tags from test input

master
Benjamin Kraft 2 years ago
parent 378143f61f
commit 82bc109ecf
  1. 5
      src/main.cpp
  2. 7
      src/util.h

@ -30,7 +30,10 @@ Input getInput(int day, string key, bool useTestInput, int testFetchIndex) {
string res = cpr::Get(cpr::Url{url}).text;
size_t i1 = findAll(res, "<code>")[testFetchIndex];
size_t i2 = findAll(res, "</code>")[testFetchIndex];
file << res.substr(i1 + 6, i2 - (i1 + 6));
string codeContent = res.substr(i1 + 6, i2 - (i1 + 6));
removeAll(codeContent, "<em>");
removeAll(codeContent, "</em>");
file << codeContent;
file.close();
}
}

@ -31,3 +31,10 @@ inline vector<size_t> findAll(const string& data, const string& toSearch){
return indices;
}
inline void removeAll(string& data, const string& toRemove) {
vector<size_t> indices = findAll(data, toRemove);
std::sort(indices.rbegin(), indices.rend());
for (size_t &i : indices)
data.erase(i, toRemove.size());
}
Loading…
Cancel
Save