mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-20 09:50:28 +00:00
cleanup
This commit is contained in:
@ -13,8 +13,6 @@
|
||||
|
||||
|
||||
|
||||
std::string stripUrls(std::string &content);
|
||||
|
||||
|
||||
inline void preprocessMetaFieldContent(std::string &content) {
|
||||
static RE2 matcher(R"((?is)(.*?)(https?://\S+))");
|
||||
@ -420,33 +418,6 @@ struct Event {
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
struct ReplyCtx {
|
||||
uint64_t timestamp;
|
||||
TemplarResult rendered;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "Decompressor.h"
|
||||
#include "events.h"
|
||||
#include "Bytes32.h"
|
||||
#include "WebData.h"
|
||||
#include "WebUtils.h"
|
||||
|
||||
|
||||
static const char USAGE[] =
|
||||
|
Reference in New Issue
Block a user