8void QQmlPreviewBlacklist::blacklist(
const QString &path)
11 m_root.insert(path, 0);
14void QQmlPreviewBlacklist::whitelist(
const QString &path)
17 m_root.remove(path, 0);
20bool QQmlPreviewBlacklist::isBlacklisted(
const QString &path)
const
22 return path.isEmpty() ?
true : m_root.findPrefix(path, 0) == Node::MatchedLeaf;
25void QQmlPreviewBlacklist::clear()
30QQmlPreviewBlacklist::Node::Node()
34QQmlPreviewBlacklist::Node::Node(
const QQmlPreviewBlacklist::Node &other) :
35 m_mine(other.m_mine), m_isLeaf(other.m_isLeaf)
37 for (
auto it = other.m_next.begin(), end = other.m_next.end(); it != end; ++it)
38 m_next.insert(it.key(),
new Node(**it));
41QQmlPreviewBlacklist::Node::Node(QQmlPreviewBlacklist::Node &&other)
noexcept
43 m_mine.swap(other.m_mine);
44 m_next.swap(other.m_next);
45 m_isLeaf = other.m_isLeaf;
48QQmlPreviewBlacklist::Node::~Node()
53QQmlPreviewBlacklist::Node &QQmlPreviewBlacklist::Node::operator=(
54 const QQmlPreviewBlacklist::Node &other)
57 m_mine = other.m_mine;
58 for (
auto it = other.m_next.begin(), end = other.m_next.end(); it != end; ++it)
59 m_next.insert(it.key(),
new Node(**it));
60 m_isLeaf = other.m_isLeaf;
65QQmlPreviewBlacklist::Node &QQmlPreviewBlacklist::Node::operator=(
66 QQmlPreviewBlacklist::Node &&other)
noexcept
69 m_mine.swap(other.m_mine);
70 m_next.swap(other.m_next);
71 m_isLeaf = other.m_isLeaf;
76void QQmlPreviewBlacklist::Node::split(QString::iterator it, QString::iterator end)
79 existing.resize(end - it - 1);
80 std::copy(it + 1, end, existing.begin());
82 Node *node =
new Node(existing, m_next, m_isLeaf);
84 m_next.insert(*it, node);
85 m_mine.resize(it - m_mine.begin());
89void QQmlPreviewBlacklist::Node::insert(
const QString &path,
int offset)
91 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
92 if (offset == path.size()) {
98 if (path.at(offset) != *it) {
102 inserted.resize(path.size() - offset - 1);
103 std::copy(path.begin() + offset + 1, path.end(), inserted.begin());
104 m_next.insert(path.at(offset),
new Node(inserted));
111 if (offset == path.size()) {
116 Node *&node = m_next[path.at(offset++)];
117 if (node ==
nullptr) {
119 inserted.resize(path.size() - offset);
120 std::copy(path.begin() + offset, path.end(), inserted.begin());
121 node =
new Node(inserted);
123 node->insert(path, offset);
127void QQmlPreviewBlacklist::Node::remove(
const QString &path,
int offset)
129 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
130 if (offset == path.size() || path.at(offset) != *it) {
138 if (offset == path.size())
141 Node *&node = m_next[path.at(offset++)];
143 node->remove(path, offset);
146 inserted.resize(path.size() - offset);
147 std::copy(path.begin() + offset, path.end(), inserted.begin());
148 node =
new Node(inserted, {},
false);
152QQmlPreviewBlacklist::Node::PrefixResult QQmlPreviewBlacklist::Node::findPrefix(
153 const QString &path,
int offset)
const
155 if (offset == path.size()) {
156 if (!m_mine.isEmpty())
158 return m_isLeaf ? MatchedLeaf : MatchedBranch;
161 for (
auto it = m_mine.begin(), end = m_mine.end(); it != end; ++it) {
162 if (path.at(offset) != *it)
165 if (++offset == path.size()) {
168 return m_isLeaf ? MatchedLeaf : MatchedBranch;
172 const QChar c = path.at(offset);
173 const auto it = m_next.find(c);
174 if (it != m_next.end()) {
175 const PrefixResult result = (*it)->findPrefix(path, offset + 1);
176 if (result != Unmatched)
181 return m_isLeaf ? MatchedLeaf : MatchedBranch;
186QQmlPreviewBlacklist::Node::Node(
const QString &mine,
187 const QHash<QChar, QQmlPreviewBlacklist::Node *> &next,
189 : m_mine(mine), m_next(next), m_isLeaf(isLeaf)