labs-edaf30/lab4/TagRemover.cc

32 lines
812 B
C++
Raw Permalink Normal View History

2024-12-11 15:54:56 +01:00
#include <iostream>
#include <regex>
#include <string>
class TagRemover {
private:
std::string content;
public:
TagRemover(std::istream& input) {
std::string line;
while (std::getline(input, line)) {
content += line + '\n';
}
}
void print(std::ostream& output) const {
std::string result = std::regex_replace(content, std::regex("<[^>]*>"), "");
result = std::regex_replace(result, std::regex("&lt;"), "<");
result = std::regex_replace(result, std::regex("&gt;"), ">");
result = std::regex_replace(result, std::regex("&nbsp;"), " ");
result = std::regex_replace(result, std::regex("&amp;"), "&");
output << result;
}
};
int main() {
TagRemover tr(std::cin);
tr.print(std::cout);
return 0;
}