diff --git a/src/apps/web/WebData.h b/src/apps/web/WebData.h index 8834486..431ba5a 100644 --- a/src/apps/web/WebData.h +++ b/src/apps/web/WebData.h @@ -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; diff --git a/src/apps/web/WebUtils.h b/src/apps/web/WebUtils.h index bcde7ee..dde7575 100644 --- a/src/apps/web/WebUtils.h +++ b/src/apps/web/WebUtils.h @@ -2,6 +2,8 @@ #include +#include "re2/re2.h" + struct Url { std::vector 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; +} diff --git a/src/apps/web/cmd_stories.cpp b/src/apps/web/cmd_stories.cpp index 8965ccd..e7753c2 100644 --- a/src/apps/web/cmd_stories.cpp +++ b/src/apps/web/cmd_stories.cpp @@ -6,7 +6,7 @@ #include "Decompressor.h" #include "events.h" #include "Bytes32.h" -#include "WebData.h" +#include "WebUtils.h" static const char USAGE[] =