2018-06-28 00:24:21 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
2023-04-23 00:58:37 +02:00
|
|
|
#include <optional>
|
|
|
|
|
2018-06-28 00:24:21 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2023-04-23 00:58:37 +02:00
|
|
|
struct ParsedLink {
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
|
|
using StringView = QStringView;
|
|
|
|
#else
|
|
|
|
using StringView = QStringRef;
|
|
|
|
#endif
|
2024-04-21 21:24:11 +02:00
|
|
|
/// The parsed protocol of the link. Can be empty.
|
|
|
|
///
|
|
|
|
/// https://www.forsen.tv/commands
|
|
|
|
/// ^------^
|
2023-04-23 00:58:37 +02:00
|
|
|
StringView protocol;
|
2024-04-21 21:24:11 +02:00
|
|
|
|
|
|
|
/// The parsed host of the link. Can not be empty.
|
|
|
|
///
|
|
|
|
/// https://www.forsen.tv/commands
|
|
|
|
/// ^-----------^
|
2023-04-23 00:58:37 +02:00
|
|
|
StringView host;
|
2024-04-21 21:24:11 +02:00
|
|
|
|
|
|
|
/// The remainder of the link. Can be empty.
|
|
|
|
///
|
|
|
|
/// https://www.forsen.tv/commands
|
|
|
|
/// ^-------^
|
2023-04-23 00:58:37 +02:00
|
|
|
StringView rest;
|
2024-04-21 21:24:11 +02:00
|
|
|
|
|
|
|
/// The original unparsed link.
|
|
|
|
///
|
|
|
|
/// https://www.forsen.tv/commands
|
|
|
|
/// ^----------------------------^
|
2023-04-23 00:58:37 +02:00
|
|
|
QString source;
|
|
|
|
};
|
|
|
|
|
2018-06-28 00:24:21 +02:00
|
|
|
class LinkParser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit LinkParser(const QString &unparsedString);
|
|
|
|
|
2023-04-23 00:58:37 +02:00
|
|
|
const std::optional<ParsedLink> &result() const;
|
2018-06-28 00:24:21 +02:00
|
|
|
|
|
|
|
private:
|
2023-04-23 00:58:37 +02:00
|
|
|
std::optional<ParsedLink> result_{};
|
2018-06-28 00:24:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|