refactor(linkparser): take string views (#6715)

Reviewed-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Nerixyz
2026-01-05 23:53:58 +01:00
committed by GitHub
parent 6110c32916
commit 90373323ec
7 changed files with 20 additions and 14 deletions
+1 -1
View File
@@ -170,7 +170,7 @@ Q_ALWAYS_INLINE bool isValidDomainChar(char16_t c)
namespace chatterino::linkparser {
std::optional<Parsed> parse(const QString &source) noexcept
std::optional<Parsed> parse(QStringView source) noexcept
{
using SizeType = QString::size_type;
+13 -5
View File
@@ -75,7 +75,9 @@ struct Parsed {
QStringView link;
/// Checks if the parsed link contains a prefix
bool hasPrefix(const QString &source) const noexcept
///
/// @param source The exact source string passed to parse()
bool hasPrefix(QStringView source) const noexcept
{
return this->link.begin() != source.begin();
}
@@ -89,13 +91,17 @@ struct Parsed {
/// https://www.forsen.tv/commands
/// (empty)
/// ```
QStringView prefix(const QString &source) const noexcept
///
/// @param source The exact source string passed to parse()
QStringView prefix(QStringView source) const noexcept
{
return {source.data(), this->link.begin()};
}
/// Checks if the parsed link contains a suffix
bool hasSuffix(const QString &source) const noexcept
///
/// @param source The exact source string passed to parse()
bool hasSuffix(QStringView source) const noexcept
{
return this->link.end() != source.end();
}
@@ -109,7 +115,9 @@ struct Parsed {
/// https://www.forsen.tv/commands
/// (empty)
/// ```
QStringView suffix(const QString &source) const noexcept
///
/// @param source The exact source string passed to parse()
QStringView suffix(QStringView source) const noexcept
{
return {
this->link.begin() + this->link.size(),
@@ -125,6 +133,6 @@ struct Parsed {
/// views into @a source.
///
/// For the accepted links, see Parsed.
std::optional<Parsed> parse(const QString &source) noexcept;
std::optional<Parsed> parse(QStringView source) noexcept;
} // namespace chatterino::linkparser