Skip to content

Commit

Permalink
try: const -> fn (idk anymore)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Sep 10, 2024
1 parent 00a84b6 commit 1c03ca0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/controllers/filters/lang/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)

/*
* Looking to add a new identifier to filters? Here's what to do:
* 1. Update validIdentifiersMap in Tokenizer.hpp
* 1. Update validIdentifiersMap in Tokenizer.cpp
* 2. Add the identifier to the list below
* 3. Add the type of the identifier to MESSAGE_TYPING_CONTEXT in Filter.hpp
* 4. Add the value for the identifier to the ContextMap returned by this function
Expand Down
73 changes: 39 additions & 34 deletions src/controllers/filters/lang/Tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,44 @@ const QRegularExpression TOKEN_REGEX(

namespace chatterino::filters {

extern const QMap<QString, QString> validIdentifiersMap = {
{"author.badges", "author badges"},
{"author.color", "author color"},
{"author.name", "author name"},
{"author.no_color", "author has no color?"},
{"author.subbed", "author subscribed?"},
{"author.sub_length", "author sub length"},
{"channel.name", "channel name"},
{"channel.watching", "/watching channel?"},
{"channel.live", "channel live?"},
{"flags.action", "action/me message?"},
{"flags.highlighted", "highlighted?"},
{"flags.points_redeemed", "redeemed points?"},
{"flags.sub_message", "sub/resub message?"},
{"flags.system_message", "system message?"},
{"flags.reward_message", "channel point reward message?"},
{"flags.first_message", "first message?"},
{"flags.elevated_message", "hype chat message?"},
// Ideally these values are unique, because ChannelFilterEditorDialog::ValueSpecifier::expressionText depends on
// std::map layout in Qt 6 and internal implementation in Qt 5.
{"flags.hype_chat", "hype chat message?"},
{"flags.cheer_message", "cheer message?"},
{"flags.whisper", "whisper message?"},
{"flags.reply", "reply message?"},
{"flags.automod", "automod message?"},
{"flags.restricted", "restricted message?"},
{"flags.monitored", "monitored message?"},
{"message.content", "message text"},
{"message.length", "message length"},
{"reward.title", "point reward title"},
{"reward.cost", "point reward cost"},
{"reward.id", "point reward id"},
};
const QMap<QString, QString> &validIdentifiersMap()
{
static const QMap<QString, QString> map = {
{"author.badges", "author badges"},
{"author.color", "author color"},
{"author.name", "author name"},
{"author.no_color", "author has no color?"},
{"author.subbed", "author subscribed?"},
{"author.sub_length", "author sub length"},
{"channel.name", "channel name"},
{"channel.watching", "/watching channel?"},
{"channel.live", "channel live?"},
{"flags.action", "action/me message?"},
{"flags.highlighted", "highlighted?"},
{"flags.points_redeemed", "redeemed points?"},
{"flags.sub_message", "sub/resub message?"},
{"flags.system_message", "system message?"},
{"flags.reward_message", "channel point reward message?"},
{"flags.first_message", "first message?"},
{"flags.elevated_message", "hype chat message?"},
// Ideally these values are unique, because ChannelFilterEditorDialog::ValueSpecifier::expressionText depends on
// std::map layout in Qt 6 and internal implementation in Qt 5.
{"flags.hype_chat", "hype chat message?"},
{"flags.cheer_message", "cheer message?"},
{"flags.whisper", "whisper message?"},
{"flags.reply", "reply message?"},
{"flags.automod", "automod message?"},
{"flags.restricted", "restricted message?"},
{"flags.monitored", "monitored message?"},
{"message.content", "message text"},
{"message.length", "message length"},
{"reward.title", "point reward title"},
{"reward.cost", "point reward cost"},
{"reward.id", "point reward id"},
};

return map;
}

QString tokenTypeToInfoString(TokenType type)
{
Expand Down Expand Up @@ -324,7 +329,7 @@ TokenType Tokenizer::tokenize(const QString &text)
return TokenType::STRING;
}

if (validIdentifiersMap.keys().contains(text))
if (validIdentifiersMap().keys().contains(text))
{
return TokenType::IDENTIFIER;
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/filters/lang/Tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace chatterino::filters {

extern const QMap<QString, QString> validIdentifiersMap;
const QMap<QString, QString> &validIdentifiersMap();

enum TokenType {
// control
Expand Down
2 changes: 1 addition & 1 deletion src/messages/Emote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EmoteMap : public std::unordered_map<EmoteName, EmotePtr>
const QString &emoteID) const;
};

const std::shared_ptr<const EmoteMap> EMPTY_EMOTE_MAP = std::make_shared<
inline const std::shared_ptr<const EmoteMap> EMPTY_EMOTE_MAP = std::make_shared<
const EmoteMap>(); // NOLINT(cert-err58-cpp) -- assume this doesn't throw an exception

EmotePtr cachedOrMakeEmotePtr(Emote &&emote, const EmoteMap &cache);
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/dialogs/ChannelFilterEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ChannelFilterEditorDialog::ValueSpecifier::ValueSpecifier()
this->typeCombo_->insertItems(
0, {"Constant Text", "Constant Number", "Variable"});

this->varCombo_->insertItems(0, filters::validIdentifiersMap.values());
this->varCombo_->insertItems(0, filters::validIdentifiersMap().values());

this->layout_->addWidget(this->typeCombo_);
this->layout_->addWidget(this->varCombo_, 1);
Expand Down Expand Up @@ -142,7 +142,7 @@ void ChannelFilterEditorDialog::ValueSpecifier::setValue(const QString &value)
if (this->typeCombo_->currentIndex() == 2)
{
this->varCombo_->setCurrentText(
filters::validIdentifiersMap.value(value));
filters::validIdentifiersMap().value(value));
}
else
{
Expand All @@ -165,7 +165,7 @@ QString ChannelFilterEditorDialog::ValueSpecifier::expressionText()
case 1: // number
return this->valueInput_->text();
case 2: // variable
return filters::validIdentifiersMap.key(
return filters::validIdentifiersMap().key(
this->varCombo_->currentText());
default:
return "";
Expand Down
4 changes: 4 additions & 0 deletions tests/src/Emojis.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "providers/emoji/Emojis.hpp"

#include "common/Literals.hpp"
#include "messages/Emote.hpp"
#include "Test.hpp"

#include <QDebug>
Expand All @@ -15,6 +16,9 @@ TEST(Emojis, ShortcodeParsing)

emojis.load();

ASSERT_NE(EMPTY_EMOTE_MAP, nullptr);
ASSERT_TRUE(EMPTY_EMOTE_MAP->empty());

struct TestCase {
QString input;
QString expectedOutput;
Expand Down

0 comments on commit 1c03ca0

Please sign in to comment.