Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hoytech committed Dec 20, 2024
1 parent 50e917a commit 8b47294
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
29 changes: 0 additions & 29 deletions src/apps/web/WebData.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@



std::string stripUrls(std::string &content);


inline void preprocessMetaFieldContent(std::string &content) {
static RE2 matcher(R"((?is)(.*?)(https?://\S+))");
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/apps/web/WebUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <string>

#include "re2/re2.h"


struct Url {
std::vector<std::string_view> path;
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/apps/web/cmd_stories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "Decompressor.h"
#include "events.h"
#include "Bytes32.h"
#include "WebData.h"
#include "WebUtils.h"


static const char USAGE[] =
Expand Down

0 comments on commit 8b47294

Please sign in to comment.