This commit is contained in:
Doug Hoyte
2024-12-19 21:17:54 -05:00
parent 7882f8baa9
commit e65d50bb22
3 changed files with 29 additions and 30 deletions

View File

@ -2,6 +2,8 @@
#include <string>
#include "re2/re2.h"
struct Url {
std::vector<std::string_view> path;
@ -82,3 +84,29 @@ inline std::string renderPoints(double points) {
return std::string(buf);
}
inline std::string stripUrls(std::string &content) {
static RE2 matcher(R"((?is)(.*?)(https?://\S+))");
std::string output;
std::string firstUrl;
std::string_view contentSv(content);
re2::StringPiece input(contentSv);
re2::StringPiece prefix, match;
auto sv = [](re2::StringPiece s){ return std::string_view(s.data(), s.size()); };
while (RE2::Consume(&input, matcher, &prefix, &match)) {
output += sv(prefix);
if (firstUrl.empty()) {
firstUrl = std::string(sv(match));
}
}
output += std::string_view(input.data(), input.size());
std::swap(output, content);
return firstUrl;
}