<commit_before>#pragma once

#include "util/rapidjson-helpers.hpp"
#include "util/serialize-custom.hpp"

#include <QRegularExpression>
#include <QString>
#include <pajlada/settings/serialize.hpp>

#include <memory>

namespace chatterino {
namespace controllers {
namespace ignores {

class IgnorePhrase
{
    QString pattern;
    bool _isRegex;
    QRegularExpression regex;

public:
    bool operator==(const IgnorePhrase &other) const
    {
        return std::tie(this->pattern, this->_isRegex) == std::tie(other.pattern, other._isRegex);
    }

    IgnorePhrase(const QString &_pattern, bool isRegex)
        : pattern(_pattern)
        , _isRegex(isRegex)
        , regex(_isRegex ? _pattern : "\\b" + QRegularExpression::escape(_pattern) + "\\b",
                QRegularExpression::CaseInsensitiveOption)
    {
    }

    const QString &getPattern() const
    {
        return this->pattern;
    }
    bool isRegex() const
    {
        return this->_isRegex;
    }

    bool isValid() const
    {
        return !this->pattern.isEmpty() && this->regex.isValid();
    }

    bool isMatch(const QString &subject) const
    {
        return this->isValid() && this->regex.match(subject).hasMatch();
    }<commit_msg>Enable unicode regular expressions in ignore phrases too<commit_after>#pragma once

#include "util/rapidjson-helpers.hpp"
#include "util/serialize-custom.hpp"

#include <QRegularExpression>
#include <QString>
#include <pajlada/settings/serialize.hpp>

#include <memory>

namespace chatterino {
namespace controllers {
namespace ignores {

class IgnorePhrase
{
    QString pattern;
    bool _isRegex;
    QRegularExpression regex;

public:
    bool operator==(const IgnorePhrase &other) const
    {
        return std::tie(this->pattern, this->_isRegex) == std::tie(other.pattern, other._isRegex);
    }

    IgnorePhrase(const QString &_pattern, bool isRegex)
        : pattern(_pattern)
        , _isRegex(isRegex)
        , regex(_isRegex ? _pattern : "\\b" + QRegularExpression::escape(_pattern) + "\\b",
                QRegularExpression::CaseInsensitiveOption |
                    QRegularExpression::UseUnicodePropertiesOption)
    {
    }

    const QString &getPattern() const
    {
        return this->pattern;
    }
    bool isRegex() const
    {
        return this->_isRegex;
    }

    bool isValid() const
    {
        return !this->pattern.isEmpty() && this->regex.isValid();
    }

    bool isMatch(const QString &subject) const
    {
        return this->isValid() && this->regex.match(subject).hasMatch();
    }
{'fraction_non_alphanumeric': 0.120203602192639, 'fraction_numerical': 0.0, 'mean_word_length': 3.0172955974842766, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2752948', 'n_tokens_mistral': 782, 'n_tokens_neox': 746, 'n_words': 162}