1 | /* |
2 | SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> |
3 | SPDX-FileCopyrightText: 2020 Jonathan Poelen <jonathan.poelen@gmail.com> |
4 | |
5 | SPDX-License-Identifier: MIT |
6 | */ |
7 | |
8 | #ifndef KSYNTAXHIGHLIGHTING_KEYWORDLIST_P_H |
9 | #define KSYNTAXHIGHLIGHTING_KEYWORDLIST_P_H |
10 | |
11 | #include <QString> |
12 | #include <QStringList> |
13 | #include <QStringView> |
14 | |
15 | #include <vector> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | class QXmlStreamReader; |
19 | QT_END_NAMESPACE |
20 | |
21 | namespace KSyntaxHighlighting |
22 | { |
23 | class Repository; |
24 | class DefinitionData; |
25 | |
26 | class KeywordList |
27 | { |
28 | public: |
29 | KeywordList() = default; |
30 | ~KeywordList() = default; |
31 | |
32 | bool isEmpty() const |
33 | { |
34 | return m_keywords.isEmpty(); |
35 | } |
36 | |
37 | const QString &name() const |
38 | { |
39 | return m_name; |
40 | } |
41 | |
42 | const QStringList &keywords() const |
43 | { |
44 | return m_keywords; |
45 | } |
46 | |
47 | Qt::CaseSensitivity caseSensitivity() const |
48 | { |
49 | return m_caseSensitive; |
50 | } |
51 | |
52 | void setKeywordList(const QStringList &keywords) |
53 | { |
54 | m_keywords = keywords; |
55 | m_keywordsSortedCaseSensitive.clear(); |
56 | m_keywordsSortedCaseInsensitive.clear(); |
57 | initLookupForCaseSensitivity(caseSensitive: m_caseSensitive); |
58 | } |
59 | |
60 | /** Checks if @p str is a keyword in this list. */ |
61 | bool contains(QStringView str) const |
62 | { |
63 | return contains(str, caseSensitive: m_caseSensitive); |
64 | } |
65 | |
66 | /** Checks if @p str is a keyword in this list, overriding the global case-sensitivity setting. */ |
67 | bool contains(QStringView str, Qt::CaseSensitivity caseSensitive) const; |
68 | |
69 | void load(QXmlStreamReader &reader); |
70 | void setCaseSensitivity(Qt::CaseSensitivity caseSensitive); |
71 | void initLookupForCaseSensitivity(Qt::CaseSensitivity caseSensitive); |
72 | void resolveIncludeKeywords(DefinitionData &def); |
73 | |
74 | private: |
75 | /** |
76 | * name of keyword list as in XML |
77 | */ |
78 | QString m_name; |
79 | |
80 | /** |
81 | * raw list of keywords, as seen in XML (but trimmed) |
82 | */ |
83 | QStringList m_keywords; |
84 | |
85 | /** |
86 | * raw list of include keywords, as seen in XML (but trimmed) |
87 | */ |
88 | QStringList m_includes; |
89 | |
90 | /** |
91 | * default case-sensitivity setting |
92 | */ |
93 | Qt::CaseSensitivity m_caseSensitive = Qt::CaseSensitive; |
94 | |
95 | /** |
96 | * case-sensitive sorted string references to m_keywords for lookup |
97 | */ |
98 | std::vector<QStringView> m_keywordsSortedCaseSensitive; |
99 | |
100 | /** |
101 | * case-insensitive sorted string references to m_keywords for lookup |
102 | */ |
103 | std::vector<QStringView> m_keywordsSortedCaseInsensitive; |
104 | }; |
105 | } |
106 | |
107 | #endif // KSYNTAXHIGHLIGHTING_KEYWORDLIST_P_H |
108 | |