Skip to content

Commit

Permalink
rangeContains()
Browse files Browse the repository at this point in the history
Because macOS still doesn't have ranges::contains().
  • Loading branch information
KitsuneRal committed Dec 30, 2024
1 parent e9c42c1 commit e102faa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions client/htmlfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ constexpr auto htmlStyleAttr = u"style";
constexpr auto mxColorAttr = u"data-mx-color";
constexpr auto mxBgColorAttr = u"data-mx-bg-color";

#ifdef __cpp_lib_ranges_contains
constexpr auto rangeContains = ranges::contains;
#else
inline auto rangeContains(const auto& c, const auto& v)
{
return std::ranges::find(c, v) != std::ranges::end(c);
}
#endif

[[nodiscard]] QString mergeMarkdown(const QString& html)
{
// This code intends to merge user-entered Markdown+HTML markup
Expand Down Expand Up @@ -225,7 +234,7 @@ constexpr auto mxBgColorAttr = u"data-mx-bg-color";
}
if (!inHead) {
// Check if it's a valid (opening or closing) tag allowed in Matrix
if (!ranges::contains(permittedTags, tag)) {
if (!rangeContains(permittedTags, tag)) {
// Invalid tag or non-tag - either remove the abusing piece or stop and report
if (options.testFlag(Validate))
return { {},
Expand Down Expand Up @@ -567,7 +576,7 @@ Processor::rewrite_t Processor::filterTag(QStringView tag, QXmlStreamAttributes
return rewrite;
}

if (!ranges::contains(permittedTags, tag))
if (!rangeContains(permittedTags, tag))
return {}; // The tag is not allowed

const auto it = ranges::find(passLists, tag, &PassList::tag);
Expand Down Expand Up @@ -660,7 +669,7 @@ Processor::rewrite_t Processor::filterTag(QStringView tag, QXmlStreamAttributes
|| (tag == u"a" && aName == u"href"
&& ranges::any_of(permittedSchemes,
[&aValue](QStringView s) { return aValue.startsWith(s); }))
|| ranges::contains(passList, a.qualifiedName()))
|| rangeContains(passList, a.qualifiedName()))
rewrite.front().second.push_back(std::move(a));
} // for (a: attributes)

Expand Down

0 comments on commit e102faa

Please sign in to comment.