Remove Redundant Parsing of Links (#4507)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2023-04-23 00:58:37 +02:00
committed by GitHub
parent f2938995c1
commit 95e7426283
10 changed files with 168 additions and 147 deletions
+16 -4
View File
@@ -2,19 +2,31 @@
#include <QString>
#include <optional>
namespace chatterino {
struct ParsedLink {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
using StringView = QStringView;
#else
using StringView = QStringRef;
#endif
StringView protocol;
StringView host;
StringView rest;
QString source;
};
class LinkParser
{
public:
explicit LinkParser(const QString &unparsedString);
bool hasMatch() const;
QString getCaptured() const;
const std::optional<ParsedLink> &result() const;
private:
bool hasMatch_{false};
QString match_;
std::optional<ParsedLink> result_{};
};
} // namespace chatterino